marko 6.0.121 → 6.0.123

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.
@@ -30,14 +30,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/translator/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- analyze: () => analyze,
34
- getRuntimeEntryFiles: () => getRuntimeEntryFiles,
33
+ analyze: () => analyze2,
34
+ createInteropTranslator: () => createInteropTranslator,
35
+ getRuntimeEntryFiles: () => getRuntimeEntryFiles2,
35
36
  internalEntryBuilder: () => entry_builder_default,
36
37
  preferAPI: () => preferAPI,
37
- tagDiscoveryDirs: () => tagDiscoveryDirs,
38
- taglibs: () => taglibs,
39
- transform: () => transform,
40
- translate: () => translate
38
+ tagDiscoveryDirs: () => tagDiscoveryDirs2,
39
+ taglibs: () => taglibs2,
40
+ transform: () => transform2,
41
+ translate: () => translate2
41
42
  });
42
43
  module.exports = __toCommonJS(index_exports);
43
44
 
@@ -747,22 +748,22 @@ function getAttributeTagParent(tag) {
747
748
  }
748
749
 
749
750
  // src/translator/util/get-root.ts
750
- function getMarkoRoot(path5) {
751
- let curPath = path5;
751
+ function getMarkoRoot(path7) {
752
+ let curPath = path7;
752
753
  do
753
754
  curPath = curPath.parentPath;
754
755
  while (curPath && !isMarko(curPath));
755
756
  return curPath;
756
757
  }
757
- function getExprRoot(path5) {
758
- let curPath = path5;
758
+ function getExprRoot(path7) {
759
+ let curPath = path7;
759
760
  while (!isMarko(curPath.parentPath)) {
760
761
  curPath = curPath.parentPath;
761
762
  }
762
763
  return curPath;
763
764
  }
764
- function getFnRoot(path5) {
765
- let curPath = path5;
765
+ function getFnRoot(path7) {
766
+ let curPath = path7;
766
767
  let fnPath;
767
768
  while (!isMarko(curPath)) {
768
769
  if (isFunction(curPath)) {
@@ -785,8 +786,8 @@ function getFnRoot(path5) {
785
786
  }
786
787
  return fnPath;
787
788
  }
788
- function getFnParent(path5) {
789
- let curPath = path5;
789
+ function getFnParent(path7) {
790
+ let curPath = path7;
790
791
  while (!isMarko(curPath)) {
791
792
  if (isFunction(curPath)) {
792
793
  return curPath;
@@ -799,8 +800,8 @@ function getFnParent(path5) {
799
800
  }
800
801
  }
801
802
  }
802
- function getDeclarationRoot(path5) {
803
- let curPath = path5;
803
+ function getDeclarationRoot(path7) {
804
+ let curPath = path7;
804
805
  let declPath;
805
806
  while (!isMarko(curPath)) {
806
807
  if (isFunctionOrVariableDeclaration(curPath)) {
@@ -815,8 +816,8 @@ function getDeclarationRoot(path5) {
815
816
  }
816
817
  return declPath;
817
818
  }
818
- function isMarko(path5) {
819
- switch (path5.type) {
819
+ function isMarko(path7) {
820
+ switch (path7.type) {
820
821
  case "MarkoTag":
821
822
  case "MarkoTagBody":
822
823
  case "MarkoAttribute":
@@ -830,10 +831,10 @@ function isMarko(path5) {
830
831
  return false;
831
832
  }
832
833
  }
833
- function isFunction(path5) {
834
- switch (path5.type) {
834
+ function isFunction(path7) {
835
+ switch (path7.type) {
835
836
  case "FunctionDeclaration":
836
- return !path5.node.declare;
837
+ return !path7.node.declare;
837
838
  case "FunctionExpression":
838
839
  case "ArrowFunctionExpression":
839
840
  case "ObjectMethod":
@@ -842,10 +843,10 @@ function isFunction(path5) {
842
843
  return false;
843
844
  }
844
845
  }
845
- function isFunctionOrVariableDeclaration(path5) {
846
- switch (path5.type) {
846
+ function isFunctionOrVariableDeclaration(path7) {
847
+ switch (path7.type) {
847
848
  case "FunctionDeclaration":
848
- return !path5.node.declare;
849
+ return !path7.node.declare;
849
850
  case "VariableDeclaration":
850
851
  return true;
851
852
  default:
@@ -873,14 +874,12 @@ function getTagName(tag) {
873
874
  // src/translator/util/is-core-tag.ts
874
875
  var { taglibId } = runtime_info_default;
875
876
  var htmlTaglibId = "marko-html";
876
- var interopTaglibId = "@marko/translator-interop-class-tags";
877
877
  function isCoreTag(tag) {
878
878
  if (tag.isMarkoTag()) {
879
879
  const tagDef = (0, import_babel_utils6.getTagDef)(tag);
880
880
  if (tagDef) {
881
881
  switch (tagDef.taglibId) {
882
882
  case taglibId:
883
- case interopTaglibId:
884
883
  return true;
885
884
  case htmlTaglibId:
886
885
  switch (tagDef.name) {
@@ -1635,37 +1634,37 @@ function analyzeTagNameType(tag, allowDynamic) {
1635
1634
  }
1636
1635
  function analyzeExpressionTagName(name2, extra) {
1637
1636
  const pending = [name2];
1638
- let path5;
1637
+ let path7;
1639
1638
  let type;
1640
1639
  let nullable = false;
1641
1640
  let tagNameImported;
1642
- while ((path5 = pending.pop()) && type !== 2 /* DynamicTag */) {
1643
- if (path5.isConditionalExpression()) {
1644
- pending.push(path5.get("consequent"));
1645
- if (path5.node.alternate) {
1646
- pending.push(path5.get("alternate"));
1647
- }
1648
- } else if (path5.isLogicalExpression()) {
1649
- if (path5.node.operator === "||") {
1650
- pending.push(path5.get("left"));
1641
+ while ((path7 = pending.pop()) && type !== 2 /* DynamicTag */) {
1642
+ if (path7.isConditionalExpression()) {
1643
+ pending.push(path7.get("consequent"));
1644
+ if (path7.node.alternate) {
1645
+ pending.push(path7.get("alternate"));
1646
+ }
1647
+ } else if (path7.isLogicalExpression()) {
1648
+ if (path7.node.operator === "||") {
1649
+ pending.push(path7.get("left"));
1651
1650
  } else {
1652
1651
  nullable = true;
1653
1652
  }
1654
- pending.push(path5.get("right"));
1655
- } else if (path5.isAssignmentExpression()) {
1656
- pending.push(path5.get("right"));
1657
- } else if (path5.isBinaryExpression()) {
1658
- type = path5.node.operator !== "+" || type === void 0 || type === 0 /* NativeTag */ ? 0 /* NativeTag */ : 2 /* DynamicTag */;
1659
- } else if (path5.isStringLiteral() || path5.isTemplateLiteral()) {
1653
+ pending.push(path7.get("right"));
1654
+ } else if (path7.isAssignmentExpression()) {
1655
+ pending.push(path7.get("right"));
1656
+ } else if (path7.isBinaryExpression()) {
1657
+ type = path7.node.operator !== "+" || type === void 0 || type === 0 /* NativeTag */ ? 0 /* NativeTag */ : 2 /* DynamicTag */;
1658
+ } else if (path7.isStringLiteral() || path7.isTemplateLiteral()) {
1660
1659
  type = type === void 0 || type === 0 /* NativeTag */ ? 0 /* NativeTag */ : 2 /* DynamicTag */;
1661
- } else if (path5.isNullLiteral()) {
1660
+ } else if (path7.isNullLiteral()) {
1662
1661
  nullable = true;
1663
- } else if (path5.isIdentifier()) {
1664
- if (path5.node.name === "undefined") {
1662
+ } else if (path7.isIdentifier()) {
1663
+ if (path7.node.name === "undefined") {
1665
1664
  nullable = true;
1666
1665
  continue;
1667
1666
  }
1668
- const binding = path5.scope.getBinding(path5.node.name);
1667
+ const binding = path7.scope.getBinding(path7.node.name);
1669
1668
  if (!binding) {
1670
1669
  type = 2 /* DynamicTag */;
1671
1670
  continue;
@@ -1719,16 +1718,16 @@ function analyzeExpressionTagName(name2, extra) {
1719
1718
  var sectionUtil = new Sorted(function compareSections(a, b) {
1720
1719
  return a.id - b.id;
1721
1720
  });
1722
- function startSection(path5) {
1723
- const extra = path5.node.extra ??= {};
1721
+ function startSection(path7) {
1722
+ const extra = path7.node.extra ??= {};
1724
1723
  let section = extra.section;
1725
- if (!section && (path5.type === "Program" || path5.get("body").length)) {
1726
- const parentTag = path5.parentPath?.isMarkoTag() ? path5.parentPath : void 0;
1727
- const parentSection = path5.parentPath ? getOrCreateSection(path5.parentPath) : void 0;
1724
+ if (!section && (path7.type === "Program" || path7.get("body").length)) {
1725
+ const parentTag = path7.parentPath?.isMarkoTag() ? path7.parentPath : void 0;
1726
+ const parentSection = path7.parentPath ? getOrCreateSection(path7.parentPath) : void 0;
1728
1727
  const sectionName = parentTag ? generateUid(
1729
1728
  (isCoreTagName(parentTag, "define") && import_compiler7.types.isIdentifier(parentTag.node.var) ? parentTag.node.var.name : parentTag.get("name").toString()) + "_content"
1730
1729
  ) : "";
1731
- const programExtra = path5.hub.file.path.node.extra ??= {};
1730
+ const programExtra = path7.hub.file.path.node.extra ??= {};
1732
1731
  const sections = programExtra.sections ??= [];
1733
1732
  section = extra.section = {
1734
1733
  id: sections.length,
@@ -1750,7 +1749,7 @@ function startSection(path5) {
1750
1749
  serializeReasons: /* @__PURE__ */ new Map(),
1751
1750
  paramReasonGroups: void 0,
1752
1751
  returnSerializeReason: void 0,
1753
- content: getContentInfo(path5),
1752
+ content: getContentInfo(path7),
1754
1753
  upstreamExpression: void 0,
1755
1754
  downstreamBinding: void 0,
1756
1755
  hasAbortSignal: false,
@@ -1760,11 +1759,11 @@ function startSection(path5) {
1760
1759
  }
1761
1760
  return section;
1762
1761
  }
1763
- function getOrCreateSection(path5) {
1764
- let cur = path5;
1762
+ function getOrCreateSection(path7) {
1763
+ let cur = path7;
1765
1764
  while (true) {
1766
1765
  if (cur.type === "Program" || cur.type === "MarkoTagBody" && !cur.node.attributeTags && !isNativeNode(cur.parentPath)) {
1767
- return (path5.node.extra ??= {}).section = startSection(cur);
1766
+ return (path7.node.extra ??= {}).section = startSection(cur);
1768
1767
  }
1769
1768
  cur = cur.parentPath;
1770
1769
  }
@@ -1772,9 +1771,9 @@ function getOrCreateSection(path5) {
1772
1771
  function getSectionForBody(body) {
1773
1772
  return body.node.extra?.section;
1774
1773
  }
1775
- function getSection(path5) {
1774
+ function getSection(path7) {
1776
1775
  let section;
1777
- let currentPath = path5;
1776
+ let currentPath = path7;
1778
1777
  while ((section = currentPath.node.extra?.section) === void 0) {
1779
1778
  currentPath = currentPath.parentPath;
1780
1779
  }
@@ -1800,8 +1799,8 @@ function forEachSectionReverse(fn) {
1800
1799
  fn(sections[i]);
1801
1800
  }
1802
1801
  }
1803
- function getContentInfo(path5) {
1804
- const body = path5.get("body");
1802
+ function getContentInfo(path7) {
1803
+ const body = path7.get("body");
1805
1804
  const contentInfo = {
1806
1805
  startType: null,
1807
1806
  endType: null,
@@ -1828,8 +1827,8 @@ function getContentInfo(path5) {
1828
1827
  }
1829
1828
  return null;
1830
1829
  }
1831
- function getNodeContentType(path5, extraMember, contentInfo) {
1832
- switch (path5.type) {
1830
+ function getNodeContentType(path7, extraMember, contentInfo) {
1831
+ switch (path7.type) {
1833
1832
  case "MarkoText":
1834
1833
  return 4 /* Text */;
1835
1834
  case "MarkoPlaceholder":
@@ -1842,7 +1841,7 @@ function getNodeContentType(path5, extraMember, contentInfo) {
1842
1841
  case "ExportDefaultDeclaration":
1843
1842
  return null;
1844
1843
  case "MarkoTag": {
1845
- const tag = path5;
1844
+ const tag = path7;
1846
1845
  if (isCoreTag(tag)) {
1847
1846
  switch (tag.node.name.value) {
1848
1847
  case "html-comment":
@@ -2064,8 +2063,8 @@ function canIgnoreRegister(markoRoot, exprRoot) {
2064
2063
  /^on[A-Z-]/.test(markoRoot.node.name) || isCoreTagName(markoRoot.parentPath, "script") || isCoreTagName(markoRoot.parentPath, "lifecycle") || isCoreTagName(markoRoot.parentPath, "for"))
2065
2064
  );
2066
2065
  }
2067
- function getStaticDeclRefs(fnExtra, path5, refs = /* @__PURE__ */ new Set()) {
2068
- const decl = getDeclarationRoot(path5);
2066
+ function getStaticDeclRefs(fnExtra, path7, refs = /* @__PURE__ */ new Set()) {
2067
+ const decl = getDeclarationRoot(path7);
2069
2068
  if (decl) {
2070
2069
  const ids = decl.getOuterBindingIdentifiers();
2071
2070
  if (ids) {
@@ -2132,13 +2131,13 @@ function registerFunction(fnExtra, reason) {
2132
2131
  `${fnExtra.section.id}/${fnExtra.name.slice(1)}`
2133
2132
  );
2134
2133
  }
2135
- function isMarkoAttribute(path5) {
2136
- return path5 ? path5.isMarkoAttribute() : false;
2134
+ function isMarkoAttribute(path7) {
2135
+ return path7 ? path7.isMarkoAttribute() : false;
2137
2136
  }
2138
- function isStaticRoot(path5) {
2139
- switch (path5.type) {
2137
+ function isStaticRoot(path7) {
2138
+ switch (path7.type) {
2140
2139
  case "MarkoScriptlet":
2141
- return path5.node.static;
2140
+ return path7.node.static;
2142
2141
  case "ExportDefaultDeclaration":
2143
2142
  case "ExportNamedDeclaration":
2144
2143
  return true;
@@ -2663,29 +2662,29 @@ var import_babel_utils14 = require("@marko/compiler/babel-utils");
2663
2662
 
2664
2663
  // src/translator/util/plugin-hooks.ts
2665
2664
  var import_compiler12 = require("@marko/compiler");
2666
- function enter(modulePlugin, path5) {
2665
+ function enter(modulePlugin, path7) {
2667
2666
  if (!modulePlugin) {
2668
2667
  return false;
2669
2668
  }
2670
- const { node } = path5;
2669
+ const { node } = path7;
2671
2670
  const plugin = isModulePlugin(modulePlugin) ? modulePlugin.default : modulePlugin;
2672
2671
  if (isFunctionPlugin(plugin)) {
2673
- plugin(path5, import_compiler12.types);
2672
+ plugin(path7, import_compiler12.types);
2674
2673
  } else if (plugin.enter) {
2675
- plugin.enter(path5, import_compiler12.types);
2674
+ plugin.enter(path7, import_compiler12.types);
2676
2675
  }
2677
- return node !== path5.node;
2676
+ return node !== path7.node;
2678
2677
  }
2679
- function exit(modulePlugin, path5) {
2678
+ function exit(modulePlugin, path7) {
2680
2679
  if (!modulePlugin) {
2681
2680
  return false;
2682
2681
  }
2683
- const { node } = path5;
2682
+ const { node } = path7;
2684
2683
  const plugin = isModulePlugin(modulePlugin) ? modulePlugin.default : modulePlugin;
2685
2684
  if (!isFunctionPlugin(plugin) && plugin.exit) {
2686
- plugin.exit(path5, import_compiler12.types);
2685
+ plugin.exit(path7, import_compiler12.types);
2687
2686
  }
2688
- return node !== path5.node;
2687
+ return node !== path7.node;
2689
2688
  }
2690
2689
  function isModulePlugin(plugin) {
2691
2690
  return Boolean(plugin.default);
@@ -2717,11 +2716,11 @@ function translateByTarget({
2717
2716
  dom
2718
2717
  }) {
2719
2718
  return {
2720
- enter(path5) {
2721
- enter(isOutputHTML() ? html : dom, path5);
2719
+ enter(path7) {
2720
+ enter(isOutputHTML() ? html : dom, path7);
2722
2721
  },
2723
- exit(path5) {
2724
- exit(isOutputHTML() ? html : dom, path5);
2722
+ exit(path7) {
2723
+ exit(isOutputHTML() ? html : dom, path7);
2725
2724
  }
2726
2725
  };
2727
2726
  }
@@ -2896,16 +2895,16 @@ var walkCodeToName = {
2896
2895
  [116 /* OutEnd */]: "outEnd",
2897
2896
  [126 /* MultiplierEnd */]: "multiplierEnd"
2898
2897
  };
2899
- function enter2(path5) {
2900
- const steps = getSteps(getSection(path5));
2898
+ function enter2(path7) {
2899
+ const steps = getSteps(getSection(path7));
2901
2900
  steps.push(0 /* Enter */);
2902
2901
  }
2903
- function exit2(path5) {
2904
- const steps = getSteps(getSection(path5));
2902
+ function exit2(path7) {
2903
+ const steps = getSteps(getSection(path7));
2905
2904
  steps.push(1 /* Exit */);
2906
2905
  }
2907
- function enterShallow(path5) {
2908
- const section = getSection(path5);
2906
+ function enterShallow(path7) {
2907
+ const section = getSection(path7);
2909
2908
  const steps = getSteps(section);
2910
2909
  steps.push(0 /* Enter */, 1 /* Exit */);
2911
2910
  }
@@ -2926,16 +2925,16 @@ function injectWalks(tag, name2, expr) {
2926
2925
  }
2927
2926
  walks.push(String.fromCharCode(38 /* EndChild */));
2928
2927
  }
2929
- function visit(path5, code) {
2928
+ function visit(path7, code) {
2930
2929
  if (isOutputHTML()) {
2931
2930
  return;
2932
2931
  }
2933
- const section = getSection(path5);
2932
+ const section = getSection(path7);
2934
2933
  const walks = getWalks(section);
2935
2934
  const walkComment = getWalkComment(section);
2936
2935
  visitInternal(section);
2937
2936
  if (code !== 32 /* Get */) {
2938
- writeTo(path5)`<!>`;
2937
+ writeTo(path7)`<!>`;
2939
2938
  }
2940
2939
  walkComment.push(`${walkCodeToName[code]}`);
2941
2940
  appendLiteral(walks, String.fromCharCode(code));
@@ -3029,8 +3028,8 @@ var [getTrailerWrites] = createSectionState(
3029
3028
  "trailerWrites",
3030
3029
  () => [""]
3031
3030
  );
3032
- function writeTo(path5, trailer) {
3033
- const section = getSection(path5);
3031
+ function writeTo(path7, trailer) {
3032
+ const section = getSection(path7);
3034
3033
  const get = trailer ? getTrailerWrites : getWrites;
3035
3034
  return (strs, ...exprs) => {
3036
3035
  const exprsLen = exprs.length;
@@ -3041,8 +3040,8 @@ function writeTo(path5, trailer) {
3041
3040
  }
3042
3041
  };
3043
3042
  }
3044
- function consumeHTML(path5) {
3045
- const section = getSection(path5);
3043
+ function consumeHTML(path7) {
3044
+ const section = getSection(path7);
3046
3045
  const writes = getWrites(section);
3047
3046
  const trailers = getTrailerWrites(section);
3048
3047
  const writeResult = normalizeStringExpression(writes.map(unwrapWrite));
@@ -3064,14 +3063,14 @@ function consumeHTML(path5) {
3064
3063
  return import_compiler16.types.expressionStatement(callRuntime("_trailers", trailerResult));
3065
3064
  }
3066
3065
  }
3067
- function flushBefore(path5) {
3068
- const expr = consumeHTML(path5);
3066
+ function flushBefore(path7) {
3067
+ const expr = consumeHTML(path7);
3069
3068
  if (expr) {
3070
- path5.insertBefore(expr)[0].skip();
3069
+ path7.insertBefore(expr)[0].skip();
3071
3070
  }
3072
3071
  }
3073
- function flushInto(path5) {
3074
- const target = path5.isProgram() ? path5 : path5.get("body");
3072
+ function flushInto(path7) {
3073
+ const target = path7.isProgram() ? path7 : path7.get("body");
3075
3074
  const expr = consumeHTML(target);
3076
3075
  if (expr) {
3077
3076
  target.node.body.push(expr);
@@ -3116,16 +3115,16 @@ function getSectionMetaIdentifiers(section) {
3116
3115
  }
3117
3116
  return meta;
3118
3117
  }
3119
- function markNode(path5, nodeBinding, reason) {
3118
+ function markNode(path7, nodeBinding, reason) {
3120
3119
  if (nodeBinding.type !== 0 /* dom */) {
3121
- throw path5.buildCodeFrameError(
3120
+ throw path7.buildCodeFrameError(
3122
3121
  "POTENTIAL MARKO BUG: Tried to mark a node that was not determined to need a mark during analyze."
3123
3122
  );
3124
3123
  }
3125
3124
  if (isOutputHTML()) {
3126
3125
  if (reason) {
3127
- const section = getSection(path5);
3128
- writeTo(path5)`${callRuntime(
3126
+ const section = getSection(path7);
3127
+ writeTo(path7)`${callRuntime(
3129
3128
  "_el_resume",
3130
3129
  getScopeIdIdentifier(section),
3131
3130
  getScopeAccessorLiteral(nodeBinding),
@@ -4021,10 +4020,10 @@ function toReturnedFunction(rawFn) {
4021
4020
  function addHTMLEffectCall(section, referencedBindings) {
4022
4021
  addStatement("effect", section, referencedBindings, void 0, false);
4023
4022
  }
4024
- function writeHTMLResumeStatements(path5) {
4025
- const section = getSectionForBody(path5);
4023
+ function writeHTMLResumeStatements(path7) {
4024
+ const section = getSectionForBody(path7);
4026
4025
  if (!section) return;
4027
- const body = path5.node.body;
4026
+ const body = path7.node.body;
4028
4027
  const allSignals = Array.from(getSignals(section).values());
4029
4028
  const scopeIdIdentifier = getScopeIdIdentifier(section);
4030
4029
  forEach(section.referencedClosures, (closure) => {
@@ -4174,7 +4173,7 @@ function writeHTMLResumeStatements(path5) {
4174
4173
  ];
4175
4174
  if (debug) {
4176
4175
  writeScopeArgs.push(
4177
- import_compiler22.types.stringLiteral(path5.hub.file.opts.filenameRelative),
4176
+ import_compiler22.types.stringLiteral(path7.hub.file.opts.filenameRelative),
4178
4177
  section.loc && section.loc.start.line != null ? import_compiler22.types.stringLiteral(
4179
4178
  `${section.loc.start.line}:${section.loc.start.column + 1}`
4180
4179
  ) : import_compiler22.types.numericLiteral(0)
@@ -4587,8 +4586,8 @@ var dom_default = {
4587
4586
  var import_compiler24 = require("@marko/compiler");
4588
4587
 
4589
4588
  // src/translator/util/is-static.ts
4590
- function isStatic(path5) {
4591
- return path5.isImportDeclaration() || path5.isExportDeclaration() || path5.isMarkoScriptlet({ static: true });
4589
+ function isStatic(path7) {
4590
+ return path7.isImportDeclaration() || path7.isExportDeclaration() || path7.isMarkoScriptlet({ static: true });
4592
4591
  }
4593
4592
 
4594
4593
  // src/translator/visitors/program/html.ts
@@ -5052,8 +5051,8 @@ function getChangeHandlerFromObjectPattern(parent) {
5052
5051
  }
5053
5052
  return changeKey;
5054
5053
  }
5055
- function getStringOrIdentifierValue(path5) {
5056
- return getLiteralName(path5.node);
5054
+ function getStringOrIdentifierValue(path7) {
5055
+ return getLiteralName(path7.node);
5057
5056
  }
5058
5057
  function getLiteralName(node) {
5059
5058
  switch (node.type) {
@@ -8385,8 +8384,8 @@ function trackAssignment(assignment, binding) {
8385
8384
  }
8386
8385
  });
8387
8386
  }
8388
- function setReferencesScope(path5) {
8389
- const fnRoot = getFnRoot(path5);
8387
+ function setReferencesScope(path7) {
8388
+ const fnRoot = getFnRoot(path7);
8390
8389
  if (fnRoot) {
8391
8390
  (fnRoot.node.extra ??= {}).referencesScope = true;
8392
8391
  }
@@ -11521,15 +11520,15 @@ function isStaticText(node) {
11521
11520
  }
11522
11521
  }
11523
11522
  }
11524
- function getPrev(path5) {
11525
- let prev = path5.getPrevSibling();
11523
+ function getPrev(path7) {
11524
+ let prev = path7.getPrevSibling();
11526
11525
  while (prev.node && (prev.isMarkoComment() || prev.isMarkoPlaceholder() && isEmptyPlaceholder(prev.node))) {
11527
11526
  prev = prev.getPrevSibling();
11528
11527
  }
11529
11528
  return prev.node;
11530
11529
  }
11531
- function getNext(path5) {
11532
- let next = path5.getNextSibling();
11530
+ function getNext(path7) {
11531
+ let next = path7.getNextSibling();
11533
11532
  while (next.node && (next.isMarkoComment() || next.isMarkoPlaceholder() && isEmptyPlaceholder(next.node))) {
11534
11533
  next = next.getNextSibling();
11535
11534
  }
@@ -12338,6 +12337,510 @@ var text_default = {
12338
12337
  }
12339
12338
  };
12340
12339
 
12340
+ // src/translator/interop/index.ts
12341
+ var import_generator = __toESM(require("@babel/generator"));
12342
+ var import_compiler65 = require("@marko/compiler");
12343
+ var import_babel_utils53 = require("@marko/compiler/babel-utils");
12344
+ var translate6 = __toESM(require("@marko/runtime-tags/translator"));
12345
+ var import_path6 = __toESM(require("path"));
12346
+
12347
+ // src/translator/interop/feature-detection.ts
12348
+ var import_babel_utils52 = require("@marko/compiler/babel-utils");
12349
+
12350
+ // src/translator/interop/build-aggregate-error.ts
12351
+ var import_code_frame = require("@babel/code-frame");
12352
+ var import_path5 = __toESM(require("path"));
12353
+ var CWD = process.cwd();
12354
+ function buildAggregateError(file, rootMsg, ...paths) {
12355
+ const err = new SyntaxError();
12356
+ const fileName = import_path5.default.relative(CWD, file.opts.filename);
12357
+ const finalMsg = `${rootMsg}:
12358
+
12359
+ ${paths.map(
12360
+ ([msg, path7]) => `\x1B[90m${msg} at ${getFileNameWithLoc(
12361
+ fileName,
12362
+ path7
12363
+ )}:\x1B[0m
12364
+ ${getFrame(file, path7)}`
12365
+ ).join("\n\n")}`;
12366
+ if (!("MARKO_DEBUG" in process.env)) {
12367
+ err.stack = finalMsg;
12368
+ }
12369
+ Object.defineProperty(err, "message", {
12370
+ get() {
12371
+ return finalMsg;
12372
+ },
12373
+ set() {
12374
+ }
12375
+ });
12376
+ return err;
12377
+ }
12378
+ function getFrame(file, { node: { loc } }) {
12379
+ return loc ? (0, import_code_frame.codeFrameColumns)(
12380
+ file.code,
12381
+ {
12382
+ start: {
12383
+ line: loc.start.line,
12384
+ column: loc.start.column + 1
12385
+ },
12386
+ end: loc.end && loc.start.line === loc.end.line ? {
12387
+ line: loc.end.line,
12388
+ column: loc.end.column + 1
12389
+ } : void 0
12390
+ },
12391
+ { highlightCode: true }
12392
+ ) : "";
12393
+ }
12394
+ function getFileNameWithLoc(fileName, { node: { loc } }) {
12395
+ if (loc) {
12396
+ return `${fileName}(${loc.start.line},${loc.start.column + 1})`;
12397
+ }
12398
+ return fileName;
12399
+ }
12400
+
12401
+ // src/translator/interop/feature-detection.ts
12402
+ function isTagsAPI(file = (0, import_babel_utils52.getFile)()) {
12403
+ const program = file.path;
12404
+ const programExtra = program.node.extra ??= {};
12405
+ let { featureType } = programExtra;
12406
+ if (!featureType) {
12407
+ const lookup = (0, import_babel_utils52.getTaglibLookup)(file);
12408
+ const tagsDir = getTagsDir(file.opts.filename);
12409
+ const state = {};
12410
+ if (tagsDir && !lookup.manualTagsDirs?.has(tagsDir)) {
12411
+ addFeature(
12412
+ state,
12413
+ "tags" /* Tags */,
12414
+ "Template file within a tags directory",
12415
+ program
12416
+ );
12417
+ }
12418
+ scanBody(state, program.get("body"));
12419
+ featureType = file.metadata.marko.api = programExtra.featureType = state.feature?.type || (lookup.exclusiveTagDiscoveryDirs === "tags" ? "tags" /* Tags */ : "class" /* Class */);
12420
+ }
12421
+ return featureType === "tags" /* Tags */;
12422
+ }
12423
+ function getTagsDir(filename) {
12424
+ const pathSeparator = /\/|\\/.exec(filename)?.[0];
12425
+ if (pathSeparator) {
12426
+ let previousIndex = filename.length - 1;
12427
+ while (previousIndex > 0) {
12428
+ const index = filename.lastIndexOf(pathSeparator, previousIndex);
12429
+ switch (previousIndex - index) {
12430
+ case 4: {
12431
+ if (filename.startsWith("tags", index + 1)) {
12432
+ return filename.slice(0, index + 5);
12433
+ }
12434
+ break;
12435
+ }
12436
+ case 10: {
12437
+ if (filename.startsWith("components", index + 1)) {
12438
+ return false;
12439
+ }
12440
+ break;
12441
+ }
12442
+ }
12443
+ previousIndex = index - 1;
12444
+ }
12445
+ }
12446
+ return false;
12447
+ }
12448
+ function scanBody(state, body) {
12449
+ if (body?.length) {
12450
+ for (const child of body) {
12451
+ switch (child.type) {
12452
+ case "MarkoTag":
12453
+ scanTag(state, child);
12454
+ break;
12455
+ case "MarkoComment":
12456
+ if (/^\s*use tags\s*$/.test(child.node.value)) {
12457
+ addFeature(state, "tags" /* Tags */, "<!-- use tags -->", child);
12458
+ } else if (/^\s*use class\s*$/.test(child.node.value)) {
12459
+ addFeature(state, "class" /* Class */, "<!-- use class -->", child);
12460
+ }
12461
+ break;
12462
+ case "MarkoScriptlet":
12463
+ if (!child.node.static) {
12464
+ addFeature(state, "class" /* Class */, "Scriptlet", child);
12465
+ }
12466
+ break;
12467
+ case "MarkoClass":
12468
+ addFeature(
12469
+ state,
12470
+ "class" /* Class */,
12471
+ "Class block",
12472
+ child.get("body")
12473
+ );
12474
+ break;
12475
+ }
12476
+ }
12477
+ }
12478
+ }
12479
+ function scanTag(state, tag) {
12480
+ if (tag.node.var) {
12481
+ addFeature(
12482
+ state,
12483
+ "tags" /* Tags */,
12484
+ "Tag variable",
12485
+ tag.get("var")
12486
+ );
12487
+ }
12488
+ const tagDef = (0, import_babel_utils52.getTagDef)(tag);
12489
+ if (tagDef) {
12490
+ if (tagDef.name === "style") {
12491
+ if (/^style(?:(?:\.[^.\s\\/:*?"<>|({]+)+)?\s*\{/.test(
12492
+ tag.node.rawValue || ""
12493
+ )) {
12494
+ addFeature(state, "class" /* Class */, `style block`, tag.get("name"));
12495
+ }
12496
+ } else if (tagDef.taglibId === runtime_info_default.taglibId) {
12497
+ const feature = getFeatureTypeFromCoreTagName(tagDef.name);
12498
+ if (feature) {
12499
+ addFeature(state, feature, `<${tagDef.name}> tag`, tag.get("name"));
12500
+ }
12501
+ }
12502
+ }
12503
+ if (!tagDef?.parseOptions?.rawOpenTag) {
12504
+ for (const attr of tag.get("attributes")) {
12505
+ if (attr.isMarkoAttribute()) {
12506
+ if (attr.node.arguments?.length) {
12507
+ addFeature(
12508
+ state,
12509
+ "class" /* Class */,
12510
+ "Attribute arguments",
12511
+ attr.get("arguments")[0]
12512
+ );
12513
+ break;
12514
+ } else if (attr.node.modifier) {
12515
+ addFeature(state, "class" /* Class */, "Attribute modifier", attr);
12516
+ break;
12517
+ } else if (attr.node.bound) {
12518
+ addFeature(state, "tags" /* Tags */, "Bound attribute", attr);
12519
+ break;
12520
+ }
12521
+ }
12522
+ }
12523
+ }
12524
+ scanBody(state, tag.get("body").get("body"));
12525
+ scanBody(state, tag.get("attributeTags"));
12526
+ }
12527
+ function getFeatureTypeFromCoreTagName(tagName) {
12528
+ switch (tagName) {
12529
+ case "await-reorderer":
12530
+ case "class":
12531
+ case "include-html":
12532
+ case "include-text":
12533
+ case "init-components":
12534
+ case "macro":
12535
+ case "module-code":
12536
+ case "while":
12537
+ return "class" /* Class */;
12538
+ case "const":
12539
+ case "debug":
12540
+ case "define":
12541
+ case "id":
12542
+ case "let":
12543
+ case "lifecycle":
12544
+ case "log":
12545
+ case "return":
12546
+ case "try":
12547
+ return "tags" /* Tags */;
12548
+ default:
12549
+ return void 0;
12550
+ }
12551
+ }
12552
+ function addFeature(state, type, name2, path7) {
12553
+ if (state.feature) {
12554
+ if (state.feature.type !== type) {
12555
+ throw buildAggregateError(
12556
+ path7.hub.file,
12557
+ "Cannot mix Tags API and Class API features in the same file",
12558
+ [state.feature.name, state.feature.path],
12559
+ [name2, path7]
12560
+ );
12561
+ }
12562
+ } else {
12563
+ state.feature = {
12564
+ name: name2,
12565
+ path: path7,
12566
+ type
12567
+ };
12568
+ }
12569
+ }
12570
+
12571
+ // src/translator/interop/index.ts
12572
+ function createInteropTranslator(translate5) {
12573
+ return {
12574
+ preferAPI: translate5.preferAPI,
12575
+ transform: mergeVisitors(translate5.transform, translate6.transform),
12576
+ analyze: mergeVisitors(translate5.analyze, translate6.analyze),
12577
+ translate: patchTranslateProgram(
12578
+ mergeVisitors(translate5.translate, translate6.translate)
12579
+ ),
12580
+ tagDiscoveryDirs: [
12581
+ ...translate6.tagDiscoveryDirs,
12582
+ ...translate5.tagDiscoveryDirs
12583
+ ],
12584
+ taglibs: mergeTaglibs(
12585
+ import_compiler65.taglib.resolveOptionalTaglibs(translate5.optionalTaglibs).concat(translate5.taglibs),
12586
+ translate6.taglibs
12587
+ ),
12588
+ getRuntimeEntryFiles(output, optimize) {
12589
+ return [
12590
+ ...translate5.getRuntimeEntryFiles(output, optimize),
12591
+ ...translate6.getRuntimeEntryFiles(output, optimize)
12592
+ ];
12593
+ }
12594
+ };
12595
+ function patchTranslateProgram(visitor) {
12596
+ const { Program } = visitor;
12597
+ const kState2 = Symbol();
12598
+ const entryBuilder = {
12599
+ build(entryFile) {
12600
+ const state = entryFile[kState2];
12601
+ if (!state) {
12602
+ throw entryFile.path.buildCodeFrameError(
12603
+ "Unable to build hydrate code, no files were visited before finalizing the build"
12604
+ );
12605
+ }
12606
+ if (state.has5) {
12607
+ if (state.has6) {
12608
+ const filename = entryFile.opts.filename;
12609
+ const baseName = `./${import_path6.default.basename(filename)}`;
12610
+ const generatorOpts = {
12611
+ ...entryFile.opts.generatorOpts,
12612
+ sourceMaps: false
12613
+ };
12614
+ const { resolveVirtualDependency } = entryFile.markoOpts;
12615
+ const importHydrateProgram = (name2, statements) => {
12616
+ return import_compiler65.types.importDeclaration(
12617
+ [import_compiler65.types.importDefaultSpecifier(import_compiler65.types.identifier(`init${name2}`))],
12618
+ import_compiler65.types.stringLiteral(
12619
+ resolveVirtualDependency(filename, {
12620
+ code: (0, import_generator.default)(import_compiler65.types.program(statements), generatorOpts).code,
12621
+ virtualPath: `${baseName}.hydrate-${name2}.js`
12622
+ })
12623
+ )
12624
+ );
12625
+ };
12626
+ return [
12627
+ importHydrateProgram(
12628
+ "6",
12629
+ translate6.internalEntryBuilder.build(entryFile, true)
12630
+ ),
12631
+ importHydrateProgram(
12632
+ "5",
12633
+ translate5.internalEntryBuilder.build(entryFile, true)
12634
+ ),
12635
+ import_compiler65.types.expressionStatement(
12636
+ import_compiler65.types.callExpression(import_compiler65.types.identifier("init6"), [])
12637
+ ),
12638
+ import_compiler65.types.expressionStatement(
12639
+ import_compiler65.types.callExpression(import_compiler65.types.identifier("init5"), [])
12640
+ )
12641
+ ];
12642
+ } else {
12643
+ return translate5.internalEntryBuilder.build(entryFile);
12644
+ }
12645
+ } else {
12646
+ return translate6.internalEntryBuilder.build(entryFile);
12647
+ }
12648
+ },
12649
+ visit(file, entryFile, visitChild) {
12650
+ const state = entryFile[kState2] ||= {
12651
+ has5: false,
12652
+ has6: false
12653
+ };
12654
+ if (isTagsAPI(file)) {
12655
+ state.has6 = true;
12656
+ translate6.internalEntryBuilder.visit(file, entryFile, visitChild);
12657
+ } else {
12658
+ state.has5 = true;
12659
+ translate5.internalEntryBuilder.visit(file, entryFile, visitChild);
12660
+ }
12661
+ }
12662
+ };
12663
+ const enterProgram = getVisitorEnter(Program);
12664
+ return {
12665
+ ...visitor,
12666
+ Program: {
12667
+ enter(program, state) {
12668
+ const entryFile = program.hub.file;
12669
+ if (entryFile.markoOpts.output !== "hydrate") {
12670
+ return enterProgram?.call(this, program, state);
12671
+ }
12672
+ const visitedFiles = /* @__PURE__ */ new Set([
12673
+ (0, import_babel_utils53.resolveRelativePath)(entryFile, entryFile.opts.filename)
12674
+ ]);
12675
+ entryBuilder.visit(
12676
+ entryFile,
12677
+ entryFile,
12678
+ function visitChild(resolved) {
12679
+ if (!visitedFiles.has(resolved)) {
12680
+ visitedFiles.add(resolved);
12681
+ const file = (0, import_babel_utils53.loadFileForImport)(entryFile, resolved);
12682
+ if (file) {
12683
+ entryBuilder.visit(
12684
+ file,
12685
+ entryFile,
12686
+ (id) => visitChild(resolveRelativeToEntry2(entryFile, file, id))
12687
+ );
12688
+ }
12689
+ }
12690
+ }
12691
+ );
12692
+ program.node.body = entryBuilder.build(entryFile);
12693
+ program.skip();
12694
+ },
12695
+ exit: getVisitorExit(Program)
12696
+ }
12697
+ };
12698
+ }
12699
+ }
12700
+ function mergeVisitors(visitor5, visitor6) {
12701
+ return mergeObjects(
12702
+ visitor5,
12703
+ visitor6,
12704
+ (_, value5, value6) => mergeVisit(value5, value6)
12705
+ );
12706
+ }
12707
+ function mergeVisit(visit5, visit6) {
12708
+ const enter5 = getVisitorEnter(visit5);
12709
+ const enter6 = getVisitorEnter(visit6);
12710
+ const enter3 = (enter5 || enter6) && function enter4(path7, state) {
12711
+ return (isTagsAPI() ? enter6 : enter5)?.call(this, path7, state);
12712
+ };
12713
+ const exit5 = getVisitorExit(visit5);
12714
+ const exit6 = getVisitorExit(visit6);
12715
+ const exit3 = (exit5 || exit6) && function exit4(path7, state) {
12716
+ return (isTagsAPI() ? exit6 : exit5)?.call(this, path7, state);
12717
+ };
12718
+ return exit3 ? enter3 ? { enter: enter3, exit: exit3 } : { exit: exit3 } : enter3;
12719
+ }
12720
+ function mergeTaglibs(libs5, libs6) {
12721
+ const libs5Map = new Map(libs5);
12722
+ const libs6Map = new Map(libs6);
12723
+ const merged = [];
12724
+ for (const taglibId2 of /* @__PURE__ */ new Set([...libs5Map.keys(), ...libs6Map.keys()])) {
12725
+ merged.push([
12726
+ taglibId2,
12727
+ mergeObjects(
12728
+ libs5Map.get(taglibId2),
12729
+ libs6Map.get(taglibId2),
12730
+ (key, value5, value6) => {
12731
+ switch (key) {
12732
+ case "migrate":
12733
+ case "analyze":
12734
+ case "transform":
12735
+ case "translate":
12736
+ return mergeVisitors(
12737
+ normalizeVisitor(value5),
12738
+ normalizeVisitor(value6)
12739
+ );
12740
+ default:
12741
+ if (key[0] === "<") {
12742
+ return mergeTagDef(
12743
+ value5,
12744
+ value6
12745
+ );
12746
+ }
12747
+ return value5 ?? value6;
12748
+ }
12749
+ }
12750
+ )
12751
+ ]);
12752
+ }
12753
+ return merged;
12754
+ }
12755
+ function mergeTagDef(def5, def6) {
12756
+ return mergeObjects(
12757
+ normalizeTagDef(def5),
12758
+ normalizeTagDef(def6),
12759
+ (key, value5, value6) => {
12760
+ switch (key) {
12761
+ case "parse":
12762
+ case "migrate":
12763
+ case "transform":
12764
+ case "analyze":
12765
+ case "translate":
12766
+ return mergeVisit(normalizeVisit(value5), normalizeVisit(value6));
12767
+ default:
12768
+ return value5 ?? value6;
12769
+ }
12770
+ }
12771
+ );
12772
+ }
12773
+ function mergeObjects(a, b, cb) {
12774
+ const merged = {};
12775
+ if (a) {
12776
+ if (b) {
12777
+ for (const key in a) {
12778
+ merged[key] = cb(key, a[key], b[key]);
12779
+ }
12780
+ for (const key in b) {
12781
+ if (!(key in a)) {
12782
+ merged[key] = cb(key, void 0, b[key]);
12783
+ }
12784
+ }
12785
+ } else {
12786
+ for (const key in a) {
12787
+ merged[key] = cb(key, a[key], void 0);
12788
+ }
12789
+ }
12790
+ } else if (b) {
12791
+ for (const key in b) {
12792
+ merged[key] = cb(key, void 0, b[key]);
12793
+ }
12794
+ }
12795
+ return merged;
12796
+ }
12797
+ function normalizeTagDef(tagDef) {
12798
+ if (tagDef) {
12799
+ const normalized = {};
12800
+ for (const key in tagDef) {
12801
+ normalized[normalizeTagDefKey(key)] = tagDef[key];
12802
+ }
12803
+ return normalized;
12804
+ }
12805
+ return void 0;
12806
+ }
12807
+ function normalizeTagDefKey(key) {
12808
+ switch (key) {
12809
+ case "code-generator":
12810
+ case "codeGenerator":
12811
+ return "translate";
12812
+ case "migrator":
12813
+ return "migrate";
12814
+ case "node-factory":
12815
+ case "nodeFactory":
12816
+ return "parse";
12817
+ case "parse-options":
12818
+ return "parseOptions";
12819
+ case "transformer":
12820
+ return "transform";
12821
+ default:
12822
+ return key;
12823
+ }
12824
+ }
12825
+ function normalizeVisitor(visitor) {
12826
+ return visitor?.default ?? visitor;
12827
+ }
12828
+ function normalizeVisit(visitor) {
12829
+ return typeof visitor === "function" ? visitor : normalizeVisitor(visitor);
12830
+ }
12831
+ function getVisitorEnter(visit2) {
12832
+ return typeof visit2 === "function" ? visit2 : visit2?.enter;
12833
+ }
12834
+ function getVisitorExit(visit2) {
12835
+ return typeof visit2 === "object" ? visit2?.exit : void 0;
12836
+ }
12837
+ function resolveRelativeToEntry2(entryFile, file, req) {
12838
+ return file === entryFile ? (0, import_babel_utils53.resolveRelativePath)(file, req) : (0, import_babel_utils53.resolveRelativePath)(
12839
+ entryFile,
12840
+ req[0] === "." ? import_path6.default.join(file.opts.filename, "..", req) : req
12841
+ );
12842
+ }
12843
+
12341
12844
  // src/translator/index.ts
12342
12845
  var visitors = extractVisitors({
12343
12846
  Program: program_default,
@@ -12353,10 +12856,10 @@ var visitors = extractVisitors({
12353
12856
  MarkoScriptlet: scriptlet_default,
12354
12857
  MarkoComment: comment_default
12355
12858
  });
12356
- var tagDiscoveryDirs = ["tags"];
12859
+ var tagDiscoveryDirs2 = ["tags"];
12357
12860
  var preferAPI = "tags";
12358
- var { transform, analyze, translate } = visitors;
12359
- var taglibs = [
12861
+ var { transform: transform2, analyze: analyze2, translate: translate2 } = visitors;
12862
+ var taglibs2 = [
12360
12863
  [
12361
12864
  core_default.taglibId,
12362
12865
  {
@@ -12365,7 +12868,7 @@ var taglibs = [
12365
12868
  }
12366
12869
  ]
12367
12870
  ];
12368
- function getRuntimeEntryFiles(output, optimize) {
12871
+ function getRuntimeEntryFiles2(output, optimize) {
12369
12872
  return [
12370
12873
  `${runtime_info_default.name}${optimize ? "" : "/debug"}/${output === "html" ? "html" : "dom"}`
12371
12874
  ];
@@ -12373,6 +12876,7 @@ function getRuntimeEntryFiles(output, optimize) {
12373
12876
  // Annotate the CommonJS export names for ESM import in node:
12374
12877
  0 && (module.exports = {
12375
12878
  analyze,
12879
+ createInteropTranslator,
12376
12880
  getRuntimeEntryFiles,
12377
12881
  internalEntryBuilder,
12378
12882
  preferAPI,