@zeus-js/compiler 0.1.0-beta.8 → 0.1.0-beta.9

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * compiler v0.1.0-beta.8
2
+ * compiler v0.1.0-beta.9
3
3
  * (c) 2026 baicie
4
4
  * Released under the MIT License.
5
5
  **/
@@ -33,6 +33,8 @@ let _babel_helper_plugin_utils = require("@babel/helper-plugin-utils");
33
33
  let _zeus_js_shared = require("@zeus-js/shared");
34
34
  let _babel_types = require("@babel/types");
35
35
  _babel_types = __toESM(_babel_types, 1);
36
+ let _babel_parser = require("@babel/parser");
37
+ let _zeus_js_compiler_shared = require("@zeus-js/compiler-shared");
36
38
  //#region packages/core/compiler/src/codegen/support/imports.ts
37
39
  /**
38
40
  * Runtime helpers registration and program injection.
@@ -266,6 +268,37 @@ function createProgramVisitor(config) {
266
268
  };
267
269
  }
268
270
  //#endregion
271
+ //#region packages/core/compiler/src/adapters/babel/expression.ts
272
+ function lowerExpressionIR(path) {
273
+ return (0, _zeus_js_compiler_shared.expressionIR)(path.toString(), sourceSpanFromBabelNode(path.node));
274
+ }
275
+ function expressionIRFromCode(code, node) {
276
+ return (0, _zeus_js_compiler_shared.expressionIR)(code, sourceSpanFromBabelNode(node));
277
+ }
278
+ function parseExpressionIR(expression) {
279
+ return (0, _babel_parser.parseExpression)(expression.code, {
280
+ sourceType: "module",
281
+ plugins: ["typescript", "jsx"]
282
+ });
283
+ }
284
+ function sourceSpanFromBabelNode(node) {
285
+ if (!(node === null || node === void 0 ? void 0 : node.loc)) return void 0;
286
+ return {
287
+ start: sourcePosition(node.loc.start.line, node.loc.start.column, node.start),
288
+ end: sourcePosition(node.loc.end.line, node.loc.end.column, node.end)
289
+ };
290
+ }
291
+ function sourcePosition(line, column, offset) {
292
+ return typeof offset === "number" ? {
293
+ line,
294
+ column,
295
+ offset
296
+ } : {
297
+ line,
298
+ column
299
+ };
300
+ }
301
+ //#endregion
269
302
  //#region packages/core/compiler/src/codegen/dom/emitBinding.ts
270
303
  function emitBindings(node, context) {
271
304
  const statements = [];
@@ -296,7 +329,7 @@ function emitRawTextValue(children) {
296
329
  const values = children.flatMap((child) => {
297
330
  switch (child.kind) {
298
331
  case "Text": return [_babel_types.stringLiteral(child.value)];
299
- case "DynamicText": return [child.expr];
332
+ case "DynamicText": return [parseExpressionIR(child.expr)];
300
333
  case "Fragment": return [emitRawTextValue(child.children)];
301
334
  default: return [];
302
335
  }
@@ -319,12 +352,12 @@ function emitChildBinding(node, context) {
319
352
  }
320
353
  function emitAttrBinding(target, binding, context) {
321
354
  const name = normalizeAttrName(binding.name);
322
- if (name === "class") return _babel_types.expressionStatement(_babel_types.callExpression(context.importRuntime("bindClass"), [_babel_types.identifier(target.ref.name), emitGetter(binding.expr)]));
323
- if (name === "style") return _babel_types.expressionStatement(_babel_types.callExpression(context.importRuntime("bindStyle"), [_babel_types.identifier(target.ref.name), emitGetter(binding.expr)]));
355
+ if (name === "class") return _babel_types.expressionStatement(_babel_types.callExpression(context.importRuntime("bindClass"), [_babel_types.identifier(target.ref.name), emitGetter(parseExpressionIR(binding.expr))]));
356
+ if (name === "style") return _babel_types.expressionStatement(_babel_types.callExpression(context.importRuntime("bindStyle"), [_babel_types.identifier(target.ref.name), emitGetter(parseExpressionIR(binding.expr))]));
324
357
  return _babel_types.expressionStatement(_babel_types.callExpression(context.importRuntime("bindAttr"), [
325
358
  _babel_types.identifier(target.ref.name),
326
359
  _babel_types.stringLiteral(name),
327
- emitGetter(binding.expr)
360
+ emitGetter(parseExpressionIR(binding.expr))
328
361
  ]));
329
362
  }
330
363
  function normalizeAttrName(name) {
@@ -335,7 +368,7 @@ function emitEventBinding(target, binding, context) {
335
368
  return _babel_types.expressionStatement(_babel_types.callExpression(context.importRuntime("bindEvent"), [
336
369
  _babel_types.identifier(target.ref.name),
337
370
  _babel_types.stringLiteral(binding.eventName),
338
- normalizeEventHandler(binding.handler, context)
371
+ normalizeEventHandler(parseExpressionIR(binding.handler), context)
339
372
  ]));
340
373
  }
341
374
  function normalizeEventHandler(handler, context) {
@@ -349,7 +382,7 @@ function emitPropBinding(target, binding, context) {
349
382
  return _babel_types.expressionStatement(_babel_types.callExpression(context.importRuntime("bindProp"), [
350
383
  _babel_types.identifier(target.ref.name),
351
384
  _babel_types.stringLiteral(binding.name),
352
- emitGetter(binding.expr)
385
+ emitGetter(parseExpressionIR(binding.expr))
353
386
  ]));
354
387
  }
355
388
  function emitGetter(expr) {
@@ -357,12 +390,13 @@ function emitGetter(expr) {
357
390
  return _babel_types.arrowFunctionExpression([], expr);
358
391
  }
359
392
  function emitRefBinding(target, binding, context) {
360
- return _babel_types.expressionStatement(_babel_types.callExpression(context.importRuntime("bindRef"), [_babel_types.identifier(target.ref.name), binding.expr]));
393
+ return _babel_types.expressionStatement(_babel_types.callExpression(context.importRuntime("bindRef"), [_babel_types.identifier(target.ref.name), parseExpressionIR(binding.expr)]));
361
394
  }
362
395
  function emitDynamicText(node, context) {
363
396
  if (!node.domPath || node.domPath.kind !== "Marker") return [];
364
397
  const textRef = context.uid("text$");
365
- if (node.once) return [_babel_types.variableDeclaration("const", [_babel_types.variableDeclarator(textRef, _babel_types.callExpression(_babel_types.memberExpression(_babel_types.identifier("document"), _babel_types.identifier("createTextNode")), [_babel_types.callExpression(_babel_types.identifier("String"), [node.expr])]))]), _babel_types.expressionStatement(_babel_types.callExpression(context.importRuntime("insert"), [
398
+ const expression = parseExpressionIR(node.expr);
399
+ if (node.once) return [_babel_types.variableDeclaration("const", [_babel_types.variableDeclarator(textRef, _babel_types.callExpression(_babel_types.memberExpression(_babel_types.identifier("document"), _babel_types.identifier("createTextNode")), [_babel_types.callExpression(_babel_types.identifier("String"), [expression])]))]), _babel_types.expressionStatement(_babel_types.callExpression(context.importRuntime("insert"), [
366
400
  _babel_types.identifier(node.domPath.parent.name),
367
401
  textRef,
368
402
  _babel_types.identifier(node.ref.name)
@@ -374,7 +408,7 @@ function emitDynamicText(node, context) {
374
408
  textRef,
375
409
  _babel_types.identifier(node.ref.name)
376
410
  ])),
377
- _babel_types.expressionStatement(_babel_types.callExpression(context.importRuntime("bindText"), [textRef, _babel_types.arrowFunctionExpression([], node.expr)]))
411
+ _babel_types.expressionStatement(_babel_types.callExpression(context.importRuntime("bindText"), [textRef, _babel_types.arrowFunctionExpression([], expression)]))
378
412
  ];
379
413
  }
380
414
  function emitComponentInsert(node, context) {
@@ -607,7 +641,7 @@ function emitFragment(node, context) {
607
641
  function emitNodeExpression(node, context) {
608
642
  switch (node.kind) {
609
643
  case "Text": return _babel_types.stringLiteral(node.value);
610
- case "DynamicText": return node.expr;
644
+ case "DynamicText": return parseExpressionIR(node.expr);
611
645
  case "Element": return emitElement(node, context);
612
646
  case "Component": return emitComponent(node, context);
613
647
  case "Fragment": return emitFragment(node, context);
@@ -622,13 +656,14 @@ function emitNodeExpression(node, context) {
622
656
  //#region packages/core/compiler/src/codegen/dom/emitComponent.ts
623
657
  function emitComponent(node, context) {
624
658
  const props = _babel_types.objectExpression(node.props.map((prop) => emitComponentProp(prop, context)));
625
- return _babel_types.callExpression(context.importRuntime("createComponent"), [node.callee, props]);
659
+ return _babel_types.callExpression(context.importRuntime("createComponent"), [parseExpressionIR(node.callee), props]);
626
660
  }
627
661
  function emitComponentProp(prop, context) {
628
662
  const key = createObjectKey$1(prop.name);
629
663
  if (Array.isArray(prop.value)) return _babel_types.objectMethod("get", key, [], _babel_types.blockStatement([_babel_types.returnStatement(emitChildrenProp(prop.value, context))]));
630
- if (isStaticPropValue(prop.value)) return _babel_types.objectProperty(key, prop.value);
631
- return _babel_types.objectMethod("get", key, [], _babel_types.blockStatement([_babel_types.returnStatement(prop.value)]));
664
+ const value = parseExpressionIR(prop.value);
665
+ if (isStaticPropValue(value)) return _babel_types.objectProperty(key, value);
666
+ return _babel_types.objectMethod("get", key, [], _babel_types.blockStatement([_babel_types.returnStatement(value)]));
632
667
  }
633
668
  function emitChildrenProp(children, context) {
634
669
  const nodes = children.map((child) => emitNodeExpression(child, context));
@@ -644,8 +679,8 @@ function createObjectKey$1(key) {
644
679
  //#endregion
645
680
  //#region packages/core/compiler/src/codegen/dom/emitBuiltin.ts
646
681
  function emitShow(node, context) {
647
- 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)))];
648
- 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));
682
+ 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)))];
683
+ 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)));
649
684
  return _babel_types.callExpression(context.importRuntime("createComponent"), [context.importRuntime("Show"), _babel_types.objectExpression(props)]);
650
685
  }
651
686
  function emitMountShow(node, context) {
@@ -654,29 +689,28 @@ function emitMountShow(node, context) {
654
689
  return _babel_types.callExpression(context.importRuntime("mountShow"), [
655
690
  _babel_types.identifier(path.parent.name),
656
691
  emitMarkerIdentifier(node),
657
- _babel_types.arrowFunctionExpression([], node.when),
692
+ _babel_types.arrowFunctionExpression([], parseExpressionIR(node.when)),
658
693
  _babel_types.arrowFunctionExpression([], emitChildrenProp(node.children, context)),
659
- node.fallback ? Array.isArray(node.fallback) ? _babel_types.arrowFunctionExpression([], emitChildrenProp(node.fallback, context)) : _babel_types.arrowFunctionExpression([], node.fallback) : _babel_types.identifier("undefined")
694
+ node.fallback ? Array.isArray(node.fallback) ? _babel_types.arrowFunctionExpression([], emitChildrenProp(node.fallback, context)) : _babel_types.arrowFunctionExpression([], parseExpressionIR(node.fallback)) : _babel_types.identifier("undefined")
660
695
  ]);
661
696
  }
662
697
  function emitFor(node, context) {
663
- const params = [node.item];
664
- if (node.index) params.push(node.index);
665
- const props = [_babel_types.objectProperty(_babel_types.identifier("each"), node.each), _babel_types.objectProperty(_babel_types.identifier("children"), _babel_types.arrowFunctionExpression(params, emitChildrenProp(node.body, context)))];
666
- if (node.by) props.push(_babel_types.objectProperty(_babel_types.identifier("by"), node.by));
698
+ const params = [_babel_types.identifier(node.item.name)];
699
+ if (node.index) params.push(_babel_types.identifier(node.index.name));
700
+ 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)))];
701
+ if (node.by) props.push(_babel_types.objectProperty(_babel_types.identifier("by"), parseExpressionIR(node.by)));
667
702
  return _babel_types.callExpression(context.importRuntime("createComponent"), [context.importRuntime("For"), _babel_types.objectExpression(props)]);
668
703
  }
669
704
  function emitMountFor(node, context) {
670
- var _node$by;
671
- const params = [node.item];
672
- if (node.index) params.push(node.index);
705
+ const params = [_babel_types.identifier(node.item.name)];
706
+ if (node.index) params.push(_babel_types.identifier(node.index.name));
673
707
  const path = node.domPath;
674
708
  if (!path || path.kind !== "Marker") throw new Error("For DOM path is not assigned");
675
709
  return _babel_types.callExpression(context.importRuntime("mountFor"), [
676
710
  _babel_types.identifier(path.parent.name),
677
711
  emitMarkerIdentifier(node),
678
- _babel_types.arrowFunctionExpression([], node.each),
679
- (_node$by = node.by) !== null && _node$by !== void 0 ? _node$by : _babel_types.identifier("undefined"),
712
+ _babel_types.arrowFunctionExpression([], parseExpressionIR(node.each)),
713
+ node.by ? parseExpressionIR(node.by) : _babel_types.identifier("undefined"),
680
714
  _babel_types.arrowFunctionExpression(params, emitChildrenProp(node.body, context))
681
715
  ]);
682
716
  }
@@ -692,8 +726,9 @@ function buildHostProps(node, context) {
692
726
  const props = [];
693
727
  for (const attr of node.attrs) {
694
728
  const key = createObjectKey(attr.name);
695
- if (isStaticValue(attr.expr) || isGetterExpression(attr.expr)) props.push(_babel_types.objectProperty(key, attr.expr));
696
- else props.push(_babel_types.objectProperty(key, _babel_types.arrowFunctionExpression([], attr.expr)));
729
+ const expression = parseExpressionIR(attr.expr);
730
+ if (isStaticValue(expression) || isGetterExpression(expression)) props.push(_babel_types.objectProperty(key, expression));
731
+ else props.push(_babel_types.objectProperty(key, _babel_types.arrowFunctionExpression([], expression)));
697
732
  }
698
733
  return props;
699
734
  }
@@ -723,7 +758,7 @@ function emitDOM(node, context) {
723
758
  case "For": return emitFor(node, context);
724
759
  case "Host": return emitHost(node, context);
725
760
  case "Slot": return emitSlot(node, context);
726
- case "DynamicText": return _babel_types.arrowFunctionExpression([], node.expr);
761
+ case "DynamicText": return _babel_types.arrowFunctionExpression([], parseExpressionIR(node.expr));
727
762
  default: throw new Error(`Unsupported root IR node: ${node.kind}`);
728
763
  }
729
764
  }
@@ -819,143 +854,6 @@ var CompilerError = class extends Error {
819
854
  }
820
855
  };
821
856
  //#endregion
822
- //#region packages/core/compiler/src/ir/semanticBuilders.ts
823
- let nextId = 0;
824
- function id() {
825
- return nextId++;
826
- }
827
- function ref(name) {
828
- return { name };
829
- }
830
- function elementIR(input) {
831
- var _input$attrs, _input$children;
832
- return {
833
- id: id(),
834
- kind: "Element",
835
- ref: input.ref,
836
- tagName: input.tagName,
837
- attrs: (_input$attrs = input.attrs) !== null && _input$attrs !== void 0 ? _input$attrs : [],
838
- children: (_input$children = input.children) !== null && _input$children !== void 0 ? _input$children : [],
839
- flags: {
840
- isSVG: false,
841
- isVoid: false,
842
- isCustomElement: input.tagName.includes("-"),
843
- ...input.flags
844
- }
845
- };
846
- }
847
- function textIR(value) {
848
- return {
849
- id: id(),
850
- kind: "Text",
851
- value
852
- };
853
- }
854
- function dynamicTextIR(expr, nodeRef, once = false) {
855
- return {
856
- id: id(),
857
- kind: "DynamicText",
858
- expr,
859
- ref: nodeRef,
860
- once
861
- };
862
- }
863
- function fragmentIR(children) {
864
- return {
865
- id: id(),
866
- kind: "Fragment",
867
- children
868
- };
869
- }
870
- function staticAttrIR(name, value) {
871
- return {
872
- id: id(),
873
- kind: "StaticAttribute",
874
- name,
875
- value
876
- };
877
- }
878
- function attrBindingIR(name, expr) {
879
- return {
880
- id: id(),
881
- kind: "AttrBinding",
882
- name,
883
- expr
884
- };
885
- }
886
- function propBindingIR(name, expr) {
887
- return {
888
- id: id(),
889
- kind: "PropBinding",
890
- name,
891
- expr
892
- };
893
- }
894
- function eventBindingIR(eventName, handler) {
895
- return {
896
- id: id(),
897
- kind: "EventBinding",
898
- eventName,
899
- handler
900
- };
901
- }
902
- function refBindingIR(expr) {
903
- return {
904
- id: id(),
905
- kind: "RefBinding",
906
- expr
907
- };
908
- }
909
- function componentIR(input) {
910
- return {
911
- id: id(),
912
- kind: "Component",
913
- ref: input.ref,
914
- callee: input.callee,
915
- props: input.props
916
- };
917
- }
918
- function showIR(input) {
919
- return {
920
- id: id(),
921
- kind: "Show",
922
- ref: input.ref,
923
- when: input.when,
924
- children: input.children,
925
- fallback: input.fallback
926
- };
927
- }
928
- function forIR(input) {
929
- return {
930
- id: id(),
931
- kind: "For",
932
- ref: input.ref,
933
- each: input.each,
934
- by: input.by,
935
- item: input.item,
936
- index: input.index,
937
- body: input.body
938
- };
939
- }
940
- function hostIR(input) {
941
- return {
942
- id: id(),
943
- kind: "Host",
944
- attrs: input.attrs,
945
- child: input.child
946
- };
947
- }
948
- function slotIR(input) {
949
- var _input$fallback;
950
- return {
951
- id: id(),
952
- kind: "Slot",
953
- ref: input.ref,
954
- name: input.name,
955
- fallback: (_input$fallback = input.fallback) !== null && _input$fallback !== void 0 ? _input$fallback : []
956
- };
957
- }
958
- //#endregion
959
857
  //#region packages/core/compiler/src/parse/jsx.ts
960
858
  /**
961
859
  * JSX AST parsing utilities.
@@ -993,36 +891,38 @@ function lowerAttribute(path, _context) {
993
891
  });
994
892
  const node = path.node;
995
893
  const name = getJSXAttrName(node.name);
996
- const value = node.value;
997
- if (!value) {
894
+ const value = path.get("value");
895
+ if (!value.node) {
998
896
  if (name === "ref") throw new CompilerError({
999
897
  code: CompilerErrorCode.EMPTY_EXPRESSION,
1000
898
  message: "ref attribute requires an expression.",
1001
899
  path,
1002
900
  hint: "Use <div ref={target} /> instead."
1003
901
  });
1004
- return staticAttrIR(name, true);
902
+ return (0, _zeus_js_compiler_shared.staticAttrIR)(name, true);
1005
903
  }
1006
- if (_babel_types.isStringLiteral(value)) {
904
+ if (value.isStringLiteral()) {
1007
905
  if (name === "ref") throw new CompilerError({
1008
906
  code: CompilerErrorCode.INVALID_REF_USAGE,
1009
907
  message: "String refs are not supported in Zeus.",
1010
908
  path,
1011
909
  hint: "Use a state holder or callback ref: <div ref={el} />."
1012
910
  });
1013
- return staticAttrIR(name, value.value);
911
+ return (0, _zeus_js_compiler_shared.staticAttrIR)(name, value.node.value);
1014
912
  }
1015
- if (_babel_types.isJSXExpressionContainer(value)) {
1016
- const expr = value.expression;
1017
- if (_babel_types.isJSXEmptyExpression(expr)) throw new CompilerError({
913
+ if (value.isJSXExpressionContainer()) {
914
+ const expression = value.get("expression");
915
+ if (expression.isJSXEmptyExpression()) throw new CompilerError({
1018
916
  code: CompilerErrorCode.EMPTY_EXPRESSION,
1019
917
  message: `Attribute "${name}" expression cannot be empty.`,
1020
918
  path
1021
919
  });
1022
- if (name === "ref") return refBindingIR(expr);
1023
- if (name.startsWith("on") && name.length > 2) return eventBindingIR(toEventName(name), expr);
1024
- if (name.startsWith("prop:")) return propBindingIR(name.slice(5), expr);
1025
- return attrBindingIR(name, expr);
920
+ if (!expression.isExpression()) return null;
921
+ const expr = lowerExpressionIR(expression);
922
+ if (name === "ref") return (0, _zeus_js_compiler_shared.refBindingIR)(expr);
923
+ if (name.startsWith("on") && name.length > 2) return (0, _zeus_js_compiler_shared.eventBindingIR)(toEventName(name), expr);
924
+ if (name.startsWith("prop:")) return (0, _zeus_js_compiler_shared.propBindingIR)(name.slice(5), expr);
925
+ return (0, _zeus_js_compiler_shared.attrBindingIR)(name, expr);
1026
926
  }
1027
927
  return null;
1028
928
  }
@@ -1033,13 +933,13 @@ function lowerChildren(children, context) {
1033
933
  for (const child of children) {
1034
934
  if (child.isJSXText()) {
1035
935
  const text = trimJSXText(child.node.value);
1036
- if (text) result.push(textIR(escapeHTML(text)));
936
+ if (text) result.push((0, _zeus_js_compiler_shared.textIR)(escapeHTML(text)));
1037
937
  continue;
1038
938
  }
1039
939
  if (child.isJSXExpressionContainer()) {
1040
- const expr = child.node.expression;
1041
- if (_babel_types.isJSXEmptyExpression(expr)) continue;
1042
- if (_babel_types.isExpression(expr)) result.push(dynamicTextIR(expr, ref(context.uid("anchor$").name)));
940
+ const expression = child.get("expression");
941
+ if (expression.isJSXEmptyExpression()) continue;
942
+ if (expression.isExpression()) result.push((0, _zeus_js_compiler_shared.dynamicTextIR)(lowerExpressionIR(expression), (0, _zeus_js_compiler_shared.ref)(context.uid("anchor$").name)));
1043
943
  continue;
1044
944
  }
1045
945
  if (child.isJSXElement() || child.isJSXFragment()) {
@@ -1081,8 +981,8 @@ function lowerBuiltin(path, context) {
1081
981
  function lowerShow(path, context) {
1082
982
  const when = requiredExpressionAttr(path, "when");
1083
983
  const fallback = optionalShowFallbackAttr(path, context);
1084
- return showIR({
1085
- ref: ref(context.uid("show$").name),
984
+ return (0, _zeus_js_compiler_shared.showIR)({
985
+ ref: (0, _zeus_js_compiler_shared.ref)(context.uid("show$").name),
1086
986
  when,
1087
987
  fallback,
1088
988
  children: lowerChildren(path.get("children"), context)
@@ -1095,27 +995,26 @@ function optionalShowFallbackAttr(path, context) {
1095
995
  });
1096
996
  if (!(attr === null || attr === void 0 ? void 0 : attr.isJSXAttribute())) return void 0;
1097
997
  const value = attr.get("value");
1098
- if (!value.node) return _babel_types.booleanLiteral(true);
1099
- if (value.isStringLiteral()) return value.node;
998
+ if (!value.node) return expressionIRFromCode("true", attr.node);
999
+ if (value.isStringLiteral()) return expressionIRFromCode(JSON.stringify(value.node.value), value.node);
1100
1000
  if (!value.isJSXExpressionContainer()) return void 0;
1101
1001
  const expression = value.get("expression");
1102
1002
  if (expression.isJSXEmptyExpression()) return void 0;
1103
1003
  if (expression.isJSXElement() || expression.isJSXFragment()) return [lowerJSX(expression, context)];
1104
- if (expression.isExpression()) return expression.node;
1004
+ if (expression.isExpression()) return lowerExpressionIR(expression);
1105
1005
  }
1106
1006
  function lowerFor(path, context) {
1107
- var _getParamIdentifier;
1108
1007
  const each = requiredExpressionAttr(path, "each");
1109
1008
  const by = optionalExpressionAttr(path, "by");
1110
1009
  const render = getOnlyRenderFunction(path);
1111
- const item = (_getParamIdentifier = getParamIdentifier(render, 0)) !== null && _getParamIdentifier !== void 0 ? _getParamIdentifier : _babel_types.identifier("item");
1010
+ const item = getParamIdentifier(render, 0, "item");
1112
1011
  const index = getParamIdentifier(render, 1);
1113
1012
  const bodyPath = render.get("body");
1114
1013
  const body = [];
1115
1014
  if (bodyPath.isJSXElement() || bodyPath.isJSXFragment()) body.push(lowerJSX(bodyPath, context));
1116
- else if (bodyPath.isExpression()) body.push(dynamicTextIR(bodyPath.node, ref(context.uid("anchor$").name)));
1117
- return forIR({
1118
- ref: ref(context.uid("for$").name),
1015
+ else if (bodyPath.isExpression()) body.push((0, _zeus_js_compiler_shared.dynamicTextIR)(lowerExpressionIR(bodyPath), (0, _zeus_js_compiler_shared.ref)(context.uid("anchor$").name)));
1016
+ return (0, _zeus_js_compiler_shared.forIR)({
1017
+ ref: (0, _zeus_js_compiler_shared.ref)(context.uid("for$").name),
1119
1018
  each,
1120
1019
  by,
1121
1020
  item,
@@ -1125,15 +1024,15 @@ function lowerFor(path, context) {
1125
1024
  }
1126
1025
  function lowerSlot(path, context) {
1127
1026
  const name = optionalStringAttr(path, "name");
1128
- return slotIR({
1129
- ref: ref(context.uid("slot$").name),
1027
+ return (0, _zeus_js_compiler_shared.slotIR)({
1028
+ ref: (0, _zeus_js_compiler_shared.ref)(context.uid("slot$").name),
1130
1029
  name,
1131
1030
  fallback: lowerChildren(path.get("children"), context)
1132
1031
  });
1133
1032
  }
1134
1033
  function requiredExpressionAttr(path, name) {
1135
1034
  const value = optionalExpressionAttr(path, name);
1136
- if (!value || Array.isArray(value)) throw new CompilerError({
1035
+ if (!value) throw new CompilerError({
1137
1036
  code: CompilerErrorCode.INVALID_BUILTIN_USAGE,
1138
1037
  message: `<${getBuiltinName(path)}> requires "${name}".`,
1139
1038
  path
@@ -1146,10 +1045,12 @@ function optionalExpressionAttr(path, name) {
1146
1045
  return getJSXAttrName(attrPath.node.name) === name;
1147
1046
  });
1148
1047
  if (!(attr === null || attr === void 0 ? void 0 : attr.isJSXAttribute())) return void 0;
1149
- const value = attr.node.value;
1150
- if (!value) return _babel_types.booleanLiteral(true);
1151
- if (_babel_types.isStringLiteral(value)) return value;
1152
- if (_babel_types.isJSXExpressionContainer(value) && !_babel_types.isJSXEmptyExpression(value.expression)) return value.expression;
1048
+ const value = attr.get("value");
1049
+ if (!value.node) return expressionIRFromCode("true", attr.node);
1050
+ if (value.isStringLiteral()) return expressionIRFromCode(JSON.stringify(value.node.value), value.node);
1051
+ if (!value.isJSXExpressionContainer()) return void 0;
1052
+ const expression = value.get("expression");
1053
+ if (expression.isExpression()) return lowerExpressionIR(expression);
1153
1054
  }
1154
1055
  function optionalStringAttr(path, name) {
1155
1056
  const attr = path.get("openingElement").get("attributes").find((attrPath) => {
@@ -1172,8 +1073,8 @@ function getOnlyRenderFunction(path) {
1172
1073
  }
1173
1074
  function getParamIdentifier(path, index, fallback) {
1174
1075
  const param = path.node.params[index];
1175
- if (_babel_types.isIdentifier(param)) return param;
1176
- if (fallback) return _babel_types.identifier(fallback);
1076
+ if (_babel_types.isIdentifier(param)) return (0, _zeus_js_compiler_shared.identifierIR)(param.name, sourceSpanFromBabelNode(param));
1077
+ if (fallback) return (0, _zeus_js_compiler_shared.identifierIR)(fallback);
1177
1078
  }
1178
1079
  function getBuiltinName(path) {
1179
1080
  const name = path.node.openingElement.name;
@@ -1210,38 +1111,41 @@ function lowerHost(path, context) {
1210
1111
  if (value.isJSXExpressionContainer()) {
1211
1112
  const expr = value.get("expression");
1212
1113
  if (expr.isExpression()) attrs.push({
1213
- id: id(),
1114
+ id: (0, _zeus_js_compiler_shared.id)(),
1214
1115
  kind: "HostAttr",
1215
1116
  name: "ref",
1216
- expr: expr.node
1117
+ expr: lowerExpressionIR(expr)
1217
1118
  });
1218
1119
  }
1219
1120
  continue;
1220
1121
  }
1221
1122
  if (isEventLikeProp(name)) continue;
1222
- const value = node.value;
1223
- if (!value) attrs.push({
1224
- id: id(),
1225
- kind: "HostAttr",
1226
- name: normalizeHostAttrName(name),
1227
- expr: _babel_types.booleanLiteral(true)
1228
- });
1229
- else if (_babel_types.isStringLiteral(value)) attrs.push({
1230
- id: id(),
1123
+ const value = attrPath.get("value");
1124
+ if (!value.node) attrs.push({
1125
+ id: (0, _zeus_js_compiler_shared.id)(),
1231
1126
  kind: "HostAttr",
1232
1127
  name: normalizeHostAttrName(name),
1233
- expr: _babel_types.stringLiteral(value.value)
1128
+ expr: expressionIRFromCode("true", node)
1234
1129
  });
1235
- else if (_babel_types.isJSXExpressionContainer(value) && !_babel_types.isJSXEmptyExpression(value.expression)) attrs.push({
1236
- id: id(),
1130
+ else if (value.isStringLiteral()) attrs.push({
1131
+ id: (0, _zeus_js_compiler_shared.id)(),
1237
1132
  kind: "HostAttr",
1238
1133
  name: normalizeHostAttrName(name),
1239
- expr: value.expression
1134
+ expr: expressionIRFromCode(JSON.stringify(value.node.value), value.node)
1240
1135
  });
1136
+ else if (value.isJSXExpressionContainer()) {
1137
+ const expression = value.get("expression");
1138
+ if (expression.isExpression()) attrs.push({
1139
+ id: (0, _zeus_js_compiler_shared.id)(),
1140
+ kind: "HostAttr",
1141
+ name: normalizeHostAttrName(name),
1142
+ expr: lowerExpressionIR(expression)
1143
+ });
1144
+ }
1241
1145
  }
1242
- return hostIR({
1146
+ return (0, _zeus_js_compiler_shared.hostIR)({
1243
1147
  attrs,
1244
- child: rawChildren.length === 0 ? void 0 : rawChildren.length === 1 ? rawChildren[0] : fragmentIR(rawChildren)
1148
+ child: rawChildren.length === 0 ? void 0 : rawChildren.length === 1 ? rawChildren[0] : (0, _zeus_js_compiler_shared.fragmentIR)(rawChildren)
1245
1149
  });
1246
1150
  }
1247
1151
  //#endregion
@@ -1257,29 +1161,31 @@ function lowerComponent(path, context) {
1257
1161
  path: attr
1258
1162
  });
1259
1163
  const name = getJSXAttrName(node.name);
1260
- if (!node.value) {
1164
+ const value = attr.get("value");
1165
+ if (!value.node) {
1261
1166
  props.push({
1262
1167
  name,
1263
- value: _babel_types.booleanLiteral(true)
1168
+ value: expressionIRFromCode("true", node)
1264
1169
  });
1265
1170
  continue;
1266
1171
  }
1267
- if (_babel_types.isStringLiteral(node.value)) {
1172
+ if (value.isStringLiteral()) {
1268
1173
  props.push({
1269
1174
  name,
1270
- value: node.value
1175
+ value: expressionIRFromCode(JSON.stringify(value.node.value), value.node)
1271
1176
  });
1272
1177
  continue;
1273
1178
  }
1274
- if (_babel_types.isJSXExpressionContainer(node.value)) {
1275
- if (_babel_types.isJSXEmptyExpression(node.value.expression)) throw new CompilerError({
1179
+ if (value.isJSXExpressionContainer()) {
1180
+ const expression = value.get("expression");
1181
+ if (expression.isJSXEmptyExpression()) throw new CompilerError({
1276
1182
  code: CompilerErrorCode.EMPTY_EXPRESSION,
1277
1183
  message: `Component prop "${name}" expression cannot be empty.`,
1278
1184
  path: attr
1279
1185
  });
1280
- props.push({
1186
+ if (expression.isExpression()) props.push({
1281
1187
  name,
1282
- value: node.value.expression
1188
+ value: lowerExpressionIR(expression)
1283
1189
  });
1284
1190
  }
1285
1191
  }
@@ -1288,25 +1194,27 @@ function lowerComponent(path, context) {
1288
1194
  name: "children",
1289
1195
  value: children
1290
1196
  });
1291
- return componentIR({
1292
- ref: ref(context.uid("cmp$").name),
1197
+ return (0, _zeus_js_compiler_shared.componentIR)({
1198
+ ref: (0, _zeus_js_compiler_shared.ref)(context.uid("cmp$").name),
1293
1199
  callee: tag,
1294
1200
  props
1295
1201
  });
1296
1202
  }
1297
1203
  function convertComponentIdentifier(node) {
1204
+ return expressionIRFromCode(componentIdentifierCode(node), node);
1205
+ }
1206
+ function componentIdentifierCode(node) {
1298
1207
  if (_babel_types.isJSXIdentifier(node)) {
1299
- if (node.name === "this") return _babel_types.thisExpression();
1300
- if (_babel_types.isValidIdentifier(node.name)) return _babel_types.identifier(node.name);
1301
- return _babel_types.stringLiteral(node.name);
1208
+ if (node.name === "this") return "this";
1209
+ return _babel_types.isValidIdentifier(node.name) ? node.name : JSON.stringify(node.name);
1302
1210
  }
1303
1211
  if (_babel_types.isJSXMemberExpression(node)) {
1304
- const object = convertComponentIdentifier(node.object);
1305
- const property = convertComponentIdentifier(node.property);
1306
- return _babel_types.memberExpression(object, property, _babel_types.isStringLiteral(property));
1212
+ const object = componentIdentifierCode(node.object);
1213
+ const property = node.property.name;
1214
+ return _babel_types.isValidIdentifier(property) ? `${object}.${property}` : `${object}[${JSON.stringify(property)}]`;
1307
1215
  }
1308
- if (_babel_types.isJSXNamespacedName(node)) return _babel_types.stringLiteral(`${node.namespace.name}:${node.name.name}`);
1309
- return node;
1216
+ if (_babel_types.isJSXNamespacedName(node)) return JSON.stringify(`${node.namespace.name}:${node.name.name}`);
1217
+ return JSON.stringify("");
1310
1218
  }
1311
1219
  //#endregion
1312
1220
  //#region packages/core/compiler/src/lower/lowerElement.ts
@@ -1315,8 +1223,8 @@ function lowerElement(path, context) {
1315
1223
  if (isBuiltinTag(tagName)) return lowerBuiltin(path, context);
1316
1224
  if (isComponentTag(tagName)) return lowerComponent(path, context);
1317
1225
  const attrs = path.get("openingElement").get("attributes").map((attr) => lowerAttribute(attr, context)).filter(Boolean);
1318
- return elementIR({
1319
- ref: ref(context.uid("el$").name),
1226
+ return (0, _zeus_js_compiler_shared.elementIR)({
1227
+ ref: (0, _zeus_js_compiler_shared.ref)(context.uid("el$").name),
1320
1228
  tagName,
1321
1229
  attrs,
1322
1230
  children: VoidElements.includes(tagName) ? [] : lowerChildren(path.get("children"), context),
@@ -1329,7 +1237,7 @@ function lowerElement(path, context) {
1329
1237
  //#endregion
1330
1238
  //#region packages/core/compiler/src/lower/lowerFragment.ts
1331
1239
  function lowerFragment(path, context) {
1332
- return fragmentIR(lowerChildren(path.get("children"), context));
1240
+ return (0, _zeus_js_compiler_shared.fragmentIR)(lowerChildren(path.get("children"), context));
1333
1241
  }
1334
1242
  //#endregion
1335
1243
  //#region packages/core/compiler/src/lower/lowerJSX.ts
@@ -1746,3 +1654,11 @@ var src_default = (0, _babel_helper_plugin_utils.declare)((api, options) => {
1746
1654
  });
1747
1655
  //#endregion
1748
1656
  exports.default = src_default;
1657
+ Object.keys(_zeus_js_compiler_shared).forEach(function(k) {
1658
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
1659
+ enumerable: true,
1660
+ get: function() {
1661
+ return _zeus_js_compiler_shared[k];
1662
+ }
1663
+ });
1664
+ });