@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 CHANGED
@@ -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
  **/
@@ -168,6 +168,7 @@ function appendEvents(path) {
168
168
  }
169
169
  //#endregion
170
170
  //#region packages/core/compiler/src/config/index.ts
171
+ const DEFAULT_SSR_RENDERER_MODULE = "@zeus-js/runtime-ssr";
171
172
  const DEFAULT_OPTIONS = {
172
173
  moduleName: DEFAULT_RENDERER_MODULE,
173
174
  generate: "dom",
@@ -192,7 +193,9 @@ const DEFAULT_OPTIONS = {
192
193
  * @returns The resolved compiler options.
193
194
  */
194
195
  function resolveConfig(options) {
195
- return (0, _zeus_js_shared.extend)(DEFAULT_OPTIONS, options);
196
+ const config = (0, _zeus_js_shared.extend)({}, DEFAULT_OPTIONS, options);
197
+ if (config.generate === "ssr" && (options === null || options === void 0 ? void 0 : options.moduleName) === void 0) config.moduleName = DEFAULT_SSR_RENDERER_MODULE;
198
+ return config;
196
199
  }
197
200
  //#endregion
198
201
  //#region packages/core/compiler/src/context/CompilerContext.ts
@@ -387,8 +390,10 @@ function enterProgram(config, path, state) {
387
390
  }
388
391
  function exitProgram(config, path, state) {
389
392
  if (state.get("skip")) return;
390
- appendTemplates(path);
391
- appendEvents(path);
393
+ if (config.generate === "dom") {
394
+ appendTemplates(path);
395
+ if (config.delegateEvents) appendEvents(path);
396
+ }
392
397
  appendImportMethods(path);
393
398
  }
394
399
  function createProgramVisitor(config) {
@@ -554,7 +559,7 @@ function emitDynamicText(node, context) {
554
559
  ];
555
560
  }
556
561
  function emitComponentInsert(node, context) {
557
- return emitMarkerInsert(node, context, emitComponent(node, context));
562
+ return emitMarkerInsert(node, context, emitComponent$1(node, context));
558
563
  }
559
564
  function emitMarkerInsert(node, context, value) {
560
565
  if (!node.domPath || node.domPath.kind !== "Marker") return [];
@@ -637,7 +642,7 @@ function emitTemplateClone(node, context) {
637
642
  }
638
643
  //#endregion
639
644
  //#region packages/core/compiler/src/codegen/dom/emitElement.ts
640
- function emitElement(node, context) {
645
+ function emitElement$1(node, context) {
641
646
  if (!hasRuntimeWork(node)) return emitTemplateClone(node, context);
642
647
  const statements = [
643
648
  _babel_types.variableDeclaration("const", [_babel_types.variableDeclarator(_babel_types.identifier(node.ref.name), emitTemplateClone(node, context))]),
@@ -784,11 +789,11 @@ function emitNodeExpression(node, context) {
784
789
  switch (node.kind) {
785
790
  case "Text": return _babel_types.stringLiteral(node.value);
786
791
  case "DynamicText": return parseExpressionIR(node.expr);
787
- case "Element": return emitElement(node, context);
788
- case "Component": return emitComponent(node, context);
792
+ case "Element": return emitElement$1(node, context);
793
+ case "Component": return emitComponent$1(node, context);
789
794
  case "Fragment": return emitFragment(node, context);
790
- case "Show": return emitShow(node, context);
791
- case "For": return emitFor(node, context);
795
+ case "Show": return emitShow$1(node, context);
796
+ case "For": return emitFor$1(node, context);
792
797
  case "Host": return emitHost(node, context);
793
798
  case "Slot": return emitSlot(node, context);
794
799
  default: return _babel_types.nullLiteral();
@@ -796,15 +801,15 @@ function emitNodeExpression(node, context) {
796
801
  }
797
802
  //#endregion
798
803
  //#region packages/core/compiler/src/codegen/dom/emitComponent.ts
799
- function emitComponent(node, context) {
800
- const props = _babel_types.objectExpression(node.props.map((prop) => emitComponentProp(prop, context)));
804
+ function emitComponent$1(node, context) {
805
+ const props = _babel_types.objectExpression(node.props.map((prop) => emitComponentProp$1(prop, context)));
801
806
  return _babel_types.callExpression(context.importRuntime("createComponent"), [parseExpressionIR(node.callee), props]);
802
807
  }
803
- function emitComponentProp(prop, context) {
804
- const key = createObjectKey$1(prop.name);
808
+ function emitComponentProp$1(prop, context) {
809
+ const key = createObjectKey$2(prop.name);
805
810
  if (Array.isArray(prop.value)) return _babel_types.objectMethod("get", key, [], _babel_types.blockStatement([_babel_types.returnStatement(emitChildrenProp(prop.value, context))]));
806
811
  const value = parseExpressionIR(prop.value);
807
- if (isStaticPropValue(value)) return _babel_types.objectProperty(key, value);
812
+ if (isStaticPropValue$1(value)) return _babel_types.objectProperty(key, value);
808
813
  return _babel_types.objectMethod("get", key, [], _babel_types.blockStatement([_babel_types.returnStatement(value)]));
809
814
  }
810
815
  function emitChildrenProp(children, context) {
@@ -812,15 +817,15 @@ function emitChildrenProp(children, context) {
812
817
  if (nodes.length === 1) return nodes[0];
813
818
  return _babel_types.arrayExpression(nodes);
814
819
  }
815
- function isStaticPropValue(value) {
820
+ function isStaticPropValue$1(value) {
816
821
  return _babel_types.isStringLiteral(value) || _babel_types.isNumericLiteral(value) || _babel_types.isBooleanLiteral(value) || _babel_types.isNullLiteral(value);
817
822
  }
818
- function createObjectKey$1(key) {
823
+ function createObjectKey$2(key) {
819
824
  return _babel_types.isValidIdentifier(key) ? _babel_types.identifier(key) : _babel_types.stringLiteral(key);
820
825
  }
821
826
  //#endregion
822
827
  //#region packages/core/compiler/src/codegen/dom/emitBuiltin.ts
823
- function emitShow(node, context) {
828
+ function emitShow$1(node, context) {
824
829
  const props = [_babel_types.objectProperty(_babel_types.identifier("when"), parseExpressionIR(node.when)), _babel_types.objectProperty(_babel_types.identifier("children"), _babel_types.arrowFunctionExpression([], emitChildrenProp(node.children, context)))];
825
830
  if (node.fallback) props.push(_babel_types.objectProperty(_babel_types.identifier("fallback"), Array.isArray(node.fallback) ? _babel_types.arrowFunctionExpression([], emitChildrenProp(node.fallback, context)) : parseExpressionIR(node.fallback)));
826
831
  return _babel_types.callExpression(context.importRuntime("createComponent"), [context.importRuntime("Show"), _babel_types.objectExpression(props)]);
@@ -836,7 +841,7 @@ function emitMountShow(node, context) {
836
841
  node.fallback ? Array.isArray(node.fallback) ? _babel_types.arrowFunctionExpression([], emitChildrenProp(node.fallback, context)) : _babel_types.arrowFunctionExpression([], parseExpressionIR(node.fallback)) : _babel_types.identifier("undefined")
837
842
  ]);
838
843
  }
839
- function emitFor(node, context) {
844
+ function emitFor$1(node, context) {
840
845
  const params = [_babel_types.identifier(node.item.name)];
841
846
  if (node.index) params.push(_babel_types.identifier(node.index.name));
842
847
  const props = [_babel_types.objectProperty(_babel_types.identifier("each"), parseExpressionIR(node.each)), _babel_types.objectProperty(_babel_types.identifier("children"), _babel_types.arrowFunctionExpression(params, emitChildrenProp(node.body, context)))];
@@ -867,7 +872,7 @@ function emitHost(node, context) {
867
872
  function buildHostProps(node, context) {
868
873
  const props = [];
869
874
  for (const attr of node.attrs) {
870
- const key = createObjectKey(attr.name);
875
+ const key = createObjectKey$1(attr.name);
871
876
  const expression = parseExpressionIR(attr.expr);
872
877
  if (isStaticValue(expression) || isGetterExpression(expression)) props.push(_babel_types.objectProperty(key, expression));
873
878
  else props.push(_babel_types.objectProperty(key, _babel_types.arrowFunctionExpression([], expression)));
@@ -880,7 +885,7 @@ function isStaticValue(expr) {
880
885
  function isGetterExpression(expr) {
881
886
  return _babel_types.isArrowFunctionExpression(expr) || _babel_types.isFunctionExpression(expr);
882
887
  }
883
- function createObjectKey(name) {
888
+ function createObjectKey$1(name) {
884
889
  return _babel_types.isValidIdentifier(name) ? _babel_types.identifier(name) : _babel_types.stringLiteral(name);
885
890
  }
886
891
  function emitSlot(node, context) {
@@ -893,11 +898,11 @@ function emitMarkerIdentifier(node) {
893
898
  //#region packages/core/compiler/src/codegen/dom/index.ts
894
899
  function emitDOM(node, context) {
895
900
  switch (node.kind) {
896
- case "Element": return emitElement(node, context);
901
+ case "Element": return emitElement$1(node, context);
897
902
  case "Fragment": return emitFragment(node, context);
898
- case "Component": return emitComponent(node, context);
899
- case "Show": return emitShow(node, context);
900
- case "For": return emitFor(node, context);
903
+ case "Component": return emitComponent$1(node, context);
904
+ case "Show": return emitShow$1(node, context);
905
+ case "For": return emitFor$1(node, context);
901
906
  case "Host": return emitHost(node, context);
902
907
  case "Slot": return emitSlot(node, context);
903
908
  case "DynamicText": return _babel_types.arrowFunctionExpression([], parseExpressionIR(node.expr));
@@ -905,6 +910,43 @@ function emitDOM(node, context) {
905
910
  }
906
911
  }
907
912
  //#endregion
913
+ //#region packages/core/compiler/src/codegen/ssr/rawText.ts
914
+ function getSSRRawTextTag(tagName) {
915
+ const normalized = tagName.toLowerCase();
916
+ return normalized === "script" || normalized === "style" ? normalized : void 0;
917
+ }
918
+ //#endregion
919
+ //#region packages/core/compiler/src/codegen/ssr/property.ts
920
+ const BOOLEAN_PROPERTY_ELEMENTS = {
921
+ checked: /* @__PURE__ */ new Set(["input"]),
922
+ disabled: /* @__PURE__ */ new Set([
923
+ "button",
924
+ "fieldset",
925
+ "input",
926
+ "optgroup",
927
+ "option",
928
+ "select",
929
+ "textarea"
930
+ ]),
931
+ multiple: /* @__PURE__ */ new Set(["input", "select"]),
932
+ readOnly: /* @__PURE__ */ new Set(["input", "textarea"]),
933
+ selected: /* @__PURE__ */ new Set(["option"])
934
+ };
935
+ const VALUE_PROPERTY_ELEMENTS = /* @__PURE__ */ new Set([
936
+ "button",
937
+ "input",
938
+ "option",
939
+ "textarea"
940
+ ]);
941
+ function isSSRPropertySupported(tag, name) {
942
+ var _BOOLEAN_PROPERTY_ELE;
943
+ const normalizedTag = tag.toLowerCase();
944
+ if (name === "tabIndex") return true;
945
+ if (name === "htmlFor") return normalizedTag === "label";
946
+ if (name === "value") return VALUE_PROPERTY_ELEMENTS.has(normalizedTag);
947
+ return Boolean((_BOOLEAN_PROPERTY_ELE = BOOLEAN_PROPERTY_ELEMENTS[name]) === null || _BOOLEAN_PROPERTY_ELE === void 0 ? void 0 : _BOOLEAN_PROPERTY_ELE.has(normalizedTag));
948
+ }
949
+ //#endregion
908
950
  //#region packages/core/compiler/src/diagnostics/codes.ts
909
951
  const CompilerErrorCode = {
910
952
  UNSUPPORTED_SPREAD_ATTRIBUTE: "ZEUS_UNSUPPORTED_SPREAD_ATTRIBUTE",
@@ -916,6 +958,9 @@ const CompilerErrorCode = {
916
958
  INVALID_TRANSFORM_RESULT: "ZEUS_INVALID_TRANSFORM_RESULT",
917
959
  UNSUPPORTED_NODE: "ZEUS_UNSUPPORTED_NODE",
918
960
  INVALID_BUILTIN_USAGE: "ZEUS_INVALID_BUILTIN_USAGE",
961
+ UNSUPPORTED_SSR_BUILTIN: "ZEUS_UNSUPPORTED_SSR_BUILTIN",
962
+ UNSUPPORTED_SSR_PROPERTY: "ZEUS_UNSUPPORTED_SSR_PROPERTY",
963
+ UNSUPPORTED_SSR_RAW_TEXT_CHILD: "ZEUS_UNSUPPORTED_SSR_RAW_TEXT_CHILD",
919
964
  INVALID_REF_USAGE: "ZEUS_INVALID_REF_USAGE"
920
965
  };
921
966
  //#endregion
@@ -958,6 +1003,169 @@ var CompilerError = class extends Error {
958
1003
  }
959
1004
  };
960
1005
  //#endregion
1006
+ //#region packages/core/compiler/src/codegen/ssr/validate.ts
1007
+ function assertSSRSupported(node, filename, rawTextTag) {
1008
+ if (rawTextTag && (node.kind === "Element" || node.kind === "Component")) throwUnsupportedSSRRawTextChild(node, rawTextTag, filename);
1009
+ switch (node.kind) {
1010
+ case "Host":
1011
+ case "Slot": throwUnsupportedSSRBuiltin(node, filename);
1012
+ case "Element":
1013
+ for (const attribute of node.attrs) if (attribute.kind === "PropBinding" && !isSSRPropertySupported(node.tagName, attribute.name)) throwUnsupportedSSRProperty(node, attribute, filename);
1014
+ const childRawTextTag = getSSRRawTextTag(node.tagName);
1015
+ for (const child of node.children) assertSSRSupported(child, filename, childRawTextTag);
1016
+ return;
1017
+ case "Fragment":
1018
+ for (const child of node.children) assertSSRSupported(child, filename, rawTextTag);
1019
+ return;
1020
+ case "Component":
1021
+ for (const prop of node.props) {
1022
+ if (!Array.isArray(prop.value)) continue;
1023
+ for (const child of prop.value) assertSSRSupported(child, filename);
1024
+ }
1025
+ return;
1026
+ case "Show":
1027
+ for (const child of node.children) assertSSRSupported(child, filename, rawTextTag);
1028
+ if (Array.isArray(node.fallback)) for (const child of node.fallback) assertSSRSupported(child, filename, rawTextTag);
1029
+ return;
1030
+ case "For":
1031
+ for (const child of node.body) assertSSRSupported(child, filename, rawTextTag);
1032
+ return;
1033
+ case "Text":
1034
+ case "DynamicText": return;
1035
+ }
1036
+ }
1037
+ function throwUnsupportedSSRRawTextChild(node, tag, filename) {
1038
+ throw new CompilerError({
1039
+ code: CompilerErrorCode.UNSUPPORTED_SSR_RAW_TEXT_CHILD,
1040
+ message: `${node.kind} children are not supported inside <${tag}> SSR raw text.`,
1041
+ hint: "Use text expressions, Fragment, Show, or For directly inside the raw-text element.",
1042
+ filename,
1043
+ span: node.span
1044
+ });
1045
+ }
1046
+ function throwUnsupportedSSRProperty(element, property, filename) {
1047
+ var _ref, _property$span;
1048
+ throw new CompilerError({
1049
+ code: CompilerErrorCode.UNSUPPORTED_SSR_PROPERTY,
1050
+ message: `Property "${property.name}" on <${element.tagName}> cannot be serialized by SSR codegen.`,
1051
+ hint: "Use an equivalent HTML attribute binding or move this DOM-only property update to client code.",
1052
+ filename,
1053
+ span: (_ref = (_property$span = property.span) !== null && _property$span !== void 0 ? _property$span : property.expr.span) !== null && _ref !== void 0 ? _ref : element.span
1054
+ });
1055
+ }
1056
+ function throwUnsupportedSSRBuiltin(node, filename) {
1057
+ throw new CompilerError({
1058
+ code: CompilerErrorCode.UNSUPPORTED_SSR_BUILTIN,
1059
+ message: `<${node.kind}> is not supported by SSR codegen.`,
1060
+ hint: "Render Web Components on the client; the SSR baseline supports DOM components only.",
1061
+ filename,
1062
+ span: node.span
1063
+ });
1064
+ }
1065
+ //#endregion
1066
+ //#region packages/core/compiler/src/codegen/ssr/index.ts
1067
+ function emitSSR(node, context, rawTextTag) {
1068
+ switch (node.kind) {
1069
+ case "Element": return emitElement(node, context);
1070
+ case "Fragment": return emitChildren(node.children, context, rawTextTag);
1071
+ case "Text":
1072
+ if (rawTextTag) return _babel_types.stringLiteral(decodeCompilerEscapedText(node.value));
1073
+ return _babel_types.callExpression(context.importRuntime("ssrStatic"), [_babel_types.stringLiteral(node.value)]);
1074
+ case "DynamicText":
1075
+ if (rawTextTag) return parseExpressionIR(node.expr);
1076
+ return _babel_types.callExpression(context.importRuntime("ssrText"), [parseExpressionIR(node.expr)]);
1077
+ case "Component": return emitComponent(node, context);
1078
+ case "Show": return emitShow(node, context, rawTextTag);
1079
+ case "For": return emitFor(node, context, rawTextTag);
1080
+ case "Host":
1081
+ case "Slot": return throwUnsupportedSSRBuiltin(node);
1082
+ default: return throwUnsupportedSSRNode(node);
1083
+ }
1084
+ }
1085
+ function emitShow(node, context, rawTextTag) {
1086
+ const args = [_babel_types.arrowFunctionExpression([], parseExpressionIR(node.when)), _babel_types.arrowFunctionExpression([], emitChildrenValue(node.children, context, rawTextTag))];
1087
+ if (node.fallback) {
1088
+ const fallback = Array.isArray(node.fallback) ? emitChildrenValue(node.fallback, context, rawTextTag) : parseExpressionIR(node.fallback);
1089
+ args.push(_babel_types.arrowFunctionExpression([], fallback));
1090
+ }
1091
+ return _babel_types.callExpression(context.importRuntime("ssrShow"), args);
1092
+ }
1093
+ function emitFor(node, context, rawTextTag) {
1094
+ const params = [_babel_types.identifier(node.item.name)];
1095
+ if (node.index) params.push(_babel_types.identifier(node.index.name));
1096
+ return _babel_types.callExpression(context.importRuntime("ssrFor"), [_babel_types.arrowFunctionExpression([], parseExpressionIR(node.each)), _babel_types.arrowFunctionExpression(params, emitChildrenValue(node.body, context, rawTextTag))]);
1097
+ }
1098
+ function emitComponent(node, context) {
1099
+ return _babel_types.callExpression(context.importRuntime("ssrComponent"), [parseExpressionIR(node.callee), _babel_types.objectExpression(node.props.map((prop) => emitComponentProp(prop, context)))]);
1100
+ }
1101
+ function emitComponentProp(prop, context) {
1102
+ const key = createObjectKey(prop.name);
1103
+ if (Array.isArray(prop.value)) return _babel_types.objectMethod("get", key, [], _babel_types.blockStatement([_babel_types.returnStatement(emitChildrenValue(prop.value, context))]));
1104
+ const value = parseExpressionIR(prop.value);
1105
+ if (isStaticPropValue(value)) return _babel_types.objectProperty(key, value);
1106
+ return _babel_types.objectMethod("get", key, [], _babel_types.blockStatement([_babel_types.returnStatement(value)]));
1107
+ }
1108
+ function emitElement(node, context) {
1109
+ const rawTextTag = getSSRRawTextTag(node.tagName);
1110
+ const args = [_babel_types.stringLiteral(node.tagName), _babel_types.arrayExpression(node.attrs.flatMap((attr) => {
1111
+ switch (attr.kind) {
1112
+ case "StaticAttribute":
1113
+ if (isEventAttributeName$1(attr.name)) return [];
1114
+ return [emitStaticAttribute(attr, context)];
1115
+ case "AttrBinding": return [emitAttributeBinding(attr, context)];
1116
+ case "PropBinding": return [emitPropertyBinding(attr, context)];
1117
+ default: return [];
1118
+ }
1119
+ }))];
1120
+ if (node.children.length > 0) args.push(emitChildren(node.children, context, rawTextTag));
1121
+ if (node.flags.isVoid) {
1122
+ if (node.children.length === 0) args.push(_babel_types.identifier("undefined"));
1123
+ args.push(_babel_types.booleanLiteral(true));
1124
+ }
1125
+ return _babel_types.callExpression(context.importRuntime("ssrElement"), args);
1126
+ }
1127
+ function emitAttributeBinding(attr, context) {
1128
+ const name = normalizeAttributeName(attr.name);
1129
+ return _babel_types.callExpression(context.importRuntime("ssrAttr"), [_babel_types.stringLiteral(name), emitBindingValue(attr.expr)]);
1130
+ }
1131
+ function emitPropertyBinding(attr, context) {
1132
+ return _babel_types.callExpression(context.importRuntime("ssrProp"), [_babel_types.stringLiteral(attr.name), emitBindingValue(attr.expr)]);
1133
+ }
1134
+ function emitBindingValue(expression) {
1135
+ const value = parseExpressionIR(expression);
1136
+ if (_babel_types.isArrowFunctionExpression(value) || _babel_types.isFunctionExpression(value)) return _babel_types.callExpression(value, []);
1137
+ return value;
1138
+ }
1139
+ function emitStaticAttribute(attr, context) {
1140
+ return _babel_types.callExpression(context.importRuntime("ssrAttr"), [_babel_types.stringLiteral(normalizeAttributeName(attr.name)), attr.value === true ? _babel_types.booleanLiteral(true) : _babel_types.stringLiteral(attr.value)]);
1141
+ }
1142
+ function emitChildren(children, context, rawTextTag) {
1143
+ return _babel_types.arrayExpression(children.map((child) => emitSSR(child, context, rawTextTag)));
1144
+ }
1145
+ function emitChildrenValue(children, context, rawTextTag) {
1146
+ if (children.length === 1) return emitSSR(children[0], context, rawTextTag);
1147
+ return emitChildren(children, context, rawTextTag);
1148
+ }
1149
+ function decodeCompilerEscapedText(value) {
1150
+ return value.replace(/&lt;/g, "<").replace(/&amp;/g, "&");
1151
+ }
1152
+ function isStaticPropValue(value) {
1153
+ return _babel_types.isStringLiteral(value) || _babel_types.isNumericLiteral(value) || _babel_types.isBooleanLiteral(value) || _babel_types.isNullLiteral(value);
1154
+ }
1155
+ function createObjectKey(name) {
1156
+ return _babel_types.isValidIdentifier(name) ? _babel_types.identifier(name) : _babel_types.stringLiteral(name);
1157
+ }
1158
+ function normalizeAttributeName(name) {
1159
+ return name === "className" ? "class" : name;
1160
+ }
1161
+ function isEventAttributeName$1(name) {
1162
+ return name.length > 2 && name.slice(0, 2).toLowerCase() === "on";
1163
+ }
1164
+ function throwUnsupportedSSRNode(node) {
1165
+ const kind = node.kind;
1166
+ throw new Error(`Unsupported SSR IR node: ${kind}`);
1167
+ }
1168
+ //#endregion
961
1169
  //#region packages/core/compiler/src/adapters/babel/diagnostic.ts
962
1170
  function createBabelCompilerError(path, options) {
963
1171
  var _hub$file;
@@ -1031,12 +1239,15 @@ function lowerAttribute(path, _context) {
1031
1239
  if (!expression.isExpression()) return null;
1032
1240
  const expr = lowerExpressionIR(expression);
1033
1241
  if (name === "ref") return (0, _zeus_js_compiler_shared.refBindingIR)(expr);
1034
- if (name.startsWith("on") && name.length > 2) return (0, _zeus_js_compiler_shared.eventBindingIR)(toEventName(name), expr);
1242
+ if (isEventAttributeName(name)) return (0, _zeus_js_compiler_shared.eventBindingIR)(toEventName(name), expr);
1035
1243
  if (name.startsWith("prop:")) return (0, _zeus_js_compiler_shared.propBindingIR)(name.slice(5), expr);
1036
1244
  return (0, _zeus_js_compiler_shared.attrBindingIR)(name, expr);
1037
1245
  }
1038
1246
  return null;
1039
1247
  }
1248
+ function isEventAttributeName(name) {
1249
+ return name.length > 2 && name.slice(0, 2).toLowerCase() === "on";
1250
+ }
1040
1251
  //#endregion
1041
1252
  //#region packages/core/compiler/src/lower/lowerChildren.ts
1042
1253
  function lowerChildren(children, context) {
@@ -1303,7 +1514,8 @@ function lowerComponent(path, context) {
1303
1514
  return (0, _zeus_js_compiler_shared.componentIR)({
1304
1515
  ref: (0, _zeus_js_compiler_shared.ref)(context.uid("cmp$").name),
1305
1516
  callee: tag,
1306
- props
1517
+ props,
1518
+ span: sourceSpanFromBabelNode(path.node)
1307
1519
  });
1308
1520
  }
1309
1521
  function convertComponentIdentifier(node) {
@@ -1334,6 +1546,7 @@ function lowerElement(path, context) {
1334
1546
  tagName,
1335
1547
  attrs,
1336
1548
  children: VoidElements.includes(tagName) ? [] : lowerChildren(path.get("children"), context),
1549
+ span: sourceSpanFromBabelNode(path.node),
1337
1550
  flags: {
1338
1551
  isVoid: VoidElements.includes(tagName),
1339
1552
  isCustomElement: tagName.includes("-")
@@ -1734,13 +1947,18 @@ function transformJSX(path, state, config) {
1734
1947
  const context = getCompilerContext(path, config);
1735
1948
  const ir = lowerJSX(path, context);
1736
1949
  normalizeChildren(ir);
1950
+ if (config.generate === "ssr") assertSSRSupported(ir, state.filename);
1737
1951
  validateBuiltins(ir, {
1738
1952
  isDefineElementRenderRoot: isDefineElementRenderRoot(path),
1739
1953
  filename: state.filename
1740
1954
  });
1955
+ analyzeBindings(ir);
1956
+ if (config.generate === "ssr") {
1957
+ path.replaceWith(emitSSR(ir, context));
1958
+ return;
1959
+ }
1741
1960
  assignDomPaths(ir);
1742
1961
  assignPhysicalDomPaths(ir);
1743
- analyzeBindings(ir);
1744
1962
  collectTemplates(ir, context);
1745
1963
  path.replaceWith(emitDOM(ir, context));
1746
1964
  }
@@ -14,7 +14,7 @@ export interface CompilerOptions {
14
14
  * The output mode of the compiler. Can be "dom"(default), "ssr". "dom" is standard output. "ssr" is for server side rendering of strings.
15
15
  * @default 'dom'
16
16
  */
17
- generate: 'dom';
17
+ generate: 'dom' | 'ssr';
18
18
  /**
19
19
  * Indicate whether the output should contain hydratable markers.
20
20
  * @default true
@@ -97,6 +97,9 @@ export declare const CompilerErrorCode: {
97
97
  readonly INVALID_TRANSFORM_RESULT: "ZEUS_INVALID_TRANSFORM_RESULT";
98
98
  readonly UNSUPPORTED_NODE: "ZEUS_UNSUPPORTED_NODE";
99
99
  readonly INVALID_BUILTIN_USAGE: "ZEUS_INVALID_BUILTIN_USAGE";
100
+ readonly UNSUPPORTED_SSR_BUILTIN: "ZEUS_UNSUPPORTED_SSR_BUILTIN";
101
+ readonly UNSUPPORTED_SSR_PROPERTY: "ZEUS_UNSUPPORTED_SSR_PROPERTY";
102
+ readonly UNSUPPORTED_SSR_RAW_TEXT_CHILD: "ZEUS_UNSUPPORTED_SSR_RAW_TEXT_CHILD";
100
103
  readonly INVALID_REF_USAGE: "ZEUS_INVALID_REF_USAGE";
101
104
  };
102
105
  export type CompilerErrorCode = (typeof CompilerErrorCode)[keyof typeof CompilerErrorCode];