@zeus-js/compiler 0.1.0 → 0.1.1-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 +246 -28
- package/dist/compiler.d.ts +4 -1
- package/dist/compiler.esm-browser.js +255 -38
- package/dist/compiler.esm-browser.prod.js +6 -6
- package/dist/compiler.esm-bundler.js +246 -28
- package/dist/compiler.global.js +255 -38
- package/dist/compiler.global.prod.js +3 -3
- package/dist/compiler.prod.cjs +246 -28
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* compiler v0.1.0
|
|
2
|
+
* compiler v0.1.1-beta.0
|
|
3
3
|
* (c) 2026 baicie
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
**/
|
|
@@ -142,6 +142,7 @@ function appendEvents(path) {
|
|
|
142
142
|
}
|
|
143
143
|
//#endregion
|
|
144
144
|
//#region packages/core/compiler/src/config/index.ts
|
|
145
|
+
const DEFAULT_SSR_RENDERER_MODULE = "@zeus-js/runtime-ssr";
|
|
145
146
|
const DEFAULT_OPTIONS = {
|
|
146
147
|
moduleName: DEFAULT_RENDERER_MODULE,
|
|
147
148
|
generate: "dom",
|
|
@@ -166,7 +167,9 @@ const DEFAULT_OPTIONS = {
|
|
|
166
167
|
* @returns The resolved compiler options.
|
|
167
168
|
*/
|
|
168
169
|
function resolveConfig(options) {
|
|
169
|
-
|
|
170
|
+
const config = extend({}, DEFAULT_OPTIONS, options);
|
|
171
|
+
if (config.generate === "ssr" && (options === null || options === void 0 ? void 0 : options.moduleName) === void 0) config.moduleName = DEFAULT_SSR_RENDERER_MODULE;
|
|
172
|
+
return config;
|
|
170
173
|
}
|
|
171
174
|
//#endregion
|
|
172
175
|
//#region packages/core/compiler/src/context/CompilerContext.ts
|
|
@@ -361,8 +364,10 @@ function enterProgram(config, path, state) {
|
|
|
361
364
|
}
|
|
362
365
|
function exitProgram(config, path, state) {
|
|
363
366
|
if (state.get("skip")) return;
|
|
364
|
-
|
|
365
|
-
|
|
367
|
+
if (config.generate === "dom") {
|
|
368
|
+
appendTemplates(path);
|
|
369
|
+
if (config.delegateEvents) appendEvents(path);
|
|
370
|
+
}
|
|
366
371
|
appendImportMethods(path);
|
|
367
372
|
}
|
|
368
373
|
function createProgramVisitor(config) {
|
|
@@ -588,7 +593,7 @@ function emitDynamicText(node, context) {
|
|
|
588
593
|
];
|
|
589
594
|
}
|
|
590
595
|
function emitComponentInsert(node, context) {
|
|
591
|
-
return emitMarkerInsert(node, context, emitComponent(node, context));
|
|
596
|
+
return emitMarkerInsert(node, context, emitComponent$1(node, context));
|
|
592
597
|
}
|
|
593
598
|
function emitMarkerInsert(node, context, value) {
|
|
594
599
|
if (!node.domPath || node.domPath.kind !== "Marker") return [];
|
|
@@ -671,7 +676,7 @@ function emitTemplateClone(node, context) {
|
|
|
671
676
|
}
|
|
672
677
|
//#endregion
|
|
673
678
|
//#region packages/core/compiler/src/codegen/dom/emitElement.ts
|
|
674
|
-
function emitElement(node, context) {
|
|
679
|
+
function emitElement$1(node, context) {
|
|
675
680
|
if (!hasRuntimeWork(node)) return emitTemplateClone(node, context);
|
|
676
681
|
const statements = [
|
|
677
682
|
t.variableDeclaration("const", [t.variableDeclarator(t.identifier(node.ref.name), emitTemplateClone(node, context))]),
|
|
@@ -818,11 +823,11 @@ function emitNodeExpression(node, context) {
|
|
|
818
823
|
switch (node.kind) {
|
|
819
824
|
case "Text": return t.stringLiteral(node.value);
|
|
820
825
|
case "DynamicText": return parseExpressionIR(node.expr);
|
|
821
|
-
case "Element": return emitElement(node, context);
|
|
822
|
-
case "Component": return emitComponent(node, context);
|
|
826
|
+
case "Element": return emitElement$1(node, context);
|
|
827
|
+
case "Component": return emitComponent$1(node, context);
|
|
823
828
|
case "Fragment": return emitFragment(node, context);
|
|
824
|
-
case "Show": return emitShow(node, context);
|
|
825
|
-
case "For": return emitFor(node, context);
|
|
829
|
+
case "Show": return emitShow$1(node, context);
|
|
830
|
+
case "For": return emitFor$1(node, context);
|
|
826
831
|
case "Host": return emitHost(node, context);
|
|
827
832
|
case "Slot": return emitSlot(node, context);
|
|
828
833
|
default: return t.nullLiteral();
|
|
@@ -830,15 +835,15 @@ function emitNodeExpression(node, context) {
|
|
|
830
835
|
}
|
|
831
836
|
//#endregion
|
|
832
837
|
//#region packages/core/compiler/src/codegen/dom/emitComponent.ts
|
|
833
|
-
function emitComponent(node, context) {
|
|
834
|
-
const props = t.objectExpression(node.props.map((prop) => emitComponentProp(prop, context)));
|
|
838
|
+
function emitComponent$1(node, context) {
|
|
839
|
+
const props = t.objectExpression(node.props.map((prop) => emitComponentProp$1(prop, context)));
|
|
835
840
|
return t.callExpression(context.importRuntime("createComponent"), [parseExpressionIR(node.callee), props]);
|
|
836
841
|
}
|
|
837
|
-
function emitComponentProp(prop, context) {
|
|
838
|
-
const key = createObjectKey$
|
|
842
|
+
function emitComponentProp$1(prop, context) {
|
|
843
|
+
const key = createObjectKey$2(prop.name);
|
|
839
844
|
if (Array.isArray(prop.value)) return t.objectMethod("get", key, [], t.blockStatement([t.returnStatement(emitChildrenProp(prop.value, context))]));
|
|
840
845
|
const value = parseExpressionIR(prop.value);
|
|
841
|
-
if (isStaticPropValue(value)) return t.objectProperty(key, value);
|
|
846
|
+
if (isStaticPropValue$1(value)) return t.objectProperty(key, value);
|
|
842
847
|
return t.objectMethod("get", key, [], t.blockStatement([t.returnStatement(value)]));
|
|
843
848
|
}
|
|
844
849
|
function emitChildrenProp(children, context) {
|
|
@@ -846,15 +851,15 @@ function emitChildrenProp(children, context) {
|
|
|
846
851
|
if (nodes.length === 1) return nodes[0];
|
|
847
852
|
return t.arrayExpression(nodes);
|
|
848
853
|
}
|
|
849
|
-
function isStaticPropValue(value) {
|
|
854
|
+
function isStaticPropValue$1(value) {
|
|
850
855
|
return t.isStringLiteral(value) || t.isNumericLiteral(value) || t.isBooleanLiteral(value) || t.isNullLiteral(value);
|
|
851
856
|
}
|
|
852
|
-
function createObjectKey$
|
|
857
|
+
function createObjectKey$2(key) {
|
|
853
858
|
return t.isValidIdentifier(key) ? t.identifier(key) : t.stringLiteral(key);
|
|
854
859
|
}
|
|
855
860
|
//#endregion
|
|
856
861
|
//#region packages/core/compiler/src/codegen/dom/emitBuiltin.ts
|
|
857
|
-
function emitShow(node, context) {
|
|
862
|
+
function emitShow$1(node, context) {
|
|
858
863
|
const props = [t.objectProperty(t.identifier("when"), parseExpressionIR(node.when)), t.objectProperty(t.identifier("children"), t.arrowFunctionExpression([], emitChildrenProp(node.children, context)))];
|
|
859
864
|
if (node.fallback) props.push(t.objectProperty(t.identifier("fallback"), Array.isArray(node.fallback) ? t.arrowFunctionExpression([], emitChildrenProp(node.fallback, context)) : parseExpressionIR(node.fallback)));
|
|
860
865
|
return t.callExpression(context.importRuntime("createComponent"), [context.importRuntime("Show"), t.objectExpression(props)]);
|
|
@@ -870,7 +875,7 @@ function emitMountShow(node, context) {
|
|
|
870
875
|
node.fallback ? Array.isArray(node.fallback) ? t.arrowFunctionExpression([], emitChildrenProp(node.fallback, context)) : t.arrowFunctionExpression([], parseExpressionIR(node.fallback)) : t.identifier("undefined")
|
|
871
876
|
]);
|
|
872
877
|
}
|
|
873
|
-
function emitFor(node, context) {
|
|
878
|
+
function emitFor$1(node, context) {
|
|
874
879
|
const params = [t.identifier(node.item.name)];
|
|
875
880
|
if (node.index) params.push(t.identifier(node.index.name));
|
|
876
881
|
const props = [t.objectProperty(t.identifier("each"), parseExpressionIR(node.each)), t.objectProperty(t.identifier("children"), t.arrowFunctionExpression(params, emitChildrenProp(node.body, context)))];
|
|
@@ -901,7 +906,7 @@ function emitHost(node, context) {
|
|
|
901
906
|
function buildHostProps(node, context) {
|
|
902
907
|
const props = [];
|
|
903
908
|
for (const attr of node.attrs) {
|
|
904
|
-
const key = createObjectKey(attr.name);
|
|
909
|
+
const key = createObjectKey$1(attr.name);
|
|
905
910
|
const expression = parseExpressionIR(attr.expr);
|
|
906
911
|
if (isStaticValue(expression) || isGetterExpression(expression)) props.push(t.objectProperty(key, expression));
|
|
907
912
|
else props.push(t.objectProperty(key, t.arrowFunctionExpression([], expression)));
|
|
@@ -914,7 +919,7 @@ function isStaticValue(expr) {
|
|
|
914
919
|
function isGetterExpression(expr) {
|
|
915
920
|
return t.isArrowFunctionExpression(expr) || t.isFunctionExpression(expr);
|
|
916
921
|
}
|
|
917
|
-
function createObjectKey(name) {
|
|
922
|
+
function createObjectKey$1(name) {
|
|
918
923
|
return t.isValidIdentifier(name) ? t.identifier(name) : t.stringLiteral(name);
|
|
919
924
|
}
|
|
920
925
|
function emitSlot(node, context) {
|
|
@@ -927,11 +932,11 @@ function emitMarkerIdentifier(node) {
|
|
|
927
932
|
//#region packages/core/compiler/src/codegen/dom/index.ts
|
|
928
933
|
function emitDOM(node, context) {
|
|
929
934
|
switch (node.kind) {
|
|
930
|
-
case "Element": return emitElement(node, context);
|
|
935
|
+
case "Element": return emitElement$1(node, context);
|
|
931
936
|
case "Fragment": return emitFragment(node, context);
|
|
932
|
-
case "Component": return emitComponent(node, context);
|
|
933
|
-
case "Show": return emitShow(node, context);
|
|
934
|
-
case "For": return emitFor(node, context);
|
|
937
|
+
case "Component": return emitComponent$1(node, context);
|
|
938
|
+
case "Show": return emitShow$1(node, context);
|
|
939
|
+
case "For": return emitFor$1(node, context);
|
|
935
940
|
case "Host": return emitHost(node, context);
|
|
936
941
|
case "Slot": return emitSlot(node, context);
|
|
937
942
|
case "DynamicText": return t.arrowFunctionExpression([], parseExpressionIR(node.expr));
|
|
@@ -939,6 +944,43 @@ function emitDOM(node, context) {
|
|
|
939
944
|
}
|
|
940
945
|
}
|
|
941
946
|
//#endregion
|
|
947
|
+
//#region packages/core/compiler/src/codegen/ssr/rawText.ts
|
|
948
|
+
function getSSRRawTextTag(tagName) {
|
|
949
|
+
const normalized = tagName.toLowerCase();
|
|
950
|
+
return normalized === "script" || normalized === "style" ? normalized : void 0;
|
|
951
|
+
}
|
|
952
|
+
//#endregion
|
|
953
|
+
//#region packages/core/compiler/src/codegen/ssr/property.ts
|
|
954
|
+
const BOOLEAN_PROPERTY_ELEMENTS = {
|
|
955
|
+
checked: /* @__PURE__ */ new Set(["input"]),
|
|
956
|
+
disabled: /* @__PURE__ */ new Set([
|
|
957
|
+
"button",
|
|
958
|
+
"fieldset",
|
|
959
|
+
"input",
|
|
960
|
+
"optgroup",
|
|
961
|
+
"option",
|
|
962
|
+
"select",
|
|
963
|
+
"textarea"
|
|
964
|
+
]),
|
|
965
|
+
multiple: /* @__PURE__ */ new Set(["input", "select"]),
|
|
966
|
+
readOnly: /* @__PURE__ */ new Set(["input", "textarea"]),
|
|
967
|
+
selected: /* @__PURE__ */ new Set(["option"])
|
|
968
|
+
};
|
|
969
|
+
const VALUE_PROPERTY_ELEMENTS = /* @__PURE__ */ new Set([
|
|
970
|
+
"button",
|
|
971
|
+
"input",
|
|
972
|
+
"option",
|
|
973
|
+
"textarea"
|
|
974
|
+
]);
|
|
975
|
+
function isSSRPropertySupported(tag, name) {
|
|
976
|
+
var _BOOLEAN_PROPERTY_ELE;
|
|
977
|
+
const normalizedTag = tag.toLowerCase();
|
|
978
|
+
if (name === "tabIndex") return true;
|
|
979
|
+
if (name === "htmlFor") return normalizedTag === "label";
|
|
980
|
+
if (name === "value") return VALUE_PROPERTY_ELEMENTS.has(normalizedTag);
|
|
981
|
+
return Boolean((_BOOLEAN_PROPERTY_ELE = BOOLEAN_PROPERTY_ELEMENTS[name]) === null || _BOOLEAN_PROPERTY_ELE === void 0 ? void 0 : _BOOLEAN_PROPERTY_ELE.has(normalizedTag));
|
|
982
|
+
}
|
|
983
|
+
//#endregion
|
|
942
984
|
//#region packages/core/compiler/src/diagnostics/codes.ts
|
|
943
985
|
const CompilerErrorCode = {
|
|
944
986
|
UNSUPPORTED_SPREAD_ATTRIBUTE: "ZEUS_UNSUPPORTED_SPREAD_ATTRIBUTE",
|
|
@@ -950,6 +992,9 @@ const CompilerErrorCode = {
|
|
|
950
992
|
INVALID_TRANSFORM_RESULT: "ZEUS_INVALID_TRANSFORM_RESULT",
|
|
951
993
|
UNSUPPORTED_NODE: "ZEUS_UNSUPPORTED_NODE",
|
|
952
994
|
INVALID_BUILTIN_USAGE: "ZEUS_INVALID_BUILTIN_USAGE",
|
|
995
|
+
UNSUPPORTED_SSR_BUILTIN: "ZEUS_UNSUPPORTED_SSR_BUILTIN",
|
|
996
|
+
UNSUPPORTED_SSR_PROPERTY: "ZEUS_UNSUPPORTED_SSR_PROPERTY",
|
|
997
|
+
UNSUPPORTED_SSR_RAW_TEXT_CHILD: "ZEUS_UNSUPPORTED_SSR_RAW_TEXT_CHILD",
|
|
953
998
|
INVALID_REF_USAGE: "ZEUS_INVALID_REF_USAGE"
|
|
954
999
|
};
|
|
955
1000
|
//#endregion
|
|
@@ -986,6 +1031,169 @@ var CompilerError = class extends Error {
|
|
|
986
1031
|
}
|
|
987
1032
|
};
|
|
988
1033
|
//#endregion
|
|
1034
|
+
//#region packages/core/compiler/src/codegen/ssr/validate.ts
|
|
1035
|
+
function assertSSRSupported(node, filename, rawTextTag) {
|
|
1036
|
+
if (rawTextTag && (node.kind === "Element" || node.kind === "Component")) throwUnsupportedSSRRawTextChild(node, rawTextTag, filename);
|
|
1037
|
+
switch (node.kind) {
|
|
1038
|
+
case "Host":
|
|
1039
|
+
case "Slot": throwUnsupportedSSRBuiltin(node, filename);
|
|
1040
|
+
case "Element":
|
|
1041
|
+
for (const attribute of node.attrs) if (attribute.kind === "PropBinding" && !isSSRPropertySupported(node.tagName, attribute.name)) throwUnsupportedSSRProperty(node, attribute, filename);
|
|
1042
|
+
const childRawTextTag = getSSRRawTextTag(node.tagName);
|
|
1043
|
+
for (const child of node.children) assertSSRSupported(child, filename, childRawTextTag);
|
|
1044
|
+
return;
|
|
1045
|
+
case "Fragment":
|
|
1046
|
+
for (const child of node.children) assertSSRSupported(child, filename, rawTextTag);
|
|
1047
|
+
return;
|
|
1048
|
+
case "Component":
|
|
1049
|
+
for (const prop of node.props) {
|
|
1050
|
+
if (!Array.isArray(prop.value)) continue;
|
|
1051
|
+
for (const child of prop.value) assertSSRSupported(child, filename);
|
|
1052
|
+
}
|
|
1053
|
+
return;
|
|
1054
|
+
case "Show":
|
|
1055
|
+
for (const child of node.children) assertSSRSupported(child, filename, rawTextTag);
|
|
1056
|
+
if (Array.isArray(node.fallback)) for (const child of node.fallback) assertSSRSupported(child, filename, rawTextTag);
|
|
1057
|
+
return;
|
|
1058
|
+
case "For":
|
|
1059
|
+
for (const child of node.body) assertSSRSupported(child, filename, rawTextTag);
|
|
1060
|
+
return;
|
|
1061
|
+
case "Text":
|
|
1062
|
+
case "DynamicText": return;
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
function throwUnsupportedSSRRawTextChild(node, tag, filename) {
|
|
1066
|
+
throw new CompilerError({
|
|
1067
|
+
code: CompilerErrorCode.UNSUPPORTED_SSR_RAW_TEXT_CHILD,
|
|
1068
|
+
message: `${node.kind} children are not supported inside <${tag}> SSR raw text.`,
|
|
1069
|
+
hint: "Use text expressions, Fragment, Show, or For directly inside the raw-text element.",
|
|
1070
|
+
filename,
|
|
1071
|
+
span: node.span
|
|
1072
|
+
});
|
|
1073
|
+
}
|
|
1074
|
+
function throwUnsupportedSSRProperty(element, property, filename) {
|
|
1075
|
+
var _ref, _property$span;
|
|
1076
|
+
throw new CompilerError({
|
|
1077
|
+
code: CompilerErrorCode.UNSUPPORTED_SSR_PROPERTY,
|
|
1078
|
+
message: `Property "${property.name}" on <${element.tagName}> cannot be serialized by SSR codegen.`,
|
|
1079
|
+
hint: "Use an equivalent HTML attribute binding or move this DOM-only property update to client code.",
|
|
1080
|
+
filename,
|
|
1081
|
+
span: (_ref = (_property$span = property.span) !== null && _property$span !== void 0 ? _property$span : property.expr.span) !== null && _ref !== void 0 ? _ref : element.span
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
function throwUnsupportedSSRBuiltin(node, filename) {
|
|
1085
|
+
throw new CompilerError({
|
|
1086
|
+
code: CompilerErrorCode.UNSUPPORTED_SSR_BUILTIN,
|
|
1087
|
+
message: `<${node.kind}> is not supported by SSR codegen.`,
|
|
1088
|
+
hint: "Render Web Components on the client; the SSR baseline supports DOM components only.",
|
|
1089
|
+
filename,
|
|
1090
|
+
span: node.span
|
|
1091
|
+
});
|
|
1092
|
+
}
|
|
1093
|
+
//#endregion
|
|
1094
|
+
//#region packages/core/compiler/src/codegen/ssr/index.ts
|
|
1095
|
+
function emitSSR(node, context, rawTextTag) {
|
|
1096
|
+
switch (node.kind) {
|
|
1097
|
+
case "Element": return emitElement(node, context);
|
|
1098
|
+
case "Fragment": return emitChildren(node.children, context, rawTextTag);
|
|
1099
|
+
case "Text":
|
|
1100
|
+
if (rawTextTag) return t.stringLiteral(decodeCompilerEscapedText(node.value));
|
|
1101
|
+
return t.callExpression(context.importRuntime("ssrStatic"), [t.stringLiteral(node.value)]);
|
|
1102
|
+
case "DynamicText":
|
|
1103
|
+
if (rawTextTag) return parseExpressionIR(node.expr);
|
|
1104
|
+
return t.callExpression(context.importRuntime("ssrText"), [parseExpressionIR(node.expr)]);
|
|
1105
|
+
case "Component": return emitComponent(node, context);
|
|
1106
|
+
case "Show": return emitShow(node, context, rawTextTag);
|
|
1107
|
+
case "For": return emitFor(node, context, rawTextTag);
|
|
1108
|
+
case "Host":
|
|
1109
|
+
case "Slot": return throwUnsupportedSSRBuiltin(node);
|
|
1110
|
+
default: return throwUnsupportedSSRNode(node);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
function emitShow(node, context, rawTextTag) {
|
|
1114
|
+
const args = [t.arrowFunctionExpression([], parseExpressionIR(node.when)), t.arrowFunctionExpression([], emitChildrenValue(node.children, context, rawTextTag))];
|
|
1115
|
+
if (node.fallback) {
|
|
1116
|
+
const fallback = Array.isArray(node.fallback) ? emitChildrenValue(node.fallback, context, rawTextTag) : parseExpressionIR(node.fallback);
|
|
1117
|
+
args.push(t.arrowFunctionExpression([], fallback));
|
|
1118
|
+
}
|
|
1119
|
+
return t.callExpression(context.importRuntime("ssrShow"), args);
|
|
1120
|
+
}
|
|
1121
|
+
function emitFor(node, context, rawTextTag) {
|
|
1122
|
+
const params = [t.identifier(node.item.name)];
|
|
1123
|
+
if (node.index) params.push(t.identifier(node.index.name));
|
|
1124
|
+
return t.callExpression(context.importRuntime("ssrFor"), [t.arrowFunctionExpression([], parseExpressionIR(node.each)), t.arrowFunctionExpression(params, emitChildrenValue(node.body, context, rawTextTag))]);
|
|
1125
|
+
}
|
|
1126
|
+
function emitComponent(node, context) {
|
|
1127
|
+
return t.callExpression(context.importRuntime("ssrComponent"), [parseExpressionIR(node.callee), t.objectExpression(node.props.map((prop) => emitComponentProp(prop, context)))]);
|
|
1128
|
+
}
|
|
1129
|
+
function emitComponentProp(prop, context) {
|
|
1130
|
+
const key = createObjectKey(prop.name);
|
|
1131
|
+
if (Array.isArray(prop.value)) return t.objectMethod("get", key, [], t.blockStatement([t.returnStatement(emitChildrenValue(prop.value, context))]));
|
|
1132
|
+
const value = parseExpressionIR(prop.value);
|
|
1133
|
+
if (isStaticPropValue(value)) return t.objectProperty(key, value);
|
|
1134
|
+
return t.objectMethod("get", key, [], t.blockStatement([t.returnStatement(value)]));
|
|
1135
|
+
}
|
|
1136
|
+
function emitElement(node, context) {
|
|
1137
|
+
const rawTextTag = getSSRRawTextTag(node.tagName);
|
|
1138
|
+
const args = [t.stringLiteral(node.tagName), t.arrayExpression(node.attrs.flatMap((attr) => {
|
|
1139
|
+
switch (attr.kind) {
|
|
1140
|
+
case "StaticAttribute":
|
|
1141
|
+
if (isEventAttributeName$1(attr.name)) return [];
|
|
1142
|
+
return [emitStaticAttribute(attr, context)];
|
|
1143
|
+
case "AttrBinding": return [emitAttributeBinding(attr, context)];
|
|
1144
|
+
case "PropBinding": return [emitPropertyBinding(attr, context)];
|
|
1145
|
+
default: return [];
|
|
1146
|
+
}
|
|
1147
|
+
}))];
|
|
1148
|
+
if (node.children.length > 0) args.push(emitChildren(node.children, context, rawTextTag));
|
|
1149
|
+
if (node.flags.isVoid) {
|
|
1150
|
+
if (node.children.length === 0) args.push(t.identifier("undefined"));
|
|
1151
|
+
args.push(t.booleanLiteral(true));
|
|
1152
|
+
}
|
|
1153
|
+
return t.callExpression(context.importRuntime("ssrElement"), args);
|
|
1154
|
+
}
|
|
1155
|
+
function emitAttributeBinding(attr, context) {
|
|
1156
|
+
const name = normalizeAttributeName(attr.name);
|
|
1157
|
+
return t.callExpression(context.importRuntime("ssrAttr"), [t.stringLiteral(name), emitBindingValue(attr.expr)]);
|
|
1158
|
+
}
|
|
1159
|
+
function emitPropertyBinding(attr, context) {
|
|
1160
|
+
return t.callExpression(context.importRuntime("ssrProp"), [t.stringLiteral(attr.name), emitBindingValue(attr.expr)]);
|
|
1161
|
+
}
|
|
1162
|
+
function emitBindingValue(expression) {
|
|
1163
|
+
const value = parseExpressionIR(expression);
|
|
1164
|
+
if (t.isArrowFunctionExpression(value) || t.isFunctionExpression(value)) return t.callExpression(value, []);
|
|
1165
|
+
return value;
|
|
1166
|
+
}
|
|
1167
|
+
function emitStaticAttribute(attr, context) {
|
|
1168
|
+
return t.callExpression(context.importRuntime("ssrAttr"), [t.stringLiteral(normalizeAttributeName(attr.name)), attr.value === true ? t.booleanLiteral(true) : t.stringLiteral(attr.value)]);
|
|
1169
|
+
}
|
|
1170
|
+
function emitChildren(children, context, rawTextTag) {
|
|
1171
|
+
return t.arrayExpression(children.map((child) => emitSSR(child, context, rawTextTag)));
|
|
1172
|
+
}
|
|
1173
|
+
function emitChildrenValue(children, context, rawTextTag) {
|
|
1174
|
+
if (children.length === 1) return emitSSR(children[0], context, rawTextTag);
|
|
1175
|
+
return emitChildren(children, context, rawTextTag);
|
|
1176
|
+
}
|
|
1177
|
+
function decodeCompilerEscapedText(value) {
|
|
1178
|
+
return value.replace(/</g, "<").replace(/&/g, "&");
|
|
1179
|
+
}
|
|
1180
|
+
function isStaticPropValue(value) {
|
|
1181
|
+
return t.isStringLiteral(value) || t.isNumericLiteral(value) || t.isBooleanLiteral(value) || t.isNullLiteral(value);
|
|
1182
|
+
}
|
|
1183
|
+
function createObjectKey(name) {
|
|
1184
|
+
return t.isValidIdentifier(name) ? t.identifier(name) : t.stringLiteral(name);
|
|
1185
|
+
}
|
|
1186
|
+
function normalizeAttributeName(name) {
|
|
1187
|
+
return name === "className" ? "class" : name;
|
|
1188
|
+
}
|
|
1189
|
+
function isEventAttributeName$1(name) {
|
|
1190
|
+
return name.length > 2 && name.slice(0, 2).toLowerCase() === "on";
|
|
1191
|
+
}
|
|
1192
|
+
function throwUnsupportedSSRNode(node) {
|
|
1193
|
+
const kind = node.kind;
|
|
1194
|
+
throw new Error(`Unsupported SSR IR node: ${kind}`);
|
|
1195
|
+
}
|
|
1196
|
+
//#endregion
|
|
989
1197
|
//#region packages/core/compiler/src/adapters/babel/diagnostic.ts
|
|
990
1198
|
function createBabelCompilerError(path, options) {
|
|
991
1199
|
var _hub$file;
|
|
@@ -1058,12 +1266,15 @@ function lowerAttribute(path, _context) {
|
|
|
1058
1266
|
if (!expression.isExpression()) return null;
|
|
1059
1267
|
const expr = lowerExpressionIR(expression);
|
|
1060
1268
|
if (name === "ref") return refBindingIR(expr);
|
|
1061
|
-
if (
|
|
1269
|
+
if (isEventAttributeName(name)) return eventBindingIR(toEventName(name), expr);
|
|
1062
1270
|
if (name.startsWith("prop:")) return propBindingIR(name.slice(5), expr);
|
|
1063
1271
|
return attrBindingIR(name, expr);
|
|
1064
1272
|
}
|
|
1065
1273
|
return null;
|
|
1066
1274
|
}
|
|
1275
|
+
function isEventAttributeName(name) {
|
|
1276
|
+
return name.length > 2 && name.slice(0, 2).toLowerCase() === "on";
|
|
1277
|
+
}
|
|
1067
1278
|
//#endregion
|
|
1068
1279
|
//#region packages/core/compiler/src/lower/lowerChildren.ts
|
|
1069
1280
|
function lowerChildren(children, context) {
|
|
@@ -1330,7 +1541,8 @@ function lowerComponent(path, context) {
|
|
|
1330
1541
|
return componentIR({
|
|
1331
1542
|
ref: ref(context.uid("cmp$").name),
|
|
1332
1543
|
callee: tag,
|
|
1333
|
-
props
|
|
1544
|
+
props,
|
|
1545
|
+
span: sourceSpanFromBabelNode(path.node)
|
|
1334
1546
|
});
|
|
1335
1547
|
}
|
|
1336
1548
|
function convertComponentIdentifier(node) {
|
|
@@ -1361,6 +1573,7 @@ function lowerElement(path, context) {
|
|
|
1361
1573
|
tagName,
|
|
1362
1574
|
attrs,
|
|
1363
1575
|
children: VoidElements.includes(tagName) ? [] : lowerChildren(path.get("children"), context),
|
|
1576
|
+
span: sourceSpanFromBabelNode(path.node),
|
|
1364
1577
|
flags: {
|
|
1365
1578
|
isVoid: VoidElements.includes(tagName),
|
|
1366
1579
|
isCustomElement: tagName.includes("-")
|
|
@@ -1742,13 +1955,18 @@ function transformJSX(path, state, config) {
|
|
|
1742
1955
|
const context = getCompilerContext(path, config);
|
|
1743
1956
|
const ir = lowerJSX(path, context);
|
|
1744
1957
|
normalizeChildren(ir);
|
|
1958
|
+
if (config.generate === "ssr") assertSSRSupported(ir, state.filename);
|
|
1745
1959
|
validateBuiltins(ir, {
|
|
1746
1960
|
isDefineElementRenderRoot: isDefineElementRenderRoot(path),
|
|
1747
1961
|
filename: state.filename
|
|
1748
1962
|
});
|
|
1963
|
+
analyzeBindings(ir);
|
|
1964
|
+
if (config.generate === "ssr") {
|
|
1965
|
+
path.replaceWith(emitSSR(ir, context));
|
|
1966
|
+
return;
|
|
1967
|
+
}
|
|
1749
1968
|
assignDomPaths(ir);
|
|
1750
1969
|
assignPhysicalDomPaths(ir);
|
|
1751
|
-
analyzeBindings(ir);
|
|
1752
1970
|
collectTemplates(ir, context);
|
|
1753
1971
|
path.replaceWith(emitDOM(ir, context));
|
|
1754
1972
|
}
|