@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.cjs.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
|
**/
|
|
@@ -35,7 +35,7 @@ _babel_plugin_syntax_jsx = __toESM(_babel_plugin_syntax_jsx);
|
|
|
35
35
|
let _zeus_js_shared = require("@zeus-js/shared");
|
|
36
36
|
let _babel_types = require("@babel/types");
|
|
37
37
|
_babel_types = __toESM(_babel_types);
|
|
38
|
-
//#region packages/compiler/src/codegen/support/imports.ts
|
|
38
|
+
//#region packages/core/compiler/src/codegen/support/imports.ts
|
|
39
39
|
/**
|
|
40
40
|
* Runtime helpers registration and program injection.
|
|
41
41
|
*
|
|
@@ -93,7 +93,7 @@ function getProgramPath(path) {
|
|
|
93
93
|
return path.scope.getProgramParent().path;
|
|
94
94
|
}
|
|
95
95
|
//#endregion
|
|
96
|
-
//#region packages/compiler/src/codegen/support/templates.ts
|
|
96
|
+
//#region packages/core/compiler/src/codegen/support/templates.ts
|
|
97
97
|
/**
|
|
98
98
|
* Template registration, scope data management, and program injection.
|
|
99
99
|
*
|
|
@@ -137,7 +137,7 @@ function appendTemplates(path) {
|
|
|
137
137
|
path.node.body.unshift(_babel_types.variableDeclaration("var", declarators));
|
|
138
138
|
}
|
|
139
139
|
//#endregion
|
|
140
|
-
//#region packages/compiler/src/codegen/support/events.ts
|
|
140
|
+
//#region packages/core/compiler/src/codegen/support/events.ts
|
|
141
141
|
/**
|
|
142
142
|
* Event registration and delegation.
|
|
143
143
|
*
|
|
@@ -167,7 +167,7 @@ function appendEvents(path) {
|
|
|
167
167
|
path.node.body.push(_babel_types.expressionStatement(_babel_types.callExpression(registerImportMethod(path, "delegateEvents", getRendererConfig(path, "dom").moduleName), [_babel_types.arrayExpression(Array.from(events).map((eventName) => _babel_types.stringLiteral(eventName)))])));
|
|
168
168
|
}
|
|
169
169
|
//#endregion
|
|
170
|
-
//#region packages/compiler/src/config/index.ts
|
|
170
|
+
//#region packages/core/compiler/src/config/index.ts
|
|
171
171
|
const DEFAULT_OPTIONS = {
|
|
172
172
|
moduleName: DEFAULT_RENDERER_MODULE,
|
|
173
173
|
generate: "dom",
|
|
@@ -195,7 +195,7 @@ function resolveConfig(options) {
|
|
|
195
195
|
return (0, _zeus_js_shared.extend)(DEFAULT_OPTIONS, options);
|
|
196
196
|
}
|
|
197
197
|
//#endregion
|
|
198
|
-
//#region packages/compiler/src/utils/constant.ts
|
|
198
|
+
//#region packages/core/compiler/src/utils/constant.ts
|
|
199
199
|
const VoidElements = [
|
|
200
200
|
"area",
|
|
201
201
|
"base",
|
|
@@ -215,7 +215,7 @@ const VoidElements = [
|
|
|
215
215
|
"wbr"
|
|
216
216
|
];
|
|
217
217
|
//#endregion
|
|
218
|
-
//#region packages/compiler/src/utils/html.ts
|
|
218
|
+
//#region packages/core/compiler/src/utils/html.ts
|
|
219
219
|
function escapeHTML(value, attr = false) {
|
|
220
220
|
let result = value.replace(/&/g, "&");
|
|
221
221
|
if (attr) return result.replace(/"/g, """).replace(/>/g, ">");
|
|
@@ -234,14 +234,14 @@ function isRawTextElement(tagName) {
|
|
|
234
234
|
return rawTextElements.has(tagName);
|
|
235
235
|
}
|
|
236
236
|
//#endregion
|
|
237
|
-
//#region packages/compiler/src/utils/metadata.ts
|
|
237
|
+
//#region packages/core/compiler/src/utils/metadata.ts
|
|
238
238
|
function setZeusMetadata(state, config) {
|
|
239
239
|
const metadata = state.file.metadata;
|
|
240
240
|
metadata.zeus = (0, _zeus_js_shared.extend)({}, metadata.zeus, { config });
|
|
241
241
|
return metadata.zeus;
|
|
242
242
|
}
|
|
243
243
|
//#endregion
|
|
244
|
-
//#region packages/compiler/src/program.ts
|
|
244
|
+
//#region packages/core/compiler/src/program.ts
|
|
245
245
|
/**
|
|
246
246
|
* Program visitor — entry and exit point for the entire transform pass.
|
|
247
247
|
*
|
|
@@ -268,7 +268,7 @@ function createProgramVisitor(config) {
|
|
|
268
268
|
};
|
|
269
269
|
}
|
|
270
270
|
//#endregion
|
|
271
|
-
//#region packages/compiler/src/codegen/dom/emitBinding.ts
|
|
271
|
+
//#region packages/core/compiler/src/codegen/dom/emitBinding.ts
|
|
272
272
|
function emitBindings(node, context) {
|
|
273
273
|
const statements = [];
|
|
274
274
|
for (const attr of node.attrs) {
|
|
@@ -391,7 +391,7 @@ function emitMarkerMount(node, context, mountCall) {
|
|
|
391
391
|
return [_babel_types.expressionStatement(mountCall)];
|
|
392
392
|
}
|
|
393
393
|
//#endregion
|
|
394
|
-
//#region packages/compiler/src/codegen/dom/emitDomPath.ts
|
|
394
|
+
//#region packages/core/compiler/src/codegen/dom/emitDomPath.ts
|
|
395
395
|
function emitPhysicalDomPath(path) {
|
|
396
396
|
switch (path.kind) {
|
|
397
397
|
case "Root": throw new Error("Root path is emitted from template clone directly");
|
|
@@ -401,7 +401,7 @@ function emitPhysicalDomPath(path) {
|
|
|
401
401
|
}
|
|
402
402
|
}
|
|
403
403
|
//#endregion
|
|
404
|
-
//#region packages/compiler/src/passes/collectTemplates.ts
|
|
404
|
+
//#region packages/core/compiler/src/passes/collectTemplates.ts
|
|
405
405
|
function collectTemplates(node, context) {
|
|
406
406
|
if (node.kind === "Element") {
|
|
407
407
|
context.registerTemplate(renderTemplateHTML(node), node.flags.isSVG);
|
|
@@ -442,7 +442,7 @@ function renderChildTemplate(node) {
|
|
|
442
442
|
case "Show":
|
|
443
443
|
case "For":
|
|
444
444
|
case "Slot": return "<!>";
|
|
445
|
-
case "Host": return node.
|
|
445
|
+
case "Host": return node.child ? renderChildTemplate(node.child) : "";
|
|
446
446
|
case "Fragment": return node.children.map(renderChildTemplate).join("");
|
|
447
447
|
}
|
|
448
448
|
}
|
|
@@ -450,7 +450,7 @@ function escapeAttr(value) {
|
|
|
450
450
|
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
451
451
|
}
|
|
452
452
|
//#endregion
|
|
453
|
-
//#region packages/compiler/src/codegen/dom/emitTemplate.ts
|
|
453
|
+
//#region packages/core/compiler/src/codegen/dom/emitTemplate.ts
|
|
454
454
|
function emitTemplateClone(node, context) {
|
|
455
455
|
const html = renderTemplateHTML(node);
|
|
456
456
|
const template = context.registerTemplate(html, node.flags.isSVG);
|
|
@@ -458,7 +458,7 @@ function emitTemplateClone(node, context) {
|
|
|
458
458
|
return _babel_types.memberExpression(templateCall, _babel_types.identifier("firstChild"));
|
|
459
459
|
}
|
|
460
460
|
//#endregion
|
|
461
|
-
//#region packages/compiler/src/codegen/dom/emitElement.ts
|
|
461
|
+
//#region packages/core/compiler/src/codegen/dom/emitElement.ts
|
|
462
462
|
function emitElement(node, context) {
|
|
463
463
|
if (!hasRuntimeWork(node)) return emitTemplateClone(node, context);
|
|
464
464
|
const statements = [
|
|
@@ -498,7 +498,7 @@ function collectRefNode(node, map) {
|
|
|
498
498
|
for (const child of node.children) collectRefNode(child, map);
|
|
499
499
|
return;
|
|
500
500
|
case "Host":
|
|
501
|
-
|
|
501
|
+
if (node.child) collectRefNode(node.child, map);
|
|
502
502
|
return;
|
|
503
503
|
default: return;
|
|
504
504
|
}
|
|
@@ -520,7 +520,7 @@ function collectRequiredDomRefDeclaration(node, statements, context, refNodeMap,
|
|
|
520
520
|
for (const child of node.children) collectRequiredDomRefDeclaration(child, statements, context, refNodeMap, declared);
|
|
521
521
|
return;
|
|
522
522
|
case "Host":
|
|
523
|
-
|
|
523
|
+
if (node.child) collectRequiredDomRefDeclaration(node.child, statements, context, refNodeMap, declared);
|
|
524
524
|
return;
|
|
525
525
|
default: return;
|
|
526
526
|
}
|
|
@@ -567,11 +567,18 @@ function needsDomRefDeclaration(node) {
|
|
|
567
567
|
case "Slot": return true;
|
|
568
568
|
case "Element": return needsDomRefDeclaration(child);
|
|
569
569
|
case "Fragment": return child.children.some((inner) => inner.kind === "Element" ? needsDomRefDeclaration(inner) : inner.kind !== "Text");
|
|
570
|
-
case "Host": return child.
|
|
570
|
+
case "Host": return child.child ? innerKind(child.child) : false;
|
|
571
571
|
default: return false;
|
|
572
572
|
}
|
|
573
573
|
});
|
|
574
574
|
}
|
|
575
|
+
function innerKind(node) {
|
|
576
|
+
switch (node.kind) {
|
|
577
|
+
case "Element": return needsDomRefDeclaration(node);
|
|
578
|
+
case "Text": return false;
|
|
579
|
+
default: return true;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
575
582
|
function hasRuntimeWork(node) {
|
|
576
583
|
return node.attrs.some((attr) => attr.kind === "AttrBinding" || attr.kind === "PropBinding" || attr.kind === "EventBinding" || attr.kind === "RefBinding") || node.children.some(hasChildRuntimeWork);
|
|
577
584
|
}
|
|
@@ -583,18 +590,18 @@ function hasChildRuntimeWork(node) {
|
|
|
583
590
|
case "For":
|
|
584
591
|
case "Slot": return true;
|
|
585
592
|
case "Element": return hasRuntimeWork(node);
|
|
586
|
-
case "Fragment":
|
|
587
|
-
case "Host": return node.
|
|
593
|
+
case "Fragment": return node.children.some(hasChildRuntimeWork);
|
|
594
|
+
case "Host": return node.child ? hasChildRuntimeWork(node.child) : false;
|
|
588
595
|
default: return false;
|
|
589
596
|
}
|
|
590
597
|
}
|
|
591
598
|
//#endregion
|
|
592
|
-
//#region packages/compiler/src/codegen/dom/emitFragment.ts
|
|
599
|
+
//#region packages/core/compiler/src/codegen/dom/emitFragment.ts
|
|
593
600
|
function emitFragment(node, context) {
|
|
594
601
|
return _babel_types.arrayExpression(node.children.map((child) => emitDOM(child, context)));
|
|
595
602
|
}
|
|
596
603
|
//#endregion
|
|
597
|
-
//#region packages/compiler/src/codegen/dom/emitNodeExpression.ts
|
|
604
|
+
//#region packages/core/compiler/src/codegen/dom/emitNodeExpression.ts
|
|
598
605
|
function emitNodeExpression(node, context) {
|
|
599
606
|
switch (node.kind) {
|
|
600
607
|
case "Text": return _babel_types.stringLiteral(node.value);
|
|
@@ -610,13 +617,13 @@ function emitNodeExpression(node, context) {
|
|
|
610
617
|
}
|
|
611
618
|
}
|
|
612
619
|
//#endregion
|
|
613
|
-
//#region packages/compiler/src/codegen/dom/emitComponent.ts
|
|
620
|
+
//#region packages/core/compiler/src/codegen/dom/emitComponent.ts
|
|
614
621
|
function emitComponent(node, context) {
|
|
615
622
|
const props = _babel_types.objectExpression(node.props.map((prop) => emitComponentProp(prop, context)));
|
|
616
623
|
return _babel_types.callExpression(context.importRuntime("createComponent"), [node.callee, props]);
|
|
617
624
|
}
|
|
618
625
|
function emitComponentProp(prop, context) {
|
|
619
|
-
const key = createObjectKey(prop.name);
|
|
626
|
+
const key = createObjectKey$1(prop.name);
|
|
620
627
|
if (Array.isArray(prop.value)) return _babel_types.objectMethod("get", key, [], _babel_types.blockStatement([_babel_types.returnStatement(emitChildrenProp(prop.value, context))]));
|
|
621
628
|
if (isStaticPropValue(prop.value)) return _babel_types.objectProperty(key, prop.value);
|
|
622
629
|
return _babel_types.objectMethod("get", key, [], _babel_types.blockStatement([_babel_types.returnStatement(prop.value)]));
|
|
@@ -629,11 +636,11 @@ function emitChildrenProp(children, context) {
|
|
|
629
636
|
function isStaticPropValue(value) {
|
|
630
637
|
return _babel_types.isStringLiteral(value) || _babel_types.isNumericLiteral(value) || _babel_types.isBooleanLiteral(value) || _babel_types.isNullLiteral(value);
|
|
631
638
|
}
|
|
632
|
-
function createObjectKey(key) {
|
|
639
|
+
function createObjectKey$1(key) {
|
|
633
640
|
return _babel_types.isValidIdentifier(key) ? _babel_types.identifier(key) : _babel_types.stringLiteral(key);
|
|
634
641
|
}
|
|
635
642
|
//#endregion
|
|
636
|
-
//#region packages/compiler/src/codegen/dom/emitBuiltin.ts
|
|
643
|
+
//#region packages/core/compiler/src/codegen/dom/emitBuiltin.ts
|
|
637
644
|
function emitShow(node, context) {
|
|
638
645
|
const props = [_babel_types.objectProperty(_babel_types.identifier("when"), node.when), _babel_types.objectProperty(_babel_types.identifier("children"), _babel_types.arrowFunctionExpression([], emitChildrenProp(node.children, context)))];
|
|
639
646
|
if (node.fallback) props.push(_babel_types.objectProperty(_babel_types.identifier("fallback"), Array.isArray(node.fallback) ? _babel_types.arrowFunctionExpression([], emitChildrenProp(node.fallback, context)) : node.fallback));
|
|
@@ -672,7 +679,29 @@ function emitMountFor(node, context) {
|
|
|
672
679
|
]);
|
|
673
680
|
}
|
|
674
681
|
function emitHost(node, context) {
|
|
675
|
-
|
|
682
|
+
const props = buildHostProps(node, context);
|
|
683
|
+
const hostCall = _babel_types.callExpression(context.importRuntime("Host"), [_babel_types.objectExpression(props)]);
|
|
684
|
+
if (!node.child) return hostCall;
|
|
685
|
+
const childExpr = emitNodeExpression(node.child, context);
|
|
686
|
+
return _babel_types.callExpression(_babel_types.arrowFunctionExpression([], _babel_types.blockStatement([_babel_types.expressionStatement(hostCall), _babel_types.returnStatement(childExpr)])), []);
|
|
687
|
+
}
|
|
688
|
+
function buildHostProps(node, context) {
|
|
689
|
+
const props = [];
|
|
690
|
+
for (const attr of node.attrs) {
|
|
691
|
+
const key = createObjectKey(attr.name);
|
|
692
|
+
if (isStaticValue(attr.expr) || isGetterExpression(attr.expr)) props.push(_babel_types.objectProperty(key, attr.expr));
|
|
693
|
+
else props.push(_babel_types.objectProperty(key, _babel_types.arrowFunctionExpression([], attr.expr)));
|
|
694
|
+
}
|
|
695
|
+
return props;
|
|
696
|
+
}
|
|
697
|
+
function isStaticValue(expr) {
|
|
698
|
+
return _babel_types.isStringLiteral(expr) || _babel_types.isNumericLiteral(expr) || _babel_types.isBooleanLiteral(expr) || _babel_types.isNullLiteral(expr);
|
|
699
|
+
}
|
|
700
|
+
function isGetterExpression(expr) {
|
|
701
|
+
return _babel_types.isArrowFunctionExpression(expr) || _babel_types.isFunctionExpression(expr);
|
|
702
|
+
}
|
|
703
|
+
function createObjectKey(name) {
|
|
704
|
+
return _babel_types.isValidIdentifier(name) ? _babel_types.identifier(name) : _babel_types.stringLiteral(name);
|
|
676
705
|
}
|
|
677
706
|
function emitSlot(node, context) {
|
|
678
707
|
return _babel_types.callExpression(context.importRuntime("createSlot"), [node.name ? _babel_types.stringLiteral(node.name) : _babel_types.identifier("undefined"), node.fallback.length > 0 ? _babel_types.arrowFunctionExpression([], emitChildrenProp(node.fallback, context)) : _babel_types.identifier("undefined")]);
|
|
@@ -681,7 +710,7 @@ function emitMarkerIdentifier(node) {
|
|
|
681
710
|
return _babel_types.identifier(node.ref.name);
|
|
682
711
|
}
|
|
683
712
|
//#endregion
|
|
684
|
-
//#region packages/compiler/src/codegen/dom/index.ts
|
|
713
|
+
//#region packages/core/compiler/src/codegen/dom/index.ts
|
|
685
714
|
function emitDOM(node, context) {
|
|
686
715
|
switch (node.kind) {
|
|
687
716
|
case "Element": return emitElement(node, context);
|
|
@@ -696,7 +725,7 @@ function emitDOM(node, context) {
|
|
|
696
725
|
}
|
|
697
726
|
}
|
|
698
727
|
//#endregion
|
|
699
|
-
//#region packages/compiler/src/context/CompilerContext.ts
|
|
728
|
+
//#region packages/core/compiler/src/context/CompilerContext.ts
|
|
700
729
|
var CompilerContext = class {
|
|
701
730
|
constructor(options, programPath) {
|
|
702
731
|
this.options = options;
|
|
@@ -759,7 +788,7 @@ function getCompilerContext(path, options) {
|
|
|
759
788
|
return new CompilerContext(options, path.scope.getProgramParent().path);
|
|
760
789
|
}
|
|
761
790
|
//#endregion
|
|
762
|
-
//#region packages/compiler/src/diagnostics/codes.ts
|
|
791
|
+
//#region packages/core/compiler/src/diagnostics/codes.ts
|
|
763
792
|
const CompilerErrorCode = {
|
|
764
793
|
UNSUPPORTED_SPREAD_ATTRIBUTE: "ZEUS_UNSUPPORTED_SPREAD_ATTRIBUTE",
|
|
765
794
|
UNSUPPORTED_SPREAD_CHILD: "ZEUS_UNSUPPORTED_SPREAD_CHILD",
|
|
@@ -773,7 +802,7 @@ const CompilerErrorCode = {
|
|
|
773
802
|
INVALID_REF_USAGE: "ZEUS_INVALID_REF_USAGE"
|
|
774
803
|
};
|
|
775
804
|
//#endregion
|
|
776
|
-
//#region packages/compiler/src/diagnostics/CompilerError.ts
|
|
805
|
+
//#region packages/core/compiler/src/diagnostics/CompilerError.ts
|
|
777
806
|
var CompilerError = class extends Error {
|
|
778
807
|
constructor(options) {
|
|
779
808
|
var _options$path;
|
|
@@ -787,7 +816,7 @@ var CompilerError = class extends Error {
|
|
|
787
816
|
}
|
|
788
817
|
};
|
|
789
818
|
//#endregion
|
|
790
|
-
//#region packages/compiler/src/ir/semanticBuilders.ts
|
|
819
|
+
//#region packages/core/compiler/src/ir/semanticBuilders.ts
|
|
791
820
|
let nextId = 0;
|
|
792
821
|
function id() {
|
|
793
822
|
return nextId++;
|
|
@@ -905,11 +934,12 @@ function forIR(input) {
|
|
|
905
934
|
body: input.body
|
|
906
935
|
};
|
|
907
936
|
}
|
|
908
|
-
function hostIR(
|
|
937
|
+
function hostIR(input) {
|
|
909
938
|
return {
|
|
910
939
|
id: id(),
|
|
911
940
|
kind: "Host",
|
|
912
|
-
|
|
941
|
+
attrs: input.attrs,
|
|
942
|
+
child: input.child
|
|
913
943
|
};
|
|
914
944
|
}
|
|
915
945
|
function slotIR(input) {
|
|
@@ -923,7 +953,7 @@ function slotIR(input) {
|
|
|
923
953
|
};
|
|
924
954
|
}
|
|
925
955
|
//#endregion
|
|
926
|
-
//#region packages/compiler/src/parse/jsx.ts
|
|
956
|
+
//#region packages/core/compiler/src/parse/jsx.ts
|
|
927
957
|
/**
|
|
928
958
|
* JSX AST parsing utilities.
|
|
929
959
|
*
|
|
@@ -950,7 +980,7 @@ function toEventName(name) {
|
|
|
950
980
|
return name.slice(2).toLowerCase();
|
|
951
981
|
}
|
|
952
982
|
//#endregion
|
|
953
|
-
//#region packages/compiler/src/lower/lowerAttribute.ts
|
|
983
|
+
//#region packages/core/compiler/src/lower/lowerAttribute.ts
|
|
954
984
|
function lowerAttribute(path, _context) {
|
|
955
985
|
if (path.isJSXSpreadAttribute() || _babel_types.isJSXSpreadAttribute(path.node)) throw new CompilerError({
|
|
956
986
|
code: CompilerErrorCode.UNSUPPORTED_SPREAD_ATTRIBUTE,
|
|
@@ -994,7 +1024,7 @@ function lowerAttribute(path, _context) {
|
|
|
994
1024
|
return null;
|
|
995
1025
|
}
|
|
996
1026
|
//#endregion
|
|
997
|
-
//#region packages/compiler/src/lower/lowerChildren.ts
|
|
1027
|
+
//#region packages/core/compiler/src/lower/lowerChildren.ts
|
|
998
1028
|
function lowerChildren(children, context) {
|
|
999
1029
|
const result = [];
|
|
1000
1030
|
for (const child of children) {
|
|
@@ -1017,7 +1047,12 @@ function lowerChildren(children, context) {
|
|
|
1017
1047
|
return result;
|
|
1018
1048
|
}
|
|
1019
1049
|
//#endregion
|
|
1020
|
-
//#region packages/compiler/src/lower/lowerBuiltin.ts
|
|
1050
|
+
//#region packages/core/compiler/src/lower/lowerBuiltin.ts
|
|
1051
|
+
const HOST_SKIP_PROPS = new Set([
|
|
1052
|
+
"key",
|
|
1053
|
+
"__slot",
|
|
1054
|
+
"__anchor"
|
|
1055
|
+
]);
|
|
1021
1056
|
function isBuiltinTag(tagName) {
|
|
1022
1057
|
return tagName === "Show" || tagName === "For" || tagName === "Host" || tagName === "Slot";
|
|
1023
1058
|
}
|
|
@@ -1031,7 +1066,7 @@ function lowerBuiltin(path, context) {
|
|
|
1031
1066
|
switch (tagName.name) {
|
|
1032
1067
|
case "Show": return lowerShow(path, context);
|
|
1033
1068
|
case "For": return lowerFor(path, context);
|
|
1034
|
-
case "Host": return
|
|
1069
|
+
case "Host": return lowerHost(path, context);
|
|
1035
1070
|
case "Slot": return lowerSlot(path, context);
|
|
1036
1071
|
default: throw new CompilerError({
|
|
1037
1072
|
code: CompilerErrorCode.INVALID_BUILTIN_USAGE,
|
|
@@ -1141,8 +1176,73 @@ function getBuiltinName(path) {
|
|
|
1141
1176
|
const name = path.node.openingElement.name;
|
|
1142
1177
|
return _babel_types.isJSXIdentifier(name) ? name.name : "Builtin";
|
|
1143
1178
|
}
|
|
1179
|
+
function isEventLikeProp(key) {
|
|
1180
|
+
return /^on[A-Z]/.test(key) || key.startsWith("on:");
|
|
1181
|
+
}
|
|
1182
|
+
function normalizeHostAttrName(name) {
|
|
1183
|
+
switch (name) {
|
|
1184
|
+
case "className": return "class";
|
|
1185
|
+
case "htmlFor": return "for";
|
|
1186
|
+
case "tabIndex": return "tabindex";
|
|
1187
|
+
case "readOnly": return "readonly";
|
|
1188
|
+
default: return name;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
function lowerHost(path, context) {
|
|
1192
|
+
const attrs = [];
|
|
1193
|
+
const rawChildren = lowerChildren(path.get("children"), context);
|
|
1194
|
+
for (const attrPath of path.get("openingElement").get("attributes")) {
|
|
1195
|
+
const node = attrPath.node;
|
|
1196
|
+
if (_babel_types.isJSXSpreadAttribute(node)) throw new CompilerError({
|
|
1197
|
+
code: CompilerErrorCode.UNSUPPORTED_COMPONENT_PROP,
|
|
1198
|
+
message: "Spread props are not supported on Host in Phase 1.",
|
|
1199
|
+
path: attrPath
|
|
1200
|
+
});
|
|
1201
|
+
if (!attrPath.isJSXAttribute()) continue;
|
|
1202
|
+
const name = getJSXAttrName(node.name);
|
|
1203
|
+
if (HOST_SKIP_PROPS.has(name)) continue;
|
|
1204
|
+
if (name === "children") continue;
|
|
1205
|
+
if (name === "ref") {
|
|
1206
|
+
const value = attrPath.get("value");
|
|
1207
|
+
if (value.isJSXExpressionContainer()) {
|
|
1208
|
+
const expr = value.get("expression");
|
|
1209
|
+
if (expr.isExpression()) attrs.push({
|
|
1210
|
+
id: id(),
|
|
1211
|
+
kind: "HostAttr",
|
|
1212
|
+
name: "ref",
|
|
1213
|
+
expr: expr.node
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
continue;
|
|
1217
|
+
}
|
|
1218
|
+
if (isEventLikeProp(name)) continue;
|
|
1219
|
+
const value = node.value;
|
|
1220
|
+
if (!value) attrs.push({
|
|
1221
|
+
id: id(),
|
|
1222
|
+
kind: "HostAttr",
|
|
1223
|
+
name: normalizeHostAttrName(name),
|
|
1224
|
+
expr: _babel_types.booleanLiteral(true)
|
|
1225
|
+
});
|
|
1226
|
+
else if (_babel_types.isStringLiteral(value)) attrs.push({
|
|
1227
|
+
id: id(),
|
|
1228
|
+
kind: "HostAttr",
|
|
1229
|
+
name: normalizeHostAttrName(name),
|
|
1230
|
+
expr: _babel_types.stringLiteral(value.value)
|
|
1231
|
+
});
|
|
1232
|
+
else if (_babel_types.isJSXExpressionContainer(value) && !_babel_types.isJSXEmptyExpression(value.expression)) attrs.push({
|
|
1233
|
+
id: id(),
|
|
1234
|
+
kind: "HostAttr",
|
|
1235
|
+
name: normalizeHostAttrName(name),
|
|
1236
|
+
expr: value.expression
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
return hostIR({
|
|
1240
|
+
attrs,
|
|
1241
|
+
child: rawChildren.length === 0 ? void 0 : rawChildren.length === 1 ? rawChildren[0] : fragmentIR(rawChildren)
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1144
1244
|
//#endregion
|
|
1145
|
-
//#region packages/compiler/src/lower/lowerComponent.ts
|
|
1245
|
+
//#region packages/core/compiler/src/lower/lowerComponent.ts
|
|
1146
1246
|
function lowerComponent(path, context) {
|
|
1147
1247
|
const tag = convertComponentIdentifier(path.node.openingElement.name);
|
|
1148
1248
|
const props = [];
|
|
@@ -1206,7 +1306,7 @@ function convertComponentIdentifier(node) {
|
|
|
1206
1306
|
return node;
|
|
1207
1307
|
}
|
|
1208
1308
|
//#endregion
|
|
1209
|
-
//#region packages/compiler/src/lower/lowerElement.ts
|
|
1309
|
+
//#region packages/core/compiler/src/lower/lowerElement.ts
|
|
1210
1310
|
function lowerElement(path, context) {
|
|
1211
1311
|
const tagName = getTagName(path.node);
|
|
1212
1312
|
if (isBuiltinTag(tagName)) return lowerBuiltin(path, context);
|
|
@@ -1224,19 +1324,19 @@ function lowerElement(path, context) {
|
|
|
1224
1324
|
});
|
|
1225
1325
|
}
|
|
1226
1326
|
//#endregion
|
|
1227
|
-
//#region packages/compiler/src/lower/lowerFragment.ts
|
|
1327
|
+
//#region packages/core/compiler/src/lower/lowerFragment.ts
|
|
1228
1328
|
function lowerFragment(path, context) {
|
|
1229
1329
|
return fragmentIR(lowerChildren(path.get("children"), context));
|
|
1230
1330
|
}
|
|
1231
1331
|
//#endregion
|
|
1232
|
-
//#region packages/compiler/src/lower/lowerJSX.ts
|
|
1332
|
+
//#region packages/core/compiler/src/lower/lowerJSX.ts
|
|
1233
1333
|
function lowerJSX(path, context) {
|
|
1234
1334
|
if (path.isJSXElement()) return lowerElement(path, context);
|
|
1235
1335
|
if (path.isJSXFragment()) return lowerFragment(path, context);
|
|
1236
1336
|
throw new Error("Unsupported JSX node");
|
|
1237
1337
|
}
|
|
1238
1338
|
//#endregion
|
|
1239
|
-
//#region packages/compiler/src/passes/normalizeChildren.ts
|
|
1339
|
+
//#region packages/core/compiler/src/passes/normalizeChildren.ts
|
|
1240
1340
|
function normalizeChildren(node) {
|
|
1241
1341
|
visit$2(node);
|
|
1242
1342
|
return node;
|
|
@@ -1245,13 +1345,15 @@ function visit$2(node) {
|
|
|
1245
1345
|
switch (node.kind) {
|
|
1246
1346
|
case "Element":
|
|
1247
1347
|
case "Fragment":
|
|
1248
|
-
case "Host":
|
|
1249
1348
|
node.children = node.children.filter((child) => {
|
|
1250
1349
|
if (child.kind === "Text") return child.value.length > 0;
|
|
1251
1350
|
return true;
|
|
1252
1351
|
});
|
|
1253
1352
|
for (const child of node.children) visit$2(child);
|
|
1254
1353
|
return;
|
|
1354
|
+
case "Host":
|
|
1355
|
+
if (node.child) visit$2(node.child);
|
|
1356
|
+
return;
|
|
1255
1357
|
case "Component":
|
|
1256
1358
|
for (const prop of node.props) {
|
|
1257
1359
|
if (!Array.isArray(prop.value)) continue;
|
|
@@ -1287,7 +1389,7 @@ function visit$2(node) {
|
|
|
1287
1389
|
}
|
|
1288
1390
|
}
|
|
1289
1391
|
//#endregion
|
|
1290
|
-
//#region packages/compiler/src/passes/assignDomPaths.ts
|
|
1392
|
+
//#region packages/core/compiler/src/passes/assignDomPaths.ts
|
|
1291
1393
|
function assignDomPaths(node) {
|
|
1292
1394
|
visitNode$1(node);
|
|
1293
1395
|
return node;
|
|
@@ -1315,7 +1417,7 @@ function visitNode$1(node, parent) {
|
|
|
1315
1417
|
for (const child of node.body) visitNode$1(child);
|
|
1316
1418
|
return;
|
|
1317
1419
|
case "Host":
|
|
1318
|
-
|
|
1420
|
+
if (node.child) visitNode$1(node.child, parent);
|
|
1319
1421
|
return;
|
|
1320
1422
|
case "Slot":
|
|
1321
1423
|
for (const child of node.fallback) visitNode$1(child);
|
|
@@ -1378,7 +1480,7 @@ function isMarkerTemplateNode(node) {
|
|
|
1378
1480
|
return node.kind === "DynamicText" || node.kind === "Component" || node.kind === "Show" || node.kind === "For" || node.kind === "Slot";
|
|
1379
1481
|
}
|
|
1380
1482
|
//#endregion
|
|
1381
|
-
//#region packages/compiler/src/passes/assignPhysicalDomPaths.ts
|
|
1483
|
+
//#region packages/core/compiler/src/passes/assignPhysicalDomPaths.ts
|
|
1382
1484
|
function assignPhysicalDomPaths(node) {
|
|
1383
1485
|
visitNode(node);
|
|
1384
1486
|
return node;
|
|
@@ -1393,7 +1495,7 @@ function visitNode(node, parent) {
|
|
|
1393
1495
|
for (const child of node.children) visitNode(child, parent);
|
|
1394
1496
|
return;
|
|
1395
1497
|
case "Host":
|
|
1396
|
-
|
|
1498
|
+
if (node.child) visitNode(node.child, parent);
|
|
1397
1499
|
return;
|
|
1398
1500
|
case "Show":
|
|
1399
1501
|
for (const child of node.children) visitNode(child);
|
|
@@ -1479,12 +1581,12 @@ function appendPhysicalChild(result, node) {
|
|
|
1479
1581
|
for (const child of node.children) appendPhysicalChild(result, child);
|
|
1480
1582
|
return;
|
|
1481
1583
|
case "Host":
|
|
1482
|
-
|
|
1584
|
+
if (node.child) appendPhysicalChild(result, node.child);
|
|
1483
1585
|
return;
|
|
1484
1586
|
}
|
|
1485
1587
|
}
|
|
1486
1588
|
//#endregion
|
|
1487
|
-
//#region packages/compiler/src/passes/validateBuiltins.ts
|
|
1589
|
+
//#region packages/core/compiler/src/passes/validateBuiltins.ts
|
|
1488
1590
|
function validateBuiltins(node) {
|
|
1489
1591
|
visit$1(node, {
|
|
1490
1592
|
insideHost: false,
|
|
@@ -1498,7 +1600,7 @@ function visit$1(node, state) {
|
|
|
1498
1600
|
code: CompilerErrorCode.INVALID_BUILTIN_USAGE,
|
|
1499
1601
|
message: "<Host> can only be used as a root host boundary."
|
|
1500
1602
|
});
|
|
1501
|
-
|
|
1603
|
+
if (node.child) visit$1(node.child, {
|
|
1502
1604
|
insideHost: true,
|
|
1503
1605
|
root: false
|
|
1504
1606
|
});
|
|
@@ -1545,7 +1647,7 @@ function visit$1(node, state) {
|
|
|
1545
1647
|
}
|
|
1546
1648
|
}
|
|
1547
1649
|
//#endregion
|
|
1548
|
-
//#region packages/compiler/src/passes/analyzeBindings.ts
|
|
1650
|
+
//#region packages/core/compiler/src/passes/analyzeBindings.ts
|
|
1549
1651
|
function analyzeBindings(node) {
|
|
1550
1652
|
const analysis = {
|
|
1551
1653
|
dynamicText: 0,
|
|
@@ -1576,9 +1678,11 @@ function visit(node, analysis) {
|
|
|
1576
1678
|
}
|
|
1577
1679
|
return;
|
|
1578
1680
|
case "Fragment":
|
|
1579
|
-
case "Host":
|
|
1580
1681
|
for (const child of node.children) visit(child, analysis);
|
|
1581
1682
|
return;
|
|
1683
|
+
case "Host":
|
|
1684
|
+
if (node.child) visit(node.child, analysis);
|
|
1685
|
+
return;
|
|
1582
1686
|
case "Slot":
|
|
1583
1687
|
for (const child of node.fallback) visit(child, analysis);
|
|
1584
1688
|
return;
|
|
@@ -1593,7 +1697,7 @@ function visit(node, analysis) {
|
|
|
1593
1697
|
}
|
|
1594
1698
|
}
|
|
1595
1699
|
//#endregion
|
|
1596
|
-
//#region packages/compiler/src/transform/index.ts
|
|
1700
|
+
//#region packages/core/compiler/src/transform/index.ts
|
|
1597
1701
|
function transformJSX(path, state, config) {
|
|
1598
1702
|
if (state.get("skip")) return;
|
|
1599
1703
|
if (!path.isJSXElement() && !path.isJSXFragment()) return;
|
|
@@ -1608,7 +1712,7 @@ function transformJSX(path, state, config) {
|
|
|
1608
1712
|
path.replaceWith(emitDOM(ir, context));
|
|
1609
1713
|
}
|
|
1610
1714
|
//#endregion
|
|
1611
|
-
//#region packages/compiler/src/visitor.ts
|
|
1715
|
+
//#region packages/core/compiler/src/visitor.ts
|
|
1612
1716
|
function createVisitor(config) {
|
|
1613
1717
|
return {
|
|
1614
1718
|
JSXElement(path, state) {
|
|
@@ -1621,7 +1725,7 @@ function createVisitor(config) {
|
|
|
1621
1725
|
};
|
|
1622
1726
|
}
|
|
1623
1727
|
//#endregion
|
|
1624
|
-
//#region packages/compiler/src/index.ts
|
|
1728
|
+
//#region packages/core/compiler/src/index.ts
|
|
1625
1729
|
var src_default = (0, _babel_helper_plugin_utils.declare)((api, options) => {
|
|
1626
1730
|
api.assertVersion(7);
|
|
1627
1731
|
return {
|