@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
|
@@ -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
|
**/
|
|
@@ -27,61 +27,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
}) : target, mod));
|
|
28
28
|
//#endregion
|
|
29
29
|
//#region node_modules/.pnpm/@babel+helper-plugin-utils@7.29.7/node_modules/@babel/helper-plugin-utils/lib/index.js
|
|
30
|
-
var require_lib$5 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
31
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.declare = declare;
|
|
33
|
-
exports.declarePreset = void 0;
|
|
34
|
-
const apiPolyfills = { assertVersion: (api) => (range) => {
|
|
35
|
-
throwVersionError(range, api.version);
|
|
36
|
-
} };
|
|
37
|
-
Object.assign(apiPolyfills, {
|
|
38
|
-
targets: () => () => {
|
|
39
|
-
return {};
|
|
40
|
-
},
|
|
41
|
-
assumption: () => () => {},
|
|
42
|
-
addExternalDependency: () => () => {}
|
|
43
|
-
});
|
|
44
|
-
function declare(builder) {
|
|
45
|
-
return (api, options, dirname) => {
|
|
46
|
-
let clonedApi;
|
|
47
|
-
for (const name of Object.keys(apiPolyfills)) {
|
|
48
|
-
if (api[name]) continue;
|
|
49
|
-
clonedApi != null || (clonedApi = copyApiObject(api));
|
|
50
|
-
clonedApi[name] = apiPolyfills[name](clonedApi);
|
|
51
|
-
}
|
|
52
|
-
return builder(clonedApi != null ? clonedApi : api, options || {}, dirname);
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
exports.declarePreset = declare;
|
|
56
|
-
function copyApiObject(api) {
|
|
57
|
-
let proto = null;
|
|
58
|
-
if (typeof api.version === "string" && api.version.startsWith("7.")) {
|
|
59
|
-
proto = Object.getPrototypeOf(api);
|
|
60
|
-
if (proto && (!hasOwnProperty.call(proto, "version") || !hasOwnProperty.call(proto, "transform") || !hasOwnProperty.call(proto, "template") || !hasOwnProperty.call(proto, "types"))) proto = null;
|
|
61
|
-
}
|
|
62
|
-
return Object.assign({}, proto, api);
|
|
63
|
-
}
|
|
64
|
-
function throwVersionError(range, version) {
|
|
65
|
-
if (typeof range === "number") {
|
|
66
|
-
if (!Number.isInteger(range)) throw new Error("Expected string or integer value.");
|
|
67
|
-
range = `^${range}.0.0-0`;
|
|
68
|
-
}
|
|
69
|
-
if (typeof range !== "string") throw new Error("Expected string or integer value.");
|
|
70
|
-
const limit = Error.stackTraceLimit;
|
|
71
|
-
if (typeof limit === "number" && limit < 25) Error.stackTraceLimit = 25;
|
|
72
|
-
let err;
|
|
73
|
-
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.`);
|
|
74
|
-
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.`);
|
|
75
|
-
if (typeof limit === "number") Error.stackTraceLimit = limit;
|
|
76
|
-
throw Object.assign(err, {
|
|
77
|
-
code: "BABEL_VERSION_UNSUPPORTED",
|
|
78
|
-
version,
|
|
79
|
-
range
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}));
|
|
83
|
-
//#endregion
|
|
84
|
-
//#region node_modules/.pnpm/@babel+helper-plugin-utils@7.28.6/node_modules/@babel/helper-plugin-utils/lib/index.js
|
|
85
30
|
var require_lib$4 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
86
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
87
32
|
exports.declare = declare;
|
|
@@ -2985,7 +2930,7 @@ var require_is = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
2985
2930
|
}
|
|
2986
2931
|
}));
|
|
2987
2932
|
//#endregion
|
|
2988
|
-
//#region node_modules/.pnpm/@babel+helper-validator-identifier@7.
|
|
2933
|
+
//#region node_modules/.pnpm/@babel+helper-validator-identifier@7.29.7/node_modules/@babel/helper-validator-identifier/lib/identifier.js
|
|
2989
2934
|
var require_identifier = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2990
2935
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2991
2936
|
exports.isIdentifierChar = isIdentifierChar;
|
|
@@ -3993,7 +3938,7 @@ var require_identifier = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
3993
3938
|
}
|
|
3994
3939
|
}));
|
|
3995
3940
|
//#endregion
|
|
3996
|
-
//#region node_modules/.pnpm/@babel+helper-validator-identifier@7.
|
|
3941
|
+
//#region node_modules/.pnpm/@babel+helper-validator-identifier@7.29.7/node_modules/@babel/helper-validator-identifier/lib/keyword.js
|
|
3997
3942
|
var require_keyword = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
3998
3943
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3999
3944
|
exports.isKeyword = isKeyword;
|
|
@@ -4072,7 +4017,7 @@ var require_keyword = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
4072
4017
|
}
|
|
4073
4018
|
}));
|
|
4074
4019
|
//#endregion
|
|
4075
|
-
//#region node_modules/.pnpm/@babel+helper-validator-identifier@7.
|
|
4020
|
+
//#region node_modules/.pnpm/@babel+helper-validator-identifier@7.29.7/node_modules/@babel/helper-validator-identifier/lib/index.js
|
|
4076
4021
|
var require_lib$2 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
4077
4022
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4078
4023
|
Object.defineProperty(exports, "isIdentifierChar", {
|
|
@@ -4141,7 +4086,7 @@ var require_isValidIdentifier = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
4141
4086
|
}
|
|
4142
4087
|
}));
|
|
4143
4088
|
//#endregion
|
|
4144
|
-
//#region node_modules/.pnpm/@babel+helper-string-parser@7.
|
|
4089
|
+
//#region node_modules/.pnpm/@babel+helper-string-parser@7.29.7/node_modules/@babel/helper-string-parser/lib/index.js
|
|
4145
4090
|
var require_lib$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
4146
4091
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4147
4092
|
exports.readCodePoint = readCodePoint;
|
|
@@ -14212,8 +14157,8 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
14212
14157
|
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!");
|
|
14213
14158
|
}));
|
|
14214
14159
|
//#endregion
|
|
14215
|
-
//#region packages/compiler/src/codegen/support/imports.ts
|
|
14216
|
-
var import_lib = require_lib$
|
|
14160
|
+
//#region packages/core/compiler/src/codegen/support/imports.ts
|
|
14161
|
+
var import_lib = require_lib$4();
|
|
14217
14162
|
var import_lib$1 = /* @__PURE__ */ __toESM(require_lib$3());
|
|
14218
14163
|
var import_lib$2 = /* @__PURE__ */ __toESM(require_lib());
|
|
14219
14164
|
const DEFAULT_RENDERER_MODULE = "@zeus-js/runtime-dom";
|
|
@@ -14266,7 +14211,7 @@ function getProgramPath(path) {
|
|
|
14266
14211
|
return path.scope.getProgramParent().path;
|
|
14267
14212
|
}
|
|
14268
14213
|
//#endregion
|
|
14269
|
-
//#region packages/compiler/src/codegen/support/templates.ts
|
|
14214
|
+
//#region packages/core/compiler/src/codegen/support/templates.ts
|
|
14270
14215
|
/**
|
|
14271
14216
|
* Template registration, scope data management, and program injection.
|
|
14272
14217
|
*
|
|
@@ -14310,7 +14255,7 @@ function appendTemplates(path) {
|
|
|
14310
14255
|
path.node.body.unshift(import_lib$2.variableDeclaration("var", declarators));
|
|
14311
14256
|
}
|
|
14312
14257
|
//#endregion
|
|
14313
|
-
//#region packages/compiler/src/codegen/support/events.ts
|
|
14258
|
+
//#region packages/core/compiler/src/codegen/support/events.ts
|
|
14314
14259
|
/**
|
|
14315
14260
|
* Event registration and delegation.
|
|
14316
14261
|
*
|
|
@@ -14340,7 +14285,7 @@ function appendEvents(path) {
|
|
|
14340
14285
|
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)))])));
|
|
14341
14286
|
}
|
|
14342
14287
|
//#endregion
|
|
14343
|
-
//#region packages/compiler/src/config/index.ts
|
|
14288
|
+
//#region packages/core/compiler/src/config/index.ts
|
|
14344
14289
|
const DEFAULT_OPTIONS = {
|
|
14345
14290
|
moduleName: DEFAULT_RENDERER_MODULE,
|
|
14346
14291
|
generate: "dom",
|
|
@@ -14368,7 +14313,7 @@ function resolveConfig(options) {
|
|
|
14368
14313
|
return extend(DEFAULT_OPTIONS, options);
|
|
14369
14314
|
}
|
|
14370
14315
|
//#endregion
|
|
14371
|
-
//#region packages/compiler/src/utils/constant.ts
|
|
14316
|
+
//#region packages/core/compiler/src/utils/constant.ts
|
|
14372
14317
|
const VoidElements = [
|
|
14373
14318
|
"area",
|
|
14374
14319
|
"base",
|
|
@@ -14388,7 +14333,7 @@ const VoidElements = [
|
|
|
14388
14333
|
"wbr"
|
|
14389
14334
|
];
|
|
14390
14335
|
//#endregion
|
|
14391
|
-
//#region packages/compiler/src/utils/html.ts
|
|
14336
|
+
//#region packages/core/compiler/src/utils/html.ts
|
|
14392
14337
|
function escapeHTML(value, attr = false) {
|
|
14393
14338
|
let result = value.replace(/&/g, "&");
|
|
14394
14339
|
if (attr) return result.replace(/"/g, """).replace(/>/g, ">");
|
|
@@ -14407,14 +14352,14 @@ function isRawTextElement(tagName) {
|
|
|
14407
14352
|
return rawTextElements.has(tagName);
|
|
14408
14353
|
}
|
|
14409
14354
|
//#endregion
|
|
14410
|
-
//#region packages/compiler/src/utils/metadata.ts
|
|
14355
|
+
//#region packages/core/compiler/src/utils/metadata.ts
|
|
14411
14356
|
function setZeusMetadata(state, config) {
|
|
14412
14357
|
const metadata = state.file.metadata;
|
|
14413
14358
|
metadata.zeus = extend({}, metadata.zeus, { config });
|
|
14414
14359
|
return metadata.zeus;
|
|
14415
14360
|
}
|
|
14416
14361
|
//#endregion
|
|
14417
|
-
//#region packages/compiler/src/program.ts
|
|
14362
|
+
//#region packages/core/compiler/src/program.ts
|
|
14418
14363
|
/**
|
|
14419
14364
|
* Program visitor — entry and exit point for the entire transform pass.
|
|
14420
14365
|
*
|
|
@@ -14441,7 +14386,7 @@ function createProgramVisitor(config) {
|
|
|
14441
14386
|
};
|
|
14442
14387
|
}
|
|
14443
14388
|
//#endregion
|
|
14444
|
-
//#region packages/compiler/src/codegen/dom/emitBinding.ts
|
|
14389
|
+
//#region packages/core/compiler/src/codegen/dom/emitBinding.ts
|
|
14445
14390
|
function emitBindings(node, context) {
|
|
14446
14391
|
const statements = [];
|
|
14447
14392
|
for (const attr of node.attrs) {
|
|
@@ -14564,7 +14509,7 @@ function emitMarkerMount(node, context, mountCall) {
|
|
|
14564
14509
|
return [import_lib$2.expressionStatement(mountCall)];
|
|
14565
14510
|
}
|
|
14566
14511
|
//#endregion
|
|
14567
|
-
//#region packages/compiler/src/codegen/dom/emitDomPath.ts
|
|
14512
|
+
//#region packages/core/compiler/src/codegen/dom/emitDomPath.ts
|
|
14568
14513
|
function emitPhysicalDomPath(path) {
|
|
14569
14514
|
switch (path.kind) {
|
|
14570
14515
|
case "Root": throw new Error("Root path is emitted from template clone directly");
|
|
@@ -14574,7 +14519,7 @@ function emitPhysicalDomPath(path) {
|
|
|
14574
14519
|
}
|
|
14575
14520
|
}
|
|
14576
14521
|
//#endregion
|
|
14577
|
-
//#region packages/compiler/src/passes/collectTemplates.ts
|
|
14522
|
+
//#region packages/core/compiler/src/passes/collectTemplates.ts
|
|
14578
14523
|
function collectTemplates(node, context) {
|
|
14579
14524
|
if (node.kind === "Element") {
|
|
14580
14525
|
context.registerTemplate(renderTemplateHTML(node), node.flags.isSVG);
|
|
@@ -14615,7 +14560,7 @@ function renderChildTemplate(node) {
|
|
|
14615
14560
|
case "Show":
|
|
14616
14561
|
case "For":
|
|
14617
14562
|
case "Slot": return "<!>";
|
|
14618
|
-
case "Host": return node.
|
|
14563
|
+
case "Host": return node.child ? renderChildTemplate(node.child) : "";
|
|
14619
14564
|
case "Fragment": return node.children.map(renderChildTemplate).join("");
|
|
14620
14565
|
}
|
|
14621
14566
|
}
|
|
@@ -14623,7 +14568,7 @@ function escapeAttr(value) {
|
|
|
14623
14568
|
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
14624
14569
|
}
|
|
14625
14570
|
//#endregion
|
|
14626
|
-
//#region packages/compiler/src/codegen/dom/emitTemplate.ts
|
|
14571
|
+
//#region packages/core/compiler/src/codegen/dom/emitTemplate.ts
|
|
14627
14572
|
function emitTemplateClone(node, context) {
|
|
14628
14573
|
const html = renderTemplateHTML(node);
|
|
14629
14574
|
const template = context.registerTemplate(html, node.flags.isSVG);
|
|
@@ -14631,7 +14576,7 @@ function emitTemplateClone(node, context) {
|
|
|
14631
14576
|
return import_lib$2.memberExpression(templateCall, import_lib$2.identifier("firstChild"));
|
|
14632
14577
|
}
|
|
14633
14578
|
//#endregion
|
|
14634
|
-
//#region packages/compiler/src/codegen/dom/emitElement.ts
|
|
14579
|
+
//#region packages/core/compiler/src/codegen/dom/emitElement.ts
|
|
14635
14580
|
function emitElement(node, context) {
|
|
14636
14581
|
if (!hasRuntimeWork(node)) return emitTemplateClone(node, context);
|
|
14637
14582
|
const statements = [
|
|
@@ -14671,7 +14616,7 @@ function collectRefNode(node, map) {
|
|
|
14671
14616
|
for (const child of node.children) collectRefNode(child, map);
|
|
14672
14617
|
return;
|
|
14673
14618
|
case "Host":
|
|
14674
|
-
|
|
14619
|
+
if (node.child) collectRefNode(node.child, map);
|
|
14675
14620
|
return;
|
|
14676
14621
|
default: return;
|
|
14677
14622
|
}
|
|
@@ -14693,7 +14638,7 @@ function collectRequiredDomRefDeclaration(node, statements, context, refNodeMap,
|
|
|
14693
14638
|
for (const child of node.children) collectRequiredDomRefDeclaration(child, statements, context, refNodeMap, declared);
|
|
14694
14639
|
return;
|
|
14695
14640
|
case "Host":
|
|
14696
|
-
|
|
14641
|
+
if (node.child) collectRequiredDomRefDeclaration(node.child, statements, context, refNodeMap, declared);
|
|
14697
14642
|
return;
|
|
14698
14643
|
default: return;
|
|
14699
14644
|
}
|
|
@@ -14740,11 +14685,18 @@ function needsDomRefDeclaration(node) {
|
|
|
14740
14685
|
case "Slot": return true;
|
|
14741
14686
|
case "Element": return needsDomRefDeclaration(child);
|
|
14742
14687
|
case "Fragment": return child.children.some((inner) => inner.kind === "Element" ? needsDomRefDeclaration(inner) : inner.kind !== "Text");
|
|
14743
|
-
case "Host": return child.
|
|
14688
|
+
case "Host": return child.child ? innerKind(child.child) : false;
|
|
14744
14689
|
default: return false;
|
|
14745
14690
|
}
|
|
14746
14691
|
});
|
|
14747
14692
|
}
|
|
14693
|
+
function innerKind(node) {
|
|
14694
|
+
switch (node.kind) {
|
|
14695
|
+
case "Element": return needsDomRefDeclaration(node);
|
|
14696
|
+
case "Text": return false;
|
|
14697
|
+
default: return true;
|
|
14698
|
+
}
|
|
14699
|
+
}
|
|
14748
14700
|
function hasRuntimeWork(node) {
|
|
14749
14701
|
return node.attrs.some((attr) => attr.kind === "AttrBinding" || attr.kind === "PropBinding" || attr.kind === "EventBinding" || attr.kind === "RefBinding") || node.children.some(hasChildRuntimeWork);
|
|
14750
14702
|
}
|
|
@@ -14756,18 +14708,18 @@ function hasChildRuntimeWork(node) {
|
|
|
14756
14708
|
case "For":
|
|
14757
14709
|
case "Slot": return true;
|
|
14758
14710
|
case "Element": return hasRuntimeWork(node);
|
|
14759
|
-
case "Fragment":
|
|
14760
|
-
case "Host": return node.
|
|
14711
|
+
case "Fragment": return node.children.some(hasChildRuntimeWork);
|
|
14712
|
+
case "Host": return node.child ? hasChildRuntimeWork(node.child) : false;
|
|
14761
14713
|
default: return false;
|
|
14762
14714
|
}
|
|
14763
14715
|
}
|
|
14764
14716
|
//#endregion
|
|
14765
|
-
//#region packages/compiler/src/codegen/dom/emitFragment.ts
|
|
14717
|
+
//#region packages/core/compiler/src/codegen/dom/emitFragment.ts
|
|
14766
14718
|
function emitFragment(node, context) {
|
|
14767
14719
|
return import_lib$2.arrayExpression(node.children.map((child) => emitDOM(child, context)));
|
|
14768
14720
|
}
|
|
14769
14721
|
//#endregion
|
|
14770
|
-
//#region packages/compiler/src/codegen/dom/emitNodeExpression.ts
|
|
14722
|
+
//#region packages/core/compiler/src/codegen/dom/emitNodeExpression.ts
|
|
14771
14723
|
function emitNodeExpression(node, context) {
|
|
14772
14724
|
switch (node.kind) {
|
|
14773
14725
|
case "Text": return import_lib$2.stringLiteral(node.value);
|
|
@@ -14783,13 +14735,13 @@ function emitNodeExpression(node, context) {
|
|
|
14783
14735
|
}
|
|
14784
14736
|
}
|
|
14785
14737
|
//#endregion
|
|
14786
|
-
//#region packages/compiler/src/codegen/dom/emitComponent.ts
|
|
14738
|
+
//#region packages/core/compiler/src/codegen/dom/emitComponent.ts
|
|
14787
14739
|
function emitComponent(node, context) {
|
|
14788
14740
|
const props = import_lib$2.objectExpression(node.props.map((prop) => emitComponentProp(prop, context)));
|
|
14789
14741
|
return import_lib$2.callExpression(context.importRuntime("createComponent"), [node.callee, props]);
|
|
14790
14742
|
}
|
|
14791
14743
|
function emitComponentProp(prop, context) {
|
|
14792
|
-
const key = createObjectKey(prop.name);
|
|
14744
|
+
const key = createObjectKey$1(prop.name);
|
|
14793
14745
|
if (Array.isArray(prop.value)) return import_lib$2.objectMethod("get", key, [], import_lib$2.blockStatement([import_lib$2.returnStatement(emitChildrenProp(prop.value, context))]));
|
|
14794
14746
|
if (isStaticPropValue(prop.value)) return import_lib$2.objectProperty(key, prop.value);
|
|
14795
14747
|
return import_lib$2.objectMethod("get", key, [], import_lib$2.blockStatement([import_lib$2.returnStatement(prop.value)]));
|
|
@@ -14802,11 +14754,11 @@ function emitChildrenProp(children, context) {
|
|
|
14802
14754
|
function isStaticPropValue(value) {
|
|
14803
14755
|
return import_lib$2.isStringLiteral(value) || import_lib$2.isNumericLiteral(value) || import_lib$2.isBooleanLiteral(value) || import_lib$2.isNullLiteral(value);
|
|
14804
14756
|
}
|
|
14805
|
-
function createObjectKey(key) {
|
|
14757
|
+
function createObjectKey$1(key) {
|
|
14806
14758
|
return import_lib$2.isValidIdentifier(key) ? import_lib$2.identifier(key) : import_lib$2.stringLiteral(key);
|
|
14807
14759
|
}
|
|
14808
14760
|
//#endregion
|
|
14809
|
-
//#region packages/compiler/src/codegen/dom/emitBuiltin.ts
|
|
14761
|
+
//#region packages/core/compiler/src/codegen/dom/emitBuiltin.ts
|
|
14810
14762
|
function emitShow(node, context) {
|
|
14811
14763
|
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)))];
|
|
14812
14764
|
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));
|
|
@@ -14845,7 +14797,29 @@ function emitMountFor(node, context) {
|
|
|
14845
14797
|
]);
|
|
14846
14798
|
}
|
|
14847
14799
|
function emitHost(node, context) {
|
|
14848
|
-
|
|
14800
|
+
const props = buildHostProps(node, context);
|
|
14801
|
+
const hostCall = import_lib$2.callExpression(context.importRuntime("Host"), [import_lib$2.objectExpression(props)]);
|
|
14802
|
+
if (!node.child) return hostCall;
|
|
14803
|
+
const childExpr = emitNodeExpression(node.child, context);
|
|
14804
|
+
return import_lib$2.callExpression(import_lib$2.arrowFunctionExpression([], import_lib$2.blockStatement([import_lib$2.expressionStatement(hostCall), import_lib$2.returnStatement(childExpr)])), []);
|
|
14805
|
+
}
|
|
14806
|
+
function buildHostProps(node, context) {
|
|
14807
|
+
const props = [];
|
|
14808
|
+
for (const attr of node.attrs) {
|
|
14809
|
+
const key = createObjectKey(attr.name);
|
|
14810
|
+
if (isStaticValue(attr.expr) || isGetterExpression(attr.expr)) props.push(import_lib$2.objectProperty(key, attr.expr));
|
|
14811
|
+
else props.push(import_lib$2.objectProperty(key, import_lib$2.arrowFunctionExpression([], attr.expr)));
|
|
14812
|
+
}
|
|
14813
|
+
return props;
|
|
14814
|
+
}
|
|
14815
|
+
function isStaticValue(expr) {
|
|
14816
|
+
return import_lib$2.isStringLiteral(expr) || import_lib$2.isNumericLiteral(expr) || import_lib$2.isBooleanLiteral(expr) || import_lib$2.isNullLiteral(expr);
|
|
14817
|
+
}
|
|
14818
|
+
function isGetterExpression(expr) {
|
|
14819
|
+
return import_lib$2.isArrowFunctionExpression(expr) || import_lib$2.isFunctionExpression(expr);
|
|
14820
|
+
}
|
|
14821
|
+
function createObjectKey(name) {
|
|
14822
|
+
return import_lib$2.isValidIdentifier(name) ? import_lib$2.identifier(name) : import_lib$2.stringLiteral(name);
|
|
14849
14823
|
}
|
|
14850
14824
|
function emitSlot(node, context) {
|
|
14851
14825
|
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")]);
|
|
@@ -14854,7 +14828,7 @@ function emitMarkerIdentifier(node) {
|
|
|
14854
14828
|
return import_lib$2.identifier(node.ref.name);
|
|
14855
14829
|
}
|
|
14856
14830
|
//#endregion
|
|
14857
|
-
//#region packages/compiler/src/codegen/dom/index.ts
|
|
14831
|
+
//#region packages/core/compiler/src/codegen/dom/index.ts
|
|
14858
14832
|
function emitDOM(node, context) {
|
|
14859
14833
|
switch (node.kind) {
|
|
14860
14834
|
case "Element": return emitElement(node, context);
|
|
@@ -14869,7 +14843,7 @@ function emitDOM(node, context) {
|
|
|
14869
14843
|
}
|
|
14870
14844
|
}
|
|
14871
14845
|
//#endregion
|
|
14872
|
-
//#region packages/compiler/src/context/CompilerContext.ts
|
|
14846
|
+
//#region packages/core/compiler/src/context/CompilerContext.ts
|
|
14873
14847
|
var CompilerContext = class {
|
|
14874
14848
|
constructor(options, programPath) {
|
|
14875
14849
|
this.options = options;
|
|
@@ -14932,7 +14906,7 @@ function getCompilerContext(path, options) {
|
|
|
14932
14906
|
return new CompilerContext(options, path.scope.getProgramParent().path);
|
|
14933
14907
|
}
|
|
14934
14908
|
//#endregion
|
|
14935
|
-
//#region packages/compiler/src/diagnostics/codes.ts
|
|
14909
|
+
//#region packages/core/compiler/src/diagnostics/codes.ts
|
|
14936
14910
|
const CompilerErrorCode = {
|
|
14937
14911
|
UNSUPPORTED_SPREAD_ATTRIBUTE: "ZEUS_UNSUPPORTED_SPREAD_ATTRIBUTE",
|
|
14938
14912
|
UNSUPPORTED_SPREAD_CHILD: "ZEUS_UNSUPPORTED_SPREAD_CHILD",
|
|
@@ -14946,7 +14920,7 @@ const CompilerErrorCode = {
|
|
|
14946
14920
|
INVALID_REF_USAGE: "ZEUS_INVALID_REF_USAGE"
|
|
14947
14921
|
};
|
|
14948
14922
|
//#endregion
|
|
14949
|
-
//#region packages/compiler/src/diagnostics/CompilerError.ts
|
|
14923
|
+
//#region packages/core/compiler/src/diagnostics/CompilerError.ts
|
|
14950
14924
|
var CompilerError = class extends Error {
|
|
14951
14925
|
constructor(options) {
|
|
14952
14926
|
var _options$path;
|
|
@@ -15021,7 +14995,7 @@ function _objectSpread2(e) {
|
|
|
15021
14995
|
return e;
|
|
15022
14996
|
}
|
|
15023
14997
|
//#endregion
|
|
15024
|
-
//#region packages/compiler/src/ir/semanticBuilders.ts
|
|
14998
|
+
//#region packages/core/compiler/src/ir/semanticBuilders.ts
|
|
15025
14999
|
let nextId = 0;
|
|
15026
15000
|
function id() {
|
|
15027
15001
|
return nextId++;
|
|
@@ -15138,11 +15112,12 @@ function forIR(input) {
|
|
|
15138
15112
|
body: input.body
|
|
15139
15113
|
};
|
|
15140
15114
|
}
|
|
15141
|
-
function hostIR(
|
|
15115
|
+
function hostIR(input) {
|
|
15142
15116
|
return {
|
|
15143
15117
|
id: id(),
|
|
15144
15118
|
kind: "Host",
|
|
15145
|
-
|
|
15119
|
+
attrs: input.attrs,
|
|
15120
|
+
child: input.child
|
|
15146
15121
|
};
|
|
15147
15122
|
}
|
|
15148
15123
|
function slotIR(input) {
|
|
@@ -15156,7 +15131,7 @@ function slotIR(input) {
|
|
|
15156
15131
|
};
|
|
15157
15132
|
}
|
|
15158
15133
|
//#endregion
|
|
15159
|
-
//#region packages/compiler/src/parse/jsx.ts
|
|
15134
|
+
//#region packages/core/compiler/src/parse/jsx.ts
|
|
15160
15135
|
/**
|
|
15161
15136
|
* JSX AST parsing utilities.
|
|
15162
15137
|
*
|
|
@@ -15183,7 +15158,7 @@ function toEventName(name) {
|
|
|
15183
15158
|
return name.slice(2).toLowerCase();
|
|
15184
15159
|
}
|
|
15185
15160
|
//#endregion
|
|
15186
|
-
//#region packages/compiler/src/lower/lowerAttribute.ts
|
|
15161
|
+
//#region packages/core/compiler/src/lower/lowerAttribute.ts
|
|
15187
15162
|
function lowerAttribute(path, _context) {
|
|
15188
15163
|
if (path.isJSXSpreadAttribute() || import_lib$2.isJSXSpreadAttribute(path.node)) throw new CompilerError({
|
|
15189
15164
|
code: CompilerErrorCode.UNSUPPORTED_SPREAD_ATTRIBUTE,
|
|
@@ -15227,7 +15202,7 @@ function lowerAttribute(path, _context) {
|
|
|
15227
15202
|
return null;
|
|
15228
15203
|
}
|
|
15229
15204
|
//#endregion
|
|
15230
|
-
//#region packages/compiler/src/lower/lowerChildren.ts
|
|
15205
|
+
//#region packages/core/compiler/src/lower/lowerChildren.ts
|
|
15231
15206
|
function lowerChildren(children, context) {
|
|
15232
15207
|
const result = [];
|
|
15233
15208
|
for (const child of children) {
|
|
@@ -15250,7 +15225,12 @@ function lowerChildren(children, context) {
|
|
|
15250
15225
|
return result;
|
|
15251
15226
|
}
|
|
15252
15227
|
//#endregion
|
|
15253
|
-
//#region packages/compiler/src/lower/lowerBuiltin.ts
|
|
15228
|
+
//#region packages/core/compiler/src/lower/lowerBuiltin.ts
|
|
15229
|
+
const HOST_SKIP_PROPS = new Set([
|
|
15230
|
+
"key",
|
|
15231
|
+
"__slot",
|
|
15232
|
+
"__anchor"
|
|
15233
|
+
]);
|
|
15254
15234
|
function isBuiltinTag(tagName) {
|
|
15255
15235
|
return tagName === "Show" || tagName === "For" || tagName === "Host" || tagName === "Slot";
|
|
15256
15236
|
}
|
|
@@ -15264,7 +15244,7 @@ function lowerBuiltin(path, context) {
|
|
|
15264
15244
|
switch (tagName.name) {
|
|
15265
15245
|
case "Show": return lowerShow(path, context);
|
|
15266
15246
|
case "For": return lowerFor(path, context);
|
|
15267
|
-
case "Host": return
|
|
15247
|
+
case "Host": return lowerHost(path, context);
|
|
15268
15248
|
case "Slot": return lowerSlot(path, context);
|
|
15269
15249
|
default: throw new CompilerError({
|
|
15270
15250
|
code: CompilerErrorCode.INVALID_BUILTIN_USAGE,
|
|
@@ -15374,8 +15354,73 @@ function getBuiltinName(path) {
|
|
|
15374
15354
|
const name = path.node.openingElement.name;
|
|
15375
15355
|
return import_lib$2.isJSXIdentifier(name) ? name.name : "Builtin";
|
|
15376
15356
|
}
|
|
15357
|
+
function isEventLikeProp(key) {
|
|
15358
|
+
return /^on[A-Z]/.test(key) || key.startsWith("on:");
|
|
15359
|
+
}
|
|
15360
|
+
function normalizeHostAttrName(name) {
|
|
15361
|
+
switch (name) {
|
|
15362
|
+
case "className": return "class";
|
|
15363
|
+
case "htmlFor": return "for";
|
|
15364
|
+
case "tabIndex": return "tabindex";
|
|
15365
|
+
case "readOnly": return "readonly";
|
|
15366
|
+
default: return name;
|
|
15367
|
+
}
|
|
15368
|
+
}
|
|
15369
|
+
function lowerHost(path, context) {
|
|
15370
|
+
const attrs = [];
|
|
15371
|
+
const rawChildren = lowerChildren(path.get("children"), context);
|
|
15372
|
+
for (const attrPath of path.get("openingElement").get("attributes")) {
|
|
15373
|
+
const node = attrPath.node;
|
|
15374
|
+
if (import_lib$2.isJSXSpreadAttribute(node)) throw new CompilerError({
|
|
15375
|
+
code: CompilerErrorCode.UNSUPPORTED_COMPONENT_PROP,
|
|
15376
|
+
message: "Spread props are not supported on Host in Phase 1.",
|
|
15377
|
+
path: attrPath
|
|
15378
|
+
});
|
|
15379
|
+
if (!attrPath.isJSXAttribute()) continue;
|
|
15380
|
+
const name = getJSXAttrName(node.name);
|
|
15381
|
+
if (HOST_SKIP_PROPS.has(name)) continue;
|
|
15382
|
+
if (name === "children") continue;
|
|
15383
|
+
if (name === "ref") {
|
|
15384
|
+
const value = attrPath.get("value");
|
|
15385
|
+
if (value.isJSXExpressionContainer()) {
|
|
15386
|
+
const expr = value.get("expression");
|
|
15387
|
+
if (expr.isExpression()) attrs.push({
|
|
15388
|
+
id: id(),
|
|
15389
|
+
kind: "HostAttr",
|
|
15390
|
+
name: "ref",
|
|
15391
|
+
expr: expr.node
|
|
15392
|
+
});
|
|
15393
|
+
}
|
|
15394
|
+
continue;
|
|
15395
|
+
}
|
|
15396
|
+
if (isEventLikeProp(name)) continue;
|
|
15397
|
+
const value = node.value;
|
|
15398
|
+
if (!value) attrs.push({
|
|
15399
|
+
id: id(),
|
|
15400
|
+
kind: "HostAttr",
|
|
15401
|
+
name: normalizeHostAttrName(name),
|
|
15402
|
+
expr: import_lib$2.booleanLiteral(true)
|
|
15403
|
+
});
|
|
15404
|
+
else if (import_lib$2.isStringLiteral(value)) attrs.push({
|
|
15405
|
+
id: id(),
|
|
15406
|
+
kind: "HostAttr",
|
|
15407
|
+
name: normalizeHostAttrName(name),
|
|
15408
|
+
expr: import_lib$2.stringLiteral(value.value)
|
|
15409
|
+
});
|
|
15410
|
+
else if (import_lib$2.isJSXExpressionContainer(value) && !import_lib$2.isJSXEmptyExpression(value.expression)) attrs.push({
|
|
15411
|
+
id: id(),
|
|
15412
|
+
kind: "HostAttr",
|
|
15413
|
+
name: normalizeHostAttrName(name),
|
|
15414
|
+
expr: value.expression
|
|
15415
|
+
});
|
|
15416
|
+
}
|
|
15417
|
+
return hostIR({
|
|
15418
|
+
attrs,
|
|
15419
|
+
child: rawChildren.length === 0 ? void 0 : rawChildren.length === 1 ? rawChildren[0] : fragmentIR(rawChildren)
|
|
15420
|
+
});
|
|
15421
|
+
}
|
|
15377
15422
|
//#endregion
|
|
15378
|
-
//#region packages/compiler/src/lower/lowerComponent.ts
|
|
15423
|
+
//#region packages/core/compiler/src/lower/lowerComponent.ts
|
|
15379
15424
|
function lowerComponent(path, context) {
|
|
15380
15425
|
const tag = convertComponentIdentifier(path.node.openingElement.name);
|
|
15381
15426
|
const props = [];
|
|
@@ -15439,7 +15484,7 @@ function convertComponentIdentifier(node) {
|
|
|
15439
15484
|
return node;
|
|
15440
15485
|
}
|
|
15441
15486
|
//#endregion
|
|
15442
|
-
//#region packages/compiler/src/lower/lowerElement.ts
|
|
15487
|
+
//#region packages/core/compiler/src/lower/lowerElement.ts
|
|
15443
15488
|
function lowerElement(path, context) {
|
|
15444
15489
|
const tagName = getTagName(path.node);
|
|
15445
15490
|
if (isBuiltinTag(tagName)) return lowerBuiltin(path, context);
|
|
@@ -15457,19 +15502,19 @@ function lowerElement(path, context) {
|
|
|
15457
15502
|
});
|
|
15458
15503
|
}
|
|
15459
15504
|
//#endregion
|
|
15460
|
-
//#region packages/compiler/src/lower/lowerFragment.ts
|
|
15505
|
+
//#region packages/core/compiler/src/lower/lowerFragment.ts
|
|
15461
15506
|
function lowerFragment(path, context) {
|
|
15462
15507
|
return fragmentIR(lowerChildren(path.get("children"), context));
|
|
15463
15508
|
}
|
|
15464
15509
|
//#endregion
|
|
15465
|
-
//#region packages/compiler/src/lower/lowerJSX.ts
|
|
15510
|
+
//#region packages/core/compiler/src/lower/lowerJSX.ts
|
|
15466
15511
|
function lowerJSX(path, context) {
|
|
15467
15512
|
if (path.isJSXElement()) return lowerElement(path, context);
|
|
15468
15513
|
if (path.isJSXFragment()) return lowerFragment(path, context);
|
|
15469
15514
|
throw new Error("Unsupported JSX node");
|
|
15470
15515
|
}
|
|
15471
15516
|
//#endregion
|
|
15472
|
-
//#region packages/compiler/src/passes/normalizeChildren.ts
|
|
15517
|
+
//#region packages/core/compiler/src/passes/normalizeChildren.ts
|
|
15473
15518
|
function normalizeChildren(node) {
|
|
15474
15519
|
visit$2(node);
|
|
15475
15520
|
return node;
|
|
@@ -15478,13 +15523,15 @@ function visit$2(node) {
|
|
|
15478
15523
|
switch (node.kind) {
|
|
15479
15524
|
case "Element":
|
|
15480
15525
|
case "Fragment":
|
|
15481
|
-
case "Host":
|
|
15482
15526
|
node.children = node.children.filter((child) => {
|
|
15483
15527
|
if (child.kind === "Text") return child.value.length > 0;
|
|
15484
15528
|
return true;
|
|
15485
15529
|
});
|
|
15486
15530
|
for (const child of node.children) visit$2(child);
|
|
15487
15531
|
return;
|
|
15532
|
+
case "Host":
|
|
15533
|
+
if (node.child) visit$2(node.child);
|
|
15534
|
+
return;
|
|
15488
15535
|
case "Component":
|
|
15489
15536
|
for (const prop of node.props) {
|
|
15490
15537
|
if (!Array.isArray(prop.value)) continue;
|
|
@@ -15520,7 +15567,7 @@ function visit$2(node) {
|
|
|
15520
15567
|
}
|
|
15521
15568
|
}
|
|
15522
15569
|
//#endregion
|
|
15523
|
-
//#region packages/compiler/src/passes/assignDomPaths.ts
|
|
15570
|
+
//#region packages/core/compiler/src/passes/assignDomPaths.ts
|
|
15524
15571
|
function assignDomPaths(node) {
|
|
15525
15572
|
visitNode$1(node);
|
|
15526
15573
|
return node;
|
|
@@ -15548,7 +15595,7 @@ function visitNode$1(node, parent) {
|
|
|
15548
15595
|
for (const child of node.body) visitNode$1(child);
|
|
15549
15596
|
return;
|
|
15550
15597
|
case "Host":
|
|
15551
|
-
|
|
15598
|
+
if (node.child) visitNode$1(node.child, parent);
|
|
15552
15599
|
return;
|
|
15553
15600
|
case "Slot":
|
|
15554
15601
|
for (const child of node.fallback) visitNode$1(child);
|
|
@@ -15611,7 +15658,7 @@ function isMarkerTemplateNode(node) {
|
|
|
15611
15658
|
return node.kind === "DynamicText" || node.kind === "Component" || node.kind === "Show" || node.kind === "For" || node.kind === "Slot";
|
|
15612
15659
|
}
|
|
15613
15660
|
//#endregion
|
|
15614
|
-
//#region packages/compiler/src/passes/assignPhysicalDomPaths.ts
|
|
15661
|
+
//#region packages/core/compiler/src/passes/assignPhysicalDomPaths.ts
|
|
15615
15662
|
function assignPhysicalDomPaths(node) {
|
|
15616
15663
|
visitNode(node);
|
|
15617
15664
|
return node;
|
|
@@ -15626,7 +15673,7 @@ function visitNode(node, parent) {
|
|
|
15626
15673
|
for (const child of node.children) visitNode(child, parent);
|
|
15627
15674
|
return;
|
|
15628
15675
|
case "Host":
|
|
15629
|
-
|
|
15676
|
+
if (node.child) visitNode(node.child, parent);
|
|
15630
15677
|
return;
|
|
15631
15678
|
case "Show":
|
|
15632
15679
|
for (const child of node.children) visitNode(child);
|
|
@@ -15712,12 +15759,12 @@ function appendPhysicalChild(result, node) {
|
|
|
15712
15759
|
for (const child of node.children) appendPhysicalChild(result, child);
|
|
15713
15760
|
return;
|
|
15714
15761
|
case "Host":
|
|
15715
|
-
|
|
15762
|
+
if (node.child) appendPhysicalChild(result, node.child);
|
|
15716
15763
|
return;
|
|
15717
15764
|
}
|
|
15718
15765
|
}
|
|
15719
15766
|
//#endregion
|
|
15720
|
-
//#region packages/compiler/src/passes/validateBuiltins.ts
|
|
15767
|
+
//#region packages/core/compiler/src/passes/validateBuiltins.ts
|
|
15721
15768
|
function validateBuiltins(node) {
|
|
15722
15769
|
visit$1(node, {
|
|
15723
15770
|
insideHost: false,
|
|
@@ -15731,7 +15778,7 @@ function visit$1(node, state) {
|
|
|
15731
15778
|
code: CompilerErrorCode.INVALID_BUILTIN_USAGE,
|
|
15732
15779
|
message: "<Host> can only be used as a root host boundary."
|
|
15733
15780
|
});
|
|
15734
|
-
|
|
15781
|
+
if (node.child) visit$1(node.child, {
|
|
15735
15782
|
insideHost: true,
|
|
15736
15783
|
root: false
|
|
15737
15784
|
});
|
|
@@ -15763,7 +15810,7 @@ function visit$1(node, state) {
|
|
|
15763
15810
|
}
|
|
15764
15811
|
}
|
|
15765
15812
|
//#endregion
|
|
15766
|
-
//#region packages/compiler/src/passes/analyzeBindings.ts
|
|
15813
|
+
//#region packages/core/compiler/src/passes/analyzeBindings.ts
|
|
15767
15814
|
function analyzeBindings(node) {
|
|
15768
15815
|
const analysis = {
|
|
15769
15816
|
dynamicText: 0,
|
|
@@ -15794,9 +15841,11 @@ function visit(node, analysis) {
|
|
|
15794
15841
|
}
|
|
15795
15842
|
return;
|
|
15796
15843
|
case "Fragment":
|
|
15797
|
-
case "Host":
|
|
15798
15844
|
for (const child of node.children) visit(child, analysis);
|
|
15799
15845
|
return;
|
|
15846
|
+
case "Host":
|
|
15847
|
+
if (node.child) visit(node.child, analysis);
|
|
15848
|
+
return;
|
|
15800
15849
|
case "Slot":
|
|
15801
15850
|
for (const child of node.fallback) visit(child, analysis);
|
|
15802
15851
|
return;
|
|
@@ -15811,7 +15860,7 @@ function visit(node, analysis) {
|
|
|
15811
15860
|
}
|
|
15812
15861
|
}
|
|
15813
15862
|
//#endregion
|
|
15814
|
-
//#region packages/compiler/src/transform/index.ts
|
|
15863
|
+
//#region packages/core/compiler/src/transform/index.ts
|
|
15815
15864
|
function transformJSX(path, state, config) {
|
|
15816
15865
|
if (state.get("skip")) return;
|
|
15817
15866
|
if (!path.isJSXElement() && !path.isJSXFragment()) return;
|
|
@@ -15826,7 +15875,7 @@ function transformJSX(path, state, config) {
|
|
|
15826
15875
|
path.replaceWith(emitDOM(ir, context));
|
|
15827
15876
|
}
|
|
15828
15877
|
//#endregion
|
|
15829
|
-
//#region packages/compiler/src/visitor.ts
|
|
15878
|
+
//#region packages/core/compiler/src/visitor.ts
|
|
15830
15879
|
function createVisitor(config) {
|
|
15831
15880
|
return {
|
|
15832
15881
|
JSXElement(path, state) {
|
|
@@ -15839,7 +15888,7 @@ function createVisitor(config) {
|
|
|
15839
15888
|
};
|
|
15840
15889
|
}
|
|
15841
15890
|
//#endregion
|
|
15842
|
-
//#region packages/compiler/src/index.ts
|
|
15891
|
+
//#region packages/core/compiler/src/index.ts
|
|
15843
15892
|
var src_default = (0, import_lib.declare)((api, options) => {
|
|
15844
15893
|
api.assertVersion(7);
|
|
15845
15894
|
return {
|