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.
- package/README.md +90 -114
- package/dist/aktion.iife.js +106 -460
- package/dist/aktion.iife.js.map +1 -1
- package/dist/aktion.js +5530 -5076
- package/dist/aktion.js.map +1 -1
- package/dist/aktion.umd.cjs +106 -460
- package/dist/aktion.umd.cjs.map +1 -1
- package/dist/devtools.js +1367 -0
- package/dist/devtools.js.map +1 -0
- package/dist/{node/index-8OvnOYPI.js → language.js} +13669 -12428
- package/dist/language.js.map +1 -0
- package/dist/plugin.cjs +2650 -0
- package/dist/plugin.cjs.map +1 -0
- package/dist/plugin.js +2650 -0
- package/dist/plugin.js.map +1 -0
- package/dist/system_prompt.txt +164 -447
- package/dist/system_prompt_chat.txt +33 -84
- package/dist/{node/index-DBgA3bHQ.cjs → testing.js} +28116 -12689
- package/dist/testing.js.map +1 -0
- package/dist/types/aktion-modules.d.ts +6 -10
- package/dist/types/compiler/index.d.ts +9 -11
- package/dist/types/compiler/linker.d.ts +11 -11
- package/dist/types/compiler/project.d.ts +45 -0
- package/dist/types/compiler/runtime.d.ts +22 -26
- package/dist/types/devtools/hook.d.ts +88 -0
- package/dist/types/devtools/index.d.ts +35 -0
- package/dist/types/devtools/panel.d.ts +109 -0
- package/dist/types/devtools/protocol.d.ts +130 -0
- package/dist/types/devtools/styles.d.ts +7 -0
- package/dist/types/element.d.ts +56 -24
- package/dist/types/index.d.ts +1 -1
- package/dist/types/language-api.d.ts +8 -8
- package/dist/types/parser/types.d.ts +8 -8
- package/dist/types/plugin/index.d.ts +13 -6
- package/dist/types/renderer/renderer.d.ts +28 -0
- package/dist/types/runtime/builtins.d.ts +5 -11
- package/dist/types/runtime/effects.d.ts +15 -0
- package/dist/types/runtime/http.d.ts +0 -1
- package/dist/types/testing/index.d.ts +201 -0
- package/dist/types/theme/index.d.ts +3 -3
- package/dist/types/theme/styles.d.ts +1 -1
- package/dist/types/tooling/formatter.d.ts +7 -1
- package/dist/types/tooling/index.d.ts +0 -3
- package/package.json +21 -19
- package/dist/node/compile-BUw0GAvN.cjs +0 -491
- package/dist/node/compile-BUw0GAvN.cjs.map +0 -1
- package/dist/node/compile-DxttTzo8.js +0 -492
- package/dist/node/compile-DxttTzo8.js.map +0 -1
- package/dist/node/compiler.cjs +0 -11
- package/dist/node/compiler.cjs.map +0 -1
- package/dist/node/compiler.js +0 -11
- package/dist/node/compiler.js.map +0 -1
- package/dist/node/index-8OvnOYPI.js.map +0 -1
- package/dist/node/index-DBgA3bHQ.cjs.map +0 -1
- package/dist/node/language.cjs +0 -1244
- package/dist/node/language.cjs.map +0 -1
- package/dist/node/language.js +0 -1244
- package/dist/node/language.js.map +0 -1
- package/dist/node/vite.cjs +0 -65
- package/dist/node/vite.cjs.map +0 -1
- package/dist/node/vite.js +0 -65
- package/dist/node/vite.js.map +0 -1
- package/dist/types/compiler/compile.d.ts +0 -54
- package/dist/types/compiler/emit.d.ts +0 -15
- package/dist/types/compiler/sourcemap.d.ts +0 -40
- package/dist/types/library/components/theme.d.ts +0 -2
- package/dist/types/plugin/vite.d.ts +0 -21
- package/dist/types/tooling/codemod.d.ts +0 -36
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParseError } from '../parser/types.js';
|
|
1
|
+
import { ParseError, Program } from '../parser/types.js';
|
|
2
2
|
export interface FormatResult {
|
|
3
3
|
/** Canonical source. Equal to the input when parse errors occur. */
|
|
4
4
|
formatted: string;
|
|
@@ -6,3 +6,9 @@ export interface FormatResult {
|
|
|
6
6
|
errors: ParseError[];
|
|
7
7
|
}
|
|
8
8
|
export declare function formatProgram(source: string): FormatResult;
|
|
9
|
+
/**
|
|
10
|
+
* Re-emit a parsed `Program` as canonical Aktion source. Exported so the
|
|
11
|
+
* module linker can serialise a merged (multi-file → single) program back to
|
|
12
|
+
* text for `mountCompiled`'s round-trip fields (reconnect re-parse, snapshots).
|
|
13
|
+
*/
|
|
14
|
+
export declare function printProgram(program: Program): string;
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
*
|
|
12
12
|
* - `formatProgram(source)` — canonical pretty-printer.
|
|
13
13
|
* - `applyDelta(source, ops)` — structured edit protocol (§14).
|
|
14
|
-
* - `migrateV1(source)` — best-effort v1 → 0.5 codemod (Appendix A).
|
|
15
14
|
* - `inspectAST(source)` — Committed + Drafting AST snapshot.
|
|
16
15
|
* - `getDiagnostics(source, library)` — language-service diagnostics.
|
|
17
16
|
* - `getCompletions(source, position, library)` — completions.
|
|
@@ -21,8 +20,6 @@ export { formatProgram } from './formatter.js';
|
|
|
21
20
|
export type { FormatResult } from './formatter.js';
|
|
22
21
|
export { applyDelta } from './delta.js';
|
|
23
22
|
export type { DeltaOp, DeltaResult } from './delta.js';
|
|
24
|
-
export { migrateV1 } from './codemod.js';
|
|
25
|
-
export type { MigrateV1Result } from './codemod.js';
|
|
26
23
|
export { inspectAST, inspectProgram } from './inspector.js';
|
|
27
24
|
export type { InspectorBinding, InspectorView } from './inspector.js';
|
|
28
25
|
export { getDiagnostics, getCompletions, getHoverInfo, } from './language-service.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aktion-runtime",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"description": "Aktion is a single web component that turns a compact, streaming-first DSL into a rich, interactive UI inside its shadow DOM. Works in React, Vue, Angular, Svelte, plain HTML — or no framework at all.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -12,20 +12,22 @@
|
|
|
12
12
|
"import": "./dist/index.js",
|
|
13
13
|
"require": "./dist/index.cjs"
|
|
14
14
|
},
|
|
15
|
-
"./
|
|
16
|
-
"types": "./dist/types/
|
|
17
|
-
"import": "./dist/
|
|
18
|
-
"require": "./dist/node/vite.cjs"
|
|
15
|
+
"./test": {
|
|
16
|
+
"types": "./dist/types/testing/index.d.ts",
|
|
17
|
+
"import": "./dist/testing.js"
|
|
19
18
|
},
|
|
20
|
-
"./
|
|
21
|
-
"types": "./dist/types/
|
|
22
|
-
"import": "./dist/
|
|
23
|
-
"require": "./dist/node/compiler.cjs"
|
|
19
|
+
"./devtools": {
|
|
20
|
+
"types": "./dist/types/devtools/index.d.ts",
|
|
21
|
+
"import": "./dist/devtools.js"
|
|
24
22
|
},
|
|
25
23
|
"./language": {
|
|
26
24
|
"types": "./dist/types/language-api.d.ts",
|
|
27
|
-
"import": "./dist/
|
|
28
|
-
|
|
25
|
+
"import": "./dist/language.js"
|
|
26
|
+
},
|
|
27
|
+
"./vite": {
|
|
28
|
+
"types": "./dist/types/plugin/index.d.ts",
|
|
29
|
+
"import": "./dist/plugin.js",
|
|
30
|
+
"require": "./dist/plugin.cjs"
|
|
29
31
|
},
|
|
30
32
|
"./aktion-modules": {
|
|
31
33
|
"types": "./dist/types/aktion-modules.d.ts"
|
|
@@ -42,9 +44,12 @@
|
|
|
42
44
|
},
|
|
43
45
|
"scripts": {
|
|
44
46
|
"dev": "npm run build && vite",
|
|
45
|
-
"build": "tsc -p tsconfig.build.json && vite build && vite build
|
|
47
|
+
"build": "tsc -p tsconfig.build.json && vite build && vite build --config vite.testing.config.ts && vite build --config vite.devtools.config.ts && vite build --config vite.language.config.ts && vite build --config vite.plugin.config.ts && node scripts/emit-prompt.mjs && node scripts/emit-entry.mjs",
|
|
46
48
|
"build:lib": "vite build",
|
|
47
|
-
"build:
|
|
49
|
+
"build:test": "vite build --config vite.testing.config.ts",
|
|
50
|
+
"build:devtools": "vite build --config vite.devtools.config.ts",
|
|
51
|
+
"build:language": "vite build --config vite.language.config.ts",
|
|
52
|
+
"build:plugin": "vite build --config vite.plugin.config.ts",
|
|
48
53
|
"build:prompt": "node scripts/emit-prompt.mjs",
|
|
49
54
|
"build:entry": "node scripts/emit-entry.mjs",
|
|
50
55
|
"build:docs": "node scripts/build-docs.mjs",
|
|
@@ -53,9 +58,6 @@
|
|
|
53
58
|
"test:watch": "vitest",
|
|
54
59
|
"prepublishOnly": "npm run build"
|
|
55
60
|
},
|
|
56
|
-
"dependencies": {
|
|
57
|
-
"magic-string": "^0.30.0"
|
|
58
|
-
},
|
|
59
61
|
"peerDependencies": {
|
|
60
62
|
"vite": "^5.0.0 || ^6.0.0"
|
|
61
63
|
},
|
|
@@ -66,12 +68,12 @@
|
|
|
66
68
|
},
|
|
67
69
|
"devDependencies": {
|
|
68
70
|
"@types/node": "^20.19.41",
|
|
69
|
-
"@vitest/web-worker": "^2.1.4",
|
|
70
|
-
"happy-dom": "^15.7.4",
|
|
71
71
|
"typescript": "^5.6.3",
|
|
72
72
|
"vite": "^5.4.10",
|
|
73
73
|
"vite-plugin-dts": "^4.3.0",
|
|
74
|
-
"vitest": "^2.1.4"
|
|
74
|
+
"vitest": "^2.1.4",
|
|
75
|
+
"@vitest/web-worker": "^2.1.4",
|
|
76
|
+
"happy-dom": "^15.7.4"
|
|
75
77
|
},
|
|
76
78
|
"keywords": [
|
|
77
79
|
"llm",
|
|
@@ -1,491 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const index = require("./index-DBgA3bHQ.cjs");
|
|
3
|
-
const MagicString = require("magic-string");
|
|
4
|
-
const node_fs = require("node:fs");
|
|
5
|
-
const node_path = require("node:path");
|
|
6
|
-
const COMPILED_PROGRAM_VERSION = 1;
|
|
7
|
-
function isCompiledProgram(value) {
|
|
8
|
-
if (!value || typeof value !== "object") return false;
|
|
9
|
-
const candidate = value;
|
|
10
|
-
return candidate.__aktionCompiled === COMPILED_PROGRAM_VERSION && typeof candidate.source === "string" && typeof candidate.path === "string" && !!candidate.program && Array.isArray(candidate.program.statements);
|
|
11
|
-
}
|
|
12
|
-
function defineCompiledProgram(compiled) {
|
|
13
|
-
return compiled;
|
|
14
|
-
}
|
|
15
|
-
function compileLite(source, options = {}) {
|
|
16
|
-
const program = index.parse(source);
|
|
17
|
-
return defineCompiledProgram({
|
|
18
|
-
__aktionCompiled: COMPILED_PROGRAM_VERSION,
|
|
19
|
-
program,
|
|
20
|
-
source,
|
|
21
|
-
path: options.path ?? "<inline>"
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
function emitModule(program, source, path, options = {}) {
|
|
25
|
-
const runtimeModuleId = options.runtimeModuleId ?? "aktion-runtime";
|
|
26
|
-
const programLiteral = JSON.stringify(JSON.stringify(program));
|
|
27
|
-
const sourceLiteral = JSON.stringify(source);
|
|
28
|
-
const pathLiteral = JSON.stringify(path);
|
|
29
|
-
const importLiteral = JSON.stringify(runtimeModuleId);
|
|
30
|
-
return `// Generated by the Aktion compiler — do not edit by hand.
|
|
31
|
-
// Source: ${path}
|
|
32
|
-
import { defineCompiledProgram } from ${importLiteral};
|
|
33
|
-
const program = /*#__PURE__*/ JSON.parse(${programLiteral});
|
|
34
|
-
const source = ${sourceLiteral};
|
|
35
|
-
export default /*#__PURE__*/ defineCompiledProgram({ __aktionCompiled: ${COMPILED_PROGRAM_VERSION}, program, source, path: ${pathLiteral} });
|
|
36
|
-
`;
|
|
37
|
-
}
|
|
38
|
-
function generateSourceMap(source, generatedCode, path) {
|
|
39
|
-
const s = new MagicString(source);
|
|
40
|
-
if (source.length > 0) {
|
|
41
|
-
s.overwrite(0, source.length, generatedCode);
|
|
42
|
-
} else {
|
|
43
|
-
s.append(generatedCode);
|
|
44
|
-
}
|
|
45
|
-
const map = s.generateMap({ source: path, hires: true });
|
|
46
|
-
return {
|
|
47
|
-
version: map.version,
|
|
48
|
-
sources: [path],
|
|
49
|
-
sourcesContent: [source],
|
|
50
|
-
names: map.names,
|
|
51
|
-
mappings: map.mappings,
|
|
52
|
-
file: `${path}.js`
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function createNodeResolver() {
|
|
56
|
-
return {
|
|
57
|
-
resolve(spec, importerPath) {
|
|
58
|
-
if (!spec.startsWith(".") && !spec.startsWith("/")) return null;
|
|
59
|
-
try {
|
|
60
|
-
return node_path.resolve(node_path.dirname(importerPath), spec);
|
|
61
|
-
} catch {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
load(path) {
|
|
66
|
-
return node_fs.readFileSync(path, "utf8");
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function linkProgram(entrySource, entryPath, resolver) {
|
|
71
|
-
const modules = /* @__PURE__ */ new Map();
|
|
72
|
-
const order = [];
|
|
73
|
-
const visiting = /* @__PURE__ */ new Set();
|
|
74
|
-
const diagnostics = [];
|
|
75
|
-
let nextId = 0;
|
|
76
|
-
const fail = (path, line, column, message) => {
|
|
77
|
-
diagnostics.push({
|
|
78
|
-
line,
|
|
79
|
-
column,
|
|
80
|
-
message: path === entryPath ? message : `${path}: ${message}`,
|
|
81
|
-
severity: "error"
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
function load(path, sourceOverride) {
|
|
85
|
-
const existing = modules.get(path);
|
|
86
|
-
if (existing) return existing;
|
|
87
|
-
if (visiting.has(path)) return void 0;
|
|
88
|
-
visiting.add(path);
|
|
89
|
-
let src;
|
|
90
|
-
if (sourceOverride !== null) {
|
|
91
|
-
src = sourceOverride;
|
|
92
|
-
} else {
|
|
93
|
-
try {
|
|
94
|
-
src = resolver.load(path);
|
|
95
|
-
} catch {
|
|
96
|
-
visiting.delete(path);
|
|
97
|
-
fail(entryPath, 0, 0, `Failed to load imported module "${path}".`);
|
|
98
|
-
return void 0;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
const program = index.parse(src);
|
|
102
|
-
const rec = {
|
|
103
|
-
id: nextId++,
|
|
104
|
-
path,
|
|
105
|
-
program,
|
|
106
|
-
edges: [],
|
|
107
|
-
declaredPlain: /* @__PURE__ */ new Set(),
|
|
108
|
-
declaredState: /* @__PURE__ */ new Set(),
|
|
109
|
-
exportedPlain: /* @__PURE__ */ new Set(),
|
|
110
|
-
exportedState: /* @__PURE__ */ new Set(),
|
|
111
|
-
renamePlain: /* @__PURE__ */ new Map(),
|
|
112
|
-
renameState: /* @__PURE__ */ new Map()
|
|
113
|
-
};
|
|
114
|
-
modules.set(path, rec);
|
|
115
|
-
buildSymbolTable(rec);
|
|
116
|
-
for (const stmt of program.statements) {
|
|
117
|
-
if (stmt.kind !== "Import") continue;
|
|
118
|
-
const resolved = resolver.resolve(stmt.source, path);
|
|
119
|
-
rec.edges.push({ stmt, resolvedPath: resolved });
|
|
120
|
-
if (resolved === null) {
|
|
121
|
-
fail(path, stmt.loc?.line ?? 0, stmt.loc?.column ?? 0, `Cannot resolve import "${stmt.source}".`);
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
load(resolved, null);
|
|
125
|
-
}
|
|
126
|
-
visiting.delete(path);
|
|
127
|
-
order.push(path);
|
|
128
|
-
return rec;
|
|
129
|
-
}
|
|
130
|
-
load(entryPath, entrySource);
|
|
131
|
-
for (const rec of modules.values()) {
|
|
132
|
-
if (rec.path === entryPath) continue;
|
|
133
|
-
for (const name of rec.declaredPlain) rec.renamePlain.set(name, `__a${rec.id}_${name}`);
|
|
134
|
-
for (const name of rec.declaredState) rec.renameState.set(name, `__a${rec.id}_${name}`);
|
|
135
|
-
}
|
|
136
|
-
for (const rec of modules.values()) {
|
|
137
|
-
for (const { stmt, resolvedPath } of rec.edges) {
|
|
138
|
-
if (resolvedPath === null) continue;
|
|
139
|
-
const src = modules.get(resolvedPath);
|
|
140
|
-
if (!src) continue;
|
|
141
|
-
for (const spec of stmt.specifiers) {
|
|
142
|
-
const line = stmt.loc?.line ?? 0;
|
|
143
|
-
const column = stmt.loc?.column ?? 0;
|
|
144
|
-
if (spec.isState) {
|
|
145
|
-
if (!src.exportedState.has(spec.imported)) {
|
|
146
|
-
fail(rec.path, line, column, `"${stmt.source}" does not export \`$${spec.imported}\`.`);
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
rec.renameState.set(spec.local, src.renameState.get(spec.imported) ?? `__a${src.id}_${spec.imported}`);
|
|
150
|
-
} else {
|
|
151
|
-
if (!src.exportedPlain.has(spec.imported)) {
|
|
152
|
-
fail(rec.path, line, column, `"${stmt.source}" does not export \`${spec.imported}\`.`);
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
rec.renamePlain.set(spec.local, src.renamePlain.get(spec.imported) ?? `__a${src.id}_${spec.imported}`);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
const merged = [];
|
|
161
|
-
for (const path of order) {
|
|
162
|
-
const rec = modules.get(path);
|
|
163
|
-
const renamer = makeRenamer(rec);
|
|
164
|
-
for (const stmt of rec.program.statements) {
|
|
165
|
-
if (stmt.kind === "Import") continue;
|
|
166
|
-
renamer.renameTopLevel(stmt);
|
|
167
|
-
stripExported(stmt);
|
|
168
|
-
if (stmt.kind === "EffectDeclaration" && rec.path !== entryPath) {
|
|
169
|
-
stmt.name = `__effect_a${rec.id}_${stmt.name.replace(/^__effect_/, "")}`;
|
|
170
|
-
}
|
|
171
|
-
merged.push(stmt);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
const entryRec = modules.get(entryPath);
|
|
175
|
-
return {
|
|
176
|
-
program: { statements: merged, errors: entryRec ? entryRec.program.errors : [] },
|
|
177
|
-
diagnostics,
|
|
178
|
-
dependencies: order.filter((p) => p !== entryPath)
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
function buildSymbolTable(rec) {
|
|
182
|
-
for (const stmt of rec.program.statements) {
|
|
183
|
-
switch (stmt.kind) {
|
|
184
|
-
case "Assignment":
|
|
185
|
-
if (stmt.isState) {
|
|
186
|
-
rec.declaredState.add(stmt.identifier);
|
|
187
|
-
if (stmt.exported) rec.exportedState.add(stmt.identifier);
|
|
188
|
-
} else {
|
|
189
|
-
rec.declaredPlain.add(stmt.identifier);
|
|
190
|
-
if (stmt.exported) rec.exportedPlain.add(stmt.identifier);
|
|
191
|
-
}
|
|
192
|
-
break;
|
|
193
|
-
case "ComponentDeclaration":
|
|
194
|
-
case "ActionDeclaration":
|
|
195
|
-
rec.declaredPlain.add(stmt.name);
|
|
196
|
-
if (stmt.exported) rec.exportedPlain.add(stmt.name);
|
|
197
|
-
break;
|
|
198
|
-
case "HookDeclaration":
|
|
199
|
-
rec.declaredState.add(stmt.name);
|
|
200
|
-
if (stmt.exported) rec.exportedState.add(stmt.name);
|
|
201
|
-
break;
|
|
202
|
-
case "DestructureStatement":
|
|
203
|
-
for (const b of stmt.bindings) if (b.name) rec.declaredPlain.add(b.name);
|
|
204
|
-
break;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
function stripExported(stmt) {
|
|
209
|
-
if (stmt.kind === "Assignment" || stmt.kind === "ComponentDeclaration" || stmt.kind === "ActionDeclaration" || stmt.kind === "HookDeclaration") {
|
|
210
|
-
delete stmt.exported;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
function makeRenamer(rec) {
|
|
214
|
-
const shadow = [];
|
|
215
|
-
const shadowed = (name) => {
|
|
216
|
-
for (const set of shadow) if (set.has(name)) return true;
|
|
217
|
-
return false;
|
|
218
|
-
};
|
|
219
|
-
const rPlain = (name) => shadowed(name) ? name : rec.renamePlain.get(name) ?? name;
|
|
220
|
-
const rState = (name) => rec.renameState.get(name) ?? name;
|
|
221
|
-
const push = (names) => {
|
|
222
|
-
shadow.push(new Set(names));
|
|
223
|
-
};
|
|
224
|
-
const pop = () => {
|
|
225
|
-
shadow.pop();
|
|
226
|
-
};
|
|
227
|
-
const patternNames = (p) => p.bindings.map((b) => b.name).filter((n) => !!n);
|
|
228
|
-
const paramNames = (params) => {
|
|
229
|
-
const out = [];
|
|
230
|
-
for (const p of params) {
|
|
231
|
-
if (p.name) out.push(p.name);
|
|
232
|
-
if (p.pattern) out.push(...patternNames(p.pattern));
|
|
233
|
-
}
|
|
234
|
-
return out;
|
|
235
|
-
};
|
|
236
|
-
const renameParamDefaults = (params) => {
|
|
237
|
-
for (const p of params) if (p.defaultValue) renameExpr(p.defaultValue);
|
|
238
|
-
};
|
|
239
|
-
function renameExpr(expr) {
|
|
240
|
-
switch (expr.kind) {
|
|
241
|
-
case "Literal":
|
|
242
|
-
return;
|
|
243
|
-
case "Identifier":
|
|
244
|
-
expr.name = rPlain(expr.name);
|
|
245
|
-
return;
|
|
246
|
-
case "StateRef":
|
|
247
|
-
expr.name = rState(expr.name);
|
|
248
|
-
return;
|
|
249
|
-
case "Array":
|
|
250
|
-
for (const el of expr.elements) renameExpr(el);
|
|
251
|
-
return;
|
|
252
|
-
case "Object":
|
|
253
|
-
for (const prop of expr.properties) {
|
|
254
|
-
if (prop.computedKey) renameExpr(prop.computedKey);
|
|
255
|
-
renameExpr(prop.value);
|
|
256
|
-
}
|
|
257
|
-
return;
|
|
258
|
-
case "Member":
|
|
259
|
-
renameExpr(expr.object);
|
|
260
|
-
if (expr.computed) renameExpr(expr.computed);
|
|
261
|
-
return;
|
|
262
|
-
case "Unary":
|
|
263
|
-
renameExpr(expr.argument);
|
|
264
|
-
return;
|
|
265
|
-
case "Binary":
|
|
266
|
-
renameExpr(expr.left);
|
|
267
|
-
renameExpr(expr.right);
|
|
268
|
-
return;
|
|
269
|
-
case "Ternary":
|
|
270
|
-
renameExpr(expr.test);
|
|
271
|
-
renameExpr(expr.consequent);
|
|
272
|
-
renameExpr(expr.alternate);
|
|
273
|
-
return;
|
|
274
|
-
case "Call":
|
|
275
|
-
expr.callee = rPlain(expr.callee);
|
|
276
|
-
for (const a of expr.arguments) renameExpr(a);
|
|
277
|
-
return;
|
|
278
|
-
case "MethodCall":
|
|
279
|
-
renameExpr(expr.object);
|
|
280
|
-
for (const a of expr.arguments) renameExpr(a);
|
|
281
|
-
return;
|
|
282
|
-
case "Invoke":
|
|
283
|
-
renameExpr(expr.callee);
|
|
284
|
-
for (const a of expr.arguments) renameExpr(a);
|
|
285
|
-
return;
|
|
286
|
-
case "BuiltinCall":
|
|
287
|
-
for (const a of expr.arguments) renameExpr(a);
|
|
288
|
-
return;
|
|
289
|
-
case "New":
|
|
290
|
-
renameExpr(expr.callee);
|
|
291
|
-
for (const a of expr.arguments) renameExpr(a);
|
|
292
|
-
return;
|
|
293
|
-
case "Template":
|
|
294
|
-
for (const e of expr.expressions) renameExpr(e);
|
|
295
|
-
return;
|
|
296
|
-
case "Spread":
|
|
297
|
-
renameExpr(expr.argument);
|
|
298
|
-
return;
|
|
299
|
-
case "Lambda":
|
|
300
|
-
push(paramNames(expr.params));
|
|
301
|
-
renameParamDefaults(expr.params);
|
|
302
|
-
renameExpr(expr.body);
|
|
303
|
-
pop();
|
|
304
|
-
return;
|
|
305
|
-
case "Block":
|
|
306
|
-
renameBlock(expr);
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
function renameBlock(block) {
|
|
311
|
-
push([]);
|
|
312
|
-
const scope = shadow[shadow.length - 1];
|
|
313
|
-
for (const stmt of block.body) {
|
|
314
|
-
renameStatement(stmt, false);
|
|
315
|
-
addBlockLocals(stmt, scope);
|
|
316
|
-
}
|
|
317
|
-
pop();
|
|
318
|
-
}
|
|
319
|
-
function addBlockLocals(stmt, scope) {
|
|
320
|
-
if (stmt.kind === "DestructureStatement") {
|
|
321
|
-
for (const b of stmt.bindings) if (b.name) scope.add(b.name);
|
|
322
|
-
} else if (stmt.kind === "ComponentDeclaration" || stmt.kind === "ActionDeclaration") {
|
|
323
|
-
scope.add(stmt.name);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
function renameTopLevel(stmt) {
|
|
327
|
-
if (stmt.kind === "DestructureStatement") {
|
|
328
|
-
renameExpr(stmt.expression);
|
|
329
|
-
for (const b of stmt.bindings) {
|
|
330
|
-
if (b.defaultValue) renameExpr(b.defaultValue);
|
|
331
|
-
b.name = rPlain(b.name);
|
|
332
|
-
}
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
renameStatement(stmt, true);
|
|
336
|
-
}
|
|
337
|
-
function renameStatement(stmt, topLevel) {
|
|
338
|
-
switch (stmt.kind) {
|
|
339
|
-
case "Import":
|
|
340
|
-
return;
|
|
341
|
-
case "Assignment":
|
|
342
|
-
stmt.identifier = stmt.isState ? rState(stmt.identifier) : rPlain(stmt.identifier);
|
|
343
|
-
renameExpr(stmt.expression);
|
|
344
|
-
return;
|
|
345
|
-
case "ComponentDeclaration":
|
|
346
|
-
case "ActionDeclaration":
|
|
347
|
-
stmt.name = rPlain(stmt.name);
|
|
348
|
-
push(paramNames(stmt.params));
|
|
349
|
-
renameParamDefaults(stmt.params);
|
|
350
|
-
renameBlock(stmt.body);
|
|
351
|
-
pop();
|
|
352
|
-
return;
|
|
353
|
-
case "HookDeclaration":
|
|
354
|
-
stmt.name = rState(stmt.name);
|
|
355
|
-
push(paramNames(stmt.params));
|
|
356
|
-
renameParamDefaults(stmt.params);
|
|
357
|
-
renameBlock(stmt.body);
|
|
358
|
-
pop();
|
|
359
|
-
return;
|
|
360
|
-
case "EffectDeclaration":
|
|
361
|
-
for (const t of stmt.triggers) if (t.kind === "state") t.name = rState(t.name);
|
|
362
|
-
renameBlock(stmt.body);
|
|
363
|
-
return;
|
|
364
|
-
case "Await":
|
|
365
|
-
renameExpr(stmt.argument);
|
|
366
|
-
return;
|
|
367
|
-
case "Return":
|
|
368
|
-
if (stmt.argument) renameExpr(stmt.argument);
|
|
369
|
-
return;
|
|
370
|
-
case "ExpressionStatement":
|
|
371
|
-
renameExpr(stmt.expression);
|
|
372
|
-
return;
|
|
373
|
-
case "IfStatement":
|
|
374
|
-
renameExpr(stmt.test);
|
|
375
|
-
renameBlock(stmt.consequent);
|
|
376
|
-
if (stmt.alternate) {
|
|
377
|
-
if (stmt.alternate.kind === "IfStatement") renameStatement(stmt.alternate, false);
|
|
378
|
-
else renameBlock(stmt.alternate);
|
|
379
|
-
}
|
|
380
|
-
return;
|
|
381
|
-
case "SwitchStatement":
|
|
382
|
-
renameExpr(stmt.discriminant);
|
|
383
|
-
for (const c of stmt.cases) {
|
|
384
|
-
if (c.test) renameExpr(c.test);
|
|
385
|
-
for (const s of c.body) renameStatement(s, false);
|
|
386
|
-
}
|
|
387
|
-
return;
|
|
388
|
-
case "ForOfStatement": {
|
|
389
|
-
renameExpr(stmt.iterable);
|
|
390
|
-
const names = [stmt.item];
|
|
391
|
-
if (stmt.index) names.push(stmt.index);
|
|
392
|
-
if (stmt.destructure) names.push(...stmt.destructure);
|
|
393
|
-
push(names);
|
|
394
|
-
renameBlock(stmt.body);
|
|
395
|
-
pop();
|
|
396
|
-
return;
|
|
397
|
-
}
|
|
398
|
-
case "ForInStatement":
|
|
399
|
-
renameExpr(stmt.iterable);
|
|
400
|
-
push([stmt.item]);
|
|
401
|
-
renameBlock(stmt.body);
|
|
402
|
-
pop();
|
|
403
|
-
return;
|
|
404
|
-
case "ForClassicStatement": {
|
|
405
|
-
const initNames = [];
|
|
406
|
-
if (stmt.init && stmt.init.kind === "Assignment" && stmt.init.identifier) {
|
|
407
|
-
initNames.push(stmt.init.identifier);
|
|
408
|
-
}
|
|
409
|
-
push(initNames);
|
|
410
|
-
if (stmt.init) renameStatement(stmt.init, false);
|
|
411
|
-
if (stmt.test) renameExpr(stmt.test);
|
|
412
|
-
if (stmt.update) renameExpr(stmt.update);
|
|
413
|
-
renameBlock(stmt.body);
|
|
414
|
-
pop();
|
|
415
|
-
return;
|
|
416
|
-
}
|
|
417
|
-
case "WhileStatement":
|
|
418
|
-
case "DoWhileStatement":
|
|
419
|
-
renameExpr(stmt.test);
|
|
420
|
-
renameBlock(stmt.body);
|
|
421
|
-
return;
|
|
422
|
-
case "DestructureStatement":
|
|
423
|
-
renameExpr(stmt.expression);
|
|
424
|
-
for (const b of stmt.bindings) if (b.defaultValue) renameExpr(b.defaultValue);
|
|
425
|
-
if (topLevel) for (const b of stmt.bindings) b.name = rPlain(b.name);
|
|
426
|
-
return;
|
|
427
|
-
case "ThrowStatement":
|
|
428
|
-
renameExpr(stmt.argument);
|
|
429
|
-
return;
|
|
430
|
-
case "TryStatement":
|
|
431
|
-
renameBlock(stmt.block);
|
|
432
|
-
if (stmt.catchBlock) {
|
|
433
|
-
push(stmt.catchParam ? [stmt.catchParam] : []);
|
|
434
|
-
renameBlock(stmt.catchBlock);
|
|
435
|
-
pop();
|
|
436
|
-
}
|
|
437
|
-
if (stmt.finallyBlock) renameBlock(stmt.finallyBlock);
|
|
438
|
-
return;
|
|
439
|
-
case "BreakStatement":
|
|
440
|
-
case "ContinueStatement":
|
|
441
|
-
return;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
return { renameTopLevel };
|
|
445
|
-
}
|
|
446
|
-
function compile(source, options = {}) {
|
|
447
|
-
const path = options.path ?? "<inline>.aktion";
|
|
448
|
-
const library = options.library ?? index.defaultLibrary;
|
|
449
|
-
const schemaErrorsFatal = options.schemaErrorsFatal ?? true;
|
|
450
|
-
const requireEntry = options.requireEntry ?? true;
|
|
451
|
-
const wantMap = options.sourcemap ?? true;
|
|
452
|
-
const link = linkProgram(source, path, options.resolver ?? createNodeResolver());
|
|
453
|
-
const program = link.program;
|
|
454
|
-
const diagnostics = [];
|
|
455
|
-
diagnostics.push(...link.diagnostics);
|
|
456
|
-
for (const error of program.errors) {
|
|
457
|
-
diagnostics.push({ line: error.line, column: error.column, message: error.message, severity: "error" });
|
|
458
|
-
}
|
|
459
|
-
for (const error of index.validateProgramSchema(program, library)) {
|
|
460
|
-
diagnostics.push({
|
|
461
|
-
line: error.line,
|
|
462
|
-
column: error.column,
|
|
463
|
-
message: error.message,
|
|
464
|
-
severity: schemaErrorsFatal ? "error" : "warning"
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
if (requireEntry && !hasEntryBinding(program)) {
|
|
468
|
-
diagnostics.push({
|
|
469
|
-
line: 1,
|
|
470
|
-
column: 1,
|
|
471
|
-
message: "No top-level `aktion = …` entry binding found — this program renders nothing. Assign your root component to `aktion` (e.g. `aktion = Card([…])`).",
|
|
472
|
-
severity: "warning"
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
|
-
const code = emitModule(program, source, path, { runtimeModuleId: options.runtimeModuleId });
|
|
476
|
-
const map = wantMap ? generateSourceMap(source, code, path) : null;
|
|
477
|
-
return { code, map, diagnostics, program, dependencies: link.dependencies };
|
|
478
|
-
}
|
|
479
|
-
function hasEntryBinding(program) {
|
|
480
|
-
return program.statements.some(
|
|
481
|
-
(stmt) => stmt.kind === "Assignment" && stmt.identifier === "aktion"
|
|
482
|
-
);
|
|
483
|
-
}
|
|
484
|
-
exports.COMPILED_PROGRAM_VERSION = COMPILED_PROGRAM_VERSION;
|
|
485
|
-
exports.compile = compile;
|
|
486
|
-
exports.compileLite = compileLite;
|
|
487
|
-
exports.defineCompiledProgram = defineCompiledProgram;
|
|
488
|
-
exports.emitModule = emitModule;
|
|
489
|
-
exports.generateSourceMap = generateSourceMap;
|
|
490
|
-
exports.isCompiledProgram = isCompiledProgram;
|
|
491
|
-
//# sourceMappingURL=compile-BUw0GAvN.cjs.map
|