svelte-effect-runtime 2.3.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dist/chunks/{client-LYwZZXy7.js → client-CfkB_G4o.js} +3 -3
- package/.dist/chunks/{client-LYwZZXy7.js.map → client-CfkB_G4o.js.map} +1 -1
- package/.dist/chunks/{descriptors-CU2g4U_i.js → descriptors-OS4VfJuW.js} +1 -1
- package/.dist/chunks/{descriptors-CU2g4U_i.js.map → descriptors-OS4VfJuW.js.map} +1 -1
- package/.dist/chunks/{dispatcher-g0HYqHOK.js → dispatcher-8B6Ol80H.js} +1 -1
- package/.dist/chunks/{dispatcher-g0HYqHOK.js.map → dispatcher-8B6Ol80H.js.map} +1 -1
- package/.dist/chunks/{preprocess-33aQ41uE.js → preprocess-Cn4JH9OO.js} +36 -15
- package/.dist/chunks/preprocess-Cn4JH9OO.js.map +1 -0
- package/.dist/chunks/{transform-B4g76Ur4.js → transform-s9gKPYu5.js} +424 -29
- package/.dist/chunks/transform-s9gKPYu5.js.map +1 -0
- package/.dist/detect.js.map +1 -1
- package/.dist/dispatcher.js +1 -1
- package/.dist/internal/generators.js +1 -1
- package/.dist/internal/remote-client.js +1 -1
- package/.dist/markup/promise.js +1 -1
- package/.dist/markup/promise.js.map +1 -1
- package/.dist/markup/run.js +1 -1
- package/.dist/markup/run.js.map +1 -1
- package/.dist/markup/transform/constants.d.ts +3 -3
- package/.dist/markup/transform/effect-bindings.d.ts +41 -0
- package/.dist/markup/transform/effect-callbacks.d.ts +26 -0
- package/.dist/markup/transform/emit.d.ts +4 -1
- package/.dist/markup/transform.js +1 -1
- package/.dist/markup/value.js +1 -1
- package/.dist/markup/value.js.map +1 -1
- package/.dist/mod.js +1 -1
- package/.dist/mod.js.map +1 -1
- package/.dist/preprocess/imports.d.ts +2 -1
- package/.dist/preprocess.js +2 -2
- package/.dist/remote/client.js +1 -1
- package/.dist/remote/server.js.map +1 -1
- package/.dist/remote/shared.js.map +1 -1
- package/.dist/runtime/preprocess.js +2 -2
- package/.dist/runtime/preprocess.js.map +1 -1
- package/.dist/server/factories.d.ts +10 -1
- package/.dist/server/types.d.ts +10 -1
- package/.dist/server.js +1 -1
- package/.dist/server.js.map +1 -1
- package/.dist/vite.js +5 -5
- package/.dist/vite.js.map +1 -1
- package/package.json +6 -3
- package/.dist/chunks/preprocess-33aQ41uE.js.map +0 -1
- package/.dist/chunks/transform-B4g76Ur4.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform-s9gKPYu5.js","names":["is_yield_star_expression"],"sources":["../../../modules/svelte-effect-runtime/src/markup/transform/constants.ts","../../../modules/svelte-effect-runtime/src/markup/transform/apply.ts","../../../modules/svelte-effect-runtime/src/markup/transform/classify.ts","../../../modules/svelte-effect-runtime/src/markup/transform/effect-bindings.ts","../../../modules/svelte-effect-runtime/src/error.ts","../../../modules/svelte-effect-runtime/src/markup/transform/expressions.ts","../../../modules/svelte-effect-runtime/src/markup/transform/effect-callbacks.ts","../../../modules/svelte-effect-runtime/src/markup/transform/emit.ts","../../../modules/svelte-effect-runtime/src/preprocess/ast.ts","../../../modules/svelte-effect-runtime/src/markup/transform/scan.ts","../../../modules/svelte-effect-runtime/src/markup/transform/index.ts"],"sourcesContent":["export const HELPERS = {\n value: \"__SER___markup_value\",\n promise: \"__SER___markup_promise\",\n run: \"__SER___markup_run\",\n} as const;\n","import type MagicString from \"magic-string\";\n\nimport { HELPERS } from \"./constants.ts\";\nimport type {\n HelperDeclaration,\n Insertion,\n MarkupRelocation,\n PendingRelocation,\n Replacement,\n} from \"./types.ts\";\n\nexport function create_source_map(\n magic: MagicString,\n filename: string,\n): Record<string, unknown> {\n const map = magic.generateMap({\n hires: true,\n includeContent: true,\n source: filename,\n });\n\n return map as unknown as Record<string, unknown>;\n}\n\nexport function blank_script_blocks(content: string): string {\n return content.replace(\n /<script\\b[^>]*>[\\s\\S]*?<\\/script\\s*>/gi,\n (match) => {\n const lines = match.split(\"\\n\");\n return lines.map((l) => \" \".repeat(l.length)).join(\"\\n\");\n },\n );\n}\n\nexport function inject_helpers(\n magic: MagicString,\n content: string,\n helpers: HelperDeclaration[] = [],\n): Insertion | undefined {\n if (content.includes(HELPERS.value)) {\n return undefined;\n }\n\n const import_helpers = unique_import_helpers(helpers);\n const local_helpers = helpers.filter((helper) => !is_import_helper(helper));\n\n const helper_segments: Array<{\n text: string;\n relocation?: PendingRelocation;\n }> = [\n `import { value as ${HELPERS.value} } from \"svelte-effect-runtime/internal/generators\";`,\n `import { promise as ${HELPERS.promise} } from \"svelte-effect-runtime/internal/generators\";`,\n `import { run as ${HELPERS.run} } from \"svelte-effect-runtime/internal/generators\";`,\n ...import_helpers,\n ...local_helpers,\n ].map((helper) => typeof helper === \"string\" ? { text: helper } : helper);\n\n const helper_block = helper_segments.map((segment) => segment.text).join(\n \"\\n\",\n );\n\n const script_tag = find_instance_script_tag(content);\n\n if (script_tag) {\n const text = `\\n${helper_block}\\n`;\n\n magic.appendLeft(script_tag.end, text);\n\n return {\n start: script_tag.end,\n text,\n relocations: make_insertion_relocations(helper_segments, \"\\n\"),\n };\n } else {\n const text = `<script>\\n${helper_block}\\n</script>\\n\\n`;\n\n magic.prepend(text);\n\n return {\n start: 0,\n text,\n relocations: make_insertion_relocations(helper_segments, \"<script>\\n\"),\n };\n }\n}\n\nexport function create_relocations(\n replacements: Replacement[],\n helper_insertion: Insertion | undefined,\n): MarkupRelocation[] {\n const edits = [\n helper_insertion && {\n start: helper_insertion.start,\n removedLength: 0,\n insertedLength: helper_insertion.text.length,\n },\n ...replacements.map((replacement) => ({\n start: replacement.start,\n removedLength: replacement.end - replacement.start,\n insertedLength: replacement.text.length,\n })),\n ].filter(Boolean) as Array<{\n start: number;\n removedLength: number;\n insertedLength: number;\n }>;\n\n const replacement_relocations = replacements.flatMap((replacement) => {\n if (!replacement.relocation) {\n return [];\n }\n\n const delta_before = edits\n .filter((edit) => edit.start < replacement.start)\n .reduce(\n (total, edit) => total + edit.insertedLength - edit.removedLength,\n 0,\n );\n const generated_start = replacement.start + delta_before;\n\n return [{\n originalStart: replacement.relocation.originalStart,\n originalEnd: replacement.relocation.originalEnd,\n generatedStart: generated_start +\n replacement.relocation.generatedStartInReplacement,\n generatedEnd: generated_start +\n replacement.relocation.generatedEndInReplacement,\n }];\n });\n\n const helper_relocations = helper_insertion?.relocations?.map(\n (relocation) => ({\n originalStart: relocation.originalStart,\n originalEnd: relocation.originalEnd,\n generatedStart: helper_insertion.start +\n relocation.generatedStartInReplacement,\n generatedEnd: helper_insertion.start +\n relocation.generatedEndInReplacement,\n }),\n ) ?? [];\n\n return [\n ...replacement_relocations,\n ...helper_relocations,\n ];\n}\n\nfunction make_insertion_relocations(\n segments: Array<{\n text: string;\n relocation?: PendingRelocation;\n }>,\n prefix: string,\n): PendingRelocation[] {\n const relocations: PendingRelocation[] = [];\n let offset = prefix.length;\n\n for (const segment of segments) {\n if (segment.relocation) {\n relocations.push({\n originalStart: segment.relocation.originalStart,\n originalEnd: segment.relocation.originalEnd,\n generatedStartInReplacement: offset +\n segment.relocation.generatedStartInReplacement,\n generatedEndInReplacement: offset +\n segment.relocation.generatedEndInReplacement,\n });\n }\n\n offset += segment.text.length + 1;\n }\n\n return relocations;\n}\n\nfunction find_instance_script_tag(\n content: string,\n): { start: number; end: number } | undefined {\n const pattern = /<script\\b([^>]*)>([\\s\\S]*?)<\\/script\\s*>/gi;\n\n for (const match of content.matchAll(pattern)) {\n if (match.index === undefined) continue;\n\n const attrs = match[1] ?? \"\";\n if (\n /\\bcontext\\s*=\\s*[\"']module[\"']/.test(attrs) ||\n /\\bmodule\\b/.test(attrs)\n ) {\n continue;\n }\n\n const open_end = match[0].indexOf(\">\") + 1;\n return {\n start: match.index + open_end,\n end: match.index + match[0].length - \"</script>\".length,\n };\n }\n\n return undefined;\n}\n\nfunction unique_import_helpers(\n helpers: HelperDeclaration[],\n): HelperDeclaration[] {\n const seen = new Set<string>();\n\n return helpers.filter((helper) => {\n if (!is_import_helper(helper)) {\n return false;\n }\n\n if (seen.has(helper.text)) {\n return false;\n }\n\n seen.add(helper.text);\n\n return true;\n });\n}\n\nfunction is_import_helper(helper: HelperDeclaration): boolean {\n return helper.text.trimStart().startsWith(\"import \");\n}\n","import type { AST } from \"svelte/compiler\";\n\nimport type { MarkupCandidate, TagKind } from \"./types.ts\";\n\n/**\n * Matches sanitized placeholders back to their Svelte AST context.\n *\n * @since 2.0.0\n * @param ast - Parsed Svelte AST for the sanitized component markup.\n * @param candidates - Placeholder candidates produced by the scanner.\n * @returns Candidates paired with the markup context that determines how they\n * should be emitted.\n */\nexport function classify_candidates(\n ast: AST.Root,\n candidates: MarkupCandidate[],\n): Array<{ candidate: MarkupCandidate; kind: TagKind }> {\n const by_placeholder = new Map(\n candidates.map((candidate) => [candidate.placeholder, candidate]),\n );\n\n const classified: Array<{ candidate: MarkupCandidate; kind: TagKind }> = [];\n const matched = new Set<string>();\n\n walk_ast(ast.fragment, by_placeholder, matched, classified);\n\n return classified;\n}\n\nfunction walk_ast(\n fragment: AST.Fragment,\n candidates: Map<string, MarkupCandidate>,\n matched: Set<string>,\n classified: Array<{ candidate: MarkupCandidate; kind: TagKind }>,\n): void {\n for (const node of fragment.nodes) {\n visit_ast_node(node, candidates, matched, classified);\n }\n}\n\nfunction visit_ast_node(\n node: AST.Fragment[\"nodes\"][number],\n candidates: Map<string, MarkupCandidate>,\n matched: Set<string>,\n classified: Array<{ candidate: MarkupCandidate; kind: TagKind }>,\n): void {\n switch (node.type) {\n case \"ExpressionTag\":\n classify_expression(\n node.expression,\n \"plain\",\n candidates,\n matched,\n classified,\n );\n return;\n\n case \"IfBlock\":\n classify_expression(node.test, \"plain\", candidates, matched, classified);\n walk_ast(node.consequent, candidates, matched, classified);\n if (node.alternate) {\n walk_ast(node.alternate, candidates, matched, classified);\n }\n return;\n\n case \"EachBlock\":\n classify_expression(\n node.expression,\n \"each\",\n candidates,\n matched,\n classified,\n );\n walk_ast(node.body, candidates, matched, classified);\n if (node.fallback) {\n walk_ast(node.fallback, candidates, matched, classified);\n }\n return;\n\n case \"AwaitBlock\":\n classify_expression(\n node.expression,\n \"await\",\n candidates,\n matched,\n classified,\n );\n if (node.pending) {\n walk_ast(node.pending, candidates, matched, classified);\n }\n if (node.then) walk_ast(node.then, candidates, matched, classified);\n if (node.catch) walk_ast(node.catch, candidates, matched, classified);\n return;\n\n case \"RenderTag\":\n classify_expression(\n node.expression,\n \"render\",\n candidates,\n matched,\n classified,\n );\n return;\n\n case \"HtmlTag\":\n classify_expression(\n node.expression,\n \"plain\",\n candidates,\n matched,\n classified,\n );\n return;\n\n case \"DebugTag\":\n classify_debug_tag(node, candidates, matched, classified);\n return;\n\n case \"ConstTag\":\n case \"DeclarationTag\":\n classify_declaration_tag(node, candidates, matched, classified);\n return;\n\n case \"KeyBlock\":\n classify_expression(\n node.expression,\n \"plain\",\n candidates,\n matched,\n classified,\n );\n walk_ast(node.fragment, candidates, matched, classified);\n return;\n\n case \"RegularElement\":\n case \"Component\":\n case \"TitleElement\":\n case \"SlotElement\":\n case \"SvelteBody\":\n case \"SvelteBoundary\":\n case \"SvelteComponent\":\n case \"SvelteDocument\":\n case \"SvelteElement\":\n case \"SvelteFragment\":\n case \"SvelteHead\":\n case \"SvelteSelf\":\n case \"SvelteWindow\":\n visit_element_attributes(node, candidates, matched, classified);\n walk_ast(node.fragment, candidates, matched, classified);\n return;\n\n default:\n return;\n }\n}\n\nfunction classify_debug_tag(\n node: Extract<AST.Fragment[\"nodes\"][number], { type: \"DebugTag\" }>,\n candidates: Map<string, MarkupCandidate>,\n matched: Set<string>,\n classified: Array<{ candidate: MarkupCandidate; kind: TagKind }>,\n): void {\n const idents = node.identifiers;\n\n if (!idents || idents.length === 0) {\n return;\n }\n\n for (const ident of idents) {\n classify_expression(ident, \"plain\", candidates, matched, classified);\n }\n}\n\nfunction classify_declaration_tag(\n node: Extract<\n AST.Fragment[\"nodes\"][number],\n { type: \"ConstTag\" | \"DeclarationTag\" }\n >,\n candidates: Map<string, MarkupCandidate>,\n matched: Set<string>,\n classified: Array<{ candidate: MarkupCandidate; kind: TagKind }>,\n): void {\n for (const decl of node.declaration.declarations) {\n if (!decl.init) {\n continue;\n }\n\n classify_expression(decl.init, \"plain\", candidates, matched, classified);\n }\n}\n\ninterface ElementLikeNode {\n attributes: Array<{\n type: string;\n name?: string;\n value?: unknown;\n expression?: unknown;\n }>;\n fragment: AST.Fragment;\n}\n\nfunction visit_element_attributes(\n node: ElementLikeNode,\n candidates: Map<string, MarkupCandidate>,\n matched: Set<string>,\n classified: Array<{ candidate: MarkupCandidate; kind: TagKind }>,\n): void {\n for (const attr of node.attributes) {\n if (\n attr.type === \"Attribute\" &&\n attr.name &&\n is_event_attribute_name(attr.name)\n ) {\n visit_attribute_value(\n attr.value as\n | true\n | AST.ExpressionTag\n | Array<AST.Text | AST.ExpressionTag>,\n \"event\",\n candidates,\n matched,\n classified,\n );\n continue;\n }\n\n if (attr.type === \"OnDirective\" && attr.expression) {\n classify_expression(\n attr.expression as ExpressionLike,\n \"event\",\n candidates,\n matched,\n classified,\n );\n continue;\n }\n }\n}\n\nfunction is_event_attribute_name(name: string): boolean {\n return name.startsWith(\"on:\") || /^on[a-z]/.test(name);\n}\n\nfunction visit_attribute_value(\n value: true | AST.ExpressionTag | Array<AST.Text | AST.ExpressionTag>,\n kind: TagKind,\n candidates: Map<string, MarkupCandidate>,\n matched: Set<string>,\n classified: Array<{ candidate: MarkupCandidate; kind: TagKind }>,\n): void {\n if (value === true) {\n return;\n }\n\n if (Array.isArray(value)) {\n for (const part of value) {\n if (part.type === \"ExpressionTag\") {\n classify_expression(\n part.expression,\n kind,\n candidates,\n matched,\n classified,\n );\n }\n }\n return;\n }\n\n classify_expression(\n value.expression,\n kind,\n candidates,\n matched,\n classified,\n );\n}\n\ntype ExpressionLike = {\n type: string;\n name?: string;\n callee?: { type: string; name?: string };\n};\n\nfunction classify_expression(\n expression: ExpressionLike | null | undefined,\n kind: TagKind,\n candidates: Map<string, MarkupCandidate>,\n matched: Set<string>,\n classified: Array<{ candidate: MarkupCandidate; kind: TagKind }>,\n): void {\n if (!expression) {\n return;\n }\n\n const found_candidates = find_candidates(expression, candidates);\n\n for (const candidate of found_candidates) {\n if (matched.has(candidate.placeholder)) {\n continue;\n }\n\n matched.add(candidate.placeholder);\n classified.push({ candidate, kind });\n }\n}\n\nfunction find_candidates(\n expression: ExpressionLike,\n candidates: Map<string, MarkupCandidate>,\n): MarkupCandidate[] {\n const found: MarkupCandidate[] = [];\n const seen_nodes = new Set<unknown>();\n const seen_placeholders = new Set<string>();\n\n visit_expression_value(\n expression,\n candidates,\n seen_nodes,\n seen_placeholders,\n found,\n );\n\n return found;\n}\n\nfunction visit_expression_value(\n value: unknown,\n candidates: Map<string, MarkupCandidate>,\n seen_nodes: Set<unknown>,\n seen_placeholders: Set<string>,\n found: MarkupCandidate[],\n): void {\n if (Array.isArray(value)) {\n for (const item of value) {\n visit_expression_value(\n item,\n candidates,\n seen_nodes,\n seen_placeholders,\n found,\n );\n }\n\n return;\n }\n\n if (!is_record(value) || seen_nodes.has(value)) {\n return;\n }\n\n seen_nodes.add(value);\n\n if (value.type === \"Identifier\" && typeof value.name === \"string\") {\n const candidate = candidates.get(value.name);\n\n if (candidate && !seen_placeholders.has(candidate.placeholder)) {\n seen_placeholders.add(candidate.placeholder);\n found.push(candidate);\n }\n }\n\n for (const child of Object.values(value)) {\n visit_expression_value(\n child,\n candidates,\n seen_nodes,\n seen_placeholders,\n found,\n );\n }\n}\n\nfunction is_record(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n","import type { HelperDeclaration } from \"./types.ts\";\n\nimport ts from \"typescript\";\n\nconst EFFECT_PACKAGE_MODULE = \"effect\";\nconst EFFECT_DIRECT_MODULE = \"effect/Effect\";\nconst GENERATED_EFFECT_NAME = \"__SER___Effect\";\n\n/**\n * Describes local bindings that resolve to Effect APIs in markup expressions.\n *\n * @example\n * ```ts\n * const context = collect_effect_callback_bindings(source);\n * context.effect_object_names.has(\"E\");\n * ```\n *\n * @since 2.4.0\n */\nexport interface EffectCallbackRewriteContext {\n /** Local names imported as the Effect object, such as `Effect` or `E`. */\n effect_object_names: ReadonlySet<string>;\n /** Namespace names imported from `effect/Effect`, such as `E.flatMap`. */\n effect_module_names: ReadonlySet<string>;\n /** Package namespace names imported from `effect`, such as `Fx.Effect`. */\n effect_package_names: ReadonlySet<string>;\n /** Direct `effect/Effect` imports mapped from local name to exported name. */\n direct_members: ReadonlyMap<string, string>;\n /** Expression used for generated `gen`, `sync`, and upgraded direct calls. */\n wrapper_expression: string;\n /** Import inserted when generated code needs a fresh Effect binding. */\n wrapper_import: HelperDeclaration | undefined;\n}\n\ninterface EffectBindingState {\n effect_object_names: string[];\n effect_module_names: string[];\n effect_package_names: string[];\n direct_members: Map<string, string>;\n local_names: Set<string>;\n implicit_effect_import: boolean;\n}\n\n/**\n * Collects Effect import bindings that markup callback rewriting can trust.\n *\n * @example\n * ```ts\n * const bindings = collect_effect_callback_bindings(\n * `<script>import { Effect as E } from \"effect\";</script>`,\n * );\n * ```\n *\n * @since 2.4.0\n * @param content - Full Svelte component source before markup lowering.\n * @returns Binding metadata used to identify Effect callback combinators.\n */\nexport function collect_effect_callback_bindings(\n content: string,\n): EffectCallbackRewriteContext {\n const state = make_effect_binding_state();\n const scripts = collect_script_blocks(content);\n\n for (const script of scripts) {\n const source_file = ts.createSourceFile(\n \"component-script.ts\",\n script,\n ts.ScriptTarget.Latest,\n true,\n ts.ScriptKind.TS,\n );\n\n collect_source_file_bindings(source_file, state);\n }\n\n ensure_implicit_effect_binding(state);\n\n const wrapper = choose_effect_wrapper(state);\n\n return {\n effect_object_names: new Set(state.effect_object_names),\n effect_module_names: new Set(state.effect_module_names),\n effect_package_names: new Set(state.effect_package_names),\n direct_members: new Map(state.direct_members),\n wrapper_expression: wrapper.expression,\n wrapper_import: wrapper.import_text\n ? { text: wrapper.import_text }\n : undefined,\n };\n}\n\nfunction make_effect_binding_state(): EffectBindingState {\n return {\n effect_object_names: [],\n effect_module_names: [],\n effect_package_names: [],\n direct_members: new Map(),\n local_names: new Set(),\n implicit_effect_import: false,\n };\n}\n\nfunction collect_script_blocks(content: string): string[] {\n const pattern = /<script\\b[^>]*>([\\s\\S]*?)<\\/script\\s*>/gi;\n\n return [...content.matchAll(pattern)].map((match) => match[1] ?? \"\");\n}\n\nfunction collect_source_file_bindings(\n source_file: ts.SourceFile,\n state: EffectBindingState,\n): void {\n for (const statement of source_file.statements) {\n collect_statement_binding(statement, state);\n }\n}\n\nfunction collect_statement_binding(\n statement: ts.Statement,\n state: EffectBindingState,\n): void {\n if (ts.isImportDeclaration(statement)) {\n collect_import_binding(statement, state);\n return;\n }\n\n if (ts.isImportEqualsDeclaration(statement)) {\n state.local_names.add(statement.name.text);\n return;\n }\n\n if (ts.isVariableStatement(statement)) {\n for (const declaration of statement.declarationList.declarations) {\n collect_binding_name(declaration.name, state.local_names);\n }\n\n return;\n }\n\n if (\n ts.isFunctionDeclaration(statement) ||\n ts.isClassDeclaration(statement) ||\n ts.isInterfaceDeclaration(statement) ||\n ts.isTypeAliasDeclaration(statement) ||\n ts.isEnumDeclaration(statement) ||\n ts.isModuleDeclaration(statement)\n ) {\n if (statement.name) {\n state.local_names.add(statement.name.text);\n }\n }\n}\n\nfunction collect_import_binding(\n statement: ts.ImportDeclaration,\n state: EffectBindingState,\n): void {\n if (!ts.isStringLiteral(statement.moduleSpecifier)) {\n return;\n }\n\n const module_name = statement.moduleSpecifier.text;\n const clause = statement.importClause;\n\n if (!clause) {\n return;\n }\n\n if (clause.name) {\n state.local_names.add(clause.name.text);\n }\n\n const named_bindings = clause.namedBindings;\n\n if (!named_bindings) {\n return;\n }\n\n if (ts.isNamespaceImport(named_bindings)) {\n collect_namespace_import_binding(\n module_name,\n named_bindings.name.text,\n state,\n );\n return;\n }\n\n for (const element of named_bindings.elements) {\n collect_named_import_binding(module_name, element, state);\n }\n}\n\nfunction collect_namespace_import_binding(\n module_name: string,\n local_name: string,\n state: EffectBindingState,\n): void {\n state.local_names.add(local_name);\n\n if (module_name === EFFECT_DIRECT_MODULE) {\n add_ordered_name(state.effect_module_names, local_name);\n return;\n }\n\n if (module_name === EFFECT_PACKAGE_MODULE) {\n add_ordered_name(state.effect_package_names, local_name);\n }\n}\n\nfunction collect_named_import_binding(\n module_name: string,\n element: ts.ImportSpecifier,\n state: EffectBindingState,\n): void {\n const imported_name = element.propertyName?.text ?? element.name.text;\n const local_name = element.name.text;\n\n state.local_names.add(local_name);\n\n if (module_name === EFFECT_PACKAGE_MODULE && imported_name === \"Effect\") {\n add_ordered_name(state.effect_object_names, local_name);\n return;\n }\n\n if (module_name === EFFECT_DIRECT_MODULE) {\n state.direct_members.set(local_name, imported_name);\n }\n}\n\nfunction collect_binding_name(\n name: ts.BindingName,\n local_names: Set<string>,\n): void {\n if (ts.isIdentifier(name)) {\n local_names.add(name.text);\n return;\n }\n\n for (const element of name.elements) {\n if (ts.isOmittedExpression(element)) {\n continue;\n }\n\n collect_binding_name(element.name, local_names);\n }\n}\n\nfunction ensure_implicit_effect_binding(state: EffectBindingState): void {\n if (has_effect_binding(state) || state.local_names.has(\"Effect\")) {\n return;\n }\n\n add_ordered_name(state.effect_object_names, \"Effect\");\n state.implicit_effect_import = true;\n}\n\nfunction has_effect_binding(state: EffectBindingState): boolean {\n return state.effect_object_names.length > 0 ||\n state.effect_module_names.length > 0 ||\n state.effect_package_names.length > 0 ||\n state.direct_members.size > 0;\n}\n\nfunction choose_effect_wrapper(\n state: EffectBindingState,\n): { expression: string; import_text?: string } {\n const effect_object = state.effect_object_names[0];\n\n if (effect_object) {\n return {\n expression: effect_object,\n import_text: state.implicit_effect_import\n ? `import { Effect } from \"effect\";`\n : undefined,\n };\n }\n\n const effect_module = state.effect_module_names[0];\n\n if (effect_module) {\n return { expression: effect_module };\n }\n\n const effect_package = state.effect_package_names[0];\n\n if (effect_package) {\n return { expression: `${effect_package}.Effect` };\n }\n\n const generated_name = make_generated_effect_name(state.local_names);\n\n return {\n expression: generated_name,\n import_text: `import { Effect as ${generated_name} } from \"effect\";`,\n };\n}\n\nfunction make_generated_effect_name(local_names: ReadonlySet<string>): string {\n if (!local_names.has(GENERATED_EFFECT_NAME)) {\n return GENERATED_EFFECT_NAME;\n }\n\n let index = 1;\n\n while (local_names.has(`${GENERATED_EFFECT_NAME}_${index}`)) {\n index += 1;\n }\n\n return `${GENERATED_EFFECT_NAME}_${index}`;\n}\n\nfunction add_ordered_name(names: string[], name: string): void {\n if (names.includes(name)) {\n return;\n }\n\n names.push(name);\n}\n","/**\n * Formats a runtime-owned error message with a stable screaming-case code.\n *\n * @example\n * ```ts\n * throw new Error(make_error_message(\"DISPATCHER_DISPOSED\", \"Dispatcher has been disposed\"));\n * ```\n *\n * @since 2.0.0\n * @param code - Stable screaming-case identifier for the error category.\n * @param message - Human-readable error message without the leading code.\n * @returns The complete error message prefixed with the stable code.\n */\nexport function make_error_message(code: string, message: string): string {\n return `[${code}]: ${message}`;\n}\n\n/**\n * Base error class for all preprocessor errors emitted during script and\n * markup transformation. Carries the source filename so error messages can\n * reference the affected file.\n *\n * @since 2.0.0\n */\nexport class PreprocessError extends Error {\n /**\n * The source filename that triggered this error.\n *\n * @since 2.0.0\n */\n readonly filename: string;\n\n constructor(message: string, filename: string) {\n super(message);\n this.name = \"PreprocessError\";\n this.filename = filename;\n }\n}\n\n/**\n * Thrown when a statement mixes JavaScript `await` with Effect `yield*` work\n * that must be lowered into an `Effect.gen` program.\n *\n * @since 2.0.0\n */\nexport class AwaitInEffectWorkError extends PreprocessError {\n /**\n * The full text of the problematic statement containing mixed async work.\n *\n * @since 2.0.0\n */\n readonly statement_text: string;\n\n constructor(filename: string, statement_text: string) {\n super(\n [\n make_error_message(\n \"AWAIT_IN_EFFECT_WORK\",\n `${filename}: await cannot be mixed with yield* in Effect work.`,\n ),\n `Top-level await is supported as ordinary Svelte async rendering, but statements lowered into Effect.gen must use yield* for async Effect work.`,\n \"\",\n `Problematic statement:`,\n statement_text,\n ].join(\"\\n\"),\n filename,\n );\n this.name = \"AwaitInEffectWorkError\";\n this.statement_text = statement_text;\n }\n}\n\n/**\n * Thrown when async Effect work appears inside a Svelte rune position that\n * must stay synchronous.\n *\n * @since 2.0.0\n */\nexport class AsyncEffectInSyncRuneError extends PreprocessError {\n /**\n * The name of the rune that contained async Effect work.\n *\n * @since 2.0.0\n */\n readonly rune_name: string;\n\n /**\n * The full text of the expression that triggered the error.\n *\n * @since 2.0.0\n */\n readonly expression_text: string;\n\n constructor(rune_name: string, expression_text: string, filename: string) {\n super(\n [\n make_error_message(\n \"ASYNC_EFFECT_IN_SYNC_RUNE\",\n `${filename}: yield* cannot be used inside ${rune_name}().`,\n ),\n `${rune_name}() must stay synchronous. Do not put async Effect work inside this rune.`,\n \"\",\n `Problematic expression:`,\n expression_text,\n ].join(\"\\n\"),\n filename,\n );\n this.name = \"AsyncEffectInSyncRuneError\";\n this.rune_name = rune_name;\n this.expression_text = expression_text;\n }\n}\n/**\n * Thrown when async Effect work appears inside a non-generator callback nested\n * in a markup event handler.\n *\n * @example\n * ```ts\n * throw new AsyncEffectInEventCallbackError(\n * \"Component.svelte\",\n * \"Effect.try(() => yield* save())\",\n * );\n * ```\n *\n * @since 2.0.0\n */\nexport class AsyncEffectInEventCallbackError extends PreprocessError {\n /**\n * The full text of the problematic event handler body.\n *\n * @since 2.0.0\n */\n readonly expression_text: string;\n\n constructor(filename: string, expression_text: string) {\n super(\n [\n make_error_message(\n \"ASYNC_EFFECT_IN_EVENT_CALLBACK\",\n `${filename}: yield* cannot be used inside a nested non-generator callback in a markup event handler.`,\n ),\n `Move the yield* to the event handler body. Effect.try and Effect.sync callbacks are plain synchronous JavaScript; do not call Effect-returning functions inside them.`,\n \"\",\n `Run the remote Effect directly:`,\n ` onclick={yield* UpvotePost(id)}`,\n \"\",\n `Recover from remote failures by composing the Effect value:`,\n ` onclick={yield* UpvotePost(id).pipe(Effect.catch(() => Effect.void))}`,\n \"\",\n `Problematic expression:`,\n expression_text,\n ].join(\"\\n\"),\n filename,\n );\n this.name = \"AsyncEffectInEventCallbackError\";\n this.expression_text = expression_text;\n }\n}\n\n/**\n * Thrown when an event handler callback contains the old raw `yield*`\n * shorthand. Effectful event handlers must put `yield*` directly in the event\n * attribute so the callback boundary is generated by the markup runtime.\n *\n * @example\n * ```ts\n * throw new YieldStarInEventCallbackError(\n * \"Component.svelte\",\n * \"() => yield* save()\",\n * );\n * ```\n *\n * @since 2.0.0\n * @param filename - Svelte component filename used to identify where the\n * invalid event handler callback was found.\n * @param expression_text - Original event handler callback text that contained\n * `yield*` and should be rewritten as a direct event Effect expression.\n */\nexport class YieldStarInEventCallbackError extends PreprocessError {\n /**\n * The full text of the problematic event handler callback.\n *\n * @since 2.0.0\n */\n readonly expression_text: string;\n\n constructor(filename: string, expression_text: string) {\n super(\n [\n make_error_message(\n \"ASYNC_EFFECT_IN_EVENT_HANDLER_CALLBACK\",\n `${filename}: yield* in markup event handlers must be written directly as the event attribute value.`,\n ),\n `SER generates the event callback for effectful event handlers; do not put yield* inside a JavaScript callback.`,\n \"\",\n `Use this form:`,\n ` onclick={yield* UpvotePost(id)}`,\n \"\",\n `Instead of this form:`,\n ` onclick={() => yield* UpvotePost(id)}`,\n \"\",\n `Problematic expression:`,\n expression_text,\n ].join(\"\\n\"),\n filename,\n );\n this.name = \"YieldStarInEventCallbackError\";\n this.expression_text = expression_text;\n }\n}\n","import ts from \"typescript\";\n\n/**\n * Strips an event handler arrow function down to its executable body.\n *\n * @since 2.0.0\n * @param expr - Event handler expression text from the original markup.\n * @returns Handler parameters, body text, and body offsets inside `expr`.\n */\nexport function strip_arrow_function(\n expr: string,\n): { params: string; body: string; body_start: number; body_end: number } {\n const arrow_idx = expr.indexOf(\"=>\");\n\n if (arrow_idx === -1) {\n return { params: \"()\", body: expr, body_start: 0, body_end: expr.length };\n }\n\n const params = expr.slice(0, arrow_idx).trim();\n const raw_body = expr.slice(arrow_idx + 2);\n const leading_ws = raw_body.length - raw_body.trimStart().length;\n let body_start = arrow_idx + 2 + leading_ws;\n let body_end = expr.length - (raw_body.length - raw_body.trimEnd().length);\n let body = expr.slice(body_start, body_end);\n\n if (body.startsWith(\"{\") && body.endsWith(\"}\")) {\n body_start += 1;\n body_end -= 1;\n body = body.slice(1, -1);\n }\n\n const body_leading_ws = body.length - body.trimStart().length;\n const body_trailing_ws = body.length - body.trimEnd().length;\n\n body_start += body_leading_ws;\n body_end -= body_trailing_ws;\n body = body.trim();\n\n if (body.endsWith(\";\")) {\n body = body.slice(0, -1);\n body_end -= 1;\n }\n\n return { params, body, body_start, body_end };\n}\n\n/**\n * Returns whether an expression is a callback function.\n *\n * @since 2.0.0\n * @param expr - Expression text from a markup attribute or expression tag.\n * @returns Whether the expression parses as an arrow or function expression.\n */\nexport function is_callback_function_expression(expr: string): boolean {\n const wrapped = `const __SER___callback = ${expr};`;\n const sf = ts.createSourceFile(\n \"callback.ts\",\n wrapped,\n ts.ScriptTarget.Latest,\n true,\n ts.ScriptKind.TS,\n );\n const stmt = sf.statements[0];\n\n if (!ts.isVariableStatement(stmt)) {\n return false;\n }\n\n const initializer = stmt.declarationList.declarations[0]?.initializer;\n\n return initializer !== undefined &&\n (ts.isArrowFunction(initializer) ||\n ts.isFunctionExpression(initializer));\n}\n\n/**\n * Classifies `yield*` placement inside an event handler body.\n *\n * @example\n * ```ts\n * analyze_event_body_yield_star(\"yield* save()\");\n * ```\n *\n * @since 2.0.0\n * @param body - Event handler body text after the outer arrow has been\n * stripped.\n * @returns Whether the body has top-level yield* expressions and whether any\n * yield* appears inside a nested non-generator callback.\n */\nexport function analyze_event_body_yield_star(body: string): {\n has_top_level_yield_star: boolean;\n has_nested_invalid_yield_star: boolean;\n} {\n const wrapped = `function* __SER___event() { ${body}; }`;\n const sf = ts.createSourceFile(\n \"event.ts\",\n wrapped,\n ts.ScriptTarget.Latest,\n true,\n ts.ScriptKind.TS,\n );\n const stmt = sf.statements[0];\n\n if (!ts.isFunctionDeclaration(stmt) || !stmt.body) {\n return {\n has_top_level_yield_star: false,\n has_nested_invalid_yield_star: /\\byield\\s*\\*/.test(body),\n };\n }\n\n const result = {\n has_top_level_yield_star: false,\n has_nested_invalid_yield_star: false,\n };\n\n visit_event_body(stmt.body, \"top_level\", result);\n\n return result;\n}\n\n/**\n * Collects free identifiers that must be captured as reactive dependencies.\n *\n * @since 2.0.0\n * @param expr_text - Markup expression text to inspect.\n * @returns Identifier names referenced by the expression.\n */\nexport function collect_free_identifiers(expr_text: string): string[] {\n const wrapped = `function* __SER___w() { return (${expr_text}); }`;\n let sf: ts.SourceFile;\n\n try {\n sf = ts.createSourceFile(\n \"expr.ts\",\n wrapped,\n ts.ScriptTarget.Latest,\n true,\n ts.ScriptKind.TS,\n );\n } catch {\n return [];\n }\n\n const fn = sf.statements[0];\n\n if (!ts.isFunctionDeclaration(fn) || !fn.body) {\n return [];\n }\n\n const ids: string[] = [];\n const seen = new Set<string>();\n\n visit_ids(fn.body, seen, ids);\n\n return ids;\n}\n\nfunction visit_ids(\n node: ts.Node,\n seen: Set<string>,\n ids: string[],\n): void {\n if (\n ts.isArrowFunction(node) ||\n ts.isFunctionExpression(node) ||\n ts.isFunctionDeclaration(node)\n ) {\n return;\n }\n\n if (ts.isIdentifier(node)) {\n if (\n node.text === \"yield\" ||\n node.text === \"undefined\" ||\n node.text === \"null\" ||\n node.text === \"true\" ||\n node.text === \"false\" ||\n node.text === \"this\"\n ) {\n return;\n }\n\n if (is_property_access_name(node)) {\n return;\n }\n\n if (!seen.has(node.text)) {\n seen.add(node.text);\n ids.push(node.text);\n }\n return;\n }\n\n node.forEachChild((child) => visit_ids(child, seen, ids));\n}\n\ntype EventYieldContext = \"top_level\" | \"nested_generator\" | \"nested_invalid\";\n\ninterface EventYieldAnalysis {\n has_top_level_yield_star: boolean;\n has_nested_invalid_yield_star: boolean;\n}\n\nfunction visit_event_body(\n node: ts.Node,\n context: EventYieldContext,\n result: EventYieldAnalysis,\n): void {\n if (is_yield_star_expression(node)) {\n if (context === \"top_level\") {\n result.has_top_level_yield_star = true;\n } else if (context === \"nested_invalid\") {\n result.has_nested_invalid_yield_star = true;\n }\n\n node.forEachChild((child) => visit_event_body(child, context, result));\n return;\n }\n\n if (is_nested_function_boundary(node)) {\n const next_context = is_generator_function_boundary(node)\n ? \"nested_generator\"\n : \"nested_invalid\";\n\n node.forEachChild((child) => visit_event_body(child, next_context, result));\n return;\n }\n\n node.forEachChild((child) => visit_event_body(child, context, result));\n}\n\nfunction is_nested_function_boundary(node: ts.Node): boolean {\n return (\n ts.isArrowFunction(node) ||\n ts.isFunctionExpression(node) ||\n ts.isFunctionDeclaration(node) ||\n ts.isMethodDeclaration(node) ||\n ts.isGetAccessorDeclaration(node) ||\n ts.isSetAccessorDeclaration(node)\n );\n}\n\nfunction is_generator_function_boundary(node: ts.Node): boolean {\n return (\n (ts.isFunctionExpression(node) || ts.isFunctionDeclaration(node) ||\n ts.isMethodDeclaration(node)) &&\n node.asteriskToken !== undefined\n );\n}\n\nfunction is_yield_star_expression(node: ts.Node): boolean {\n if (ts.isYieldExpression(node)) {\n return node.asteriskToken !== undefined;\n }\n\n return (\n ts.isBinaryExpression(node) &&\n node.operatorToken.kind === ts.SyntaxKind.AsteriskToken &&\n ts.isIdentifier(node.left) &&\n node.left.text === \"yield\"\n );\n}\n\nfunction is_property_access_name(node: ts.Identifier): boolean {\n const parent = node.parent;\n\n return (\n (ts.isPropertyAccessExpression(parent) && parent.name === node) ||\n (ts.isPropertyAssignment(parent) && parent.name === node) ||\n (ts.isBindingElement(parent) && parent.propertyName === node) ||\n ts.isImportSpecifier(parent) ||\n ts.isExportSpecifier(parent)\n );\n}\n","import { contains_top_level_yield_star } from \"$/detect.ts\";\nimport type { EffectCallbackRewriteContext } from \"./effect-bindings.ts\";\nimport type { HelperDeclaration } from \"./types.ts\";\n\nimport MagicString from \"magic-string\";\nimport ts from \"typescript\";\n\nconst MATCH_EFFECT_MEMBERS = new Map([\n [\"match\", \"matchEffect\"],\n [\"matchCause\", \"matchCauseEffect\"],\n]);\n\nconst EFFECTFUL_CALLBACK_MEMBERS = new Set([\n \"andThen\",\n \"catchAll\",\n \"catchAllCause\",\n \"catchCause\",\n \"catchTag\",\n \"flatMap\",\n \"forEach\",\n \"tap\",\n \"tapError\",\n \"tapErrorCause\",\n]);\n\nconst EFFECTFUL_HANDLER_MEMBERS = new Set([\n \"matchCauseEffect\",\n \"matchEffect\",\n \"tapBoth\",\n]);\n\ninterface RewriteContext {\n source_file: ts.SourceFile;\n source_text: string;\n magic: MagicString;\n offset: number;\n bindings: EffectCallbackRewriteContext;\n changed: boolean;\n uses_wrapper: boolean;\n}\n\ninterface EffectMember {\n name: string;\n name_start: number;\n name_end: number;\n direct: boolean;\n}\n\ntype EffectWrapperMember = \"gen\" | \"sync\";\n\n/**\n * Rewrites effectful callback shorthand inside event handler expressions.\n *\n * @example\n * ```ts\n * normalize_effect_callback_yields(\n * `yield* action.pipe(Effect.flatMap((value) => yield* next(value)))`,\n * collect_effect_callback_bindings(source),\n * );\n * ```\n *\n * @since 2.0.0\n * @param expr_text - Markup expression text before it is wrapped in the\n * generated Effect runner.\n * @param bindings - Local Effect import bindings collected from the Svelte\n * component's script blocks.\n * @returns The expression with nested Effect callback `yield*` shorthand\n * lowered into explicit Effect callbacks, plus any import needed by generated\n * wrapper calls.\n */\nexport function normalize_effect_callback_yields(\n expr_text: string,\n bindings: EffectCallbackRewriteContext,\n): { expr_text: string; helpers: HelperDeclaration[] } {\n const prefix = \"const __SER___expression = \";\n const source_text = `${prefix}${expr_text};`;\n const source_file = ts.createSourceFile(\n \"event-expression.ts\",\n source_text,\n ts.ScriptTarget.Latest,\n true,\n ts.ScriptKind.TS,\n );\n const statement = source_file.statements[0];\n const magic = new MagicString(expr_text);\n const context: RewriteContext = {\n source_file,\n source_text,\n magic,\n offset: prefix.length,\n bindings,\n changed: false,\n uses_wrapper: false,\n };\n\n if (!ts.isVariableStatement(statement)) {\n return { expr_text, helpers: [] };\n }\n\n const expression = statement.declarationList.declarations[0]?.initializer;\n\n if (!expression) {\n return { expr_text, helpers: [] };\n }\n\n visit_expression(expression, context);\n\n if (!context.changed) {\n return { expr_text, helpers: [] };\n }\n\n const helpers = context.uses_wrapper && bindings.wrapper_import\n ? [bindings.wrapper_import]\n : [];\n\n return {\n expr_text: magic.toString(),\n helpers,\n };\n}\n\nfunction visit_expression(node: ts.Node, context: RewriteContext): void {\n if (is_non_generator_callback_with_top_level_yield(node)) {\n return;\n }\n\n if (ts.isCallExpression(node)) {\n rewrite_match_call(node, context);\n rewrite_effectful_handler_call(node, context);\n rewrite_effectful_callback_arguments(node, context);\n }\n\n node.forEachChild((child) => {\n visit_expression(child, context);\n });\n}\n\nfunction rewrite_match_call(\n call: ts.CallExpression,\n context: RewriteContext,\n): void {\n const member = get_effect_member(call.expression, context);\n const upgraded_name = member && MATCH_EFFECT_MEMBERS.get(member.name);\n const options = get_last_object_argument(call);\n\n if (!member || !upgraded_name || !options) {\n return;\n }\n\n const handlers = get_handler_properties(options);\n const should_upgrade = handlers.some((handler) =>\n handler.callback &&\n is_non_generator_callback_with_top_level_yield(handler.callback)\n );\n\n if (!should_upgrade) {\n return;\n }\n\n rewrite_effect_member_name(member, upgraded_name, context);\n context.changed = true;\n\n for (const handler of handlers) {\n if (!handler.callback) {\n continue;\n }\n\n if (is_non_generator_callback_with_top_level_yield(handler.callback)) {\n rewrite_callback_to_effect_gen(handler.callback, context);\n } else {\n rewrite_callback_to_effect_sync(handler.callback, context);\n }\n }\n}\n\nfunction rewrite_effectful_handler_call(\n call: ts.CallExpression,\n context: RewriteContext,\n): void {\n const member = get_effect_member(call.expression, context);\n const options = get_last_object_argument(call);\n\n if (!member || !EFFECTFUL_HANDLER_MEMBERS.has(member.name) || !options) {\n return;\n }\n\n for (const handler of get_handler_properties(options)) {\n if (\n handler.callback &&\n is_non_generator_callback_with_top_level_yield(handler.callback)\n ) {\n rewrite_callback_to_effect_gen(handler.callback, context);\n }\n }\n}\n\nfunction rewrite_effectful_callback_arguments(\n call: ts.CallExpression,\n context: RewriteContext,\n): void {\n const member = get_effect_member(call.expression, context);\n\n if (!member || !EFFECTFUL_CALLBACK_MEMBERS.has(member.name)) {\n return;\n }\n\n for (const argument of call.arguments) {\n if (\n is_callback_expression(argument) &&\n is_non_generator_callback_with_top_level_yield(argument)\n ) {\n rewrite_callback_to_effect_gen(argument, context);\n }\n }\n}\n\nfunction rewrite_callback_to_effect_gen(\n callback: ts.ArrowFunction | ts.FunctionExpression,\n context: RewriteContext,\n): void {\n if (is_async_function(callback)) {\n return;\n }\n\n if (ts.isArrowFunction(callback)) {\n rewrite_arrow_callback(callback, \"gen\", context);\n return;\n }\n\n rewrite_function_body(callback, \"gen\", context);\n}\n\nfunction rewrite_callback_to_effect_sync(\n callback: ts.ArrowFunction | ts.FunctionExpression,\n context: RewriteContext,\n): void {\n if (is_async_function(callback)) {\n return;\n }\n\n if (ts.isArrowFunction(callback)) {\n rewrite_arrow_callback(callback, \"sync\", context);\n return;\n }\n\n rewrite_function_body(callback, \"sync\", context);\n}\n\nfunction rewrite_arrow_callback(\n callback: ts.ArrowFunction,\n wrapper: EffectWrapperMember,\n context: RewriteContext,\n): void {\n const start = to_expr_pos(callback.getStart(context.source_file), context);\n const end = to_expr_pos(callback.end, context);\n const params_text = context.source_text\n .slice(\n callback.getStart(context.source_file),\n callback.equalsGreaterThanToken.getStart(context.source_file),\n )\n .trim();\n const body_text = get_body_text(callback.body, context);\n const rewritten_body = make_effect_body(\n callback.body,\n body_text,\n wrapper,\n context,\n );\n const replacement = `${params_text} => ${rewritten_body}`;\n\n context.magic.overwrite(start, end, replacement);\n context.changed = true;\n}\n\nfunction rewrite_function_body(\n callback: ts.FunctionExpression,\n wrapper: EffectWrapperMember,\n context: RewriteContext,\n): void {\n const body_start = to_expr_pos(\n callback.body.getStart(context.source_file),\n context,\n );\n const body_end = to_expr_pos(callback.body.end, context);\n const body_text = get_body_text(callback.body, context);\n const rewritten_body = make_effect_body(\n callback.body,\n body_text,\n wrapper,\n context,\n );\n\n context.magic.overwrite(\n body_start,\n body_end,\n `{ return ${rewritten_body}; }`,\n );\n context.changed = true;\n}\n\nfunction make_effect_body(\n body: ts.ConciseBody,\n body_text: string,\n wrapper: EffectWrapperMember,\n context: RewriteContext,\n): string {\n const wrapper_access = make_effect_access(wrapper, context);\n\n if (wrapper === \"gen\") {\n if (ts.isBlock(body)) {\n return `${wrapper_access}(function* () ${body_text})`;\n }\n\n return `${wrapper_access}(function* () { return (${body_text}); })`;\n }\n\n if (ts.isBlock(body)) {\n return `${wrapper_access}(() => ${body_text})`;\n }\n\n return `${wrapper_access}(() => (${body_text}))`;\n}\n\nfunction get_body_text(body: ts.ConciseBody, context: RewriteContext): string {\n return context.source_text\n .slice(body.getStart(context.source_file), body.end)\n .trim();\n}\n\nfunction get_handler_properties(\n object_literal: ts.ObjectLiteralExpression,\n): Array<{\n callback: ts.ArrowFunction | ts.FunctionExpression | undefined;\n}> {\n return object_literal.properties.flatMap((property) => {\n if (!ts.isPropertyAssignment(property)) {\n return [];\n }\n\n const name = get_property_name(property.name);\n\n if (name !== \"onFailure\" && name !== \"onSuccess\") {\n return [];\n }\n\n const callback = is_callback_expression(property.initializer)\n ? property.initializer\n : undefined;\n\n return [{ callback }];\n });\n}\n\nfunction get_last_object_argument(\n call: ts.CallExpression,\n): ts.ObjectLiteralExpression | undefined {\n const last_argument = call.arguments[call.arguments.length - 1];\n\n if (!last_argument || !ts.isObjectLiteralExpression(last_argument)) {\n return undefined;\n }\n\n return last_argument;\n}\n\nfunction get_effect_member(\n expression: ts.Expression,\n context: RewriteContext,\n): EffectMember | undefined {\n if (ts.isIdentifier(expression)) {\n const direct_member = context.bindings.direct_members.get(expression.text);\n\n if (!direct_member) {\n return undefined;\n }\n\n return {\n name: direct_member,\n name_start: to_expr_pos(\n expression.getStart(context.source_file),\n context,\n ),\n name_end: to_expr_pos(expression.end, context),\n direct: true,\n };\n }\n\n if (!ts.isPropertyAccessExpression(expression)) {\n return undefined;\n }\n\n if (!is_effect_namespace_expression(expression.expression, context)) {\n return undefined;\n }\n\n return {\n name: expression.name.text,\n name_start: to_expr_pos(\n expression.name.getStart(context.source_file),\n context,\n ),\n name_end: to_expr_pos(expression.name.end, context),\n direct: false,\n };\n}\n\nfunction rewrite_effect_member_name(\n member: EffectMember,\n upgraded_name: string,\n context: RewriteContext,\n): void {\n if (member.direct) {\n context.magic.overwrite(\n member.name_start,\n member.name_end,\n make_effect_access(upgraded_name, context),\n );\n\n return;\n }\n\n context.magic.overwrite(member.name_start, member.name_end, upgraded_name);\n}\n\nfunction make_effect_access(\n member_name: string,\n context: RewriteContext,\n): string {\n context.uses_wrapper = true;\n\n return `${context.bindings.wrapper_expression}.${member_name}`;\n}\n\nfunction is_effect_namespace_expression(\n expression: ts.Expression,\n context: RewriteContext,\n): boolean {\n if (ts.isIdentifier(expression)) {\n return context.bindings.effect_object_names.has(expression.text) ||\n context.bindings.effect_module_names.has(expression.text);\n }\n\n if (!ts.isPropertyAccessExpression(expression)) {\n return false;\n }\n\n if (expression.name.text !== \"Effect\") {\n return false;\n }\n\n if (!ts.isIdentifier(expression.expression)) {\n return false;\n }\n\n return context.bindings.effect_package_names.has(expression.expression.text);\n}\n\nfunction get_property_name(name: ts.PropertyName): string | undefined {\n if (ts.isIdentifier(name) || ts.isStringLiteral(name)) {\n return name.text;\n }\n\n return undefined;\n}\n\nfunction is_callback_expression(\n node: ts.Node,\n): node is ts.ArrowFunction | ts.FunctionExpression {\n return ts.isArrowFunction(node) || ts.isFunctionExpression(node);\n}\n\nfunction is_non_generator_callback_with_top_level_yield(\n node: ts.Node,\n): node is ts.ArrowFunction | ts.FunctionExpression {\n if (!is_callback_expression(node)) {\n return false;\n }\n\n if (ts.isFunctionExpression(node) && node.asteriskToken) {\n return false;\n }\n\n return contains_top_level_yield_star(node.body);\n}\n\nfunction is_async_function(\n node: ts.ArrowFunction | ts.FunctionExpression,\n): boolean {\n return node.modifiers?.some(\n (modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword,\n ) ?? false;\n}\n\nfunction to_expr_pos(pos: number, context: RewriteContext): number {\n return pos - context.offset;\n}\n","import {\n AsyncEffectInEventCallbackError,\n YieldStarInEventCallbackError,\n} from \"$/error.ts\";\nimport type { EffectCallbackRewriteContext } from \"./effect-bindings.ts\";\nimport {\n analyze_event_body_yield_star,\n collect_free_identifiers,\n is_callback_function_expression,\n} from \"./expressions.ts\";\nimport { normalize_effect_callback_yields } from \"./effect-callbacks.ts\";\nimport { HELPERS } from \"./constants.ts\";\nimport type {\n HelperDeclaration,\n MarkupCandidate,\n PendingRelocation,\n Replacement,\n TagKind,\n} from \"./types.ts\";\n\n/**\n * Emits source edits for classified markup Effect expressions.\n *\n * @since 2.0.0\n * @param classified - Candidates paired with their Svelte markup context.\n * @param effect_context - Effect import bindings available to markup\n * expression rewrites.\n * @returns Replacements ready to apply to the original component source.\n */\nexport function emit_replacements(\n classified: Array<{ candidate: MarkupCandidate; kind: TagKind }>,\n effect_context: EffectCallbackRewriteContext,\n): Replacement[] {\n return classified.map(({ candidate, kind }) =>\n emit_replacement(candidate, kind, effect_context)\n );\n}\n\nfunction emit_replacement(\n candidate: MarkupCandidate,\n kind: TagKind,\n effect_context: EffectCallbackRewriteContext,\n): Replacement {\n const normalized = normalize_effect_callback_yields(\n candidate.expr_text,\n effect_context,\n );\n const normalized_candidate = {\n ...candidate,\n expr_text: normalized.expr_text,\n };\n const id = make_cache_id(candidate);\n const id_text = JSON.stringify(id);\n const helper_name = make_helper_name(candidate);\n\n let replacement_text: string;\n let helpers: HelperDeclaration[];\n let relocation: PendingRelocation | undefined;\n\n if (kind === \"await\") {\n const effect = make_effect_helper(normalized_candidate, helper_name);\n\n replacement_text = emit_promise_expression(id_text, effect);\n helpers = [...normalized.helpers, effect.helper];\n } else if (kind === \"render\") {\n const effect = make_effect_helper(normalized_candidate, helper_name);\n\n replacement_text = emit_render_expression(id_text, effect);\n helpers = [...normalized.helpers, effect.helper];\n } else if (kind === \"each\") {\n const effect = make_effect_helper(normalized_candidate, helper_name);\n\n replacement_text = emit_each_expression(id_text, effect);\n helpers = [...normalized.helpers, effect.helper];\n } else if (kind === \"event\") {\n const event = make_event_handler(normalized_candidate);\n\n replacement_text = event.text;\n helpers = normalized.helpers;\n relocation = make_relocation(candidate, replacement_text, {\n originalStart: 0,\n originalEnd: candidate.expr_text.length,\n generatedText: event.expr_text,\n });\n } else {\n const effect = make_effect_helper(normalized_candidate, helper_name);\n\n replacement_text = emit_each_expression(id_text, effect);\n helpers = [...normalized.helpers, effect.helper];\n }\n\n return {\n start: candidate.start,\n end: candidate.end,\n text: replacement_text,\n helpers,\n relocation,\n };\n}\n\nfunction make_event_handler(\n candidate: MarkupCandidate,\n): { text: string; expr_text: string } {\n const expr_text = candidate.expr_text;\n\n if (is_callback_function_expression(expr_text)) {\n throw new YieldStarInEventCallbackError(\n candidate.filename,\n expr_text,\n );\n }\n\n const analysis = analyze_event_body_yield_star(expr_text);\n\n if (analysis.has_nested_invalid_yield_star) {\n throw new AsyncEffectInEventCallbackError(\n candidate.filename,\n expr_text,\n );\n }\n\n return {\n expr_text,\n text: `(event) => { ${HELPERS.run}(function* () { ${expr_text}; }); }`,\n };\n}\n\nfunction emit_promise_expression(\n id_text: string,\n effect: EffectHelper,\n): string {\n return `${HELPERS.promise}(${id_text}, ${effect.deps_text}, () => ${effect.call})`;\n}\n\nfunction emit_render_expression(\n id_text: string,\n effect: EffectHelper,\n): string {\n return `(await ${emit_promise_expression(id_text, effect)})()`;\n}\n\nfunction emit_each_expression(\n id_text: string,\n effect: EffectHelper,\n): string {\n return `await ${emit_promise_expression(id_text, effect)}`;\n}\n\ninterface EffectHelper {\n helper: HelperDeclaration;\n call: string;\n deps_text: string;\n}\n\nfunction make_effect_helper(\n candidate: MarkupCandidate,\n helper_name: string,\n): EffectHelper {\n const deps = collect_free_identifiers(candidate.expr_text);\n const params_text = deps.join(\", \");\n const args_text = deps.join(\", \");\n const deps_text = deps.length === 0 ? \"[]\" : `[${args_text}]`;\n const call = `${helper_name}(${args_text})`;\n const text =\n `function* ${helper_name}(${params_text}) { return (${candidate.expr_text}); }`;\n const generated_start = text.indexOf(candidate.expr_text);\n\n return {\n call,\n deps_text,\n helper: {\n text,\n relocation: {\n originalStart: candidate.start,\n originalEnd: candidate.end,\n generatedStartInReplacement: generated_start,\n generatedEndInReplacement: generated_start +\n candidate.expr_text.length,\n },\n },\n };\n}\n\nfunction make_cache_id(candidate: MarkupCandidate): string {\n return `${candidate.filename}:${candidate.start}:${candidate.end}`;\n}\n\nfunction make_helper_name(candidate: MarkupCandidate): string {\n return `__SER___markup_effect_${candidate.start}_${candidate.end}`;\n}\n\nfunction make_relocation(\n candidate: MarkupCandidate,\n replacement_text: string,\n inner: {\n originalStart: number;\n originalEnd: number;\n generatedText: string;\n },\n): PendingRelocation | undefined {\n const generated_start = replacement_text.indexOf(inner.generatedText);\n\n if (generated_start === -1) {\n return undefined;\n }\n\n return {\n originalStart: candidate.start + inner.originalStart,\n originalEnd: candidate.start + inner.originalEnd,\n generatedStartInReplacement: generated_start,\n generatedEndInReplacement: generated_start + inner.generatedText.length,\n };\n}\n","import ts from \"typescript\";\n\n/**\n * Checks whether a node is a `yield*` binary expression.\n *\n * @since 2.0.0\n * @param node - TypeScript AST node to check.\n * @returns Whether the node represents `yield * operand`.\n */\nexport function is_yield_star_expression(node: ts.Node): boolean {\n return (\n ts.isBinaryExpression(node) &&\n node.operatorToken.kind === ts.SyntaxKind.AsteriskToken &&\n ts.isIdentifier(node.left) &&\n node.left.text === \"yield\"\n );\n}\n\n/**\n * Checks whether a node owns its own yield semantics.\n *\n * @since 2.0.0\n * @param node - TypeScript AST node to check.\n * @returns Whether traversal should stop at this function boundary.\n */\nexport function is_function_boundary_node(node: ts.Node): boolean {\n return (\n ts.isArrowFunction(node) ||\n ts.isFunctionDeclaration(node) ||\n ts.isFunctionExpression(node) ||\n ts.isMethodDeclaration(node) ||\n ts.isGetAccessorDeclaration(node) ||\n ts.isSetAccessorDeclaration(node)\n );\n}\n\n/**\n * Returns `true` if the node tree contains a top-level `await`.\n *\n * @since 2.0.0\n * @param node - Root node to search.\n * @returns Whether a top-level await expression was found.\n */\nexport function contains_top_level_await(node: ts.Node): boolean {\n if (ts.isAwaitExpression(node)) {\n return true;\n }\n\n return node.getChildren().some(\n (child) =>\n !is_function_boundary_node(child) && contains_top_level_await(child),\n );\n}\n\n/**\n * Collects top-level `yield*` nodes under an expression.\n *\n * @since 2.0.0\n * @param node - Root node to search.\n * @param on_found - Callback invoked for each matching yield node.\n * @returns Nothing.\n */\nexport function collect_yield_star_nodes(\n node: ts.Node,\n on_found: (node: ts.Node) => void,\n): void {\n if (is_function_boundary_node(node)) {\n return;\n }\n\n if (is_yield_star_expression(node)) {\n on_found(node);\n return;\n }\n\n node.forEachChild((child) => {\n collect_yield_star_nodes(child, on_found);\n });\n}\n\n/**\n * Finds the first top-level `yield*` expression below a node.\n *\n * @since 2.0.0\n * @param node - Root node to search.\n * @param on_found - Callback invoked with the first matching node.\n * @returns Nothing.\n */\nexport function find_yield_star_node(\n node: ts.Node,\n on_found: (node: ts.Node) => void,\n): void {\n if (is_function_boundary_node(node)) {\n return;\n }\n\n if (is_yield_star_expression(node)) {\n on_found(node);\n return;\n }\n\n node.forEachChild((child) => {\n find_yield_star_node(child, on_found);\n });\n}\n\n/**\n * Extracts identifier names from a TypeScript binding name.\n *\n * @since 2.0.0\n * @param name - Binding name node to flatten.\n * @returns Identifier names from identifiers and destructuring patterns.\n */\nexport function extract_binding_names(name: ts.BindingName): string[] {\n if (ts.isIdentifier(name)) {\n return [name.text];\n }\n\n const result: string[] = [];\n\n for (const element of name.elements) {\n if (ts.isOmittedExpression(element)) {\n continue;\n }\n\n result.push(...extract_binding_names(element.name));\n }\n\n return result;\n}\n","import { collect_yield_star_nodes } from \"$/preprocess/ast.ts\";\nimport { contains_top_level_yield_star } from \"$/detect.ts\";\nimport MagicString from \"magic-string\";\nimport ts from \"typescript\";\n\nimport {\n analyze_event_body_yield_star,\n strip_arrow_function,\n} from \"./expressions.ts\";\nimport type { MarkupCandidate, TagKind } from \"./types.ts\";\n\ninterface SanitizeResult {\n code: string;\n candidates: MarkupCandidate[];\n}\n\ninterface DeclarationYieldExpression {\n start: number;\n end: number;\n expr_text: string;\n}\n\nexport function sanitize_markup(\n content: string,\n filename: string,\n): SanitizeResult {\n const candidates: MarkupCandidate[] = [];\n const magic = new MagicString(content);\n let helper_index = 0;\n let cursor = 0;\n\n while (cursor < content.length) {\n const open = content.indexOf(\"{\", cursor);\n if (open === -1) break;\n\n /** Skip braces inside <script> and <style> blocks. */\n if (is_inside_excluded_block(content, open)) {\n cursor = open + 1;\n continue;\n }\n\n /** Find the matching closing brace. */\n const close = find_closing_brace(content, open + 1);\n if (close === -1) {\n cursor = open + 1;\n continue;\n }\n\n const inner = content.slice(open + 1, close);\n\n const trimmed = inner.trimStart();\n const leading_ws = inner.length - trimmed.length;\n\n const tag_info = get_tag_info(trimmed);\n\n const declaration_yields = collect_declaration_yield_expressions(\n content,\n open,\n leading_ws,\n trimmed,\n );\n\n if (declaration_yields.length > 0) {\n for (const declaration_yield of declaration_yields) {\n const placeholder = `__SER___markup_placeholder_${helper_index}`;\n helper_index += 1;\n\n candidates.push({\n placeholder,\n start: declaration_yield.start,\n end: declaration_yield.end,\n expr_text: declaration_yield.expr_text,\n filename,\n key: \"plain\",\n });\n\n magic.overwrite(\n declaration_yield.start,\n declaration_yield.end,\n placeholder,\n );\n }\n\n cursor = close + 1;\n continue;\n }\n\n let expr_body = trimmed.slice(tag_info.prefix_length);\n\n /** For @const, only use the RHS after `=` as the expression body. */\n const equal_idx = tag_info.kind === \"plain\" && trimmed.startsWith(\"@const \")\n ? expr_body.indexOf(\"=\")\n : -1;\n\n /** Check if this is a callback handler containing yield*. */\n const is_event_callback = is_event_callback_expression(inner);\n\n /** Determine if this brace contains yield* that needs lowering. */\n const event_yield = is_event_callback\n ? analyze_event_yield(inner)\n : undefined;\n const has_yield = event_yield?.has_top_level_yield_star ??\n contains_yield_star_in_text(expr_body);\n\n if (!has_yield) {\n cursor = close + 1;\n continue;\n }\n\n /** The expression starts after the tag prefix. For @const, after the `=`. */\n let extra_prefix = 0;\n\n if (equal_idx !== -1) {\n const after_eq_raw = expr_body.slice(equal_idx + 1);\n expr_body = after_eq_raw.trimStart();\n extra_prefix = equal_idx + 1 + (after_eq_raw.length - expr_body.length);\n }\n\n const expr_start = open + 1 + leading_ws + tag_info.prefix_length +\n extra_prefix;\n\n /** For each/await, the expression ends before ` as ` or ` then `/` catch `. */\n let expr_end = close;\n\n const key = tag_info.kind;\n\n if (key === \"each\") {\n const as_idx = expr_body.lastIndexOf(\" as \");\n if (as_idx !== -1) expr_end = expr_start + as_idx;\n }\n\n if (key === \"await\") {\n const then_idx = expr_body.indexOf(\" then \");\n const catch_idx = expr_body.indexOf(\" catch \");\n const boundary = Math.min(\n then_idx === -1 ? Infinity : then_idx,\n catch_idx === -1 ? Infinity : catch_idx,\n );\n if (boundary !== Infinity) expr_end = expr_start + boundary;\n }\n\n const expr_text = content.slice(expr_start, expr_end).trim();\n\n if (expr_text.length === 0) {\n cursor = close + 1;\n continue;\n }\n\n /** Create a placeholder and replace the expression (preserving tag prefixes). */\n const placeholder = `__SER___markup_placeholder_${helper_index}`;\n helper_index += 1;\n\n candidates.push({\n placeholder,\n start: expr_start,\n end: expr_end,\n expr_text,\n filename,\n key,\n });\n\n magic.overwrite(\n expr_start,\n expr_end,\n key === \"render\" ? `${placeholder}()` : placeholder,\n );\n\n cursor = close + 1;\n }\n\n return { code: magic.toString(), candidates };\n}\n\nfunction is_inside_excluded_block(content: string, pos: number): boolean {\n const script = find_tag_end(content, \"script\", pos);\n const style = find_tag_end(content, \"style\", pos);\n\n return (\n (script !== undefined && pos < script.end && pos > script.start) ||\n (style !== undefined && pos < style.end && pos > style.start)\n );\n}\n\nfunction find_tag_end(\n content: string,\n tag: string,\n after_pos: number,\n): { start: number; end: number } | undefined {\n const pattern = new RegExp(\n `<${tag}\\\\b[^>]*>([\\\\s\\\\S]*?)<\\\\/${tag}\\\\s*>`,\n \"gi\",\n );\n\n for (const match of content.matchAll(pattern)) {\n if (match.index === undefined) continue;\n const end_pos = match.index + match[0].length;\n if (match.index <= after_pos && after_pos < end_pos) {\n return { start: match.index, end: end_pos };\n }\n }\n\n return undefined;\n}\n\n/** Brace matching helpers for extracting complete markup expressions. */\n\nfunction find_closing_brace(content: string, start: number): number {\n let depth = 0;\n\n for (let i = start; i < content.length; i += 1) {\n const ch = content[i];\n\n if (ch === \"{\" && content[i - 1] !== \"$\") {\n depth += 1;\n } else if (ch === \"}\") {\n if (depth === 0) return i;\n depth -= 1;\n } else if (ch === \"'\" || ch === '\"' || ch === \"`\") {\n i = skip_string(content, i, ch);\n if (i === -1) return -1;\n } else if (ch === \"/\" && content[i + 1] === \"/\") {\n i = skip_line_comment(content, i);\n } else if (ch === \"/\" && content[i + 1] === \"*\") {\n i = skip_block_comment(content, i);\n if (i === -1) return -1;\n }\n }\n\n return -1;\n}\n\nfunction skip_string(content: string, start: number, quote: string): number {\n for (let i = start + 1; i < content.length; i += 1) {\n if (content[i] === \"\\\\\") {\n i += 1;\n continue;\n }\n if (content[i] === quote) return i;\n }\n return -1;\n}\n\nfunction skip_line_comment(content: string, start: number): number {\n for (let i = start + 2; i < content.length; i += 1) {\n if (content[i] === \"\\n\") return i;\n }\n return content.length;\n}\n\nfunction skip_block_comment(content: string, start: number): number {\n for (let i = start + 2; i < content.length; i += 1) {\n if (content[i] === \"*\" && content[i + 1] === \"/\") return i + 1;\n }\n return -1;\n}\n\ninterface TagInfo {\n kind: TagKind;\n prefix_length: number;\n}\n\nfunction get_tag_info(trimmed: string): TagInfo {\n if (trimmed.startsWith(\"#each \")) {\n return { kind: \"each\", prefix_length: \"#each \".length };\n }\n if (trimmed.startsWith(\"#await \")) {\n return { kind: \"await\", prefix_length: \"#await \".length };\n }\n if (trimmed.startsWith(\"@render \")) {\n return { kind: \"render\", prefix_length: \"@render \".length };\n }\n\n /** Strip prefix-only tags — the expression starts after the tag keyword. */\n if (trimmed.startsWith(\"#if \")) {\n return { kind: \"plain\", prefix_length: \"#if \".length };\n }\n if (trimmed.startsWith(\":else if \")) {\n return { kind: \"plain\", prefix_length: \":else if \".length };\n }\n if (trimmed.startsWith(\"#key \")) {\n return { kind: \"plain\", prefix_length: \"#key \".length };\n }\n if (trimmed.startsWith(\"@const \")) {\n return { kind: \"plain\", prefix_length: \"@const \".length };\n }\n if (trimmed.startsWith(\"@html \")) {\n return { kind: \"plain\", prefix_length: \"@html \".length };\n }\n if (trimmed.startsWith(\"@debug \")) {\n return { kind: \"plain\", prefix_length: \"@debug \".length };\n }\n\n return { kind: \"plain\", prefix_length: 0 };\n}\n\nfunction collect_declaration_yield_expressions(\n content: string,\n open: number,\n leading_ws: number,\n trimmed: string,\n): DeclarationYieldExpression[] {\n if (!is_declaration_tag_text(trimmed)) {\n return [];\n }\n\n const source_file = ts.createSourceFile(\n \"declaration-tag.ts\",\n `${trimmed};`,\n ts.ScriptTarget.Latest,\n true,\n ts.ScriptKind.TS,\n );\n\n const stmt = source_file.statements[0];\n\n if (!stmt || !ts.isVariableStatement(stmt)) {\n return [];\n }\n\n const tag_start = open + 1 + leading_ws;\n\n return stmt.declarationList.declarations.flatMap((decl) => {\n const initializer = decl.initializer;\n\n if (!initializer || !contains_top_level_yield_star(initializer)) {\n return [];\n }\n\n const expressions: DeclarationYieldExpression[] = [];\n\n collect_yield_star_nodes(initializer, (yield_node) => {\n const start = tag_start + yield_node.getStart(source_file);\n const end = tag_start + yield_node.end;\n const expr_text = content.slice(start, end).trim();\n\n expressions.push({\n start,\n end,\n expr_text,\n });\n });\n\n return expressions;\n });\n}\n\nfunction is_declaration_tag_text(trimmed: string): boolean {\n return /^(?:const|let)\\s/.test(trimmed);\n}\n\nfunction is_event_callback_expression(inner: string): boolean {\n const trimmed = inner.trimStart();\n\n return /^(?:async\\s+)?(?:\\([^)]*\\)|[A-Za-z_$][\\w$]*)\\s*=>/.test(trimmed) ||\n /^(?:async\\s+)?function\\b/.test(trimmed);\n}\n\nfunction analyze_event_yield(\n inner: string,\n): {\n has_top_level_yield_star: boolean;\n} {\n const event = strip_arrow_function(inner);\n const analysis = analyze_event_body_yield_star(event.body);\n\n return {\n has_top_level_yield_star: analysis.has_top_level_yield_star ||\n analysis.has_nested_invalid_yield_star ||\n /\\byield\\s*\\*/.test(event.body),\n };\n}\n\nfunction contains_yield_star_in_text(text: string): boolean {\n if (!/\\byield\\s*\\*/.test(text)) return false;\n\n try {\n const sf = ts.createSourceFile(\n \"expr.ts\",\n `const x = ${text};`,\n ts.ScriptTarget.Latest,\n true,\n ts.ScriptKind.TS,\n );\n const stmt = sf.statements[0];\n if (!ts.isVariableStatement(stmt)) return false;\n const decl = stmt.declarationList.declarations[0];\n if (!decl?.initializer) return false;\n return contains_top_level_yield_star(decl.initializer);\n } catch {\n return true;\n }\n}\n\n/** Free identifier collection helpers for generated closures. */\n","import { type AST, parse } from \"svelte/compiler\";\n\nimport MagicString from \"magic-string\";\n\nimport {\n blank_script_blocks,\n create_relocations,\n create_source_map,\n inject_helpers,\n} from \"./apply.ts\";\nimport { classify_candidates } from \"./classify.ts\";\nimport { collect_effect_callback_bindings } from \"./effect-bindings.ts\";\nimport { emit_replacements } from \"./emit.ts\";\nimport { sanitize_markup } from \"./scan.ts\";\nimport type { MarkupTransformResult } from \"./types.ts\";\n\nexport type { MarkupRelocation, MarkupTransformResult } from \"./types.ts\";\n\n/**\n * Transforms Svelte markup containing `{yield* expr}` brace expressions\n * into calls to the markup runtime helpers (`value`, `promise`, `run`).\n *\n * Strategy: first find all brace expressions containing `yield*` via\n * character scanning, replace them with placeholder identifiers, then\n * parse the sanitized markup with Svelte's AST to determine the correct\n * context for each placeholder (plain expression, #each, #await, event\n * handler, etc.).\n *\n * @since 2.0.0\n * @param content - The raw `.svelte` file content.\n * @param filename - The source filename, used in error messages.\n * @returns The transformed markup and a flag indicating whether yield* was\n * found.\n */\nexport function transform_markup_effect(\n content: string,\n filename: string,\n): MarkupTransformResult {\n if (!/\\byield\\s*\\*/.test(content)) {\n return { code: content, has_yield: false };\n }\n\n /** Find all brace expressions containing yield* and replace with placeholders. */\n const work = sanitize_markup(content, filename);\n const effect_context = collect_effect_callback_bindings(content);\n\n if (work.candidates.length === 0) {\n return { code: content, has_yield: false };\n }\n\n /** Parse the sanitized markup with Svelte's AST. Strip <script> blocks\n * first so TypeScript syntax (import type, etc.) doesn't break the parser. */\n const clean = blank_script_blocks(work.code);\n const ast = parse(clean, { filename, modern: true }) as AST.Root;\n\n /** Match placeholders to their AST context and build replacements. */\n const classified = classify_candidates(\n ast,\n work.candidates,\n );\n const replacements = emit_replacements(classified, effect_context);\n const helpers = replacements.flatMap((replacement) =>\n replacement.helpers ?? []\n );\n\n const magic = new MagicString(content);\n\n replacements.sort((a, b) => b.start - a.start);\n\n for (const r of replacements) {\n magic.overwrite(r.start, r.end, r.text);\n }\n\n const helper_insertion = inject_helpers(magic, content, helpers);\n const relocations = create_relocations(replacements, helper_insertion);\n\n return {\n code: magic.toString(),\n has_yield: true,\n map: create_source_map(magic, filename),\n relocations,\n };\n}\n"],"mappings":";;;;;AAAA,MAAa,UAAU;CACrB,OAAO;CACP,SAAS;CACT,KAAK;AACP;;;ACOA,SAAgB,kBACd,OACA,UACyB;CAOzB,OANY,MAAM,YAAY;EAC5B,OAAO;EACP,gBAAgB;EAChB,QAAQ;CACV,CAES;AACX;AAEA,SAAgB,oBAAoB,SAAyB;CAC3D,OAAO,QAAQ,QACb,2CACC,UAAU;EAET,OADc,MAAM,MAAM,IACf,EAAE,KAAK,MAAM,IAAI,OAAO,EAAE,MAAM,CAAC,EAAE,KAAK,IAAI;CACzD,CACF;AACF;AAEA,SAAgB,eACd,OACA,SACA,UAA+B,CAAC,GACT;CACvB,IAAI,QAAQ,SAAS,QAAQ,KAAK,GAChC;CAGF,MAAM,iBAAiB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AS;EACrB,WAAW;EACX,KAAK,kBAAkB,OAAO,QAAQ;EACtC;CACF;AACF"}
|
package/.dist/detect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect.js","names":[],"sources":["../../modules/svelte-effect-runtime/src/detect.ts"],"sourcesContent":["import ts from \"typescript\";\n\n/**\n * Returns `true` when the node tree contains a `yield*` expression that is\n * not inside any function boundary (arrow function, function declaration,\n * function expression, method).\n *\n * @example\n * ```ts\n * const sf = ts.createSourceFile(\"test.ts\", \"yield* foo()\", ...);\n * contains_top_level_yield_star(sf.statements[0]); // true\n * ```\n *\n * @since 2.0.0\n * @param node - The root node to search from.\n * @returns Whether a top-level yield* expression was found.\n */\nexport function contains_top_level_yield_star(node: ts.Node): boolean {\n\n if (is_function_boundary(node)) {\n return false;\n }\n\n if (is_yield_star_expression(node)) {\n return true;\n }\n\n return node.getChildren().some(\n (child) => contains_top_level_yield_star(child),\n );\n}\n\n/**\n * Returns `true` when the node is a function-like boundary that owns its\n * own yield/yield* semantics. A function boundary includes arrow functions,\n * function declarations, function expressions, methods, get accessors, and\n * set accessors.\n *\n * @example\n * ```ts\n * const stmt = parseStatement(\"function foo() {}\");\n * is_function_boundary(stmt); // true\n * ```\n *\n * @since 2.0.0\n * @param node - The node to check.\n * @returns Whether the node is a function boundary.\n */\nexport function is_function_boundary(node: ts.Node): boolean {\n return (\n ts.isArrowFunction(node) ||\n ts.isFunctionDeclaration(node) ||\n ts.isFunctionExpression(node) ||\n ts.isMethodDeclaration(node) ||\n ts.isGetAccessorDeclaration(node) ||\n ts.isSetAccessorDeclaration(node)\n );\n}\n\n/**\n * Returns `true` when the node is a binary expression shaped like\n * `yield * operand` — a yield* delegate expression in TypeScript's AST.\n *\n * @since 2.0.0\n * @param node - The node to check.\n * @returns Whether the node is a `yield*` expression.\n */\nfunction is_yield_star_expression(node: ts.Node): boolean {\n return (\n ts.isBinaryExpression(node) &&\n node.operatorToken.kind === ts.SyntaxKind.AsteriskToken &&\n ts.isIdentifier(node.left) &&\n node.left.text === \"yield\"\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,SAAgB,8BAA8B,MAAwB;
|
|
1
|
+
{"version":3,"file":"detect.js","names":[],"sources":["../../modules/svelte-effect-runtime/src/detect.ts"],"sourcesContent":["import ts from \"typescript\";\n\n/**\n * Returns `true` when the node tree contains a `yield*` expression that is\n * not inside any function boundary (arrow function, function declaration,\n * function expression, method).\n *\n * @example\n * ```ts\n * const sf = ts.createSourceFile(\"test.ts\", \"yield* foo()\", ...);\n * contains_top_level_yield_star(sf.statements[0]); // true\n * ```\n *\n * @since 2.0.0\n * @param node - The root node to search from.\n * @returns Whether a top-level yield* expression was found.\n */\nexport function contains_top_level_yield_star(node: ts.Node): boolean {\n\n if (is_function_boundary(node)) {\n return false;\n }\n\n if (is_yield_star_expression(node)) {\n return true;\n }\n\n return node.getChildren().some(\n (child) => contains_top_level_yield_star(child),\n );\n}\n\n/**\n * Returns `true` when the node is a function-like boundary that owns its\n * own yield/yield* semantics. A function boundary includes arrow functions,\n * function declarations, function expressions, methods, get accessors, and\n * set accessors.\n *\n * @example\n * ```ts\n * const stmt = parseStatement(\"function foo() {}\");\n * is_function_boundary(stmt); // true\n * ```\n *\n * @since 2.0.0\n * @param node - The node to check.\n * @returns Whether the node is a function boundary.\n */\nexport function is_function_boundary(node: ts.Node): boolean {\n return (\n ts.isArrowFunction(node) ||\n ts.isFunctionDeclaration(node) ||\n ts.isFunctionExpression(node) ||\n ts.isMethodDeclaration(node) ||\n ts.isGetAccessorDeclaration(node) ||\n ts.isSetAccessorDeclaration(node)\n );\n}\n\n/**\n * Returns `true` when the node is a binary expression shaped like\n * `yield * operand` — a yield* delegate expression in TypeScript's AST.\n *\n * @since 2.0.0\n * @param node - The node to check.\n * @returns Whether the node is a `yield*` expression.\n */\nfunction is_yield_star_expression(node: ts.Node): boolean {\n return (\n ts.isBinaryExpression(node) &&\n node.operatorToken.kind === ts.SyntaxKind.AsteriskToken &&\n ts.isIdentifier(node.left) &&\n node.left.text === \"yield\"\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,SAAgB,8BAA8B,MAAwB;CAEpE,IAAI,qBAAqB,IAAI,GAC3B,OAAO;CAGT,IAAI,yBAAyB,IAAI,GAC/B,OAAO;CAGT,OAAO,KAAK,YAAY,EAAE,MACvB,UAAU,8BAA8B,KAAK,CAChD;AACF;;;;;;;;;;;;;;;;;AAkBA,SAAgB,qBAAqB,MAAwB;CAC3D,OACE,GAAG,gBAAgB,IAAI,KACvB,GAAG,sBAAsB,IAAI,KAC7B,GAAG,qBAAqB,IAAI,KAC5B,GAAG,oBAAoB,IAAI,KAC3B,GAAG,yBAAyB,IAAI,KAChC,GAAG,yBAAyB,IAAI;AAEpC;;;;;;;;;AAUA,SAAS,yBAAyB,MAAwB;CACxD,OACE,GAAG,mBAAmB,IAAI,KAC1B,KAAK,cAAc,SAAS,GAAG,WAAW,iBAC1C,GAAG,aAAa,KAAK,IAAI,KACzB,KAAK,KAAK,SAAS;AAEvB"}
|
package/.dist/dispatcher.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as get_dispatcher, r as reset_dispatcher, t as Dispatcher } from "./chunks/dispatcher-
|
|
1
|
+
import { n as get_dispatcher, r as reset_dispatcher, t as Dispatcher } from "./chunks/dispatcher-8B6Ol80H.js";
|
|
2
2
|
export { Dispatcher, get_dispatcher, reset_dispatcher };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as get_dispatcher } from "../chunks/dispatcher-
|
|
1
|
+
import { n as get_dispatcher } from "../chunks/dispatcher-8B6Ol80H.js";
|
|
2
2
|
import { value } from "../markup/value.js";
|
|
3
3
|
import { promise } from "../markup/promise.js";
|
|
4
4
|
import { run } from "../markup/run.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as create_remote_command_adapter, n as create_remote_query_adapter, r as create_remote_form_adapter, t as create_remote_live_query_adapter } from "../chunks/client-
|
|
1
|
+
import { i as create_remote_command_adapter, n as create_remote_query_adapter, r as create_remote_form_adapter, t as create_remote_live_query_adapter } from "../chunks/client-CfkB_G4o.js";
|
|
2
2
|
export { create_remote_command_adapter, create_remote_form_adapter, create_remote_live_query_adapter, create_remote_query_adapter };
|
package/.dist/markup/promise.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/markup/promise.ts"],"sourcesContent":["import { get_dispatcher } from \"$/dispatcher.ts\";\nimport type { Effect } from \"effect\";\n\n/**\n * Runtime helper emitted by the markup preprocessor for\n * `{#await yield* expr}` blocks. Delegates to the dispatcher's\n * promise mechanism — returns a Promise that resolves when the effect\n * completes.\n *\n * @since 2.0.0\n * @param id - Stable identifier generated from the expression's source\n * position, used for cache lookups.\n * @param deps - Array of reactive dependencies.\n * @param factory - Generator function that yields the effect to run.\n * @returns A Promise that resolves with the effect's result.\n */\nexport function promise<A, E, R>(\n id: string,\n deps: readonly unknown[],\n factory: () => Effect.gen.Return<A, E, R>,\n): Promise<A> {\n return get_dispatcher().promise({ id, deps, factory });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAgB,QACd,IACA,MACA,SACY;
|
|
1
|
+
{"version":3,"file":"promise.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/markup/promise.ts"],"sourcesContent":["import { get_dispatcher } from \"$/dispatcher.ts\";\nimport type { Effect } from \"effect\";\n\n/**\n * Runtime helper emitted by the markup preprocessor for\n * `{#await yield* expr}` blocks. Delegates to the dispatcher's\n * promise mechanism — returns a Promise that resolves when the effect\n * completes.\n *\n * @since 2.0.0\n * @param id - Stable identifier generated from the expression's source\n * position, used for cache lookups.\n * @param deps - Array of reactive dependencies.\n * @param factory - Generator function that yields the effect to run.\n * @returns A Promise that resolves with the effect's result.\n */\nexport function promise<A, E, R>(\n id: string,\n deps: readonly unknown[],\n factory: () => Effect.gen.Return<A, E, R>,\n): Promise<A> {\n return get_dispatcher().promise({ id, deps, factory });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAgB,QACd,IACA,MACA,SACY;CACZ,OAAO,eAAe,EAAE,QAAQ;EAAE;EAAI;EAAM;CAAQ,CAAC;AACvD"}
|
package/.dist/markup/run.js
CHANGED
package/.dist/markup/run.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/markup/run.ts"],"sourcesContent":["import { get_dispatcher } from \"$/dispatcher.ts\";\nimport { Effect } from \"effect\";\n\n/**\n * Runtime helper emitted by the markup preprocessor for inline event\n * handlers containing `yield*`. Wraps the user's generator in an\n * `Effect.gen` and delegates to the dispatcher's fire-and-forget\n * mechanism.\n *\n * @since 2.0.0\n * @param factory - Generator function that yields the effect to run.\n * @returns A Promise that resolves or rejects when the effect completes.\n */\nexport function run<A, E, R>(\n factory: () => Effect.gen.Return<A, E, R>,\n): Promise<A> {\n const effect = Effect.gen(factory);\n\n return get_dispatcher().run(effect);\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,IACd,SACY;CACZ,MAAM,SAAS,OAAO,IAAI,
|
|
1
|
+
{"version":3,"file":"run.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/markup/run.ts"],"sourcesContent":["import { get_dispatcher } from \"$/dispatcher.ts\";\nimport { Effect } from \"effect\";\n\n/**\n * Runtime helper emitted by the markup preprocessor for inline event\n * handlers containing `yield*`. Wraps the user's generator in an\n * `Effect.gen` and delegates to the dispatcher's fire-and-forget\n * mechanism.\n *\n * @since 2.0.0\n * @param factory - Generator function that yields the effect to run.\n * @returns A Promise that resolves or rejects when the effect completes.\n */\nexport function run<A, E, R>(\n factory: () => Effect.gen.Return<A, E, R>,\n): Promise<A> {\n const effect = Effect.gen(factory);\n\n return get_dispatcher().run(effect);\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,IACd,SACY;CACZ,MAAM,SAAS,OAAO,IAAI,OAAO;CAEjC,OAAO,eAAe,EAAE,IAAI,MAAM;AACpC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const HELPERS: {
|
|
2
|
-
readonly value: "
|
|
3
|
-
readonly promise: "
|
|
4
|
-
readonly run: "
|
|
2
|
+
readonly value: "__SER___markup_value";
|
|
3
|
+
readonly promise: "__SER___markup_promise";
|
|
4
|
+
readonly run: "__SER___markup_run";
|
|
5
5
|
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { HelperDeclaration } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Describes local bindings that resolve to Effect APIs in markup expressions.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const context = collect_effect_callback_bindings(source);
|
|
8
|
+
* context.effect_object_names.has("E");
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @since 2.4.0
|
|
12
|
+
*/
|
|
13
|
+
export interface EffectCallbackRewriteContext {
|
|
14
|
+
/** Local names imported as the Effect object, such as `Effect` or `E`. */
|
|
15
|
+
effect_object_names: ReadonlySet<string>;
|
|
16
|
+
/** Namespace names imported from `effect/Effect`, such as `E.flatMap`. */
|
|
17
|
+
effect_module_names: ReadonlySet<string>;
|
|
18
|
+
/** Package namespace names imported from `effect`, such as `Fx.Effect`. */
|
|
19
|
+
effect_package_names: ReadonlySet<string>;
|
|
20
|
+
/** Direct `effect/Effect` imports mapped from local name to exported name. */
|
|
21
|
+
direct_members: ReadonlyMap<string, string>;
|
|
22
|
+
/** Expression used for generated `gen`, `sync`, and upgraded direct calls. */
|
|
23
|
+
wrapper_expression: string;
|
|
24
|
+
/** Import inserted when generated code needs a fresh Effect binding. */
|
|
25
|
+
wrapper_import: HelperDeclaration | undefined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Collects Effect import bindings that markup callback rewriting can trust.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const bindings = collect_effect_callback_bindings(
|
|
33
|
+
* `<script>import { Effect as E } from "effect";</script>`,
|
|
34
|
+
* );
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @since 2.4.0
|
|
38
|
+
* @param content - Full Svelte component source before markup lowering.
|
|
39
|
+
* @returns Binding metadata used to identify Effect callback combinators.
|
|
40
|
+
*/
|
|
41
|
+
export declare function collect_effect_callback_bindings(content: string): EffectCallbackRewriteContext;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { EffectCallbackRewriteContext } from "./effect-bindings.js";
|
|
2
|
+
import type { HelperDeclaration } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Rewrites effectful callback shorthand inside event handler expressions.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* normalize_effect_callback_yields(
|
|
9
|
+
* `yield* action.pipe(Effect.flatMap((value) => yield* next(value)))`,
|
|
10
|
+
* collect_effect_callback_bindings(source),
|
|
11
|
+
* );
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @since 2.0.0
|
|
15
|
+
* @param expr_text - Markup expression text before it is wrapped in the
|
|
16
|
+
* generated Effect runner.
|
|
17
|
+
* @param bindings - Local Effect import bindings collected from the Svelte
|
|
18
|
+
* component's script blocks.
|
|
19
|
+
* @returns The expression with nested Effect callback `yield*` shorthand
|
|
20
|
+
* lowered into explicit Effect callbacks, plus any import needed by generated
|
|
21
|
+
* wrapper calls.
|
|
22
|
+
*/
|
|
23
|
+
export declare function normalize_effect_callback_yields(expr_text: string, bindings: EffectCallbackRewriteContext): {
|
|
24
|
+
expr_text: string;
|
|
25
|
+
helpers: HelperDeclaration[];
|
|
26
|
+
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import type { EffectCallbackRewriteContext } from "./effect-bindings.js";
|
|
1
2
|
import type { MarkupCandidate, Replacement, TagKind } from "./types.js";
|
|
2
3
|
/**
|
|
3
4
|
* Emits source edits for classified markup Effect expressions.
|
|
4
5
|
*
|
|
5
6
|
* @since 2.0.0
|
|
6
7
|
* @param classified - Candidates paired with their Svelte markup context.
|
|
8
|
+
* @param effect_context - Effect import bindings available to markup
|
|
9
|
+
* expression rewrites.
|
|
7
10
|
* @returns Replacements ready to apply to the original component source.
|
|
8
11
|
*/
|
|
9
12
|
export declare function emit_replacements(classified: Array<{
|
|
10
13
|
candidate: MarkupCandidate;
|
|
11
14
|
kind: TagKind;
|
|
12
|
-
}
|
|
15
|
+
}>, effect_context: EffectCallbackRewriteContext): Replacement[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as transform_markup_effect } from "../chunks/transform-
|
|
1
|
+
import { t as transform_markup_effect } from "../chunks/transform-s9gKPYu5.js";
|
|
2
2
|
export { transform_markup_effect };
|
package/.dist/markup/value.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"value.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/markup/value.ts"],"sourcesContent":["import { get_dispatcher } from \"$/dispatcher.ts\";\nimport type { Effect } from \"effect\";\n\n/**\n * Runtime helper emitted by the markup preprocessor for `{yield* expr}`\n * expressions in Svelte templates. Delegates to the dispatcher's\n * cached reactive value mechanism — returns the fallback synchronously,\n * then the resolved value once the effect completes. The effect is still\n * started during SSR so SvelteKit remote queries can register hydratable\n * data before the HTML is sent.\n *\n * @since 2.0.0\n * @param id - Stable identifier generated from the expression's source\n * position, used for cache lookups.\n * @param deps - Array of reactive dependencies (free identifiers in the\n * expression). When any dep changes, the previous fiber is cancelled\n * and a new one starts.\n * @param fallback - Value returned while the effect is running.\n * @param factory - Generator function that yields the effect to run.\n * @returns The cached value if resolved, or the fallback.\n */\nexport function value(\n id: string,\n deps: readonly unknown[],\n fallback: unknown,\n factory: () => Effect.gen.Return<unknown, unknown, unknown>,\n): unknown {\n return get_dispatcher().value({ id, deps, fallback, factory });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,MACd,IACA,MACA,UACA,SACS;
|
|
1
|
+
{"version":3,"file":"value.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/markup/value.ts"],"sourcesContent":["import { get_dispatcher } from \"$/dispatcher.ts\";\nimport type { Effect } from \"effect\";\n\n/**\n * Runtime helper emitted by the markup preprocessor for `{yield* expr}`\n * expressions in Svelte templates. Delegates to the dispatcher's\n * cached reactive value mechanism — returns the fallback synchronously,\n * then the resolved value once the effect completes. The effect is still\n * started during SSR so SvelteKit remote queries can register hydratable\n * data before the HTML is sent.\n *\n * @since 2.0.0\n * @param id - Stable identifier generated from the expression's source\n * position, used for cache lookups.\n * @param deps - Array of reactive dependencies (free identifiers in the\n * expression). When any dep changes, the previous fiber is cancelled\n * and a new one starts.\n * @param fallback - Value returned while the effect is running.\n * @param factory - Generator function that yields the effect to run.\n * @returns The cached value if resolved, or the fallback.\n */\nexport function value(\n id: string,\n deps: readonly unknown[],\n fallback: unknown,\n factory: () => Effect.gen.Return<unknown, unknown, unknown>,\n): unknown {\n return get_dispatcher().value({ id, deps, fallback, factory });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,MACd,IACA,MACA,UACA,SACS;CACT,OAAO,eAAe,EAAE,MAAM;EAAE;EAAI;EAAM;EAAU;CAAQ,CAAC;AAC/D"}
|
package/.dist/mod.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as Dispatcher } from "./chunks/dispatcher-
|
|
1
|
+
import { t as Dispatcher } from "./chunks/dispatcher-8B6Ol80H.js";
|
|
2
2
|
import { is_form_error, is_remote_http_error, is_remote_transport_error, is_remote_validation_error } from "./remote/shared.js";
|
|
3
3
|
import { effect } from "./vite.js";
|
|
4
4
|
//#region src/mod.ts
|
package/.dist/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","names":[],"sources":["../../modules/svelte-effect-runtime/src/mod.ts"],"sourcesContent":["import { Dispatcher as InternalDispatcher } from \"$/dispatcher.ts\";\nimport type {\n ErrorEffectFactory,\n RedirectEffectFactory,\n} from \"$/server/control-flow.ts\";\nimport type { RequestEvent as RequestEventShape } from \"$/server/runtime.ts\";\nimport type {\n CommandFactory,\n FormFactory,\n PrerenderFactory,\n QueryFactory,\n ServerRuntimeFactory,\n} from \"$/server/types.ts\";\nimport type { Context, Layer, ManagedRuntime } from \"effect\";\n\n/**\n * Result returned by the root Svelte markup preprocessor hook.\n *\n * @since 2.0.0\n */\ninterface MarkupResult {\n code: string;\n}\n\n/**\n * Root preprocessor group shape. The root export keeps transform code lazy so\n * client imports do not pull parser-only dependencies into the browser.\n *\n * @since 2.0.0\n */\ninterface PreprocessGroup {\n name: string;\n markup(\n options: { content: string; filename?: string },\n ): MarkupResult | Promise<MarkupResult>;\n}\n\n/**\n * Public API surface for `svelte-effect-runtime`.\n *\n * Call {@link ClientRuntime.make} in `hooks.client.ts`, call\n * {@link ServerRuntime.make} in `hooks.server.ts`, and let the Vite plugin\n * route server-only helpers to the server entrypoint automatically.\n *\n * @module\n */\n\n/**\n * Client-side runtime singleton. Call `ClientRuntime.make(layer?)` once\n * in `hooks.client.ts` to provide services to every component's effect\n * blocks.\n *\n * If never called, a default empty-layer runtime is created lazily on\n * the first `yield*` expression.\n *\n * @example\n * ```ts\n * import { ClientRuntime } from \"svelte-effect-runtime\";\n * import { Db } from \"./db.ts\";\n *\n * ClientRuntime.make(Db.Live);\n * ```\n *\n * @since 2.0.0\n */\nexport class ClientRuntime {\n /**\n * Build and cache the client-side dispatcher runtime.\n *\n * @since 2.0.0\n * @param layer - Optional Effect layer to provide to the runtime.\n */\n static make<R = never>(layer?: Layer.Layer<R>): void {\n InternalDispatcher.make(layer);\n }\n}\n\n/**\n * Server-side runtime singleton export. In SvelteKit server files the Vite\n * plugin rewrites root imports to `svelte-effect-runtime/server`, so this\n * name resolves to the real server implementation before it is evaluated.\n *\n * @example\n * ```ts\n * import { ServerRuntime } from \"svelte-effect-runtime\";\n *\n * ServerRuntime.make();\n * ```\n *\n * @since 2.0.0\n */\nexport const ServerRuntime: ServerRuntimeFactory = make_server_only_class(\n \"ServerRuntime\",\n) as never;\n\n/**\n * Remote query factory export for `.remote.ts` files imported from the root\n * entrypoint. The Vite plugin rewrites it to the real server implementation.\n *\n * @example\n * ```ts\n * import { Query } from \"svelte-effect-runtime\";\n *\n * export const GetPosts = Query(Effect.succeed([]));\n * ```\n *\n * @since 2.0.0\n */\nexport const Query: QueryFactory = Object.assign(\n make_server_only_function(\"Query\"),\n {\n batch: make_server_only_function(\"Query.batch\"),\n live: make_server_only_function(\"Query.live\"),\n },\n) as never;\n\n/**\n * Remote command factory export for `.remote.ts` files imported from the root\n * entrypoint. The Vite plugin rewrites it to the real server implementation.\n *\n * @example\n * ```ts\n * import { Command } from \"svelte-effect-runtime\";\n *\n * export const SavePost = Command(Schema.String, (id) => Effect.succeed(id));\n * ```\n *\n * @since 2.0.0\n */\nexport const Command: CommandFactory = make_server_only_function(\n \"Command\",\n) as never;\n\n/**\n * SvelteKit HTTP error control-flow export for `.remote.ts` files imported\n * from the root entrypoint. The Vite plugin rewrites it to the real server\n * implementation.\n *\n * @example\n * ```ts\n * import { Error } from \"svelte-effect-runtime\";\n *\n * return yield* Error(\"NotFound\", \"Post not found\");\n * ```\n *\n * @since 2.3.0\n */\nexport const Error: ErrorEffectFactory = make_server_only_function(\n \"Error\",\n) as never;\n\n/**\n * Remote form factory export for `.remote.ts` files imported from the root\n * entrypoint. The Vite plugin rewrites it to the real server implementation.\n *\n * @example\n * ```ts\n * import { Form } from \"svelte-effect-runtime\";\n *\n * export const CreatePost = Form(PostInput, ({ data }) => Effect.succeed(data));\n * ```\n *\n * @since 2.0.0\n */\nexport const Form: FormFactory = make_server_only_function(\n \"Form\",\n) as never;\n\n/**\n * Remote prerender factory export for `.remote.ts` files imported from the\n * root entrypoint. The Vite plugin rewrites it to the real server\n * implementation.\n *\n * @example\n * ```ts\n * import { Prerender } from \"svelte-effect-runtime\";\n *\n * export const GetBuildInfo = Prerender(() => Effect.succeed(\"ready\"));\n * ```\n *\n * @since 2.0.0\n */\nexport const Prerender: PrerenderFactory = make_server_only_function(\n \"Prerender\",\n) as never;\n\n/**\n * SvelteKit redirect control-flow export for `.remote.ts` files imported from\n * the root entrypoint. The Vite plugin rewrites it to the real server\n * implementation.\n *\n * @example\n * ```ts\n * import { Redirect } from \"svelte-effect-runtime\";\n *\n * return yield* Redirect(\"SeeOther\", \"/posts\");\n * ```\n *\n * @since 2.3.0\n */\nexport const Redirect: RedirectEffectFactory = make_server_only_function(\n \"Redirect\",\n) as never;\n\n/**\n * Current SvelteKit request event service export for `.remote.ts` files\n * imported from the root entrypoint. The Vite plugin rewrites it to the real\n * server implementation.\n *\n * @example\n * ```ts\n * import { RequestEvent } from \"svelte-effect-runtime\";\n *\n * const event = yield* RequestEvent;\n * ```\n *\n * @since 2.0.0\n */\nexport const RequestEvent: Context.Reference<RequestEventShape> =\n make_server_only_function(\"RequestEvent\") as never;\n\n/**\n * Returns the active server runtime when imported from a server file. The Vite\n * plugin rewrites root imports to the real server implementation.\n *\n * @example\n * ```ts\n * import { get_server_runtime_or_throw } from \"svelte-effect-runtime\";\n *\n * const runtime = get_server_runtime_or_throw();\n * ```\n *\n * @since 2.0.0\n */\nexport const get_server_runtime_or_throw: () => ManagedRuntime.ManagedRuntime<\n unknown,\n never\n> = make_server_only_function(\"get_server_runtime_or_throw\") as never;\n\n/** Re-export error types users need for typed catch handlers. */\nexport type {\n FormError,\n FormIssue,\n RemoteFailure,\n RemoteHttpError,\n RemoteTransportError,\n RemoteValidationError,\n} from \"$/remote/shared.ts\";\n\nexport {\n is_form_error,\n is_remote_http_error,\n is_remote_transport_error,\n is_remote_validation_error,\n} from \"$/remote/shared.ts\";\n\n/** Re-export app setup helpers so users can import them from root. */\nexport { effect, type EffectOptions } from \"$/vite.ts\";\n\n/** Re-export server helper types from the root entrypoint. */\nexport type {\n ErrorEffectFactory,\n ErrorStatus,\n ErrorStatusName,\n RedirectEffectFactory,\n RedirectStatus,\n RedirectStatusName,\n} from \"$/server/control-flow.ts\";\n\n/** Re-export server helper types from the root entrypoint. */\nexport type {\n CommandFactory,\n EffectLike,\n EffectRemoteBatchHandler,\n EffectRemoteCommand,\n EffectRemoteForm,\n EffectRemoteFunction,\n EffectRemoteLiveQuery,\n EffectRemoteLiveQueryFunction,\n EffectRemoteLiveQueryResource,\n EffectRemoteLiveSource,\n EffectRemoteQuery,\n EffectRemoteQueryFunction,\n FormFactory,\n FormInvalid,\n PrerenderFactory,\n PrerenderOptions,\n QueryBatchFactory,\n QueryFactory,\n QueryLiveFactory,\n RemoteFormHandler,\n RemoteHandler,\n RemoteLiveHandler,\n SchemaInput,\n ServerRuntimeFactory,\n StandardSchema,\n} from \"$/server/types.ts\";\n\n/**\n * Creates the Svelte preprocessor that lowers script and markup `yield*`\n * expressions. The heavy transform module is loaded lazily so browser imports\n * from the package root stay client-safe.\n *\n * @example\n * ```js\n * import { preprocess } from \"svelte-effect-runtime\";\n *\n * export default {\n * preprocess: [preprocess()],\n * };\n * ```\n *\n * @since 2.0.0\n * @returns A Svelte preprocessor group with an async markup hook.\n */\nexport function preprocess(): PreprocessGroup {\n return {\n name: \"svelte-effect-runtime\",\n\n async markup(options: { content: string; filename?: string }) {\n const runtime = await import(\"./runtime/preprocess.ts\");\n const group = runtime.preprocess();\n\n return await group.markup(options);\n },\n };\n}\n\nfunction make_server_only_class(name: string): unknown {\n return class ServerOnlyRuntime {\n static make(): never {\n throw make_server_only_error(name);\n }\n };\n}\n\nfunction make_server_only_function(\n name: string,\n): (...args: unknown[]) => never {\n return (..._args: unknown[]): never => {\n throw make_server_only_error(name);\n };\n}\n\nfunction make_server_only_error(name: string): globalThis.Error {\n return new globalThis.Error(\n `[SERVER_ONLY_IMPORT]: ${name} is only available in SvelteKit server files. ` +\n `Ensure the SER Vite plugin is enabled so root imports are rewritten ` +\n `to \\`svelte-effect-runtime/server\\` before evaluation.`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,IAAa,gBAAb,MAA2B;;;;;;;CAOzB,OAAO,KAAgB,OAA8B;AACnD,aAAmB,KAAK,MAAM;;;;;;;;;;;;;;;;;AAkBlC,MAAa,gBAAsC,uBACjD,gBACD;;;;;;;;;;;;;;AAeD,MAAa,QAAsB,OAAO,OACxC,0BAA0B,QAAQ,EAClC;CACE,OAAO,0BAA0B,cAAc;CAC/C,MAAM,0BAA0B,aAAa;CAC9C,CACF;;;;;;;;;;;;;;AAeD,MAAa,UAA0B,0BACrC,UACD;;;;;;;;;;;;;;;AAgBD,MAAa,QAA4B,0BACvC,QACD;;;;;;;;;;;;;;AAeD,MAAa,OAAoB,0BAC/B,OACD;;;;;;;;;;;;;;;AAgBD,MAAa,YAA8B,0BACzC,YACD;;;;;;;;;;;;;;;AAgBD,MAAa,WAAkC,0BAC7C,WACD;;;;;;;;;;;;;;;AAgBD,MAAa,eACX,0BAA0B,eAAe;;;;;;;;;;;;;;AAe3C,MAAa,8BAGT,0BAA0B,8BAA8B;;;;;;;;;;;;;;;;;;AA8E5D,SAAgB,aAA8B;AAC5C,QAAO;EACL,MAAM;EAEN,MAAM,OAAO,SAAiD;AAI5D,UAAO,OAHS,MAAM,OAAO,4BACP,YAAY,CAEf,OAAO,QAAQ;;EAErC;;AAGH,SAAS,uBAAuB,MAAuB;AACrD,QAAO,MAAM,kBAAkB;EAC7B,OAAO,OAAc;AACnB,SAAM,uBAAuB,KAAK;;;;AAKxC,SAAS,0BACP,MAC+B;AAC/B,SAAQ,GAAG,UAA4B;AACrC,QAAM,uBAAuB,KAAK;;;AAItC,SAAS,uBAAuB,MAAgC;AAC9D,QAAO,IAAI,WAAW,MACpB,yBAAyB,KAAK,0KAG/B"}
|
|
1
|
+
{"version":3,"file":"mod.js","names":[],"sources":["../../modules/svelte-effect-runtime/src/mod.ts"],"sourcesContent":["import { Dispatcher as InternalDispatcher } from \"$/dispatcher.ts\";\nimport type {\n ErrorEffectFactory,\n RedirectEffectFactory,\n} from \"$/server/control-flow.ts\";\nimport type { RequestEvent as RequestEventShape } from \"$/server/runtime.ts\";\nimport type {\n CommandFactory,\n FormFactory,\n PrerenderFactory,\n QueryFactory,\n ServerRuntimeFactory,\n} from \"$/server/types.ts\";\nimport type { Context, Layer, ManagedRuntime } from \"effect\";\n\n/**\n * Result returned by the root Svelte markup preprocessor hook.\n *\n * @since 2.0.0\n */\ninterface MarkupResult {\n code: string;\n}\n\n/**\n * Root preprocessor group shape. The root export keeps transform code lazy so\n * client imports do not pull parser-only dependencies into the browser.\n *\n * @since 2.0.0\n */\ninterface PreprocessGroup {\n name: string;\n markup(\n options: { content: string; filename?: string },\n ): MarkupResult | Promise<MarkupResult>;\n}\n\n/**\n * Public API surface for `svelte-effect-runtime`.\n *\n * Call {@link ClientRuntime.make} in `hooks.client.ts`, call\n * {@link ServerRuntime.make} in `hooks.server.ts`, and let the Vite plugin\n * route server-only helpers to the server entrypoint automatically.\n *\n * @module\n */\n\n/**\n * Client-side runtime singleton. Call `ClientRuntime.make(layer?)` once\n * in `hooks.client.ts` to provide services to every component's effect\n * blocks.\n *\n * If never called, a default empty-layer runtime is created lazily on\n * the first `yield*` expression.\n *\n * @example\n * ```ts\n * import { ClientRuntime } from \"svelte-effect-runtime\";\n * import { Db } from \"./db.ts\";\n *\n * ClientRuntime.make(Db.Live);\n * ```\n *\n * @since 2.0.0\n */\nexport class ClientRuntime {\n /**\n * Build and cache the client-side dispatcher runtime.\n *\n * @since 2.0.0\n * @param layer - Optional Effect layer to provide to the runtime.\n */\n static make<R = never>(layer?: Layer.Layer<R>): void {\n InternalDispatcher.make(layer);\n }\n}\n\n/**\n * Server-side runtime singleton export. In SvelteKit server files the Vite\n * plugin rewrites root imports to `svelte-effect-runtime/server`, so this\n * name resolves to the real server implementation before it is evaluated.\n *\n * @example\n * ```ts\n * import { ServerRuntime } from \"svelte-effect-runtime\";\n *\n * ServerRuntime.make();\n * ```\n *\n * @since 2.0.0\n */\nexport const ServerRuntime: ServerRuntimeFactory = make_server_only_class(\n \"ServerRuntime\",\n) as never;\n\n/**\n * Remote query factory export for `.remote.ts` files imported from the root\n * entrypoint. The Vite plugin rewrites it to the real server implementation.\n *\n * @example\n * ```ts\n * import { Query } from \"svelte-effect-runtime\";\n *\n * export const GetPosts = Query(Effect.succeed([]));\n * ```\n *\n * @since 2.0.0\n */\nexport const Query: QueryFactory = Object.assign(\n make_server_only_function(\"Query\"),\n {\n batch: make_server_only_function(\"Query.batch\"),\n live: make_server_only_function(\"Query.live\"),\n },\n) as never;\n\n/**\n * Remote command factory export for `.remote.ts` files imported from the root\n * entrypoint. The Vite plugin rewrites it to the real server implementation.\n *\n * @example\n * ```ts\n * import { Command } from \"svelte-effect-runtime\";\n *\n * export const SavePost = Command(Schema.String, (id) => Effect.succeed(id));\n * ```\n *\n * @since 2.0.0\n */\nexport const Command: CommandFactory = make_server_only_function(\n \"Command\",\n) as never;\n\n/**\n * SvelteKit HTTP error control-flow export for `.remote.ts` files imported\n * from the root entrypoint. The Vite plugin rewrites it to the real server\n * implementation.\n *\n * @example\n * ```ts\n * import { Error } from \"svelte-effect-runtime\";\n *\n * return yield* Error(\"NotFound\", \"Post not found\");\n * ```\n *\n * @since 2.3.0\n */\nexport const Error: ErrorEffectFactory = make_server_only_function(\n \"Error\",\n) as never;\n\n/**\n * Remote form factory export for `.remote.ts` files imported from the root\n * entrypoint. The Vite plugin rewrites it to the real server implementation.\n *\n * @example\n * ```ts\n * import { Form } from \"svelte-effect-runtime\";\n *\n * export const CreatePost = Form(PostInput, ({ data }) => Effect.succeed(data));\n * ```\n *\n * @since 2.0.0\n */\nexport const Form: FormFactory = make_server_only_function(\n \"Form\",\n) as never;\n\n/**\n * Remote prerender factory export for `.remote.ts` files imported from the\n * root entrypoint. The Vite plugin rewrites it to the real server\n * implementation.\n *\n * @example\n * ```ts\n * import { Prerender } from \"svelte-effect-runtime\";\n *\n * export const GetBuildInfo = Prerender(() => Effect.succeed(\"ready\"));\n * ```\n *\n * @since 2.0.0\n */\nexport const Prerender: PrerenderFactory = make_server_only_function(\n \"Prerender\",\n) as never;\n\n/**\n * SvelteKit redirect control-flow export for `.remote.ts` files imported from\n * the root entrypoint. The Vite plugin rewrites it to the real server\n * implementation.\n *\n * @example\n * ```ts\n * import { Redirect } from \"svelte-effect-runtime\";\n *\n * return yield* Redirect(\"SeeOther\", \"/posts\");\n * ```\n *\n * @since 2.3.0\n */\nexport const Redirect: RedirectEffectFactory = make_server_only_function(\n \"Redirect\",\n) as never;\n\n/**\n * Current SvelteKit request event service export for `.remote.ts` files\n * imported from the root entrypoint. The Vite plugin rewrites it to the real\n * server implementation.\n *\n * @example\n * ```ts\n * import { RequestEvent } from \"svelte-effect-runtime\";\n *\n * const event = yield* RequestEvent;\n * ```\n *\n * @since 2.0.0\n */\nexport const RequestEvent: Context.Reference<RequestEventShape> =\n make_server_only_function(\"RequestEvent\") as never;\n\n/**\n * Returns the active server runtime when imported from a server file. The Vite\n * plugin rewrites root imports to the real server implementation.\n *\n * @example\n * ```ts\n * import { get_server_runtime_or_throw } from \"svelte-effect-runtime\";\n *\n * const runtime = get_server_runtime_or_throw();\n * ```\n *\n * @since 2.0.0\n */\nexport const get_server_runtime_or_throw: () => ManagedRuntime.ManagedRuntime<\n unknown,\n never\n> = make_server_only_function(\"get_server_runtime_or_throw\") as never;\n\n/** Re-export error types users need for typed catch handlers. */\nexport type {\n FormError,\n FormIssue,\n RemoteFailure,\n RemoteHttpError,\n RemoteTransportError,\n RemoteValidationError,\n} from \"$/remote/shared.ts\";\n\nexport {\n is_form_error,\n is_remote_http_error,\n is_remote_transport_error,\n is_remote_validation_error,\n} from \"$/remote/shared.ts\";\n\n/** Re-export app setup helpers so users can import them from root. */\nexport { effect, type EffectOptions } from \"$/vite.ts\";\n\n/** Re-export server helper types from the root entrypoint. */\nexport type {\n ErrorEffectFactory,\n ErrorStatus,\n ErrorStatusName,\n RedirectEffectFactory,\n RedirectStatus,\n RedirectStatusName,\n} from \"$/server/control-flow.ts\";\n\n/** Re-export server helper types from the root entrypoint. */\nexport type {\n CommandFactory,\n EffectLike,\n EffectRemoteBatchHandler,\n EffectRemoteCommand,\n EffectRemoteForm,\n EffectRemoteFunction,\n EffectRemoteLiveQuery,\n EffectRemoteLiveQueryFunction,\n EffectRemoteLiveQueryResource,\n EffectRemoteLiveSource,\n EffectRemoteQuery,\n EffectRemoteQueryFunction,\n FormFactory,\n FormInvalid,\n PrerenderFactory,\n PrerenderOptions,\n QueryBatchFactory,\n QueryFactory,\n QueryLiveFactory,\n RemoteFormHandler,\n RemoteHandler,\n RemoteLiveHandler,\n SchemaInput,\n ServerRuntimeFactory,\n StandardSchema,\n} from \"$/server/types.ts\";\n\n/**\n * Creates the Svelte preprocessor that lowers script and markup `yield*`\n * expressions. The heavy transform module is loaded lazily so browser imports\n * from the package root stay client-safe.\n *\n * @example\n * ```js\n * import { preprocess } from \"svelte-effect-runtime\";\n *\n * export default {\n * preprocess: [preprocess()],\n * };\n * ```\n *\n * @since 2.0.0\n * @returns A Svelte preprocessor group with an async markup hook.\n */\nexport function preprocess(): PreprocessGroup {\n return {\n name: \"svelte-effect-runtime\",\n\n async markup(options: { content: string; filename?: string }) {\n const runtime = await import(\"./runtime/preprocess.ts\");\n const group = runtime.preprocess();\n\n return await group.markup(options);\n },\n };\n}\n\nfunction make_server_only_class(name: string): unknown {\n return class ServerOnlyRuntime {\n static make(): never {\n throw make_server_only_error(name);\n }\n };\n}\n\nfunction make_server_only_function(\n name: string,\n): (...args: unknown[]) => never {\n return (..._args: unknown[]): never => {\n throw make_server_only_error(name);\n };\n}\n\nfunction make_server_only_error(name: string): globalThis.Error {\n return new globalThis.Error(\n `[SERVER_ONLY_IMPORT]: ${name} is only available in SvelteKit server files. ` +\n `Ensure the SER Vite plugin is enabled so root imports are rewritten ` +\n `to \\`svelte-effect-runtime/server\\` before evaluation.`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,IAAa,gBAAb,MAA2B;;;;;;;CAOzB,OAAO,KAAgB,OAA8B;EACnD,WAAmB,KAAK,KAAK;CAC/B;AACF;;;;;;;;;;;;;;;AAgBA,MAAa,gBAAsC,uBACjD,eACF;;;;;;;;;;;;;;AAeA,MAAa,QAAsB,OAAO,OACxC,0BAA0B,OAAO,GACjC;CACE,OAAO,0BAA0B,aAAa;CAC9C,MAAM,0BAA0B,YAAY;AAC9C,CACF;;;;;;;;;;;;;;AAeA,MAAa,UAA0B,0BACrC,SACF;;;;;;;;;;;;;;;AAgBA,MAAa,QAA4B,0BACvC,OACF;;;;;;;;;;;;;;AAeA,MAAa,OAAoB,0BAC/B,MACF;;;;;;;;;;;;;;;AAgBA,MAAa,YAA8B,0BACzC,WACF;;;;;;;;;;;;;;;AAgBA,MAAa,WAAkC,0BAC7C,UACF;;;;;;;;;;;;;;;AAgBA,MAAa,eACX,0BAA0B,cAAc;;;;;;;;;;;;;;AAe1C,MAAa,8BAGT,0BAA0B,6BAA6B;;;;;;;;;;;;;;;;;;AA8E3D,SAAgB,aAA8B;CAC5C,OAAO;EACL,MAAM;EAEN,MAAM,OAAO,SAAiD;GAI5D,OAAO,OAFO,MADQ,OAAO,4BACP,WAEL,EAAE,OAAO,OAAO;EACnC;CACF;AACF;AAEA,SAAS,uBAAuB,MAAuB;CACrD,OAAO,MAAM,kBAAkB;EAC7B,OAAO,OAAc;GACnB,MAAM,uBAAuB,IAAI;EACnC;CACF;AACF;AAEA,SAAS,0BACP,MAC+B;CAC/B,QAAQ,GAAG,UAA4B;EACrC,MAAM,uBAAuB,IAAI;CACnC;AACF;AAEA,SAAS,uBAAuB,MAAgC;CAC9D,OAAO,IAAI,WAAW,MACpB,yBAAyB,KAAK,yKAGhC;AACF"}
|
|
@@ -6,9 +6,10 @@ import ts from "typescript";
|
|
|
6
6
|
* @param has_effect_import - Whether the user already imports `Effect`.
|
|
7
7
|
* @param has_dispatcher_import - Whether the user already imports
|
|
8
8
|
* `get_dispatcher`.
|
|
9
|
+
* @param has_untrack_import - Whether the user already imports `untrack`.
|
|
9
10
|
* @returns Newline-separated import statements to inject.
|
|
10
11
|
*/
|
|
11
|
-
export declare function make_imports(has_effect_import: boolean, has_dispatcher_import: boolean): string;
|
|
12
|
+
export declare function make_imports(has_effect_import: boolean, has_dispatcher_import: boolean, has_untrack_import: boolean): string;
|
|
12
13
|
/**
|
|
13
14
|
* Checks whether a source file imports a local binding from a module.
|
|
14
15
|
*
|
package/.dist/preprocess.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as transform_markup_effect } from "./chunks/transform-
|
|
2
|
-
import { t as transform_script_effect } from "./chunks/preprocess-
|
|
1
|
+
import { t as transform_markup_effect } from "./chunks/transform-s9gKPYu5.js";
|
|
2
|
+
import { t as transform_script_effect } from "./chunks/preprocess-Cn4JH9OO.js";
|
|
3
3
|
export { transform_markup_effect, transform_script_effect };
|
package/.dist/remote/client.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as create_remote_command_adapter, n as create_remote_query_adapter, r as create_remote_form_adapter, t as create_remote_live_query_adapter } from "../chunks/client-
|
|
1
|
+
import { i as create_remote_command_adapter, n as create_remote_query_adapter, r as create_remote_form_adapter, t as create_remote_live_query_adapter } from "../chunks/client-CfkB_G4o.js";
|
|
2
2
|
export { create_remote_command_adapter, create_remote_form_adapter, create_remote_live_query_adapter, create_remote_query_adapter };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/remote/server.ts"],"sourcesContent":["import { create_serialized_remote_failure_envelope } from \"$/remote/shared.ts\";\nimport type { FormIssue } from \"$/remote/shared.ts\";\nimport { isHttpError, isRedirect, isValidationError } from \"@sveltejs/kit\";\nimport { Cause, Effect, Exit } from \"effect\";\nimport { stringify } from \"devalue\";\n\ntype CauseReason = {\n readonly _tag: string;\n readonly defect?: unknown;\n readonly error?: unknown;\n};\n\n/**\n * Runs a user-supplied Effect program through a ManagedRuntime, maps its\n * exit into the shape expected by SvelteKit, and returns the result or\n * throws a SvelteKit-compatible error.\n *\n * @since 2.0.0\n * @param effect - The Effect program to execute.\n * @param runtime - The server-side ManagedRuntime.\n * @param invalid - SvelteKit's `invalid` helper (bound per-request).\n * @param error - SvelteKit's `error` helper.\n * @returns A Promise that resolves with the effect's success value.\n * @internal\n */\nexport async function run_remote_effect<A>(\n effect: Effect.Effect<A, unknown, unknown>,\n runtime: {\n runPromise: (\n e: Effect.Effect<unknown, unknown, unknown>,\n ) => Promise<unknown>;\n },\n invalid: (status: number, body: unknown) => never,\n error: (status: number, body: unknown) => never,\n): Promise<A> {\n const exit: Exit.Exit<A, unknown> = await runtime.runPromise(\n Effect.exit(effect) as Effect.Effect<unknown, unknown, unknown>,\n ) as Exit.Exit<A, unknown>;\n\n if (Exit.isSuccess(exit)) {\n return exit.value;\n }\n\n handle_failure(exit.cause, invalid, error);\n}\n\n/**\n * Inspects the Effect Cause for failures and either throws a form\n * validation error (via SvelteKit's `invalid`) or encodes the error\n * and throws it via SvelteKit's `error`.\n */\nfunction handle_failure(\n cause: Cause.Cause<unknown>,\n invalid: (status: number, body: unknown) => never,\n error: (status: number, body: unknown) => never,\n): never {\n const reasons = get_cause_reasons(cause);\n\n /**\n * Phase 1 — let SvelteKit's thrown control-flow sentinels escape.\n */\n for (const reason of reasons) {\n if (!Cause.isDieReason(reason as never)) {\n continue;\n }\n\n const defect = reason.defect;\n\n if (is_sveltekit_control_flow(defect)) {\n throw defect;\n }\n }\n\n /**\n * Phase 2 — preserve typed form validation failures.\n */\n for (const reason of reasons) {\n if (Cause.isFailReason(reason as never)) {\n const failure = reason.error;\n if (\n typeof failure === \"object\" &&\n failure !== null &&\n (failure as Record<string, unknown>)._tag === \"FormError\"\n ) {\n const issues = (failure as { issues?: readonly FormIssue[] }).issues ??\n [];\n invalid(400, { issues });\n }\n }\n }\n\n /**\n * Phase 3 — encode all other failures for the remote client.\n */\n const encoded = encode_remote_failure(cause);\n const envelope = create_serialized_remote_failure_envelope(encoded);\n\n error(500, envelope);\n}\n\n/**\n * Encodes an Effect Cause into a string that the client-side adapter can\n * decode back into a typed `RemoteFailure`.\n *\n * @since 2.0.0\n * @param cause - The Effect Cause from a failed execution.\n * @returns A devalue-encoded string representing the serialised failure.\n * @internal\n */\nexport function encode_remote_failure(cause: Cause.Cause<unknown>): string {\n const reasons = get_cause_reasons(cause);\n\n for (const reason of reasons) {\n if (Cause.isFailReason(reason as never)) {\n const failure = reason.error;\n\n const encoded = stringify_failure(failure);\n\n if (encoded !== undefined) {\n return encoded;\n }\n\n const serializable_failure = to_serializable_failure(failure);\n const serializable_encoded = stringify_failure(serializable_failure);\n\n if (serializable_encoded !== undefined) {\n return serializable_encoded;\n }\n }\n }\n\n return stringify({ message: \"[UNKNOWN_REMOTE_FAILURE]: Unknown error\" });\n}\n\nfunction get_cause_reasons(\n cause: Cause.Cause<unknown>,\n): readonly CauseReason[] {\n const reasons = (cause as unknown as { reasons?: readonly CauseReason[] })\n .reasons;\n\n return reasons ?? [];\n}\n\nfunction is_sveltekit_control_flow(value: unknown): boolean {\n return isRedirect(value) || isHttpError(value) || isValidationError(value);\n}\n\nfunction stringify_failure(value: unknown): string | undefined {\n try {\n return stringify(value);\n } catch {\n return undefined;\n }\n}\n\nfunction to_serializable_failure(\n value: unknown,\n seen = new WeakSet<object>(),\n): unknown {\n if (typeof value === \"function\" || typeof value === \"symbol\") {\n return undefined;\n }\n\n if (!is_object_like(value)) {\n return value;\n }\n\n if (stringify_failure(value) !== undefined) {\n return value;\n }\n\n if (seen.has(value)) {\n return undefined;\n }\n\n seen.add(value);\n\n const serializable = Array.isArray(value)\n ? value.map((item) => to_serializable_failure(item, seen))\n : to_plain_record(value, seen);\n\n seen.delete(value);\n\n return serializable;\n}\n\nfunction to_plain_record(\n value: object,\n seen: WeakSet<object>,\n): Record<string, unknown> {\n const descriptors = Object.getOwnPropertyDescriptors(value);\n const record: Record<string, unknown> = {};\n\n for (const [key, descriptor] of Object.entries(descriptors)) {\n if (key === \"stack\" || !(\"value\" in descriptor)) {\n continue;\n }\n\n record[key] = to_serializable_failure(descriptor.value, seen);\n }\n\n if (value instanceof Error && !(\"message\" in record)) {\n record.message = value.message;\n }\n\n return record;\n}\n\nfunction is_object_like(value: unknown): value is object {\n return typeof value === \"object\" && value !== null;\n}\n\n/**\n * Throws a SvelteKit `invalid` response from a {@link FormError}, calling\n * through to the request-scoped `invalid` helper.\n *\n * @example\n * ```ts\n * throw_form_error(\n * [{ message: \"Name is required\", path: [\"name\"] }],\n * invalid,\n * );\n * ```\n *\n * @since 2.0.0\n * @param issues - The list of form validation issues.\n * @param invalid - SvelteKit's `invalid` helper bound to the current request.\n * @internal\n */\nexport function throw_form_error(\n issues: readonly FormIssue[],\n invalid: (status: number, body: unknown) => never,\n): never {\n invalid(400, { issues });\n}\n\n/**\n * Remaps low-level SvelteKit errors (e.g. \"Cannot use ___ outside a route\")\n * into clear, actionable messages.\n *\n * @example\n * ```ts\n * try {\n * return native_query(handler);\n * } catch (err) {\n * throw normalize_remote_helper_error(err, \"Query\");\n * }\n * ```\n *\n * @since 2.0.0\n * @param err - The error thrown by SvelteKit's native functions.\n * @param helper_name - Name of the helper that triggered the error.\n * @returns A more descriptive error.\n * @internal\n */\nexport function normalize_remote_helper_error(\n err: unknown,\n helper_name: string,\n): globalThis.Error {\n const message = err instanceof Error ? err.message : String(err);\n\n if (message.includes(\"Cannot use\") || message.includes(\"outside a route\")) {\n return new globalThis.Error(\n `[REMOTE_HELPER_CONTEXT]: ${helper_name} was called outside a .remote.ts file. ` +\n `Ensure the file is named \\`*.remote.ts\\` and is located in a route directory.`,\n );\n }\n\n return err instanceof Error\n ? err\n : new globalThis.Error(`[REMOTE_HELPER_ERROR]: ${message}`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyBA,eAAsB,kBACpB,QACA,SAKA,SACA,OACY;CACZ,MAAM,OAA8B,MAAM,QAAQ,WAChD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"server.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/remote/server.ts"],"sourcesContent":["import { create_serialized_remote_failure_envelope } from \"$/remote/shared.ts\";\nimport type { FormIssue } from \"$/remote/shared.ts\";\nimport { isHttpError, isRedirect, isValidationError } from \"@sveltejs/kit\";\nimport { Cause, Effect, Exit } from \"effect\";\nimport { stringify } from \"devalue\";\n\ntype CauseReason = {\n readonly _tag: string;\n readonly defect?: unknown;\n readonly error?: unknown;\n};\n\n/**\n * Runs a user-supplied Effect program through a ManagedRuntime, maps its\n * exit into the shape expected by SvelteKit, and returns the result or\n * throws a SvelteKit-compatible error.\n *\n * @since 2.0.0\n * @param effect - The Effect program to execute.\n * @param runtime - The server-side ManagedRuntime.\n * @param invalid - SvelteKit's `invalid` helper (bound per-request).\n * @param error - SvelteKit's `error` helper.\n * @returns A Promise that resolves with the effect's success value.\n * @internal\n */\nexport async function run_remote_effect<A>(\n effect: Effect.Effect<A, unknown, unknown>,\n runtime: {\n runPromise: (\n e: Effect.Effect<unknown, unknown, unknown>,\n ) => Promise<unknown>;\n },\n invalid: (status: number, body: unknown) => never,\n error: (status: number, body: unknown) => never,\n): Promise<A> {\n const exit: Exit.Exit<A, unknown> = await runtime.runPromise(\n Effect.exit(effect) as Effect.Effect<unknown, unknown, unknown>,\n ) as Exit.Exit<A, unknown>;\n\n if (Exit.isSuccess(exit)) {\n return exit.value;\n }\n\n handle_failure(exit.cause, invalid, error);\n}\n\n/**\n * Inspects the Effect Cause for failures and either throws a form\n * validation error (via SvelteKit's `invalid`) or encodes the error\n * and throws it via SvelteKit's `error`.\n */\nfunction handle_failure(\n cause: Cause.Cause<unknown>,\n invalid: (status: number, body: unknown) => never,\n error: (status: number, body: unknown) => never,\n): never {\n const reasons = get_cause_reasons(cause);\n\n /**\n * Phase 1 — let SvelteKit's thrown control-flow sentinels escape.\n */\n for (const reason of reasons) {\n if (!Cause.isDieReason(reason as never)) {\n continue;\n }\n\n const defect = reason.defect;\n\n if (is_sveltekit_control_flow(defect)) {\n throw defect;\n }\n }\n\n /**\n * Phase 2 — preserve typed form validation failures.\n */\n for (const reason of reasons) {\n if (Cause.isFailReason(reason as never)) {\n const failure = reason.error;\n if (\n typeof failure === \"object\" &&\n failure !== null &&\n (failure as Record<string, unknown>)._tag === \"FormError\"\n ) {\n const issues = (failure as { issues?: readonly FormIssue[] }).issues ??\n [];\n invalid(400, { issues });\n }\n }\n }\n\n /**\n * Phase 3 — encode all other failures for the remote client.\n */\n const encoded = encode_remote_failure(cause);\n const envelope = create_serialized_remote_failure_envelope(encoded);\n\n error(500, envelope);\n}\n\n/**\n * Encodes an Effect Cause into a string that the client-side adapter can\n * decode back into a typed `RemoteFailure`.\n *\n * @since 2.0.0\n * @param cause - The Effect Cause from a failed execution.\n * @returns A devalue-encoded string representing the serialised failure.\n * @internal\n */\nexport function encode_remote_failure(cause: Cause.Cause<unknown>): string {\n const reasons = get_cause_reasons(cause);\n\n for (const reason of reasons) {\n if (Cause.isFailReason(reason as never)) {\n const failure = reason.error;\n\n const encoded = stringify_failure(failure);\n\n if (encoded !== undefined) {\n return encoded;\n }\n\n const serializable_failure = to_serializable_failure(failure);\n const serializable_encoded = stringify_failure(serializable_failure);\n\n if (serializable_encoded !== undefined) {\n return serializable_encoded;\n }\n }\n }\n\n return stringify({ message: \"[UNKNOWN_REMOTE_FAILURE]: Unknown error\" });\n}\n\nfunction get_cause_reasons(\n cause: Cause.Cause<unknown>,\n): readonly CauseReason[] {\n const reasons = (cause as unknown as { reasons?: readonly CauseReason[] })\n .reasons;\n\n return reasons ?? [];\n}\n\nfunction is_sveltekit_control_flow(value: unknown): boolean {\n return isRedirect(value) || isHttpError(value) || isValidationError(value);\n}\n\nfunction stringify_failure(value: unknown): string | undefined {\n try {\n return stringify(value);\n } catch {\n return undefined;\n }\n}\n\nfunction to_serializable_failure(\n value: unknown,\n seen = new WeakSet<object>(),\n): unknown {\n if (typeof value === \"function\" || typeof value === \"symbol\") {\n return undefined;\n }\n\n if (!is_object_like(value)) {\n return value;\n }\n\n if (stringify_failure(value) !== undefined) {\n return value;\n }\n\n if (seen.has(value)) {\n return undefined;\n }\n\n seen.add(value);\n\n const serializable = Array.isArray(value)\n ? value.map((item) => to_serializable_failure(item, seen))\n : to_plain_record(value, seen);\n\n seen.delete(value);\n\n return serializable;\n}\n\nfunction to_plain_record(\n value: object,\n seen: WeakSet<object>,\n): Record<string, unknown> {\n const descriptors = Object.getOwnPropertyDescriptors(value);\n const record: Record<string, unknown> = {};\n\n for (const [key, descriptor] of Object.entries(descriptors)) {\n if (key === \"stack\" || !(\"value\" in descriptor)) {\n continue;\n }\n\n record[key] = to_serializable_failure(descriptor.value, seen);\n }\n\n if (value instanceof Error && !(\"message\" in record)) {\n record.message = value.message;\n }\n\n return record;\n}\n\nfunction is_object_like(value: unknown): value is object {\n return typeof value === \"object\" && value !== null;\n}\n\n/**\n * Throws a SvelteKit `invalid` response from a {@link FormError}, calling\n * through to the request-scoped `invalid` helper.\n *\n * @example\n * ```ts\n * throw_form_error(\n * [{ message: \"Name is required\", path: [\"name\"] }],\n * invalid,\n * );\n * ```\n *\n * @since 2.0.0\n * @param issues - The list of form validation issues.\n * @param invalid - SvelteKit's `invalid` helper bound to the current request.\n * @internal\n */\nexport function throw_form_error(\n issues: readonly FormIssue[],\n invalid: (status: number, body: unknown) => never,\n): never {\n invalid(400, { issues });\n}\n\n/**\n * Remaps low-level SvelteKit errors (e.g. \"Cannot use ___ outside a route\")\n * into clear, actionable messages.\n *\n * @example\n * ```ts\n * try {\n * return native_query(handler);\n * } catch (err) {\n * throw normalize_remote_helper_error(err, \"Query\");\n * }\n * ```\n *\n * @since 2.0.0\n * @param err - The error thrown by SvelteKit's native functions.\n * @param helper_name - Name of the helper that triggered the error.\n * @returns A more descriptive error.\n * @internal\n */\nexport function normalize_remote_helper_error(\n err: unknown,\n helper_name: string,\n): globalThis.Error {\n const message = err instanceof Error ? err.message : String(err);\n\n if (message.includes(\"Cannot use\") || message.includes(\"outside a route\")) {\n return new globalThis.Error(\n `[REMOTE_HELPER_CONTEXT]: ${helper_name} was called outside a .remote.ts file. ` +\n `Ensure the file is named \\`*.remote.ts\\` and is located in a route directory.`,\n );\n }\n\n return err instanceof Error\n ? err\n : new globalThis.Error(`[REMOTE_HELPER_ERROR]: ${message}`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyBA,eAAsB,kBACpB,QACA,SAKA,SACA,OACY;CACZ,MAAM,OAA8B,MAAM,QAAQ,WAChD,OAAO,KAAK,MAAM,CACpB;CAEA,IAAI,KAAK,UAAU,IAAI,GACrB,OAAO,KAAK;CAGd,eAAe,KAAK,OAAO,SAAS,KAAK;AAC3C;;;;;;AAOA,SAAS,eACP,OACA,SACA,OACO;CACP,MAAM,UAAU,kBAAkB,KAAK;;;;CAKvC,KAAK,MAAM,UAAU,SAAS;EAC5B,IAAI,CAAC,MAAM,YAAY,MAAe,GACpC;EAGF,MAAM,SAAS,OAAO;EAEtB,IAAI,0BAA0B,MAAM,GAClC,MAAM;CAEV;;;;CAKA,KAAK,MAAM,UAAU,SACnB,IAAI,MAAM,aAAa,MAAe,GAAG;EACvC,MAAM,UAAU,OAAO;EACvB,IACE,OAAO,YAAY,YACnB,YAAY,QACX,QAAoC,SAAS,aAI9C,QAAQ,KAAK,EAAE,QAFC,QAA8C,UAC5D,CAAC,EACmB,CAAC;CAE3B;CASF,MAAM,KAFW,0CADD,sBAAsB,KAC2B,CAE/C,CAAC;AACrB;;;;;;;;;;AAWA,SAAgB,sBAAsB,OAAqC;CACzE,MAAM,UAAU,kBAAkB,KAAK;CAEvC,KAAK,MAAM,UAAU,SACnB,IAAI,MAAM,aAAa,MAAe,GAAG;EACvC,MAAM,UAAU,OAAO;EAEvB,MAAM,UAAU,kBAAkB,OAAO;EAEzC,IAAI,YAAY,KAAA,GACd,OAAO;EAIT,MAAM,uBAAuB,kBAD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