aktion-runtime 0.5.4 → 0.5.5

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.
Files changed (68) hide show
  1. package/README.md +90 -114
  2. package/dist/aktion.iife.js +106 -460
  3. package/dist/aktion.iife.js.map +1 -1
  4. package/dist/aktion.js +5530 -5076
  5. package/dist/aktion.js.map +1 -1
  6. package/dist/aktion.umd.cjs +106 -460
  7. package/dist/aktion.umd.cjs.map +1 -1
  8. package/dist/devtools.js +1367 -0
  9. package/dist/devtools.js.map +1 -0
  10. package/dist/{node/index-8OvnOYPI.js → language.js} +13669 -12428
  11. package/dist/language.js.map +1 -0
  12. package/dist/plugin.cjs +2650 -0
  13. package/dist/plugin.cjs.map +1 -0
  14. package/dist/plugin.js +2650 -0
  15. package/dist/plugin.js.map +1 -0
  16. package/dist/system_prompt.txt +164 -447
  17. package/dist/system_prompt_chat.txt +33 -84
  18. package/dist/{node/index-DBgA3bHQ.cjs → testing.js} +28116 -12689
  19. package/dist/testing.js.map +1 -0
  20. package/dist/types/aktion-modules.d.ts +6 -10
  21. package/dist/types/compiler/index.d.ts +9 -11
  22. package/dist/types/compiler/linker.d.ts +11 -11
  23. package/dist/types/compiler/project.d.ts +45 -0
  24. package/dist/types/compiler/runtime.d.ts +22 -26
  25. package/dist/types/devtools/hook.d.ts +88 -0
  26. package/dist/types/devtools/index.d.ts +35 -0
  27. package/dist/types/devtools/panel.d.ts +109 -0
  28. package/dist/types/devtools/protocol.d.ts +130 -0
  29. package/dist/types/devtools/styles.d.ts +7 -0
  30. package/dist/types/element.d.ts +56 -24
  31. package/dist/types/index.d.ts +1 -1
  32. package/dist/types/language-api.d.ts +8 -8
  33. package/dist/types/parser/types.d.ts +8 -8
  34. package/dist/types/plugin/index.d.ts +13 -6
  35. package/dist/types/renderer/renderer.d.ts +28 -0
  36. package/dist/types/runtime/builtins.d.ts +5 -11
  37. package/dist/types/runtime/effects.d.ts +15 -0
  38. package/dist/types/runtime/http.d.ts +0 -1
  39. package/dist/types/testing/index.d.ts +201 -0
  40. package/dist/types/theme/index.d.ts +3 -3
  41. package/dist/types/theme/styles.d.ts +1 -1
  42. package/dist/types/tooling/formatter.d.ts +7 -1
  43. package/dist/types/tooling/index.d.ts +0 -3
  44. package/package.json +21 -19
  45. package/dist/node/compile-BUw0GAvN.cjs +0 -491
  46. package/dist/node/compile-BUw0GAvN.cjs.map +0 -1
  47. package/dist/node/compile-DxttTzo8.js +0 -492
  48. package/dist/node/compile-DxttTzo8.js.map +0 -1
  49. package/dist/node/compiler.cjs +0 -11
  50. package/dist/node/compiler.cjs.map +0 -1
  51. package/dist/node/compiler.js +0 -11
  52. package/dist/node/compiler.js.map +0 -1
  53. package/dist/node/index-8OvnOYPI.js.map +0 -1
  54. package/dist/node/index-DBgA3bHQ.cjs.map +0 -1
  55. package/dist/node/language.cjs +0 -1244
  56. package/dist/node/language.cjs.map +0 -1
  57. package/dist/node/language.js +0 -1244
  58. package/dist/node/language.js.map +0 -1
  59. package/dist/node/vite.cjs +0 -65
  60. package/dist/node/vite.cjs.map +0 -1
  61. package/dist/node/vite.js +0 -65
  62. package/dist/node/vite.js.map +0 -1
  63. package/dist/types/compiler/compile.d.ts +0 -54
  64. package/dist/types/compiler/emit.d.ts +0 -15
  65. package/dist/types/compiler/sourcemap.d.ts +0 -40
  66. package/dist/types/library/components/theme.d.ts +0 -2
  67. package/dist/types/plugin/vite.d.ts +0 -21
  68. package/dist/types/tooling/codemod.d.ts +0 -36
