@zeus-js/compiler 0.0.2 → 0.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compiler.cjs.js +161 -57
- package/dist/compiler.cjs.prod.js +161 -57
- package/dist/compiler.d.ts +2 -10
- package/dist/compiler.esm-browser.js +166 -117
- package/dist/compiler.esm-browser.prod.js +5 -5
- package/dist/compiler.esm-bundler.js +161 -57
- package/dist/compiler.global.js +165 -116
- package/dist/compiler.global.prod.js +5 -5
- package/package.json +4 -4
package/dist/compiler.global.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* compiler v0.0.
|
|
2
|
+
* compiler v0.1.0-beta.0
|
|
3
3
|
* (c) 2026 baicie
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
**/
|
|
@@ -32,61 +32,6 @@ var ZeusCompiler = (function(exports) {
|
|
|
32
32
|
}) : target, mod));
|
|
33
33
|
//#endregion
|
|
34
34
|
//#region node_modules/.pnpm/@babel+helper-plugin-utils@7.29.7/node_modules/@babel/helper-plugin-utils/lib/index.js
|
|
35
|
-
var require_lib$5 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
36
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.declare = declare;
|
|
38
|
-
exports.declarePreset = void 0;
|
|
39
|
-
const apiPolyfills = { assertVersion: (api) => (range) => {
|
|
40
|
-
throwVersionError(range, api.version);
|
|
41
|
-
} };
|
|
42
|
-
Object.assign(apiPolyfills, {
|
|
43
|
-
targets: () => () => {
|
|
44
|
-
return {};
|
|
45
|
-
},
|
|
46
|
-
assumption: () => () => {},
|
|
47
|
-
addExternalDependency: () => () => {}
|
|
48
|
-
});
|
|
49
|
-
function declare(builder) {
|
|
50
|
-
return (api, options, dirname) => {
|
|
51
|
-
let clonedApi;
|
|
52
|
-
for (const name of Object.keys(apiPolyfills)) {
|
|
53
|
-
if (api[name]) continue;
|
|
54
|
-
clonedApi != null || (clonedApi = copyApiObject(api));
|
|
55
|
-
clonedApi[name] = apiPolyfills[name](clonedApi);
|
|
56
|
-
}
|
|
57
|
-
return builder(clonedApi != null ? clonedApi : api, options || {}, dirname);
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
exports.declarePreset = declare;
|
|
61
|
-
function copyApiObject(api) {
|
|
62
|
-
let proto = null;
|
|
63
|
-
if (typeof api.version === "string" && api.version.startsWith("7.")) {
|
|
64
|
-
proto = Object.getPrototypeOf(api);
|
|
65
|
-
if (proto && (!hasOwnProperty.call(proto, "version") || !hasOwnProperty.call(proto, "transform") || !hasOwnProperty.call(proto, "template") || !hasOwnProperty.call(proto, "types"))) proto = null;
|
|
66
|
-
}
|
|
67
|
-
return Object.assign({}, proto, api);
|
|
68
|
-
}
|
|
69
|
-
function throwVersionError(range, version) {
|
|
70
|
-
if (typeof range === "number") {
|
|
71
|
-
if (!Number.isInteger(range)) throw new Error("Expected string or integer value.");
|
|
72
|
-
range = `^${range}.0.0-0`;
|
|
73
|
-
}
|
|
74
|
-
if (typeof range !== "string") throw new Error("Expected string or integer value.");
|
|
75
|
-
const limit = Error.stackTraceLimit;
|
|
76
|
-
if (typeof limit === "number" && limit < 25) Error.stackTraceLimit = 25;
|
|
77
|
-
let err;
|
|
78
|
-
if (version.startsWith("7.")) err = /* @__PURE__ */ new Error(`Requires Babel "^7.0.0-beta.41", but was loaded with "${version}". You'll need to update your @babel/core version.`);
|
|
79
|
-
else err = /* @__PURE__ */ new Error(`Requires Babel "${range}", but was loaded with "${version}". If you are sure you have a compatible version of @babel/core, it is likely that something in your build process is loading the wrong version. Inspect the stack trace of this error to look for the first entry that doesn't mention "@babel/core" or "babel-core" to see what is calling Babel.`);
|
|
80
|
-
if (typeof limit === "number") Error.stackTraceLimit = limit;
|
|
81
|
-
throw Object.assign(err, {
|
|
82
|
-
code: "BABEL_VERSION_UNSUPPORTED",
|
|
83
|
-
version,
|
|
84
|
-
range
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}));
|
|
88
|
-
//#endregion
|
|
89
|
-
//#region node_modules/.pnpm/@babel+helper-plugin-utils@7.28.6/node_modules/@babel/helper-plugin-utils/lib/index.js
|
|
90
35
|
var require_lib$4 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
91
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
92
37
|
exports.declare = declare;
|
|
@@ -2990,7 +2935,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
2990
2935
|
}
|
|
2991
2936
|
}));
|
|
2992
2937
|
//#endregion
|
|
2993
|
-
//#region node_modules/.pnpm/@babel+helper-validator-identifier@7.
|
|
2938
|
+
//#region node_modules/.pnpm/@babel+helper-validator-identifier@7.29.7/node_modules/@babel/helper-validator-identifier/lib/identifier.js
|
|
2994
2939
|
var require_identifier = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2995
2940
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2996
2941
|
exports.isIdentifierChar = isIdentifierChar;
|
|
@@ -3998,7 +3943,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
3998
3943
|
}
|
|
3999
3944
|
}));
|
|
4000
3945
|
//#endregion
|
|
4001
|
-
//#region node_modules/.pnpm/@babel+helper-validator-identifier@7.
|
|
3946
|
+
//#region node_modules/.pnpm/@babel+helper-validator-identifier@7.29.7/node_modules/@babel/helper-validator-identifier/lib/keyword.js
|
|
4002
3947
|
var require_keyword = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
4003
3948
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4004
3949
|
exports.isKeyword = isKeyword;
|
|
@@ -4077,7 +4022,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
4077
4022
|
}
|
|
4078
4023
|
}));
|
|
4079
4024
|
//#endregion
|
|
4080
|
-
//#region node_modules/.pnpm/@babel+helper-validator-identifier@7.
|
|
4025
|
+
//#region node_modules/.pnpm/@babel+helper-validator-identifier@7.29.7/node_modules/@babel/helper-validator-identifier/lib/index.js
|
|
4081
4026
|
var require_lib$2 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
4082
4027
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4083
4028
|
Object.defineProperty(exports, "isIdentifierChar", {
|
|
@@ -4146,7 +4091,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
4146
4091
|
}
|
|
4147
4092
|
}));
|
|
4148
4093
|
//#endregion
|
|
4149
|
-
//#region node_modules/.pnpm/@babel+helper-string-parser@7.
|
|
4094
|
+
//#region node_modules/.pnpm/@babel+helper-string-parser@7.29.7/node_modules/@babel/helper-string-parser/lib/index.js
|
|
4150
4095
|
var require_lib$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
4151
4096
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4152
4097
|
exports.readCodePoint = readCodePoint;
|
|
@@ -14217,8 +14162,8 @@ var ZeusCompiler = (function(exports) {
|
|
|
14217
14162
|
if (process.env.BABEL_TYPES_8_BREAKING) console.warn("BABEL_TYPES_8_BREAKING is not supported anymore. Use the latest Babel 8.0.0 pre-release instead!");
|
|
14218
14163
|
}));
|
|
14219
14164
|
//#endregion
|
|
14220
|
-
//#region packages/compiler/src/codegen/support/imports.ts
|
|
14221
|
-
var import_lib = require_lib$
|
|
14165
|
+
//#region packages/core/compiler/src/codegen/support/imports.ts
|
|
14166
|
+
var import_lib = require_lib$4();
|
|
14222
14167
|
var import_lib$1 = /* @__PURE__ */ __toESM(require_lib$3());
|
|
14223
14168
|
var import_lib$2 = /* @__PURE__ */ __toESM(require_lib());
|
|
14224
14169
|
const DEFAULT_RENDERER_MODULE = "@zeus-js/runtime-dom";
|
|
@@ -14271,7 +14216,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
14271
14216
|
return path.scope.getProgramParent().path;
|
|
14272
14217
|
}
|
|
14273
14218
|
//#endregion
|
|
14274
|
-
//#region packages/compiler/src/codegen/support/templates.ts
|
|
14219
|
+
//#region packages/core/compiler/src/codegen/support/templates.ts
|
|
14275
14220
|
/**
|
|
14276
14221
|
* Template registration, scope data management, and program injection.
|
|
14277
14222
|
*
|
|
@@ -14315,7 +14260,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
14315
14260
|
path.node.body.unshift(import_lib$2.variableDeclaration("var", declarators));
|
|
14316
14261
|
}
|
|
14317
14262
|
//#endregion
|
|
14318
|
-
//#region packages/compiler/src/codegen/support/events.ts
|
|
14263
|
+
//#region packages/core/compiler/src/codegen/support/events.ts
|
|
14319
14264
|
/**
|
|
14320
14265
|
* Event registration and delegation.
|
|
14321
14266
|
*
|
|
@@ -14345,7 +14290,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
14345
14290
|
path.node.body.push(import_lib$2.expressionStatement(import_lib$2.callExpression(registerImportMethod(path, "delegateEvents", getRendererConfig(path, "dom").moduleName), [import_lib$2.arrayExpression(Array.from(events).map((eventName) => import_lib$2.stringLiteral(eventName)))])));
|
|
14346
14291
|
}
|
|
14347
14292
|
//#endregion
|
|
14348
|
-
//#region packages/compiler/src/config/index.ts
|
|
14293
|
+
//#region packages/core/compiler/src/config/index.ts
|
|
14349
14294
|
const DEFAULT_OPTIONS = {
|
|
14350
14295
|
moduleName: DEFAULT_RENDERER_MODULE,
|
|
14351
14296
|
generate: "dom",
|
|
@@ -14373,7 +14318,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
14373
14318
|
return extend(DEFAULT_OPTIONS, options);
|
|
14374
14319
|
}
|
|
14375
14320
|
//#endregion
|
|
14376
|
-
//#region packages/compiler/src/utils/constant.ts
|
|
14321
|
+
//#region packages/core/compiler/src/utils/constant.ts
|
|
14377
14322
|
const VoidElements = [
|
|
14378
14323
|
"area",
|
|
14379
14324
|
"base",
|
|
@@ -14393,7 +14338,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
14393
14338
|
"wbr"
|
|
14394
14339
|
];
|
|
14395
14340
|
//#endregion
|
|
14396
|
-
//#region packages/compiler/src/utils/html.ts
|
|
14341
|
+
//#region packages/core/compiler/src/utils/html.ts
|
|
14397
14342
|
function escapeHTML(value, attr = false) {
|
|
14398
14343
|
let result = value.replace(/&/g, "&");
|
|
14399
14344
|
if (attr) return result.replace(/"/g, """).replace(/>/g, ">");
|
|
@@ -14412,14 +14357,14 @@ var ZeusCompiler = (function(exports) {
|
|
|
14412
14357
|
return rawTextElements.has(tagName);
|
|
14413
14358
|
}
|
|
14414
14359
|
//#endregion
|
|
14415
|
-
//#region packages/compiler/src/utils/metadata.ts
|
|
14360
|
+
//#region packages/core/compiler/src/utils/metadata.ts
|
|
14416
14361
|
function setZeusMetadata(state, config) {
|
|
14417
14362
|
const metadata = state.file.metadata;
|
|
14418
14363
|
metadata.zeus = extend({}, metadata.zeus, { config });
|
|
14419
14364
|
return metadata.zeus;
|
|
14420
14365
|
}
|
|
14421
14366
|
//#endregion
|
|
14422
|
-
//#region packages/compiler/src/program.ts
|
|
14367
|
+
//#region packages/core/compiler/src/program.ts
|
|
14423
14368
|
/**
|
|
14424
14369
|
* Program visitor — entry and exit point for the entire transform pass.
|
|
14425
14370
|
*
|
|
@@ -14446,7 +14391,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
14446
14391
|
};
|
|
14447
14392
|
}
|
|
14448
14393
|
//#endregion
|
|
14449
|
-
//#region packages/compiler/src/codegen/dom/emitBinding.ts
|
|
14394
|
+
//#region packages/core/compiler/src/codegen/dom/emitBinding.ts
|
|
14450
14395
|
function emitBindings(node, context) {
|
|
14451
14396
|
const statements = [];
|
|
14452
14397
|
for (const attr of node.attrs) {
|
|
@@ -14569,7 +14514,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
14569
14514
|
return [import_lib$2.expressionStatement(mountCall)];
|
|
14570
14515
|
}
|
|
14571
14516
|
//#endregion
|
|
14572
|
-
//#region packages/compiler/src/codegen/dom/emitDomPath.ts
|
|
14517
|
+
//#region packages/core/compiler/src/codegen/dom/emitDomPath.ts
|
|
14573
14518
|
function emitPhysicalDomPath(path) {
|
|
14574
14519
|
switch (path.kind) {
|
|
14575
14520
|
case "Root": throw new Error("Root path is emitted from template clone directly");
|
|
@@ -14579,7 +14524,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
14579
14524
|
}
|
|
14580
14525
|
}
|
|
14581
14526
|
//#endregion
|
|
14582
|
-
//#region packages/compiler/src/passes/collectTemplates.ts
|
|
14527
|
+
//#region packages/core/compiler/src/passes/collectTemplates.ts
|
|
14583
14528
|
function collectTemplates(node, context) {
|
|
14584
14529
|
if (node.kind === "Element") {
|
|
14585
14530
|
context.registerTemplate(renderTemplateHTML(node), node.flags.isSVG);
|
|
@@ -14620,7 +14565,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
14620
14565
|
case "Show":
|
|
14621
14566
|
case "For":
|
|
14622
14567
|
case "Slot": return "<!>";
|
|
14623
|
-
case "Host": return node.
|
|
14568
|
+
case "Host": return node.child ? renderChildTemplate(node.child) : "";
|
|
14624
14569
|
case "Fragment": return node.children.map(renderChildTemplate).join("");
|
|
14625
14570
|
}
|
|
14626
14571
|
}
|
|
@@ -14628,7 +14573,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
14628
14573
|
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
14629
14574
|
}
|
|
14630
14575
|
//#endregion
|
|
14631
|
-
//#region packages/compiler/src/codegen/dom/emitTemplate.ts
|
|
14576
|
+
//#region packages/core/compiler/src/codegen/dom/emitTemplate.ts
|
|
14632
14577
|
function emitTemplateClone(node, context) {
|
|
14633
14578
|
const html = renderTemplateHTML(node);
|
|
14634
14579
|
const template = context.registerTemplate(html, node.flags.isSVG);
|
|
@@ -14636,7 +14581,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
14636
14581
|
return import_lib$2.memberExpression(templateCall, import_lib$2.identifier("firstChild"));
|
|
14637
14582
|
}
|
|
14638
14583
|
//#endregion
|
|
14639
|
-
//#region packages/compiler/src/codegen/dom/emitElement.ts
|
|
14584
|
+
//#region packages/core/compiler/src/codegen/dom/emitElement.ts
|
|
14640
14585
|
function emitElement(node, context) {
|
|
14641
14586
|
if (!hasRuntimeWork(node)) return emitTemplateClone(node, context);
|
|
14642
14587
|
const statements = [
|
|
@@ -14676,7 +14621,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
14676
14621
|
for (const child of node.children) collectRefNode(child, map);
|
|
14677
14622
|
return;
|
|
14678
14623
|
case "Host":
|
|
14679
|
-
|
|
14624
|
+
if (node.child) collectRefNode(node.child, map);
|
|
14680
14625
|
return;
|
|
14681
14626
|
default: return;
|
|
14682
14627
|
}
|
|
@@ -14698,7 +14643,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
14698
14643
|
for (const child of node.children) collectRequiredDomRefDeclaration(child, statements, context, refNodeMap, declared);
|
|
14699
14644
|
return;
|
|
14700
14645
|
case "Host":
|
|
14701
|
-
|
|
14646
|
+
if (node.child) collectRequiredDomRefDeclaration(node.child, statements, context, refNodeMap, declared);
|
|
14702
14647
|
return;
|
|
14703
14648
|
default: return;
|
|
14704
14649
|
}
|
|
@@ -14745,11 +14690,18 @@ var ZeusCompiler = (function(exports) {
|
|
|
14745
14690
|
case "Slot": return true;
|
|
14746
14691
|
case "Element": return needsDomRefDeclaration(child);
|
|
14747
14692
|
case "Fragment": return child.children.some((inner) => inner.kind === "Element" ? needsDomRefDeclaration(inner) : inner.kind !== "Text");
|
|
14748
|
-
case "Host": return child.
|
|
14693
|
+
case "Host": return child.child ? innerKind(child.child) : false;
|
|
14749
14694
|
default: return false;
|
|
14750
14695
|
}
|
|
14751
14696
|
});
|
|
14752
14697
|
}
|
|
14698
|
+
function innerKind(node) {
|
|
14699
|
+
switch (node.kind) {
|
|
14700
|
+
case "Element": return needsDomRefDeclaration(node);
|
|
14701
|
+
case "Text": return false;
|
|
14702
|
+
default: return true;
|
|
14703
|
+
}
|
|
14704
|
+
}
|
|
14753
14705
|
function hasRuntimeWork(node) {
|
|
14754
14706
|
return node.attrs.some((attr) => attr.kind === "AttrBinding" || attr.kind === "PropBinding" || attr.kind === "EventBinding" || attr.kind === "RefBinding") || node.children.some(hasChildRuntimeWork);
|
|
14755
14707
|
}
|
|
@@ -14761,18 +14713,18 @@ var ZeusCompiler = (function(exports) {
|
|
|
14761
14713
|
case "For":
|
|
14762
14714
|
case "Slot": return true;
|
|
14763
14715
|
case "Element": return hasRuntimeWork(node);
|
|
14764
|
-
case "Fragment":
|
|
14765
|
-
case "Host": return node.
|
|
14716
|
+
case "Fragment": return node.children.some(hasChildRuntimeWork);
|
|
14717
|
+
case "Host": return node.child ? hasChildRuntimeWork(node.child) : false;
|
|
14766
14718
|
default: return false;
|
|
14767
14719
|
}
|
|
14768
14720
|
}
|
|
14769
14721
|
//#endregion
|
|
14770
|
-
//#region packages/compiler/src/codegen/dom/emitFragment.ts
|
|
14722
|
+
//#region packages/core/compiler/src/codegen/dom/emitFragment.ts
|
|
14771
14723
|
function emitFragment(node, context) {
|
|
14772
14724
|
return import_lib$2.arrayExpression(node.children.map((child) => emitDOM(child, context)));
|
|
14773
14725
|
}
|
|
14774
14726
|
//#endregion
|
|
14775
|
-
//#region packages/compiler/src/codegen/dom/emitNodeExpression.ts
|
|
14727
|
+
//#region packages/core/compiler/src/codegen/dom/emitNodeExpression.ts
|
|
14776
14728
|
function emitNodeExpression(node, context) {
|
|
14777
14729
|
switch (node.kind) {
|
|
14778
14730
|
case "Text": return import_lib$2.stringLiteral(node.value);
|
|
@@ -14788,13 +14740,13 @@ var ZeusCompiler = (function(exports) {
|
|
|
14788
14740
|
}
|
|
14789
14741
|
}
|
|
14790
14742
|
//#endregion
|
|
14791
|
-
//#region packages/compiler/src/codegen/dom/emitComponent.ts
|
|
14743
|
+
//#region packages/core/compiler/src/codegen/dom/emitComponent.ts
|
|
14792
14744
|
function emitComponent(node, context) {
|
|
14793
14745
|
const props = import_lib$2.objectExpression(node.props.map((prop) => emitComponentProp(prop, context)));
|
|
14794
14746
|
return import_lib$2.callExpression(context.importRuntime("createComponent"), [node.callee, props]);
|
|
14795
14747
|
}
|
|
14796
14748
|
function emitComponentProp(prop, context) {
|
|
14797
|
-
const key = createObjectKey(prop.name);
|
|
14749
|
+
const key = createObjectKey$1(prop.name);
|
|
14798
14750
|
if (Array.isArray(prop.value)) return import_lib$2.objectMethod("get", key, [], import_lib$2.blockStatement([import_lib$2.returnStatement(emitChildrenProp(prop.value, context))]));
|
|
14799
14751
|
if (isStaticPropValue(prop.value)) return import_lib$2.objectProperty(key, prop.value);
|
|
14800
14752
|
return import_lib$2.objectMethod("get", key, [], import_lib$2.blockStatement([import_lib$2.returnStatement(prop.value)]));
|
|
@@ -14807,11 +14759,11 @@ var ZeusCompiler = (function(exports) {
|
|
|
14807
14759
|
function isStaticPropValue(value) {
|
|
14808
14760
|
return import_lib$2.isStringLiteral(value) || import_lib$2.isNumericLiteral(value) || import_lib$2.isBooleanLiteral(value) || import_lib$2.isNullLiteral(value);
|
|
14809
14761
|
}
|
|
14810
|
-
function createObjectKey(key) {
|
|
14762
|
+
function createObjectKey$1(key) {
|
|
14811
14763
|
return import_lib$2.isValidIdentifier(key) ? import_lib$2.identifier(key) : import_lib$2.stringLiteral(key);
|
|
14812
14764
|
}
|
|
14813
14765
|
//#endregion
|
|
14814
|
-
//#region packages/compiler/src/codegen/dom/emitBuiltin.ts
|
|
14766
|
+
//#region packages/core/compiler/src/codegen/dom/emitBuiltin.ts
|
|
14815
14767
|
function emitShow(node, context) {
|
|
14816
14768
|
const props = [import_lib$2.objectProperty(import_lib$2.identifier("when"), node.when), import_lib$2.objectProperty(import_lib$2.identifier("children"), import_lib$2.arrowFunctionExpression([], emitChildrenProp(node.children, context)))];
|
|
14817
14769
|
if (node.fallback) props.push(import_lib$2.objectProperty(import_lib$2.identifier("fallback"), Array.isArray(node.fallback) ? import_lib$2.arrowFunctionExpression([], emitChildrenProp(node.fallback, context)) : node.fallback));
|
|
@@ -14850,7 +14802,29 @@ var ZeusCompiler = (function(exports) {
|
|
|
14850
14802
|
]);
|
|
14851
14803
|
}
|
|
14852
14804
|
function emitHost(node, context) {
|
|
14853
|
-
|
|
14805
|
+
const props = buildHostProps(node, context);
|
|
14806
|
+
const hostCall = import_lib$2.callExpression(context.importRuntime("Host"), [import_lib$2.objectExpression(props)]);
|
|
14807
|
+
if (!node.child) return hostCall;
|
|
14808
|
+
const childExpr = emitNodeExpression(node.child, context);
|
|
14809
|
+
return import_lib$2.callExpression(import_lib$2.arrowFunctionExpression([], import_lib$2.blockStatement([import_lib$2.expressionStatement(hostCall), import_lib$2.returnStatement(childExpr)])), []);
|
|
14810
|
+
}
|
|
14811
|
+
function buildHostProps(node, context) {
|
|
14812
|
+
const props = [];
|
|
14813
|
+
for (const attr of node.attrs) {
|
|
14814
|
+
const key = createObjectKey(attr.name);
|
|
14815
|
+
if (isStaticValue(attr.expr) || isGetterExpression(attr.expr)) props.push(import_lib$2.objectProperty(key, attr.expr));
|
|
14816
|
+
else props.push(import_lib$2.objectProperty(key, import_lib$2.arrowFunctionExpression([], attr.expr)));
|
|
14817
|
+
}
|
|
14818
|
+
return props;
|
|
14819
|
+
}
|
|
14820
|
+
function isStaticValue(expr) {
|
|
14821
|
+
return import_lib$2.isStringLiteral(expr) || import_lib$2.isNumericLiteral(expr) || import_lib$2.isBooleanLiteral(expr) || import_lib$2.isNullLiteral(expr);
|
|
14822
|
+
}
|
|
14823
|
+
function isGetterExpression(expr) {
|
|
14824
|
+
return import_lib$2.isArrowFunctionExpression(expr) || import_lib$2.isFunctionExpression(expr);
|
|
14825
|
+
}
|
|
14826
|
+
function createObjectKey(name) {
|
|
14827
|
+
return import_lib$2.isValidIdentifier(name) ? import_lib$2.identifier(name) : import_lib$2.stringLiteral(name);
|
|
14854
14828
|
}
|
|
14855
14829
|
function emitSlot(node, context) {
|
|
14856
14830
|
return import_lib$2.callExpression(context.importRuntime("createSlot"), [node.name ? import_lib$2.stringLiteral(node.name) : import_lib$2.identifier("undefined"), node.fallback.length > 0 ? import_lib$2.arrowFunctionExpression([], emitChildrenProp(node.fallback, context)) : import_lib$2.identifier("undefined")]);
|
|
@@ -14859,7 +14833,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
14859
14833
|
return import_lib$2.identifier(node.ref.name);
|
|
14860
14834
|
}
|
|
14861
14835
|
//#endregion
|
|
14862
|
-
//#region packages/compiler/src/codegen/dom/index.ts
|
|
14836
|
+
//#region packages/core/compiler/src/codegen/dom/index.ts
|
|
14863
14837
|
function emitDOM(node, context) {
|
|
14864
14838
|
switch (node.kind) {
|
|
14865
14839
|
case "Element": return emitElement(node, context);
|
|
@@ -14874,7 +14848,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
14874
14848
|
}
|
|
14875
14849
|
}
|
|
14876
14850
|
//#endregion
|
|
14877
|
-
//#region packages/compiler/src/context/CompilerContext.ts
|
|
14851
|
+
//#region packages/core/compiler/src/context/CompilerContext.ts
|
|
14878
14852
|
var CompilerContext = class {
|
|
14879
14853
|
constructor(options, programPath) {
|
|
14880
14854
|
this.options = options;
|
|
@@ -14937,7 +14911,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
14937
14911
|
return new CompilerContext(options, path.scope.getProgramParent().path);
|
|
14938
14912
|
}
|
|
14939
14913
|
//#endregion
|
|
14940
|
-
//#region packages/compiler/src/diagnostics/codes.ts
|
|
14914
|
+
//#region packages/core/compiler/src/diagnostics/codes.ts
|
|
14941
14915
|
const CompilerErrorCode = {
|
|
14942
14916
|
UNSUPPORTED_SPREAD_ATTRIBUTE: "ZEUS_UNSUPPORTED_SPREAD_ATTRIBUTE",
|
|
14943
14917
|
UNSUPPORTED_SPREAD_CHILD: "ZEUS_UNSUPPORTED_SPREAD_CHILD",
|
|
@@ -14951,7 +14925,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
14951
14925
|
INVALID_REF_USAGE: "ZEUS_INVALID_REF_USAGE"
|
|
14952
14926
|
};
|
|
14953
14927
|
//#endregion
|
|
14954
|
-
//#region packages/compiler/src/diagnostics/CompilerError.ts
|
|
14928
|
+
//#region packages/core/compiler/src/diagnostics/CompilerError.ts
|
|
14955
14929
|
var CompilerError = class extends Error {
|
|
14956
14930
|
constructor(options) {
|
|
14957
14931
|
var _options$path;
|
|
@@ -15026,7 +15000,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
15026
15000
|
return e;
|
|
15027
15001
|
}
|
|
15028
15002
|
//#endregion
|
|
15029
|
-
//#region packages/compiler/src/ir/semanticBuilders.ts
|
|
15003
|
+
//#region packages/core/compiler/src/ir/semanticBuilders.ts
|
|
15030
15004
|
let nextId = 0;
|
|
15031
15005
|
function id() {
|
|
15032
15006
|
return nextId++;
|
|
@@ -15143,11 +15117,12 @@ var ZeusCompiler = (function(exports) {
|
|
|
15143
15117
|
body: input.body
|
|
15144
15118
|
};
|
|
15145
15119
|
}
|
|
15146
|
-
function hostIR(
|
|
15120
|
+
function hostIR(input) {
|
|
15147
15121
|
return {
|
|
15148
15122
|
id: id(),
|
|
15149
15123
|
kind: "Host",
|
|
15150
|
-
|
|
15124
|
+
attrs: input.attrs,
|
|
15125
|
+
child: input.child
|
|
15151
15126
|
};
|
|
15152
15127
|
}
|
|
15153
15128
|
function slotIR(input) {
|
|
@@ -15161,7 +15136,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
15161
15136
|
};
|
|
15162
15137
|
}
|
|
15163
15138
|
//#endregion
|
|
15164
|
-
//#region packages/compiler/src/parse/jsx.ts
|
|
15139
|
+
//#region packages/core/compiler/src/parse/jsx.ts
|
|
15165
15140
|
/**
|
|
15166
15141
|
* JSX AST parsing utilities.
|
|
15167
15142
|
*
|
|
@@ -15188,7 +15163,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
15188
15163
|
return name.slice(2).toLowerCase();
|
|
15189
15164
|
}
|
|
15190
15165
|
//#endregion
|
|
15191
|
-
//#region packages/compiler/src/lower/lowerAttribute.ts
|
|
15166
|
+
//#region packages/core/compiler/src/lower/lowerAttribute.ts
|
|
15192
15167
|
function lowerAttribute(path, _context) {
|
|
15193
15168
|
if (path.isJSXSpreadAttribute() || import_lib$2.isJSXSpreadAttribute(path.node)) throw new CompilerError({
|
|
15194
15169
|
code: CompilerErrorCode.UNSUPPORTED_SPREAD_ATTRIBUTE,
|
|
@@ -15232,7 +15207,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
15232
15207
|
return null;
|
|
15233
15208
|
}
|
|
15234
15209
|
//#endregion
|
|
15235
|
-
//#region packages/compiler/src/lower/lowerChildren.ts
|
|
15210
|
+
//#region packages/core/compiler/src/lower/lowerChildren.ts
|
|
15236
15211
|
function lowerChildren(children, context) {
|
|
15237
15212
|
const result = [];
|
|
15238
15213
|
for (const child of children) {
|
|
@@ -15255,7 +15230,12 @@ var ZeusCompiler = (function(exports) {
|
|
|
15255
15230
|
return result;
|
|
15256
15231
|
}
|
|
15257
15232
|
//#endregion
|
|
15258
|
-
//#region packages/compiler/src/lower/lowerBuiltin.ts
|
|
15233
|
+
//#region packages/core/compiler/src/lower/lowerBuiltin.ts
|
|
15234
|
+
const HOST_SKIP_PROPS = new Set([
|
|
15235
|
+
"key",
|
|
15236
|
+
"__slot",
|
|
15237
|
+
"__anchor"
|
|
15238
|
+
]);
|
|
15259
15239
|
function isBuiltinTag(tagName) {
|
|
15260
15240
|
return tagName === "Show" || tagName === "For" || tagName === "Host" || tagName === "Slot";
|
|
15261
15241
|
}
|
|
@@ -15269,7 +15249,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
15269
15249
|
switch (tagName.name) {
|
|
15270
15250
|
case "Show": return lowerShow(path, context);
|
|
15271
15251
|
case "For": return lowerFor(path, context);
|
|
15272
|
-
case "Host": return
|
|
15252
|
+
case "Host": return lowerHost(path, context);
|
|
15273
15253
|
case "Slot": return lowerSlot(path, context);
|
|
15274
15254
|
default: throw new CompilerError({
|
|
15275
15255
|
code: CompilerErrorCode.INVALID_BUILTIN_USAGE,
|
|
@@ -15379,8 +15359,73 @@ var ZeusCompiler = (function(exports) {
|
|
|
15379
15359
|
const name = path.node.openingElement.name;
|
|
15380
15360
|
return import_lib$2.isJSXIdentifier(name) ? name.name : "Builtin";
|
|
15381
15361
|
}
|
|
15362
|
+
function isEventLikeProp(key) {
|
|
15363
|
+
return /^on[A-Z]/.test(key) || key.startsWith("on:");
|
|
15364
|
+
}
|
|
15365
|
+
function normalizeHostAttrName(name) {
|
|
15366
|
+
switch (name) {
|
|
15367
|
+
case "className": return "class";
|
|
15368
|
+
case "htmlFor": return "for";
|
|
15369
|
+
case "tabIndex": return "tabindex";
|
|
15370
|
+
case "readOnly": return "readonly";
|
|
15371
|
+
default: return name;
|
|
15372
|
+
}
|
|
15373
|
+
}
|
|
15374
|
+
function lowerHost(path, context) {
|
|
15375
|
+
const attrs = [];
|
|
15376
|
+
const rawChildren = lowerChildren(path.get("children"), context);
|
|
15377
|
+
for (const attrPath of path.get("openingElement").get("attributes")) {
|
|
15378
|
+
const node = attrPath.node;
|
|
15379
|
+
if (import_lib$2.isJSXSpreadAttribute(node)) throw new CompilerError({
|
|
15380
|
+
code: CompilerErrorCode.UNSUPPORTED_COMPONENT_PROP,
|
|
15381
|
+
message: "Spread props are not supported on Host in Phase 1.",
|
|
15382
|
+
path: attrPath
|
|
15383
|
+
});
|
|
15384
|
+
if (!attrPath.isJSXAttribute()) continue;
|
|
15385
|
+
const name = getJSXAttrName(node.name);
|
|
15386
|
+
if (HOST_SKIP_PROPS.has(name)) continue;
|
|
15387
|
+
if (name === "children") continue;
|
|
15388
|
+
if (name === "ref") {
|
|
15389
|
+
const value = attrPath.get("value");
|
|
15390
|
+
if (value.isJSXExpressionContainer()) {
|
|
15391
|
+
const expr = value.get("expression");
|
|
15392
|
+
if (expr.isExpression()) attrs.push({
|
|
15393
|
+
id: id(),
|
|
15394
|
+
kind: "HostAttr",
|
|
15395
|
+
name: "ref",
|
|
15396
|
+
expr: expr.node
|
|
15397
|
+
});
|
|
15398
|
+
}
|
|
15399
|
+
continue;
|
|
15400
|
+
}
|
|
15401
|
+
if (isEventLikeProp(name)) continue;
|
|
15402
|
+
const value = node.value;
|
|
15403
|
+
if (!value) attrs.push({
|
|
15404
|
+
id: id(),
|
|
15405
|
+
kind: "HostAttr",
|
|
15406
|
+
name: normalizeHostAttrName(name),
|
|
15407
|
+
expr: import_lib$2.booleanLiteral(true)
|
|
15408
|
+
});
|
|
15409
|
+
else if (import_lib$2.isStringLiteral(value)) attrs.push({
|
|
15410
|
+
id: id(),
|
|
15411
|
+
kind: "HostAttr",
|
|
15412
|
+
name: normalizeHostAttrName(name),
|
|
15413
|
+
expr: import_lib$2.stringLiteral(value.value)
|
|
15414
|
+
});
|
|
15415
|
+
else if (import_lib$2.isJSXExpressionContainer(value) && !import_lib$2.isJSXEmptyExpression(value.expression)) attrs.push({
|
|
15416
|
+
id: id(),
|
|
15417
|
+
kind: "HostAttr",
|
|
15418
|
+
name: normalizeHostAttrName(name),
|
|
15419
|
+
expr: value.expression
|
|
15420
|
+
});
|
|
15421
|
+
}
|
|
15422
|
+
return hostIR({
|
|
15423
|
+
attrs,
|
|
15424
|
+
child: rawChildren.length === 0 ? void 0 : rawChildren.length === 1 ? rawChildren[0] : fragmentIR(rawChildren)
|
|
15425
|
+
});
|
|
15426
|
+
}
|
|
15382
15427
|
//#endregion
|
|
15383
|
-
//#region packages/compiler/src/lower/lowerComponent.ts
|
|
15428
|
+
//#region packages/core/compiler/src/lower/lowerComponent.ts
|
|
15384
15429
|
function lowerComponent(path, context) {
|
|
15385
15430
|
const tag = convertComponentIdentifier(path.node.openingElement.name);
|
|
15386
15431
|
const props = [];
|
|
@@ -15444,7 +15489,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
15444
15489
|
return node;
|
|
15445
15490
|
}
|
|
15446
15491
|
//#endregion
|
|
15447
|
-
//#region packages/compiler/src/lower/lowerElement.ts
|
|
15492
|
+
//#region packages/core/compiler/src/lower/lowerElement.ts
|
|
15448
15493
|
function lowerElement(path, context) {
|
|
15449
15494
|
const tagName = getTagName(path.node);
|
|
15450
15495
|
if (isBuiltinTag(tagName)) return lowerBuiltin(path, context);
|
|
@@ -15462,19 +15507,19 @@ var ZeusCompiler = (function(exports) {
|
|
|
15462
15507
|
});
|
|
15463
15508
|
}
|
|
15464
15509
|
//#endregion
|
|
15465
|
-
//#region packages/compiler/src/lower/lowerFragment.ts
|
|
15510
|
+
//#region packages/core/compiler/src/lower/lowerFragment.ts
|
|
15466
15511
|
function lowerFragment(path, context) {
|
|
15467
15512
|
return fragmentIR(lowerChildren(path.get("children"), context));
|
|
15468
15513
|
}
|
|
15469
15514
|
//#endregion
|
|
15470
|
-
//#region packages/compiler/src/lower/lowerJSX.ts
|
|
15515
|
+
//#region packages/core/compiler/src/lower/lowerJSX.ts
|
|
15471
15516
|
function lowerJSX(path, context) {
|
|
15472
15517
|
if (path.isJSXElement()) return lowerElement(path, context);
|
|
15473
15518
|
if (path.isJSXFragment()) return lowerFragment(path, context);
|
|
15474
15519
|
throw new Error("Unsupported JSX node");
|
|
15475
15520
|
}
|
|
15476
15521
|
//#endregion
|
|
15477
|
-
//#region packages/compiler/src/passes/normalizeChildren.ts
|
|
15522
|
+
//#region packages/core/compiler/src/passes/normalizeChildren.ts
|
|
15478
15523
|
function normalizeChildren(node) {
|
|
15479
15524
|
visit$2(node);
|
|
15480
15525
|
return node;
|
|
@@ -15483,13 +15528,15 @@ var ZeusCompiler = (function(exports) {
|
|
|
15483
15528
|
switch (node.kind) {
|
|
15484
15529
|
case "Element":
|
|
15485
15530
|
case "Fragment":
|
|
15486
|
-
case "Host":
|
|
15487
15531
|
node.children = node.children.filter((child) => {
|
|
15488
15532
|
if (child.kind === "Text") return child.value.length > 0;
|
|
15489
15533
|
return true;
|
|
15490
15534
|
});
|
|
15491
15535
|
for (const child of node.children) visit$2(child);
|
|
15492
15536
|
return;
|
|
15537
|
+
case "Host":
|
|
15538
|
+
if (node.child) visit$2(node.child);
|
|
15539
|
+
return;
|
|
15493
15540
|
case "Component":
|
|
15494
15541
|
for (const prop of node.props) {
|
|
15495
15542
|
if (!Array.isArray(prop.value)) continue;
|
|
@@ -15525,7 +15572,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
15525
15572
|
}
|
|
15526
15573
|
}
|
|
15527
15574
|
//#endregion
|
|
15528
|
-
//#region packages/compiler/src/passes/assignDomPaths.ts
|
|
15575
|
+
//#region packages/core/compiler/src/passes/assignDomPaths.ts
|
|
15529
15576
|
function assignDomPaths(node) {
|
|
15530
15577
|
visitNode$1(node);
|
|
15531
15578
|
return node;
|
|
@@ -15553,7 +15600,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
15553
15600
|
for (const child of node.body) visitNode$1(child);
|
|
15554
15601
|
return;
|
|
15555
15602
|
case "Host":
|
|
15556
|
-
|
|
15603
|
+
if (node.child) visitNode$1(node.child, parent);
|
|
15557
15604
|
return;
|
|
15558
15605
|
case "Slot":
|
|
15559
15606
|
for (const child of node.fallback) visitNode$1(child);
|
|
@@ -15616,7 +15663,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
15616
15663
|
return node.kind === "DynamicText" || node.kind === "Component" || node.kind === "Show" || node.kind === "For" || node.kind === "Slot";
|
|
15617
15664
|
}
|
|
15618
15665
|
//#endregion
|
|
15619
|
-
//#region packages/compiler/src/passes/assignPhysicalDomPaths.ts
|
|
15666
|
+
//#region packages/core/compiler/src/passes/assignPhysicalDomPaths.ts
|
|
15620
15667
|
function assignPhysicalDomPaths(node) {
|
|
15621
15668
|
visitNode(node);
|
|
15622
15669
|
return node;
|
|
@@ -15631,7 +15678,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
15631
15678
|
for (const child of node.children) visitNode(child, parent);
|
|
15632
15679
|
return;
|
|
15633
15680
|
case "Host":
|
|
15634
|
-
|
|
15681
|
+
if (node.child) visitNode(node.child, parent);
|
|
15635
15682
|
return;
|
|
15636
15683
|
case "Show":
|
|
15637
15684
|
for (const child of node.children) visitNode(child);
|
|
@@ -15717,12 +15764,12 @@ var ZeusCompiler = (function(exports) {
|
|
|
15717
15764
|
for (const child of node.children) appendPhysicalChild(result, child);
|
|
15718
15765
|
return;
|
|
15719
15766
|
case "Host":
|
|
15720
|
-
|
|
15767
|
+
if (node.child) appendPhysicalChild(result, node.child);
|
|
15721
15768
|
return;
|
|
15722
15769
|
}
|
|
15723
15770
|
}
|
|
15724
15771
|
//#endregion
|
|
15725
|
-
//#region packages/compiler/src/passes/validateBuiltins.ts
|
|
15772
|
+
//#region packages/core/compiler/src/passes/validateBuiltins.ts
|
|
15726
15773
|
function validateBuiltins(node) {
|
|
15727
15774
|
visit$1(node, {
|
|
15728
15775
|
insideHost: false,
|
|
@@ -15736,7 +15783,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
15736
15783
|
code: CompilerErrorCode.INVALID_BUILTIN_USAGE,
|
|
15737
15784
|
message: "<Host> can only be used as a root host boundary."
|
|
15738
15785
|
});
|
|
15739
|
-
|
|
15786
|
+
if (node.child) visit$1(node.child, {
|
|
15740
15787
|
insideHost: true,
|
|
15741
15788
|
root: false
|
|
15742
15789
|
});
|
|
@@ -15768,7 +15815,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
15768
15815
|
}
|
|
15769
15816
|
}
|
|
15770
15817
|
//#endregion
|
|
15771
|
-
//#region packages/compiler/src/passes/analyzeBindings.ts
|
|
15818
|
+
//#region packages/core/compiler/src/passes/analyzeBindings.ts
|
|
15772
15819
|
function analyzeBindings(node) {
|
|
15773
15820
|
const analysis = {
|
|
15774
15821
|
dynamicText: 0,
|
|
@@ -15799,9 +15846,11 @@ var ZeusCompiler = (function(exports) {
|
|
|
15799
15846
|
}
|
|
15800
15847
|
return;
|
|
15801
15848
|
case "Fragment":
|
|
15802
|
-
case "Host":
|
|
15803
15849
|
for (const child of node.children) visit(child, analysis);
|
|
15804
15850
|
return;
|
|
15851
|
+
case "Host":
|
|
15852
|
+
if (node.child) visit(node.child, analysis);
|
|
15853
|
+
return;
|
|
15805
15854
|
case "Slot":
|
|
15806
15855
|
for (const child of node.fallback) visit(child, analysis);
|
|
15807
15856
|
return;
|
|
@@ -15816,7 +15865,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
15816
15865
|
}
|
|
15817
15866
|
}
|
|
15818
15867
|
//#endregion
|
|
15819
|
-
//#region packages/compiler/src/transform/index.ts
|
|
15868
|
+
//#region packages/core/compiler/src/transform/index.ts
|
|
15820
15869
|
function transformJSX(path, state, config) {
|
|
15821
15870
|
if (state.get("skip")) return;
|
|
15822
15871
|
if (!path.isJSXElement() && !path.isJSXFragment()) return;
|
|
@@ -15831,7 +15880,7 @@ var ZeusCompiler = (function(exports) {
|
|
|
15831
15880
|
path.replaceWith(emitDOM(ir, context));
|
|
15832
15881
|
}
|
|
15833
15882
|
//#endregion
|
|
15834
|
-
//#region packages/compiler/src/visitor.ts
|
|
15883
|
+
//#region packages/core/compiler/src/visitor.ts
|
|
15835
15884
|
function createVisitor(config) {
|
|
15836
15885
|
return {
|
|
15837
15886
|
JSXElement(path, state) {
|