chocola 2.0.0-next.10 → 2.0.0-next.12
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/LICENSE +1 -1
- package/README.md +24 -5
- package/compiler/component-processor.js +306 -72
- package/compiler/config.js +40 -22
- package/compiler/index.js +61 -126
- package/compiler/module-graph.js +57 -19
- package/compiler/pipeline.js +3 -1
- package/compiler/render.js +3 -1
- package/compiler/utils.js +102 -116
- package/package.json +56 -43
- package/parser/component.js +77 -5
- package/parser/index.js +1 -0
- package/parser/script.js +485 -0
- package/utils.js +39 -52
- package/dev/index.js +0 -172
- package/index.js +0 -0
- package/server/index.js +0 -402
package/package.json
CHANGED
|
@@ -1,43 +1,56 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "chocola",
|
|
3
|
-
"version": "2.0.0-next.
|
|
4
|
-
"description": "The sweetest way to build the web",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"web",
|
|
7
|
-
"app",
|
|
8
|
-
"pipeline",
|
|
9
|
-
"framework",
|
|
10
|
-
"gui",
|
|
11
|
-
"components",
|
|
12
|
-
"ui"
|
|
13
|
-
],
|
|
14
|
-
"homepage": "https://chocolaframework.web.app/",
|
|
15
|
-
"bugs": {
|
|
16
|
-
"url": "https://github.com/chocolajs/chocola/issues"
|
|
17
|
-
},
|
|
18
|
-
"repository": {
|
|
19
|
-
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/chocolajs/chocola.git"
|
|
21
|
-
},
|
|
22
|
-
"license": "MIT",
|
|
23
|
-
"author": "SadGabi",
|
|
24
|
-
"type": "module",
|
|
25
|
-
"main": "index.js",
|
|
26
|
-
"funding": {
|
|
27
|
-
"type": "github",
|
|
28
|
-
"url": "https://github.com/sponsors/chocolajs"
|
|
29
|
-
},
|
|
30
|
-
"scripts": {
|
|
31
|
-
"test": "node --test \"tests/**/*.test.js\"",
|
|
32
|
-
"bench": "node bench/index.js",
|
|
33
|
-
"bench:csv": "node bench/index.js --csv"
|
|
34
|
-
},
|
|
35
|
-
"exports": {
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "chocola",
|
|
3
|
+
"version": "2.0.0-next.12",
|
|
4
|
+
"description": "The sweetest way to build the web",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"web",
|
|
7
|
+
"app",
|
|
8
|
+
"pipeline",
|
|
9
|
+
"framework",
|
|
10
|
+
"gui",
|
|
11
|
+
"components",
|
|
12
|
+
"ui"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://chocolaframework.web.app/",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/chocolajs/chocola/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/chocolajs/chocola.git"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "SadGabi",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "compiler/index.js",
|
|
26
|
+
"funding": {
|
|
27
|
+
"type": "github",
|
|
28
|
+
"url": "https://github.com/sponsors/chocolajs"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"test": "node --test \"tests/**/*.test.js\"",
|
|
32
|
+
"bench": "node bench/index.js",
|
|
33
|
+
"bench:csv": "node bench/index.js --csv"
|
|
34
|
+
},
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"import": "./compiler/index.js",
|
|
38
|
+
"require": "./compiler/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./compiler": "./compiler/index.js",
|
|
41
|
+
"./compiler/*": "./compiler/*",
|
|
42
|
+
"./runtime": "./runtime/index.js",
|
|
43
|
+
"./parser": "./parser/index.js",
|
|
44
|
+
"./parser/*": "./parser/*"
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"compiler/",
|
|
48
|
+
"parser/",
|
|
49
|
+
"runtime/",
|
|
50
|
+
"utils.js"
|
|
51
|
+
],
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"acorn": "^8.18.0",
|
|
54
|
+
"linkedom": "^0.18.13"
|
|
55
|
+
}
|
|
56
|
+
}
|
package/parser/component.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { parseScript } from "./script.js";
|
|
2
|
+
|
|
3
|
+
// --- Legacy regex-based implementations (fallback) ---
|
|
4
|
+
|
|
5
|
+
function legacyExtractPropsDefaults(script) {
|
|
2
6
|
if (!script) return [];
|
|
3
7
|
const propsRegex = /export\s+let\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*(?:=\s*([^;]+))?;/g;
|
|
4
8
|
let props = [];
|
|
@@ -9,7 +13,7 @@ export function extractPropsDefaults(script) {
|
|
|
9
13
|
return props;
|
|
10
14
|
}
|
|
11
15
|
|
|
12
|
-
|
|
16
|
+
function legacyExtractRuntime(script, compName) {
|
|
13
17
|
const startRegex = /(?:async\s+)?function\s+\$runtime\(([^)]*)\)\s*\{/;
|
|
14
18
|
const match = script.match(startRegex);
|
|
15
19
|
if (!match) return null;
|
|
@@ -47,7 +51,7 @@ export function extractRuntime(script, compName) {
|
|
|
47
51
|
throw new Error(`${compName} $runtime function has unclosed curly braces`);
|
|
48
52
|
}
|
|
49
53
|
|
|
50
|
-
|
|
54
|
+
function legacyExtractTopLevelVariables(script) {
|
|
51
55
|
if (!script) return [];
|
|
52
56
|
const vars = [];
|
|
53
57
|
let i = 0;
|
|
@@ -94,7 +98,7 @@ export function extractTopLevelVariables(script) {
|
|
|
94
98
|
|
|
95
99
|
if (depth === 0 && parenDepth === 0 && bracketDepth === 0) {
|
|
96
100
|
const rest = script.slice(i);
|
|
97
|
-
const m = rest.match(/^(let|const)\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*/);
|
|
101
|
+
const m = rest.match(/^(let|const|var)\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*/);
|
|
98
102
|
if (m) {
|
|
99
103
|
const keyword = m[1];
|
|
100
104
|
const before = script.slice(0, i).trimEnd();
|
|
@@ -186,7 +190,7 @@ function findDeclaratorEnd(script, start) {
|
|
|
186
190
|
return i;
|
|
187
191
|
}
|
|
188
192
|
|
|
189
|
-
|
|
193
|
+
function legacyExtractTopLevelFunctions(script, excludeName) {
|
|
190
194
|
const funcs = [];
|
|
191
195
|
let i = 0;
|
|
192
196
|
let depth = 0;
|
|
@@ -266,3 +270,71 @@ export function extractTopLevelFunctions(script, excludeName) {
|
|
|
266
270
|
|
|
267
271
|
return funcs;
|
|
268
272
|
}
|
|
273
|
+
|
|
274
|
+
// --- New AST-backed wrappers (Step A) ---
|
|
275
|
+
|
|
276
|
+
export function extractPropsDefaults(script) {
|
|
277
|
+
if (!script) return [];
|
|
278
|
+
const parsed = parseScript(script);
|
|
279
|
+
if (parsed.ast) {
|
|
280
|
+
// Use AST-derived props; map to legacy shape
|
|
281
|
+
return parsed.props.map((p) => ({ name: p.name, defaultValue: p.defaultValue }));
|
|
282
|
+
}
|
|
283
|
+
return legacyExtractPropsDefaults(script);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function extractRuntime(script, compName) {
|
|
287
|
+
if (!script) return null;
|
|
288
|
+
const parsed = parseScript(script);
|
|
289
|
+
if (parsed.ast) {
|
|
290
|
+
return parsed.runtime;
|
|
291
|
+
}
|
|
292
|
+
return legacyExtractRuntime(script, compName);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export function extractTopLevelVariables(script) {
|
|
296
|
+
if (!script) return [];
|
|
297
|
+
const parsed = parseScript(script);
|
|
298
|
+
if (parsed.ast) {
|
|
299
|
+
const vars = [];
|
|
300
|
+
for (const v of parsed.topVars) {
|
|
301
|
+
if (v.isDestructuring) {
|
|
302
|
+
// Expand destructuring per binding name for back-compat
|
|
303
|
+
// e.g., const {a,b}=obj -> two entries with same initializer
|
|
304
|
+
for (const n of v.names) {
|
|
305
|
+
if (n === "self" || n === "ctx") continue;
|
|
306
|
+
vars.push({ keyword: v.keyword, name: n, value: v.value });
|
|
307
|
+
}
|
|
308
|
+
} else {
|
|
309
|
+
vars.push({ keyword: v.keyword, name: v.name, value: v.value });
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return vars;
|
|
313
|
+
}
|
|
314
|
+
return legacyExtractTopLevelVariables(script);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export function extractTopLevelFunctions(script, excludeName) {
|
|
318
|
+
if (!script) return [];
|
|
319
|
+
const parsed = parseScript(script);
|
|
320
|
+
if (parsed.ast) {
|
|
321
|
+
if (excludeName === "$runtime") {
|
|
322
|
+
return parsed.topFuncs;
|
|
323
|
+
}
|
|
324
|
+
// Generic exclude
|
|
325
|
+
const filtered = [];
|
|
326
|
+
for (const src of parsed.topFuncs) {
|
|
327
|
+
const m = src.match(/^(?:async\s+)?function\s+([a-zA-Z_$][0-9a-zA-Z_$]*)/);
|
|
328
|
+
if (m && m[1] === excludeName) continue;
|
|
329
|
+
filtered.push(src);
|
|
330
|
+
}
|
|
331
|
+
// If excludeName is null/undefined, return all except $runtime handled above
|
|
332
|
+
// Need to also exclude $runtime if caller passed different name? For safety include all non-excluded
|
|
333
|
+
if (!excludeName) {
|
|
334
|
+
// parsed.topFuncs already excludes $runtime, so return as is
|
|
335
|
+
return parsed.topFuncs;
|
|
336
|
+
}
|
|
337
|
+
return filtered;
|
|
338
|
+
}
|
|
339
|
+
return legacyExtractTopLevelFunctions(script, excludeName);
|
|
340
|
+
}
|
package/parser/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { extractPropsDefaults, extractRuntime, extractTopLevelFunctions, extractTopLevelVariables } from "./component.js";
|
|
2
|
+
export { parseScript, extractBindingNames, computeReachable } from "./script.js";
|
|
2
3
|
export { extractCtxFromEl, hasMountIf, getMountIf, removeMountIf } from "./context.js";
|
|
3
4
|
export { reservedAttrs, getLineNumber, validateChainStructure, applyConditionalToElement, interpolateNode } from "./template.js";
|
|
4
5
|
export { scopeCss } from "./css.js";
|