@@ -1 +0,0 @@
1
- {"version":3,"file":"compile-BUw0GAvN.cjs","sources":["../../src/compiler/runtime.ts","../../src/compiler/emit.ts","../../src/compiler/sourcemap.ts","../../src/compiler/linker.ts","../../src/compiler/compile.ts"],"sourcesContent":["/**\n * Browser-safe compiler runtime helpers.\n *\n * This is the ONLY file under `src/compiler/` that the browser bundle is\n * allowed to reach. It contains nothing but the `CompiledProgram` data\n * contract, two guards, and `compileLite` — a parse-and-wrap helper whose\n * only dependencies (`parse`, the `Program`/`ComponentLibrary` types) are\n * already part of the runtime bundle. The heavyweight code-generation and\n * source-map machinery lives in `compile.ts` / `emit.ts` / `sourcemap.ts`,\n * which are Node-oriented and must never be imported from `src/index.ts`.\n *\n * A `CompiledProgram` is the build-time artefact the Vite/Rollup plugin\n * emits and `<aktion-app>.mountCompiled(...)` consumes: the already-parsed\n * component-tree AST plus the original source. Shipping the parsed AST is\n * what \"pre-evaluated component tree\" means in practice — the reactive\n * runtime (state, HTTP, effects, routing) still runs in the browser exactly\n * as it does for the streamed-string path, but the parser no longer has to.\n */\n\nimport { parse } from \"../parser/index.js\";\nimport type { Program } from \"../parser/types.js\";\nimport type { ComponentLibrary } from \"../library/types.js\";\n\n/**\n * Schema version of the compiled-program contract. Bumped only on a\n * breaking change to the `CompiledProgram` shape so the runtime can reject\n * an artefact produced by an incompatible compiler version instead of\n * mounting garbage.\n */\nexport const COMPILED_PROGRAM_VERSION = 1;\n\n/**\n * The build-time artefact produced by the Aktion compiler and consumed by\n * `<aktion-app>.mountCompiled(...)`. It carries the parsed AST so the runtime\n * skips `parse()`, plus the original source so text-based features\n * (`applyDelta`, `serializeState` round-trips, debugging) keep working.\n */\nexport interface CompiledProgram {\n /** Version marker — see {@link COMPILED_PROGRAM_VERSION}. */\n readonly __aktionCompiled: typeof COMPILED_PROGRAM_VERSION;\n /** Already-parsed component-tree AST. Mounted without re-parsing. */\n readonly program: Program;\n /** Original DSL source — retained for `applyDelta`/snapshots/debugging. */\n readonly source: string;\n /** Module id / file path — used for diagnostics, source maps, HMR targeting. */\n readonly path: string;\n}\n\n/**\n * Narrowing guard for values that cross the `mountCompiled` boundary (or\n * arrive over an HMR channel) so a stray object can't be mistaken for a\n * compiled artefact.\n */\nexport function isCompiledProgram(value: unknown): value is CompiledProgram {\n if (!value || typeof value !== \"object\") return false;\n const candidate = value as Partial<CompiledProgram>;\n return (\n candidate.__aktionCompiled === COMPILED_PROGRAM_VERSION &&\n typeof candidate.source === \"string\" &&\n typeof candidate.path === \"string\" &&\n !!candidate.program &&\n Array.isArray((candidate.program as Program).statements)\n );\n}\n\n/**\n * Identity helper the emitted module wraps its payload with. It gives authors\n * a single, typed construction point —\n * `defineCompiledProgram({...})` returns a value typed as `CompiledProgram`,\n * so a malformed payload is a compile error rather than a runtime surprise.\n */\nexport function defineCompiledProgram(compiled: CompiledProgram): CompiledProgram {\n return compiled;\n}\n\n/** Options for {@link compileLite}. */\nexport interface CompileLiteOptions {\n /** Module id / file path stamped onto the artefact (default `\"<inline>\"`). */\n path?: string;\n /**\n * Library reserved for future lite-path validation. The browser runtime\n * already re-runs `validateProgramSchema` on mount (see `element.ts`\n * `replan()`), so the lite path intentionally skips validation here to\n * avoid duplicating diagnostics — it only parses and wraps.\n */\n library?: ComponentLibrary;\n}\n\n/**\n * Parse `source` and wrap it as a {@link CompiledProgram} — the minimal,\n * browser-safe single-file compile path. Useful for mounting a program string\n * via `mountCompiled` without the streamed-string `setResponse` API, and as a\n * lightweight programmatic entry. It deliberately performs no code generation,\n * no source map, no module linking, and no schema validation (the runtime\n * validates on mount), so it adds nothing to the browser bundle beyond the\n * parser that already ships there.\n *\n * For build-time use (code generation + source maps + build diagnostics) the\n * Node-only `compile()` from `aktion-runtime/compiler` is the right entry.\n */\nexport function compileLite(source: string, options: CompileLiteOptions = {}): CompiledProgram {\n const program = parse(source);\n return defineCompiledProgram({\n __aktionCompiled: COMPILED_PROGRAM_VERSION,\n program,\n source,\n path: options.path ?? \"<inline>\",\n });\n}\n","/**\n * Code generation for the build-time compiler (Node-oriented).\n *\n * Turns a parsed `Program` into the text of an ES module that exports a\n * `CompiledProgram`. The AST is embedded as `JSON.parse(\"…\")` rather than an\n * object literal for two reasons: engines parse a JSON string faster than the\n * equivalent literal for large LLM-generated trees, and the payload is\n * guaranteed inert data (no accidental identifier resolution).\n *\n * The emitted module imports `defineCompiledProgram` from the *runtime* entry\n * (default `\"aktion-runtime\"`), NOT from `aktion-runtime/compiler` — the\n * runtime entry re-exports the inert helper, so the compiler never leaks into\n * the browser bundle.\n */\n\nimport type { Program } from \"../parser/types.js\";\nimport { COMPILED_PROGRAM_VERSION } from \"./runtime.js\";\n\nexport interface EmitOptions {\n /**\n * Module specifier the emitted code imports `defineCompiledProgram` from.\n * Defaults to `\"aktion-runtime\"`. Override for monorepos / local examples\n * that resolve the runtime under a different name.\n */\n runtimeModuleId?: string;\n}\n\n/**\n * Build the ES module source that exports the compiled program. The result is\n * deterministic for a given `(program, source, path)` so repeated builds and\n * resumed/cached transforms produce byte-identical output.\n */\nexport function emitModule(\n program: Program,\n source: string,\n path: string,\n options: EmitOptions = {},\n): string {\n const runtimeModuleId = options.runtimeModuleId ?? \"aktion-runtime\";\n // Double-encode: `JSON.stringify(program)` is the AST as JSON text;\n // `JSON.stringify(<that text>)` wraps it as a valid JS string literal whose\n // runtime value is the JSON text — `JSON.parse(...)` then rebuilds the tree.\n const programLiteral = JSON.stringify(JSON.stringify(program));\n const sourceLiteral = JSON.stringify(source);\n const pathLiteral = JSON.stringify(path);\n const importLiteral = JSON.stringify(runtimeModuleId);\n\n return (\n `// Generated by the Aktion compiler — do not edit by hand.\\n` +\n `// Source: ${path}\\n` +\n `import { defineCompiledProgram } from ${importLiteral};\\n` +\n `const program = /*#__PURE__*/ JSON.parse(${programLiteral});\\n` +\n `const source = ${sourceLiteral};\\n` +\n `export default /*#__PURE__*/ defineCompiledProgram({ ` +\n `__aktionCompiled: ${COMPILED_PROGRAM_VERSION}, program, source, path: ${pathLiteral} });\\n`\n );\n}\n","/**\n * Source-map generation for the build-time compiler (Node-oriented).\n *\n * Fidelity note — read before \"improving\" this. The Aktion DSL is compiled to\n * an inert data blob (`JSON.parse(...)`), NOT transpiled line-for-line to JS,\n * and the parser records start-only `loc` (line + column, 1-indexed) with no\n * end position or byte offset (see `src/parser/types.ts`). So a high-precision\n * range map is neither possible nor meaningful here. What IS valuable, and\n * what we produce, is a valid v3 map that:\n *\n * - registers the original `.aktion` file as a source with its full content\n * (`sourcesContent`), so it shows up in browser devtools, and\n * - anchors the generated module back to the original source,\n *\n * which is exactly what lets Vite chain the map and surface the original file.\n * Per-statement range mappings are a future enhancement gated on the parser\n * recording end positions.\n *\n * We use `magic-string` (already a transitive dep, promoted to a direct one)\n * because it is the de-facto standard every Vite/Rollup plugin uses, so the\n * VLQ-encoded output is guaranteed compatible with Vite's source-map pipeline.\n */\n\nimport MagicString from \"magic-string\";\n\n/**\n * Plain v3 source map object (decoupled from magic-string's class instance).\n * Shaped to match Vite/Rollup's `ExistingRawSourceMap` so it flows straight\n * into the bundler's source-map pipeline when returned from `transform`.\n */\nexport interface RawSourceMap {\n version: number;\n sources: string[];\n sourcesContent: string[];\n names: string[];\n mappings: string;\n file?: string;\n}\n\n/**\n * Produce a v3 source map tying `generatedCode` back to `source`. `path` names\n * the original file in `sources`; the map's `file` is `path + \".js\"`.\n */\nexport function generateSourceMap(\n source: string,\n generatedCode: string,\n path: string,\n): RawSourceMap {\n const s = new MagicString(source);\n if (source.length > 0) {\n // Replace the whole original buffer with the generated module. This anchors\n // the generated output to the start of the original source while keeping\n // the original content available via `includeContent`.\n s.overwrite(0, source.length, generatedCode);\n } else {\n s.append(generatedCode);\n }\n const map = s.generateMap({ source: path, hires: true });\n // Set `sources`/`sourcesContent`/`file` directly from our known inputs rather\n // than magic-string's values: it relativizes `sources` against `file`, which\n // would drop the full path we want to preserve for tooling.\n return {\n version: map.version,\n sources: [path],\n sourcesContent: [source],\n names: map.names,\n mappings: map.mappings,\n file: `${path}.js`,\n };\n}\n","/**\n * Build-time module linker for multi-file `.aktion` programs (Node-oriented;\n * reachable only via `aktion-runtime/compiler`, never the browser bundle).\n *\n * Resolves the `import`/`export` graph rooted at an entry file and merges it\n * into a single `Program` AST that the runtime evaluates unchanged. Each file\n * gets **true module scope**: its non-exported top-level names are private. We\n * achieve this by renaming every module-local declaration (and `$state` atom,\n * and the references to them) to a per-module-unique symbol, rewriting imported\n * aliases to the source module's renamed export, and concatenating the result.\n *\n * Why renaming is correct (verified against the evaluator): the runtime keys\n * every top-level binding / action / component / hook / `$state` atom purely by\n * string name, and per-instance keys derive from SOURCE LOCATION, not name. So\n * consistent renaming yields an independent, correctly-scoped symbol with no\n * runtime change. The only names that must NOT be renamed are those resolved\n * outside the module (library components, JS globals, `route`, `$util`/\n * `$console`/`$storage`) — they're simply never in a module's rename map — and\n * genuine block-locals introduced by `loopVars` binders (params, loop vars,\n * `catch`, destructuring patterns), which the renamer tracks as shadows.\n */\n\nimport { readFileSync } from \"node:fs\";\nimport { dirname, resolve as resolvePath } from \"node:path\";\n\nimport { parse } from \"../parser/index.js\";\nimport type {\n Program,\n Statement,\n Expression,\n BlockExpr,\n DeclParam,\n LambdaParam,\n DestructuringPattern,\n ImportStatement,\n} from \"../parser/types.js\";\nimport type { CompileDiagnostic } from \"./compile.js\";\n\n/** Injected so the linker can be unit-tested with an in-memory file map. */\nexport interface ModuleResolver {\n /** Resolve a specifier relative to the importer; `null` = unresolved. */\n resolve(spec: string, importerPath: string): string | null;\n /** Load module text by resolved (absolute) path. Throws if missing. */\n load(path: string): string;\n}\n\nexport interface LinkResult {\n /** The merged, scope-renamed program (import statements dropped). */\n program: Program;\n /** Linker errors: unresolved import, missing export, duplicate local, dep parse errors. */\n diagnostics: CompileDiagnostic[];\n /** Absolute paths of the imported modules (excludes the entry). */\n dependencies: string[];\n}\n\n/**\n * Default resolver backed by Node's filesystem: relative specifiers resolve\n * against the importer's directory. (Top-level `node:` imports are externalized\n * in the Node build and this module never enters the browser bundle.)\n */\nexport function createNodeResolver(): ModuleResolver {\n return {\n resolve(spec, importerPath) {\n if (!spec.startsWith(\".\") && !spec.startsWith(\"/\")) return null; // only relative/absolute\n try {\n return resolvePath(dirname(importerPath), spec);\n } catch {\n return null;\n }\n },\n load(path) {\n return readFileSync(path, \"utf8\");\n },\n };\n}\n\ninterface ModuleRecord {\n id: number;\n path: string;\n program: Program;\n /** Resolved import edges (after path resolution). */\n edges: { stmt: ImportStatement; resolvedPath: string | null }[];\n /** Top-level declared names, by keyspace. */\n declaredPlain: Set<string>;\n declaredState: Set<string>;\n /** Exported subset, by keyspace. */\n exportedPlain: Set<string>;\n exportedState: Set<string>;\n /** Rename maps (own locals + imported aliases), by keyspace. */\n renamePlain: Map<string, string>;\n renameState: Map<string, string>;\n}\n\n/**\n * Link the import graph rooted at `entrySource`/`entryPath` into one program.\n */\nexport function linkProgram(\n entrySource: string,\n entryPath: string,\n resolver: ModuleResolver,\n): LinkResult {\n const modules = new Map<string, ModuleRecord>();\n const order: string[] = []; // post-order: dependencies before dependents\n const visiting = new Set<string>();\n const diagnostics: CompileDiagnostic[] = [];\n let nextId = 0;\n\n const fail = (path: string, line: number, column: number, message: string): void => {\n // Path-prefix non-entry diagnostics so the author knows which file.\n diagnostics.push({\n line,\n column,\n message: path === entryPath ? message : `${path}: ${message}`,\n severity: \"error\",\n });\n };\n\n function load(path: string, sourceOverride: string | null): ModuleRecord | undefined {\n const existing = modules.get(path);\n if (existing) return existing;\n if (visiting.has(path)) return undefined; // cycle: in-progress; refs resolve post-merge\n visiting.add(path);\n\n let src: string;\n if (sourceOverride !== null) {\n src = sourceOverride;\n } else {\n try {\n src = resolver.load(path);\n } catch {\n visiting.delete(path);\n fail(entryPath, 0, 0, `Failed to load imported module \"${path}\".`);\n return undefined;\n }\n }\n\n const program = parse(src);\n const rec: ModuleRecord = {\n id: nextId++,\n path,\n program,\n edges: [],\n declaredPlain: new Set(),\n declaredState: new Set(),\n exportedPlain: new Set(),\n exportedState: new Set(),\n renamePlain: new Map(),\n renameState: new Map(),\n };\n modules.set(path, rec);\n buildSymbolTable(rec);\n\n for (const stmt of program.statements) {\n if (stmt.kind !== \"Import\") continue;\n const resolved = resolver.resolve(stmt.source, path);\n rec.edges.push({ stmt, resolvedPath: resolved });\n if (resolved === null) {\n fail(path, stmt.loc?.line ?? 0, stmt.loc?.column ?? 0, `Cannot resolve import \"${stmt.source}\".`);\n continue;\n }\n load(resolved, null);\n }\n\n visiting.delete(path);\n order.push(path);\n return rec;\n }\n\n load(entryPath, entrySource);\n\n // Build rename maps: own declarations first (so imports can target them).\n // The ENTRY module keeps its own names CANONICAL — they are the program's\n // public surface: the `aktion` entry binding, and the `$state` names that\n // `serializeState` / `hydrateState` / `applyDelta` target. Only imported\n // (non-entry) modules are renamed for privacy + collision-freedom. This also\n // makes a single-file program a true no-op (its rename maps stay empty).\n for (const rec of modules.values()) {\n if (rec.path === entryPath) continue;\n for (const name of rec.declaredPlain) rec.renamePlain.set(name, `__a${rec.id}_${name}`);\n for (const name of rec.declaredState) rec.renameState.set(name, `__a${rec.id}_${name}`);\n }\n // Resolve imported aliases to the source module's renamed export.\n for (const rec of modules.values()) {\n for (const { stmt, resolvedPath } of rec.edges) {\n if (resolvedPath === null) continue;\n const src = modules.get(resolvedPath);\n if (!src) continue; // load failed (already diagnosed)\n for (const spec of stmt.specifiers) {\n const line = stmt.loc?.line ?? 0;\n const column = stmt.loc?.column ?? 0;\n if (spec.isState) {\n if (!src.exportedState.has(spec.imported)) {\n fail(rec.path, line, column, `\"${stmt.source}\" does not export \\`$${spec.imported}\\`.`);\n continue;\n }\n rec.renameState.set(spec.local, src.renameState.get(spec.imported) ?? `__a${src.id}_${spec.imported}`);\n } else {\n if (!src.exportedPlain.has(spec.imported)) {\n fail(rec.path, line, column, `\"${stmt.source}\" does not export \\`${spec.imported}\\`.`);\n continue;\n }\n rec.renamePlain.set(spec.local, src.renamePlain.get(spec.imported) ?? `__a${src.id}_${spec.imported}`);\n }\n }\n }\n }\n\n // Rename + merge in dependency order.\n const merged: Statement[] = [];\n for (const path of order) {\n const rec = modules.get(path)!;\n const renamer = makeRenamer(rec);\n for (const stmt of rec.program.statements) {\n if (stmt.kind === \"Import\") continue; // dropped\n renamer.renameTopLevel(stmt);\n stripExported(stmt);\n if (stmt.kind === \"EffectDeclaration\" && rec.path !== entryPath) {\n // De-collide location-named effects across IMPORTED files (linker-only).\n // The entry's effect names stay canonical (single-file = no-op).\n stmt.name = `__effect_a${rec.id}_${stmt.name.replace(/^__effect_/, \"\")}`;\n }\n merged.push(stmt);\n }\n }\n\n const entryRec = modules.get(entryPath);\n // Shape matches `parse()` exactly (no `warnings` key) so a single-file\n // program's merged AST deep-equals `parse(source)`.\n return {\n program: { statements: merged, errors: entryRec ? entryRec.program.errors : [] },\n diagnostics,\n dependencies: order.filter((p) => p !== entryPath),\n };\n}\n\n/**\n * Collect a module's top-level declared/exported names. Names are deduped by\n * the `Set`s; Aktion's top-level bindings are last-wins (re-assignment is legal),\n * so duplicate top-level names are NOT errors.\n */\nfunction buildSymbolTable(rec: ModuleRecord): void {\n for (const stmt of rec.program.statements) {\n switch (stmt.kind) {\n case \"Assignment\":\n if (stmt.isState) {\n rec.declaredState.add(stmt.identifier);\n if (stmt.exported) rec.exportedState.add(stmt.identifier);\n } else {\n rec.declaredPlain.add(stmt.identifier);\n if (stmt.exported) rec.exportedPlain.add(stmt.identifier);\n }\n break;\n case \"ComponentDeclaration\":\n case \"ActionDeclaration\":\n rec.declaredPlain.add(stmt.name);\n if (stmt.exported) rec.exportedPlain.add(stmt.name);\n break;\n case \"HookDeclaration\":\n // Hooks are referenced as `$useX()` → the state keyspace.\n rec.declaredState.add(stmt.name);\n if (stmt.exported) rec.exportedState.add(stmt.name);\n break;\n case \"DestructureStatement\":\n // Top-level destructuring declares module-local (plain) bindings.\n for (const b of stmt.bindings) if (b.name) rec.declaredPlain.add(b.name);\n break;\n default:\n break; // Import / Effect / control-flow declare nothing importable\n }\n }\n}\n\n/** Drop the build-time `exported` flag so the merged AST is clean. */\nfunction stripExported(stmt: Statement): void {\n if (\n stmt.kind === \"Assignment\" ||\n stmt.kind === \"ComponentDeclaration\" ||\n stmt.kind === \"ActionDeclaration\" ||\n stmt.kind === \"HookDeclaration\"\n ) {\n delete (stmt as { exported?: boolean }).exported;\n }\n}\n\n/**\n * Build a scope-aware renamer bound to one module's rename maps. Mutates AST\n * nodes in place (the linker owns freshly-parsed trees).\n */\nfunction makeRenamer(rec: ModuleRecord) {\n const shadow: Set<string>[] = []; // PLAIN local names only (loopVars binders)\n\n const shadowed = (name: string): boolean => {\n for (const set of shadow) if (set.has(name)) return true;\n return false;\n };\n const rPlain = (name: string): string => (shadowed(name) ? name : rec.renamePlain.get(name) ?? name);\n const rState = (name: string): string => rec.renameState.get(name) ?? name;\n const push = (names: string[]): void => {\n shadow.push(new Set(names));\n };\n const pop = (): void => {\n shadow.pop();\n };\n\n const patternNames = (p: DestructuringPattern): string[] =>\n p.bindings.map((b) => b.name).filter((n): n is string => !!n);\n const paramNames = (params: ReadonlyArray<DeclParam | LambdaParam>): string[] => {\n const out: string[] = [];\n for (const p of params) {\n if (p.name) out.push(p.name);\n if (p.pattern) out.push(...patternNames(p.pattern));\n }\n return out;\n };\n const renameParamDefaults = (params: ReadonlyArray<DeclParam | LambdaParam>): void => {\n for (const p of params) if (p.defaultValue) renameExpr(p.defaultValue);\n };\n\n function renameExpr(expr: Expression): void {\n switch (expr.kind) {\n case \"Literal\":\n return;\n case \"Identifier\":\n expr.name = rPlain(expr.name);\n return;\n case \"StateRef\":\n expr.name = rState(expr.name);\n return;\n case \"Array\":\n for (const el of expr.elements) renameExpr(el);\n return;\n case \"Object\":\n for (const prop of expr.properties) {\n if (prop.computedKey) renameExpr(prop.computedKey);\n renameExpr(prop.value); // shorthand `{ x }` keeps key, renames the value Identifier\n }\n return;\n case \"Member\":\n renameExpr(expr.object);\n if (expr.computed) renameExpr(expr.computed);\n return; // never touch `.property`\n case \"Unary\":\n renameExpr(expr.argument);\n return;\n case \"Binary\":\n renameExpr(expr.left);\n renameExpr(expr.right);\n return;\n case \"Ternary\":\n renameExpr(expr.test);\n renameExpr(expr.consequent);\n renameExpr(expr.alternate);\n return;\n case \"Call\":\n expr.callee = rPlain(expr.callee);\n for (const a of expr.arguments) renameExpr(a);\n return;\n case \"MethodCall\":\n renameExpr(expr.object);\n for (const a of expr.arguments) renameExpr(a);\n return; // never touch `.method`\n case \"Invoke\":\n renameExpr(expr.callee); // `$useX()` → StateRef callee handled by renameExpr\n for (const a of expr.arguments) renameExpr(a);\n return;\n case \"BuiltinCall\":\n for (const a of expr.arguments) renameExpr(a);\n return; // internal name, never a user binding\n case \"New\":\n renameExpr(expr.callee);\n for (const a of expr.arguments) renameExpr(a);\n return;\n case \"Template\":\n for (const e of expr.expressions) renameExpr(e);\n return;\n case \"Spread\":\n renameExpr(expr.argument);\n return;\n case \"Lambda\":\n push(paramNames(expr.params));\n renameParamDefaults(expr.params);\n renameExpr(expr.body); // may be a Block\n pop();\n return;\n case \"Block\":\n renameBlock(expr);\n return;\n }\n }\n\n /** Walk a block; block-local destructures / nested decls shadow LATER statements. */\n function renameBlock(block: BlockExpr): void {\n push([]);\n const scope = shadow[shadow.length - 1]!;\n for (const stmt of block.body) {\n renameStatement(stmt, false);\n addBlockLocals(stmt, scope);\n }\n pop();\n }\n\n function addBlockLocals(stmt: Statement, scope: Set<string>): void {\n if (stmt.kind === \"DestructureStatement\") {\n for (const b of stmt.bindings) if (b.name) scope.add(b.name);\n } else if (stmt.kind === \"ComponentDeclaration\" || stmt.kind === \"ActionDeclaration\") {\n scope.add(stmt.name);\n }\n }\n\n /** Top-level statements: destructuring binding names ARE module-locals (renamed). */\n function renameTopLevel(stmt: Statement): void {\n if (stmt.kind === \"DestructureStatement\") {\n renameExpr(stmt.expression);\n for (const b of stmt.bindings) {\n if (b.defaultValue) renameExpr(b.defaultValue);\n b.name = rPlain(b.name);\n }\n return;\n }\n renameStatement(stmt, true);\n }\n\n function renameStatement(stmt: Statement, topLevel: boolean): void {\n switch (stmt.kind) {\n case \"Import\":\n return;\n case \"Assignment\":\n stmt.identifier = stmt.isState ? rState(stmt.identifier) : rPlain(stmt.identifier);\n renameExpr(stmt.expression);\n return;\n case \"ComponentDeclaration\":\n case \"ActionDeclaration\":\n stmt.name = rPlain(stmt.name);\n push(paramNames(stmt.params));\n renameParamDefaults(stmt.params);\n renameBlock(stmt.body);\n pop();\n return;\n case \"HookDeclaration\":\n stmt.name = rState(stmt.name);\n push(paramNames(stmt.params));\n renameParamDefaults(stmt.params);\n renameBlock(stmt.body);\n pop();\n return;\n case \"EffectDeclaration\":\n for (const t of stmt.triggers) if (t.kind === \"state\") t.name = rState(t.name);\n renameBlock(stmt.body);\n return;\n case \"Await\":\n renameExpr(stmt.argument);\n return;\n case \"Return\":\n if (stmt.argument) renameExpr(stmt.argument);\n return;\n case \"ExpressionStatement\":\n renameExpr(stmt.expression);\n return;\n case \"IfStatement\":\n renameExpr(stmt.test);\n renameBlock(stmt.consequent);\n if (stmt.alternate) {\n if (stmt.alternate.kind === \"IfStatement\") renameStatement(stmt.alternate, false);\n else renameBlock(stmt.alternate);\n }\n return;\n case \"SwitchStatement\":\n renameExpr(stmt.discriminant);\n for (const c of stmt.cases) {\n if (c.test) renameExpr(c.test);\n for (const s of c.body) renameStatement(s, false);\n }\n return;\n case \"ForOfStatement\": {\n renameExpr(stmt.iterable);\n const names = [stmt.item];\n if (stmt.index) names.push(stmt.index);\n if (stmt.destructure) names.push(...stmt.destructure);\n push(names);\n renameBlock(stmt.body);\n pop();\n return;\n }\n case \"ForInStatement\":\n renameExpr(stmt.iterable);\n push([stmt.item]);\n renameBlock(stmt.body);\n pop();\n return;\n case \"ForClassicStatement\": {\n const initNames: string[] = [];\n if (stmt.init && stmt.init.kind === \"Assignment\" && stmt.init.identifier) {\n initNames.push(stmt.init.identifier);\n }\n push(initNames);\n if (stmt.init) renameStatement(stmt.init, false);\n if (stmt.test) renameExpr(stmt.test);\n if (stmt.update) renameExpr(stmt.update);\n renameBlock(stmt.body);\n pop();\n return;\n }\n case \"WhileStatement\":\n case \"DoWhileStatement\":\n renameExpr(stmt.test);\n renameBlock(stmt.body);\n return;\n case \"DestructureStatement\":\n // Nested (block-local): rename RHS + defaults, but NOT binding names\n // (they're locals; `renameBlock` adds them to the shadow scope).\n renameExpr(stmt.expression);\n for (const b of stmt.bindings) if (b.defaultValue) renameExpr(b.defaultValue);\n if (topLevel) for (const b of stmt.bindings) b.name = rPlain(b.name);\n return;\n case \"ThrowStatement\":\n renameExpr(stmt.argument);\n return;\n case \"TryStatement\":\n renameBlock(stmt.block);\n if (stmt.catchBlock) {\n push(stmt.catchParam ? [stmt.catchParam] : []);\n renameBlock(stmt.catchBlock);\n pop();\n }\n if (stmt.finallyBlock) renameBlock(stmt.finallyBlock);\n return;\n case \"BreakStatement\":\n case \"ContinueStatement\":\n return;\n }\n }\n\n return { renameTopLevel };\n}\n","/**\n * The build-time compiler core (Node-oriented; NEVER imported by the browser\n * bundle — reachable only via the `aktion-runtime/compiler` entry and the\n * Vite/Rollup plugin).\n *\n * `compile()` is deliberately the SAME two-call sequence the runtime runs in\n * `element.ts` `replan()` — `parse()` then `validateProgramSchema()` — so the\n * build-time diagnostics and the runtime/editor diagnostics can never drift.\n * It additionally generates the emitted module and a source map, and adds one\n * build-only lint (a missing `aktion` entry binding) that's impossible to\n * surface as usefully at runtime.\n */\n\nimport { validateProgramSchema, defaultLibrary } from \"../library/index.js\";\nimport type { ComponentLibrary } from \"../library/types.js\";\nimport type { Program } from \"../parser/types.js\";\nimport { emitModule } from \"./emit.js\";\nimport { generateSourceMap, type RawSourceMap } from \"./sourcemap.js\";\nimport { linkProgram, createNodeResolver, type ModuleResolver } from \"./linker.js\";\n\n/** A single build-time diagnostic. Positions are 1-indexed, matching `loc`. */\nexport interface CompileDiagnostic {\n line: number;\n column: number;\n message: string;\n severity: \"error\" | \"warning\";\n}\n\nexport interface CompileOptions {\n /** Module id / file path — embedded in the artefact + diagnostics + map. */\n path?: string;\n /** Library to validate against. Default: `defaultLibrary`. */\n library?: ComponentLibrary;\n /** Treat schema violations as `error` (fatal) vs `warning`. Default: true. */\n schemaErrorsFatal?: boolean;\n /** Warn when no top-level `aktion = …` entry binding exists. Default: true. */\n requireEntry?: boolean;\n /** Generate a source map. Default: true. */\n sourcemap?: boolean;\n /** Specifier the emitted module imports the runtime helper from. */\n runtimeModuleId?: string;\n /**\n * Resolver for cross-file `import`/`export`. Defaults to a Node fs resolver\n * (relative specifiers resolved against the importer's directory). Tests pass\n * an in-memory resolver. A single-file program never invokes it.\n */\n resolver?: ModuleResolver;\n}\n\nexport interface CompileResult {\n /** ES module text exporting a `CompiledProgram` (default export). */\n code: string;\n /** v3 source map, or `null` when `sourcemap: false`. */\n map: RawSourceMap | null;\n /** Parse + schema + lint diagnostics. The caller decides fatality. */\n diagnostics: CompileDiagnostic[];\n /** The parsed (and, once linked, merged) AST — returned for tests / callers. */\n program: Program;\n /**\n * Absolute paths of imported `.aktion` modules pulled into this program\n * (empty for a single-file program). The Vite plugin registers these with\n * `addWatchFile` so editing a dependency re-triggers the entry's transform.\n */\n dependencies: string[];\n}\n\n/**\n * Parse + validate `source` and generate the compiled ES module. Always\n * returns `code` (even when diagnostics contain errors) so the plugin can\n * choose between failing the build (driving the Vite overlay) and emitting\n * anyway; the plugin owns that policy.\n */\nexport function compile(source: string, options: CompileOptions = {}): CompileResult {\n const path = options.path ?? \"<inline>.aktion\";\n const library = options.library ?? defaultLibrary;\n const schemaErrorsFatal = options.schemaErrorsFatal ?? true;\n const requireEntry = options.requireEntry ?? true;\n const wantMap = options.sourcemap ?? true;\n\n // Resolve + link the import graph into a single merged program. A single-file\n // program (no imports) links to itself — the linker is a no-op and `program`\n // deep-equals `parse(source)`.\n const link = linkProgram(source, path, options.resolver ?? createNodeResolver());\n const program = link.program;\n const diagnostics: CompileDiagnostic[] = [];\n\n // Linker errors (unresolved import, missing export, duplicate local, and\n // imported-module parse errors — already path-prefixed) come first.\n diagnostics.push(...link.diagnostics);\n\n // Entry-file parse errors are always fatal — a malformed program can't mount.\n for (const error of program.errors) {\n diagnostics.push({ line: error.line, column: error.column, message: error.message, severity: \"error\" });\n }\n\n // Schema validation — identical call to the runtime's, so messages match\n // `getDiagnostics(...)` exactly (validation parity).\n for (const error of validateProgramSchema(program, library)) {\n diagnostics.push({\n line: error.line,\n column: error.column,\n message: error.message,\n severity: schemaErrorsFatal ? \"error\" : \"warning\",\n });\n }\n\n // Build-only lint: a program with no `aktion` entry binding renders nothing.\n if (requireEntry && !hasEntryBinding(program)) {\n diagnostics.push({\n line: 1,\n column: 1,\n message:\n \"No top-level `aktion = …` entry binding found — this program renders \" +\n \"nothing. Assign your root component to `aktion` (e.g. `aktion = Card([…])`).\",\n severity: \"warning\",\n });\n }\n\n const code = emitModule(program, source, path, { runtimeModuleId: options.runtimeModuleId });\n const map = wantMap ? generateSourceMap(source, code, path) : null;\n\n return { code, map, diagnostics, program, dependencies: link.dependencies };\n}\n\n/** Whether the program declares the `aktion` entry binding the runtime reads. */\nfunction hasEntryBinding(program: Program): boolean {\n return program.statements.some(\n (stmt) => stmt.kind === \"Assignment\" && stmt.identifier === \"aktion\",\n );\n}\n"],"names":["parse","resolvePath","dirname","readFileSync","defaultLibrary","validateProgramSchema"],"mappings":";;;;;AA6BO,MAAM,2BAA2B;AAwBjC,SAAS,kBAAkB,OAA0C;AAC1E,MAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO;AAChD,QAAM,YAAY;AAClB,SACE,UAAU,qBAAqB,4BAC/B,OAAO,UAAU,WAAW,YAC5B,OAAO,UAAU,SAAS,YAC1B,CAAC,CAAC,UAAU,WACZ,MAAM,QAAS,UAAU,QAAoB,UAAU;AAE3D;AAQO,SAAS,sBAAsB,UAA4C;AAChF,SAAO;AACT;AA2BO,SAAS,YAAY,QAAgB,UAA8B,IAAqB;AAC7F,QAAM,UAAUA,MAAAA,MAAM,MAAM;AAC5B,SAAO,sBAAsB;AAAA,IAC3B,kBAAkB;AAAA,IAClB;AAAA,IACA;AAAA,IACA,MAAM,QAAQ,QAAQ;AAAA,EAAA,CACvB;AACH;AC5EO,SAAS,WACd,SACA,QACA,MACA,UAAuB,CAAA,GACf;AACR,QAAM,kBAAkB,QAAQ,mBAAmB;AAInD,QAAM,iBAAiB,KAAK,UAAU,KAAK,UAAU,OAAO,CAAC;AAC7D,QAAM,gBAAgB,KAAK,UAAU,MAAM;AAC3C,QAAM,cAA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,aAAa;AAKrC,QAAM,OAAO,YAAY,QAAQ,MAAM,QAAQ,YAAY,oBAAoB;AAC/E,QAAM,UAAU,KAAK;AACrB,QAAM,cAAmC,CAAA;AAIzC,cAAY,KAAK,GAAG,KAAK,WAAW;AAGpC,aAAW,SAAS,QAAQ,QAAQ;AAClC,gBAAY,KAAK,EAAE,MAAM,MAAM,MAAM,QAAQ,MAAM,QAAQ,SAAS,MAAM,SAAS,UAAU,SAAS;AAAA,EACxG;AAIA,aAAW,SAASC,MAAAA,sBAAsB,SAAS,OAAO,GAAG;AAC3D,gBAAY,KAAK;AAAA,MACf,MAAM,MAAM;AAAA,MACZ,QAAQ,MAAM;AAAA,MACd,SAAS,MAAM;AAAA,MACf,UAAU,oBAAoB,UAAU;AAAA,IAAA,CACzC;AAAA,EACH;AAGA,MAAI,gBAAgB,CAAC,gBAAgB,OAAO,GAAG;AAC7C,gBAAY,KAAK;AAAA,MACf,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,SACE;AAAA,MAEF,UAAU;AAAA,IAAA,CACX;AAAA,EACH;AAEA,QAAM,OAAO,WAAW,SAAS,QAAQ,MAAM,EAAE,iBAAiB,QAAQ,iBAAiB;AAC3F,QAAM,MAAM,UAAU,kBAAkB,QAAQ,MAAM,IAAI,IAAI;AAE9D,SAAO,EAAE,MAAM,KAAK,aAAa,SAAS,cAAc,KAAK,aAAA;AAC/D;AAGA,SAAS,gBAAgB,SAA2B;AAClD,SAAO,QAAQ,WAAW;AAAA,IACxB,CAAC,SAAS,KAAK,SAAS,gBAAgB,KAAK,eAAe;AAAA,EAAA;AAEhE;;;;;;;;"}
@@ -1,492 +0,0 @@
1
- import { p as parse, d as defaultLibrary, v as validateProgramSchema } from "./index-8OvnOYPI.js";
2
- import MagicString from "magic-string";
3
- import { readFileSync } from "node:fs";
4
- import { resolve, dirname } from "node:path";
5
- const COMPILED_PROGRAM_VERSION = 1;
6
- function isCompiledProgram(value) {
7
- if (!value || typeof value !== "object") return false;
8
- const candidate = value;
9
- return candidate.__aktionCompiled === COMPILED_PROGRAM_VERSION && typeof candidate.source === "string" && typeof candidate.path === "string" && !!candidate.program && Array.isArray(candidate.program.statements);
10
- }
11
- function defineCompiledProgram(compiled) {
12
- return compiled;
13
- }
14
- function compileLite(source, options = {}) {
15
- const program = parse(source);
16
- return defineCompiledProgram({
17
- __aktionCompiled: COMPILED_PROGRAM_VERSION,
18
- program,
19
- source,
20
- path: options.path ?? "<inline>"
21
- });
22
- }
23
- function emitModule(program, source, path, options = {}) {
24
- const runtimeModuleId = options.runtimeModuleId ?? "aktion-runtime";
25
- const programLiteral = JSON.stringify(JSON.stringify(program));
26
- const sourceLiteral = JSON.stringify(source);
27
- const pathLiteral = JSON.stringify(path);
28
- const importLiteral = JSON.stringify(runtimeModuleId);
29
- return `// Generated by the Aktion compiler — do not edit by hand.
30
- // Source: ${path}
31
- import { defineCompiledProgram } from ${importLiteral};
32
- const program = /*#__PURE__*/ JSON.parse(${programLiteral});
33
- const source = ${sourceLiteral};
34
- export default /*#__PURE__*/ defineCompiledProgram({ __aktionCompiled: ${COMPILED_PROGRAM_VERSION}, program, source, path: ${pathLiteral} });
35
- `;
36
- }
37
- function generateSourceMap(source, generatedCode, path) {
38
- const s = new MagicString(source);
39
- if (source.length > 0) {
40
- s.overwrite(0, source.length, generatedCode);
41
- } else {
42
- s.append(generatedCode);
43
- }
44
- const map = s.generateMap({ source: path, hires: true });
45
- return {
46
- version: map.version,
47
- sources: [path],
48
- sourcesContent: [source],
49
- names: map.names,
50
- mappings: map.mappings,
51
- file: `${path}.js`
52
- };
53
- }
54
- function createNodeResolver() {
55
- return {
56
- resolve(spec, importerPath) {
57
- if (!spec.startsWith(".") && !spec.startsWith("/")) return null;
58
- try {
59
- return resolve(dirname(importerPath), spec);
60
- } catch {
61
- return null;
62
- }
63
- },
64
- load(path) {
65
- return readFileSync(path, "utf8");
66
- }
67
- };
68
- }
69
- function linkProgram(entrySource, entryPath, resolver) {
70
- const modules = /* @__PURE__ */ new Map();
71
- const order = [];
72
- const visiting = /* @__PURE__ */ new Set();
73
- const diagnostics = [];
74
- let nextId = 0;
75
- const fail = (path, line, column, message) => {
76
- diagnostics.push({
77
- line,
78
- column,
79
- message: path === entryPath ? message : `${path}: ${message}`,
80
- severity: "error"
81
- });
82
- };
83
- function load(path, sourceOverride) {
84
- const existing = modules.get(path);
85
- if (existing) return existing;
86
- if (visiting.has(path)) return void 0;
87
- visiting.add(path);
88
- let src;
89
- if (sourceOverride !== null) {
90
- src = sourceOverride;
91
- } else {
92
- try {
93
- src = resolver.load(path);
94
- } catch {
95
- visiting.delete(path);
96
- fail(entryPath, 0, 0, `Failed to load imported module "${path}".`);
97
- return void 0;
98
- }
99
- }
100
- const program = parse(src);
101
- const rec = {
102
- id: nextId++,
103
- path,
104
- program,
105
- edges: [],
106
- declaredPlain: /* @__PURE__ */ new Set(),
107
- declaredState: /* @__PURE__ */ new Set(),
108
- exportedPlain: /* @__PURE__ */ new Set(),
109
- exportedState: /* @__PURE__ */ new Set(),
110
- renamePlain: /* @__PURE__ */ new Map(),
111
- renameState: /* @__PURE__ */ new Map()
112
- };
113
- modules.set(path, rec);
114
- buildSymbolTable(rec);
115
- for (const stmt of program.statements) {
116
- if (stmt.kind !== "Import") continue;
117
- const resolved = resolver.resolve(stmt.source, path);
118
- rec.edges.push({ stmt, resolvedPath: resolved });
119
- if (resolved === null) {
120
- fail(path, stmt.loc?.line ?? 0, stmt.loc?.column ?? 0, `Cannot resolve import "${stmt.source}".`);
121
- continue;
122
- }
123
- load(resolved, null);
124
- }
125
- visiting.delete(path);
126
- order.push(path);
127
- return rec;
128
- }
129
- load(entryPath, entrySource);
130
- for (const rec of modules.values()) {
131
- if (rec.path === entryPath) continue;
132
- for (const name of rec.declaredPlain) rec.renamePlain.set(name, `__a${rec.id}_${name}`);
133
- for (const name of rec.declaredState) rec.renameState.set(name, `__a${rec.id}_${name}`);
134
- }
135
- for (const rec of modules.values()) {
136
- for (const { stmt, resolvedPath } of rec.edges) {
137
- if (resolvedPath === null) continue;
138
- const src = modules.get(resolvedPath);
139
- if (!src) continue;
140
- for (const spec of stmt.specifiers) {
141
- const line = stmt.loc?.line ?? 0;
142
- const column = stmt.loc?.column ?? 0;
143
- if (spec.isState) {
144
- if (!src.exportedState.has(spec.imported)) {
145
- fail(rec.path, line, column, `"${stmt.source}" does not export \`$${spec.imported}\`.`);
146
- continue;
147
- }
148
- rec.renameState.set(spec.local, src.renameState.get(spec.imported) ?? `__a${src.id}_${spec.imported}`);
149
- } else {
150
- if (!src.exportedPlain.has(spec.imported)) {
151
- fail(rec.path, line, column, `"${stmt.source}" does not export \`${spec.imported}\`.`);
152
- continue;
153
- }
154
- rec.renamePlain.set(spec.local, src.renamePlain.get(spec.imported) ?? `__a${src.id}_${spec.imported}`);
155
- }
156
- }
157
- }
158
- }
159
- const merged = [];
160
- for (const path of order) {
161
- const rec = modules.get(path);
162
- const renamer = makeRenamer(rec);
163
- for (const stmt of rec.program.statements) {
164
- if (stmt.kind === "Import") continue;
165
- renamer.renameTopLevel(stmt);
166
- stripExported(stmt);
167
- if (stmt.kind === "EffectDeclaration" && rec.path !== entryPath) {
168
- stmt.name = `__effect_a${rec.id}_${stmt.name.replace(/^__effect_/, "")}`;
169
- }
170
- merged.push(stmt);
171
- }
172
- }
173
- const entryRec = modules.get(entryPath);
174
- return {
175
- program: { statements: merged, errors: entryRec ? entryRec.program.errors : [] },
176
- diagnostics,
177
- dependencies: order.filter((p) => p !== entryPath)
178
- };
179
- }
180
- function buildSymbolTable(rec) {
181
- for (const stmt of rec.program.statements) {
182
- switch (stmt.kind) {
183
- case "Assignment":
184
- if (stmt.isState) {
185
- rec.declaredState.add(stmt.identifier);
186
- if (stmt.exported) rec.exportedState.add(stmt.identifier);
187
- } else {
188
- rec.declaredPlain.add(stmt.identifier);
189
- if (stmt.exported) rec.exportedPlain.add(stmt.identifier);
190
- }
191
- break;
192
- case "ComponentDeclaration":
193
- case "ActionDeclaration":
194
- rec.declaredPlain.add(stmt.name);
195
- if (stmt.exported) rec.exportedPlain.add(stmt.name);
196
- break;
197
- case "HookDeclaration":
198
- rec.declaredState.add(stmt.name);
199
- if (stmt.exported) rec.exportedState.add(stmt.name);
200
- break;
201
- case "DestructureStatement":
202
- for (const b of stmt.bindings) if (b.name) rec.declaredPlain.add(b.name);
203
- break;
204
- }
205
- }
206
- }
207
- function stripExported(stmt) {
208
- if (stmt.kind === "Assignment" || stmt.kind === "ComponentDeclaration" || stmt.kind === "ActionDeclaration" || stmt.kind === "HookDeclaration") {
209
- delete stmt.exported;
210
- }
211
- }
212
- function makeRenamer(rec) {
213
- const shadow = [];
214
- const shadowed = (name) => {
215
- for (const set of shadow) if (set.has(name)) return true;
216
- return false;
217
- };
218
- const rPlain = (name) => shadowed(name) ? name : rec.renamePlain.get(name) ?? name;
219
- const rState = (name) => rec.renameState.get(name) ?? name;
220
- const push = (names) => {
221
- shadow.push(new Set(names));
222
- };
223
- const pop = () => {
224
- shadow.pop();
225
- };
226
- const patternNames = (p) => p.bindings.map((b) => b.name).filter((n) => !!n);
227
- const paramNames = (params) => {
228
- const out = [];
229
- for (const p of params) {
230
- if (p.name) out.push(p.name);
231
- if (p.pattern) out.push(...patternNames(p.pattern));
232
- }
233
- return out;
234
- };
235
- const renameParamDefaults = (params) => {
236
- for (const p of params) if (p.defaultValue) renameExpr(p.defaultValue);
237
- };
238
- function renameExpr(expr) {
239
- switch (expr.kind) {
240
- case "Literal":
241
- return;
242
- case "Identifier":
243
- expr.name = rPlain(expr.name);
244
- return;
245
- case "StateRef":
246
- expr.name = rState(expr.name);
247
- return;
248
- case "Array":
249
- for (const el of expr.elements) renameExpr(el);
250
- return;
251
- case "Object":
252
- for (const prop of expr.properties) {
253
- if (prop.computedKey) renameExpr(prop.computedKey);
254
- renameExpr(prop.value);
255
- }
256
- return;
257
- case "Member":
258
- renameExpr(expr.object);
259
- if (expr.computed) renameExpr(expr.computed);
260
- return;
261
- case "Unary":
262
- renameExpr(expr.argument);
263
- return;
264
- case "Binary":
265
- renameExpr(expr.left);
266
- renameExpr(expr.right);
267
- return;
268
- case "Ternary":
269
- renameExpr(expr.test);
270
- renameExpr(expr.consequent);
271
- renameExpr(expr.alternate);
272
- return;
273
- case "Call":
274
- expr.callee = rPlain(expr.callee);
275
- for (const a of expr.arguments) renameExpr(a);
276
- return;
277
- case "MethodCall":
278
- renameExpr(expr.object);
279
- for (const a of expr.arguments) renameExpr(a);
280
- return;
281
- case "Invoke":
282
- renameExpr(expr.callee);
283
- for (const a of expr.arguments) renameExpr(a);
284
- return;
285
- case "BuiltinCall":
286
- for (const a of expr.arguments) renameExpr(a);
287
- return;
288
- case "New":
289
- renameExpr(expr.callee);
290
- for (const a of expr.arguments) renameExpr(a);
291
- return;
292
- case "Template":
293
- for (const e of expr.expressions) renameExpr(e);
294
- return;
295
- case "Spread":
296
- renameExpr(expr.argument);
297
- return;
298
- case "Lambda":
299
- push(paramNames(expr.params));
300
- renameParamDefaults(expr.params);
301
- renameExpr(expr.body);
302
- pop();
303
- return;
304
- case "Block":
305
- renameBlock(expr);
306
- return;
307
- }
308
- }
309
- function renameBlock(block) {
310
- push([]);
311
- const scope = shadow[shadow.length - 1];
312
- for (const stmt of block.body) {
313
- renameStatement(stmt, false);
314
- addBlockLocals(stmt, scope);
315
- }
316
- pop();
317
- }
318
- function addBlockLocals(stmt, scope) {
319
- if (stmt.kind === "DestructureStatement") {
320
- for (const b of stmt.bindings) if (b.name) scope.add(b.name);
321
- } else if (stmt.kind === "ComponentDeclaration" || stmt.kind === "ActionDeclaration") {
322
- scope.add(stmt.name);
323
- }
324
- }
325
- function renameTopLevel(stmt) {
326
- if (stmt.kind === "DestructureStatement") {
327
- renameExpr(stmt.expression);
328
- for (const b of stmt.bindings) {
329
- if (b.defaultValue) renameExpr(b.defaultValue);
330
- b.name = rPlain(b.name);
331
- }
332
- return;
333
- }
334
- renameStatement(stmt, true);
335
- }
336
- function renameStatement(stmt, topLevel) {
337
- switch (stmt.kind) {
338
- case "Import":
339
- return;
340
- case "Assignment":
341
- stmt.identifier = stmt.isState ? rState(stmt.identifier) : rPlain(stmt.identifier);
342
- renameExpr(stmt.expression);
343
- return;
344
- case "ComponentDeclaration":
345
- case "ActionDeclaration":
346
- stmt.name = rPlain(stmt.name);
347
- push(paramNames(stmt.params));
348
- renameParamDefaults(stmt.params);
349
- renameBlock(stmt.body);
350
- pop();
351
- return;
352
- case "HookDeclaration":
353
- stmt.name = rState(stmt.name);
354
- push(paramNames(stmt.params));
355
- renameParamDefaults(stmt.params);
356
- renameBlock(stmt.body);
357
- pop();
358
- return;
359
- case "EffectDeclaration":
360
- for (const t of stmt.triggers) if (t.kind === "state") t.name = rState(t.name);
361
- renameBlock(stmt.body);
362
- return;
363
- case "Await":
364
- renameExpr(stmt.argument);
365
- return;
366
- case "Return":
367
- if (stmt.argument) renameExpr(stmt.argument);
368
- return;
369
- case "ExpressionStatement":
370
- renameExpr(stmt.expression);
371
- return;
372
- case "IfStatement":
373
- renameExpr(stmt.test);
374
- renameBlock(stmt.consequent);
375
- if (stmt.alternate) {
376
- if (stmt.alternate.kind === "IfStatement") renameStatement(stmt.alternate, false);
377
- else renameBlock(stmt.alternate);
378
- }
379
- return;
380
- case "SwitchStatement":
381
- renameExpr(stmt.discriminant);
382
- for (const c of stmt.cases) {
383
- if (c.test) renameExpr(c.test);
384
- for (const s of c.body) renameStatement(s, false);
385
- }
386
- return;
387
- case "ForOfStatement": {
388
- renameExpr(stmt.iterable);
389
- const names = [stmt.item];
390
- if (stmt.index) names.push(stmt.index);
391
- if (stmt.destructure) names.push(...stmt.destructure);
392
- push(names);
393
- renameBlock(stmt.body);
394
- pop();
395
- return;
396
- }
397
- case "ForInStatement":
398
- renameExpr(stmt.iterable);
399
- push([stmt.item]);
400
- renameBlock(stmt.body);
401
- pop();
402
- return;
403
- case "ForClassicStatement": {
404
- const initNames = [];
405
- if (stmt.init && stmt.init.kind === "Assignment" && stmt.init.identifier) {
406
- initNames.push(stmt.init.identifier);
407
- }
408
- push(initNames);
409
- if (stmt.init) renameStatement(stmt.init, false);
410
- if (stmt.test) renameExpr(stmt.test);
411
- if (stmt.update) renameExpr(stmt.update);
412
- renameBlock(stmt.body);
413
- pop();
414
- return;
415
- }
416
- case "WhileStatement":
417
- case "DoWhileStatement":
418
- renameExpr(stmt.test);
419
- renameBlock(stmt.body);
420
- return;
421
- case "DestructureStatement":
422
- renameExpr(stmt.expression);
423
- for (const b of stmt.bindings) if (b.defaultValue) renameExpr(b.defaultValue);
424
- if (topLevel) for (const b of stmt.bindings) b.name = rPlain(b.name);
425
- return;
426
- case "ThrowStatement":
427
- renameExpr(stmt.argument);
428
- return;
429
- case "TryStatement":
430
- renameBlock(stmt.block);
431
- if (stmt.catchBlock) {
432
- push(stmt.catchParam ? [stmt.catchParam] : []);
433
- renameBlock(stmt.catchBlock);
434
- pop();
435
- }
436
- if (stmt.finallyBlock) renameBlock(stmt.finallyBlock);
437
- return;
438
- case "BreakStatement":
439
- case "ContinueStatement":
440
- return;
441
- }
442
- }
443
- return { renameTopLevel };
444
- }
445
- function compile(source, options = {}) {
446
- const path = options.path ?? "<inline>.aktion";
447
- const library = options.library ?? defaultLibrary;
448
- const schemaErrorsFatal = options.schemaErrorsFatal ?? true;
449
- const requireEntry = options.requireEntry ?? true;
450
- const wantMap = options.sourcemap ?? true;
451
- const link = linkProgram(source, path, options.resolver ?? createNodeResolver());
452
- const program = link.program;
453
- const diagnostics = [];
454
- diagnostics.push(...link.diagnostics);
455
- for (const error of program.errors) {
456
- diagnostics.push({ line: error.line, column: error.column, message: error.message, severity: "error" });
457
- }
458
- for (const error of validateProgramSchema(program, library)) {
459
- diagnostics.push({
460
- line: error.line,
461
- column: error.column,
462
- message: error.message,
463
- severity: schemaErrorsFatal ? "error" : "warning"
464
- });
465
- }
466
- if (requireEntry && !hasEntryBinding(program)) {
467
- diagnostics.push({
468
- line: 1,
469
- column: 1,
470
- message: "No top-level `aktion = …` entry binding found — this program renders nothing. Assign your root component to `aktion` (e.g. `aktion = Card([…])`).",
471
- severity: "warning"
472
- });
473
- }
474
- const code = emitModule(program, source, path, { runtimeModuleId: options.runtimeModuleId });
475
- const map = wantMap ? generateSourceMap(source, code, path) : null;
476
- return { code, map, diagnostics, program, dependencies: link.dependencies };
477
- }
478
- function hasEntryBinding(program) {
479
- return program.statements.some(
480
- (stmt) => stmt.kind === "Assignment" && stmt.identifier === "aktion"
481
- );
482
- }
483
- export {
484
- COMPILED_PROGRAM_VERSION as C,
485
- compileLite as a,
486
- compile as c,
487
- defineCompiledProgram as d,
488
- emitModule as e,
489
- generateSourceMap as g,
490
- isCompiledProgram as i
491
- };
492
- //# sourceMappingURL=compile-DxttTzo8.js.map