marko 6.3.52 → 6.3.53

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.
Files changed (58) hide show
  1. package/dist/debug/dom/catch.feat.js +1 -1
  2. package/dist/debug/dom/catch.feat.mjs +1 -1
  3. package/dist/debug/dom/controllable-input.feat.js +1 -1
  4. package/dist/debug/dom/controllable-input.feat.mjs +1 -1
  5. package/dist/debug/dom/controllable-open.feat.js +1 -1
  6. package/dist/debug/dom/controllable-open.feat.mjs +1 -1
  7. package/dist/debug/dom/controllable-select.feat.js +1 -1
  8. package/dist/debug/dom/controllable-select.feat.mjs +1 -1
  9. package/dist/debug/dom/controllable-textarea.feat.js +1 -1
  10. package/dist/debug/dom/controllable-textarea.feat.mjs +1 -1
  11. package/dist/debug/dom/controllable.feat.js +1 -1
  12. package/dist/debug/dom/controllable.feat.mjs +1 -1
  13. package/dist/debug/dom/dynamic-tag-script.feat.js +5 -0
  14. package/dist/debug/dom/dynamic-tag-script.feat.mjs +4 -0
  15. package/dist/debug/dom/dynamic-tag-var.feat.js +2 -3
  16. package/dist/debug/dom/dynamic-tag-var.feat.mjs +2 -3
  17. package/dist/debug/dom/placeholder.feat.js +1 -1
  18. package/dist/debug/dom/placeholder.feat.mjs +1 -1
  19. package/dist/debug/{dom-BJKb8-wr.js → dom-CBLlE8L-.js} +27 -10
  20. package/dist/debug/{dom-Dq_Yu7MS.mjs → dom-DQCODUa1.mjs} +12 -7
  21. package/dist/debug/dom.js +2 -2
  22. package/dist/debug/dom.mjs +2 -2
  23. package/dist/debug/html.js +1 -1
  24. package/dist/debug/html.mjs +1 -1
  25. package/dist/dom/catch.feat.js +3 -3
  26. package/dist/dom/catch.feat.mjs +1 -1
  27. package/dist/dom/control-flow.d.ts +1 -3
  28. package/dist/dom/controllable-input.feat.js +1 -1
  29. package/dist/dom/controllable-input.feat.mjs +1 -1
  30. package/dist/dom/controllable-open.feat.js +1 -1
  31. package/dist/dom/controllable-open.feat.mjs +1 -1
  32. package/dist/dom/controllable-select.feat.js +1 -1
  33. package/dist/dom/controllable-select.feat.mjs +1 -1
  34. package/dist/dom/controllable-textarea.feat.js +1 -1
  35. package/dist/dom/controllable-textarea.feat.mjs +1 -1
  36. package/dist/dom/controllable.feat.js +1 -1
  37. package/dist/dom/controllable.feat.mjs +1 -1
  38. package/dist/dom/dynamic-tag-script.feat.d.ts +1 -0
  39. package/dist/dom/dynamic-tag-script.feat.js +4 -0
  40. package/dist/dom/dynamic-tag-script.feat.mjs +4 -0
  41. package/dist/dom/dynamic-tag-var.feat.js +1 -2
  42. package/dist/dom/dynamic-tag-var.feat.mjs +2 -3
  43. package/dist/dom/placeholder.feat.js +3 -3
  44. package/dist/dom/placeholder.feat.mjs +1 -1
  45. package/dist/dom/resume.d.ts +1 -0
  46. package/dist/{dom-CzGPOsST.js → dom-vuB05Hnj.js} +75 -59
  47. package/dist/{dom-CzfddxCE.mjs → dom-z4IMlmeO.mjs} +8 -2
  48. package/dist/dom.d.ts +2 -2
  49. package/dist/dom.js +33 -33
  50. package/dist/dom.mjs +2 -2
  51. package/dist/html.js +1 -1
  52. package/dist/html.mjs +1 -1
  53. package/dist/translator/index.js +527 -525
  54. package/dist/translator/util/references.d.ts +6 -3
  55. package/dist/translator/util/runtime.d.ts +1 -1
  56. package/dist/translator/util/sections.d.ts +0 -2
  57. package/dist/translator/util/serialize-guard.d.ts +0 -6
  58. package/package.json +4 -4
@@ -961,277 +961,6 @@ function rest(data) {
961
961
  return Array.isArray(data) ? data.length === 2 ? data[1] : data.slice(1) : void 0;
962
962
  }
963
963
  //#endregion
964
- //#region src/common/errors.ts
965
- function assertExclusiveAttrs(attrs, onError = throwErr) {
966
- if (attrs) {
967
- let exclusiveAttrs;
968
- if (attrs.checkedChange) (exclusiveAttrs ||= []).push("checkedChange");
969
- if ("checkedValue" in attrs) {
970
- (exclusiveAttrs ||= []).push("checkedValue");
971
- if ("checked" in attrs) exclusiveAttrs.push("checked");
972
- } else if (attrs.checkedValueChange) {
973
- (exclusiveAttrs ||= []).push("checkedValueChange");
974
- if ("checked" in attrs) exclusiveAttrs.push("checked");
975
- }
976
- if (attrs.valueChange) {
977
- (exclusiveAttrs ||= []).push("valueChange");
978
- if ("checked" in attrs && !exclusiveAttrs.includes("checked")) exclusiveAttrs.push("checked");
979
- }
980
- if (exclusiveAttrs && exclusiveAttrs.length > 1) onError(`The attributes ${joinWithAnd(exclusiveAttrs)} are mutually exclusive.`);
981
- }
982
- }
983
- function throwErr(msg) {
984
- throw new Error(msg);
985
- }
986
- function joinWithAnd(a) {
987
- switch (a.length) {
988
- case 0: return "";
989
- case 1: return a[0];
990
- case 2: return `${a[0]} and ${a[1]}`;
991
- default: return `${a.slice(0, -1).join(", ")}, and ${a[a.length - 1]}`;
992
- }
993
- }
994
- //#endregion
995
- //#region src/html/content.ts
996
- function _unescaped(val) {
997
- return val ? val + "" : val === 0 ? "0" : "";
998
- }
999
- const unsafeXMLReg = /[<&\r]/g;
1000
- const replaceUnsafeXML = (c) => c === "&" ? "&amp;" : c === "<" ? "&lt;" : "&#13;";
1001
- const escapeXMLStr = (str) => unsafeXMLReg.test(str) ? str.replace(unsafeXMLReg, replaceUnsafeXML) : str;
1002
- function _escape(val) {
1003
- return val ? escapeXMLStr(val + "") : val === 0 ? "0" : "";
1004
- }
1005
- const unsafeScriptReg = /<(\/?script|!--)/gi;
1006
- const escapeScriptStr = (str) => unsafeScriptReg.test(str) ? str.replace(unsafeScriptReg, "\\x3C$1") : str;
1007
- function _escape_script(val) {
1008
- return val ? escapeScriptStr(val + "") : val === 0 ? "0" : "";
1009
- }
1010
- const unsafeStyleReg = /<(\/style)/gi;
1011
- const escapeStyleStr = (str) => unsafeStyleReg.test(str) ? str.replace(unsafeStyleReg, "\\3C$1") : str;
1012
- function _escape_style(val) {
1013
- return val ? escapeStyleStr(val + "") : val === 0 ? "0" : "";
1014
- }
1015
- const unsafeCommentReg = />/g;
1016
- const escapeCommentStr = (str) => unsafeCommentReg.test(str) ? str.replace(unsafeCommentReg, "&gt;") : str;
1017
- function _escape_comment(val) {
1018
- return val ? escapeCommentStr(val + "") : val === 0 ? "0" : "";
1019
- }
1020
- globalThis.setImmediate || globalThis.setTimeout || globalThis.queueMicrotask;
1021
- //#endregion
1022
- //#region src/html/attrs.ts
1023
- function _attr_class(value) {
1024
- return stringAttr("class", toDelimitedString(value, " ", stringifyClassObject));
1025
- }
1026
- function _attr_style(value) {
1027
- return stringAttr("style", toDelimitedString(value, ";", stringifyStyleObject));
1028
- }
1029
- function _attr(name, value) {
1030
- return isVoid(value) ? "" : nonVoidAttr(name, value);
1031
- }
1032
- function stringAttr(name, value) {
1033
- return value && " " + name + attrAssignment(value);
1034
- }
1035
- function nonVoidAttr(name, value) {
1036
- switch (typeof value) {
1037
- case "string": return " " + name + attrAssignment(value);
1038
- case "boolean": return " " + name;
1039
- case "number": return " " + name + "=" + value;
1040
- }
1041
- return " " + name + attrAssignment(value + "");
1042
- }
1043
- const singleQuoteAttrReplacements = /['\r]|&(?=[#a-zA-Z])/g;
1044
- const doubleQuoteAttrReplacements = /["\r]|&(?=[#a-zA-Z])/g;
1045
- const needsQuotedAttr = /["'>\s]|&[#a-zA-Z]|\/$/g;
1046
- function attrAssignment(value) {
1047
- return value ? needsQuotedAttr.test(value) ? value[needsQuotedAttr.lastIndex - 1] === (needsQuotedAttr.lastIndex = 0, "\"") ? "='" + escapeSingleQuotedAttrValue(value) + "'" : "=\"" + escapeDoubleQuotedAttrValue(value) + "\"" : "=" + value : "";
1048
- }
1049
- function escapeSingleQuotedAttrValue(value) {
1050
- return singleQuoteAttrReplacements.test(value) ? value.replace(singleQuoteAttrReplacements, replaceUnsafeSingleQuoteAttrChar) : value;
1051
- }
1052
- function replaceUnsafeSingleQuoteAttrChar(match) {
1053
- return match === "'" ? "&#39;" : match === "\r" ? "&#13;" : "&amp;";
1054
- }
1055
- function escapeDoubleQuotedAttrValue(value) {
1056
- return doubleQuoteAttrReplacements.test(value) ? value.replace(doubleQuoteAttrReplacements, replaceUnsafeDoubleQuoteAttrChar) : value;
1057
- }
1058
- function replaceUnsafeDoubleQuoteAttrChar(match) {
1059
- return match === "\"" ? "&#34;" : match === "\r" ? "&#13;" : "&amp;";
1060
- }
1061
- //#endregion
1062
- //#region src/translator/util/marko-config.ts
1063
- function isOutputHTML() {
1064
- return getMarkoOpts().output === "html";
1065
- }
1066
- function isOutputDOM() {
1067
- return getMarkoOpts().output === "dom";
1068
- }
1069
- function getMarkoOpts() {
1070
- return (0, _marko_compiler_babel_utils.getFile)().markoOpts;
1071
- }
1072
- function isOptimize() {
1073
- return getMarkoOpts().optimize;
1074
- }
1075
- function getReadyId(file = (0, _marko_compiler_babel_utils.getFile)()) {
1076
- const { markoOpts } = file;
1077
- if (!markoOpts.linkAssets) return void 0;
1078
- return (markoOpts.optimize ? "_" : "ready:") + (0, _marko_compiler_babel_utils.getTemplateId)(markoOpts, file.opts.filename);
1079
- }
1080
- //#endregion
1081
- //#region src/translator/util/state.ts
1082
- function createProgramState(init) {
1083
- const map = /* @__PURE__ */ new WeakMap();
1084
- return [() => {
1085
- let state = map.get((0, _marko_compiler_babel_utils.getProgram)());
1086
- if (!state) map.set((0, _marko_compiler_babel_utils.getProgram)(), state = init());
1087
- return state;
1088
- }, (value) => {
1089
- map.set((0, _marko_compiler_babel_utils.getProgram)(), value);
1090
- }];
1091
- }
1092
- function createSectionState(key, init) {
1093
- return [(section) => {
1094
- const arrayOfSectionData = (0, _marko_compiler_babel_utils.getProgram)().state[key] ??= {};
1095
- return arrayOfSectionData[section.id] ??= init && init(section);
1096
- }, (section, value) => {
1097
- const arrayOfSectionData = (0, _marko_compiler_babel_utils.getProgram)().state[key] ??= {};
1098
- arrayOfSectionData[section.id] = value;
1099
- }];
1100
- }
1101
- //#endregion
1102
- //#region src/translator/util/to-property-name.ts
1103
- function getMemberExpressionPropString(expr) {
1104
- switch (expr.property.type) {
1105
- case "StringLiteral": return expr.property.value;
1106
- case "NumericLiteral": return "" + expr.property.value;
1107
- case "Identifier":
1108
- if (expr.computed) return;
1109
- return expr.property.name;
1110
- }
1111
- }
1112
- function isValidPropertyIdentifier(name) {
1113
- return /^[a-z_$][a-z0-9_$]*$/i.test(name);
1114
- }
1115
- function toPropertyName(name) {
1116
- if (isValidPropertyIdentifier(name)) return _marko_compiler.types.identifier(name);
1117
- else if (/^(?:0|[1-9][0-9]*)$/.test(name)) return _marko_compiler.types.numericLiteral(parseInt(name, 10));
1118
- return _marko_compiler.types.stringLiteral(name);
1119
- }
1120
- function toObjectProperty(name, value) {
1121
- return _marko_compiler.types.objectProperty(toPropertyName(name), value);
1122
- }
1123
- function toMemberExpression(object, key, optional) {
1124
- const prop = toPropertyName(key);
1125
- const computed = prop.type !== "Identifier";
1126
- return optional ? _marko_compiler.types.optionalMemberExpression(object, prop, computed, true) : _marko_compiler.types.memberExpression(object, prop, computed);
1127
- }
1128
- //#endregion
1129
- //#region src/translator/util/runtime.ts
1130
- const pureDOMFunctions = /* @__PURE__ */ new Set([
1131
- "_await_promise",
1132
- "_await_content",
1133
- "_child_setup",
1134
- "_if",
1135
- "_if_closure",
1136
- "_show",
1137
- "_try",
1138
- "_dynamic_tag",
1139
- "_dynamic_tag_content",
1140
- "_content_closures",
1141
- "_content",
1142
- "_template",
1143
- "_closure",
1144
- "_closure_get",
1145
- "_or",
1146
- "_for_closure",
1147
- "_for_selector",
1148
- "_for_in",
1149
- "_for_of",
1150
- "_for_to",
1151
- "_for_until",
1152
- "_hoist",
1153
- "_let",
1154
- "_let_change",
1155
- "_const",
1156
- "_load_signal",
1157
- "_load_setup",
1158
- "_load_template",
1159
- "_load_visible_trigger",
1160
- "_load_event_trigger",
1161
- "_load_idle_trigger",
1162
- "_load_media_trigger",
1163
- "_load_race_trigger"
1164
- ]);
1165
- const [getRuntimeImports] = createProgramState(() => /* @__PURE__ */ new Map());
1166
- function importRuntime(name) {
1167
- if (!isTranslate()) throw new Error(`\`importRuntime(${JSON.stringify(name)})\` may only be called during the translate stage.`);
1168
- const { output } = getMarkoOpts();
1169
- const imports = getRuntimeImports();
1170
- let localName = imports.get(name);
1171
- if (!localName) {
1172
- localName = (0, _marko_compiler_babel_utils.importNamed)((0, _marko_compiler_babel_utils.getFile)(), getRuntimePath(output), name).name;
1173
- imports.set(name, localName);
1174
- }
1175
- return _marko_compiler.types.identifier(localName);
1176
- }
1177
- function registerRuntimeValue(id, value) {
1178
- return _marko_compiler.types.assignmentExpression("=", toMemberExpression(importRuntime("_resumed"), id), value);
1179
- }
1180
- function callRuntime(name, ...args) {
1181
- const callExpression = _marko_compiler.types.callExpression(importRuntime(name), filterArguments(args));
1182
- if (isOutputDOM() && pureDOMFunctions.has(name)) return _marko_compiler.types.addComment(callExpression, "leading", "@__PURE__");
1183
- return callExpression;
1184
- }
1185
- const domRuntimeFeatures = [
1186
- "catch",
1187
- "controllable",
1188
- "controllable-input",
1189
- "controllable-open",
1190
- "controllable-select",
1191
- "controllable-textarea",
1192
- "dynamic-tag-var",
1193
- "placeholder"
1194
- ];
1195
- const importedFeatures = /* @__PURE__ */ new WeakMap();
1196
- function importRuntimeFeature(feature) {
1197
- if (!isTranslate()) throw new Error(`\`importRuntimeFeature(${JSON.stringify(feature)})\` may only be called during the translate stage.`);
1198
- const program = (0, _marko_compiler_babel_utils.getProgram)().node;
1199
- let features = importedFeatures.get(program);
1200
- if (!features) importedFeatures.set(program, features = /* @__PURE__ */ new Set());
1201
- if (!features.has(feature)) {
1202
- features.add(feature);
1203
- program.body.push(_marko_compiler.types.importDeclaration([], _marko_compiler.types.stringLiteral(`${getRuntimePath("dom")}/${feature}.feat`)));
1204
- }
1205
- }
1206
- function getHTMLRuntime() {
1207
- return {
1208
- _escape,
1209
- _escape_comment,
1210
- _unescaped,
1211
- _attr,
1212
- _attr_class,
1213
- _attr_style,
1214
- _escape_script,
1215
- _escape_style
1216
- };
1217
- }
1218
- function getRuntimePath(output) {
1219
- const { optimize } = getMarkoOpts();
1220
- return `${runtime_info_default.name}/${optimize ? "" : "debug/"}${output === "html" ? "html" : "dom"}`;
1221
- }
1222
- function filterArguments(args) {
1223
- const filteredArgs = [];
1224
- for (let i = args.length; i--;) {
1225
- const arg = args[i];
1226
- if (arg || filteredArgs.length) filteredArgs[i] = arg || _marko_compiler.types.unaryExpression("void", _marko_compiler.types.numericLiteral(0));
1227
- }
1228
- return filteredArgs;
1229
- }
1230
- function getCompatRuntimeFile() {
1231
- const markoOpts = getMarkoOpts();
1232
- return `marko/${markoOpts.optimize ? "dist" : "src"}/runtime/helpers/tags-compat/${isOutputHTML() ? "html" : "dom"}${markoOpts.optimize ? "" : "-debug"}.${markoOpts.modules === "esm" ? "mjs" : "js"}`;
1233
- }
1234
- //#endregion
1235
964
  //#region src/common/constants/accessor-prefix.ts
1236
965
  var accessor_prefix_exports = /* @__PURE__ */ __exportAll({
1237
966
  BranchScopes: () => "A",
@@ -1283,6 +1012,25 @@ var accessor_prop_exports = /* @__PURE__ */ __exportAll({
1283
1012
  TagVariableChange: () => "U"
1284
1013
  });
1285
1014
  //#endregion
1015
+ //#region src/translator/util/marko-config.ts
1016
+ function isOutputHTML() {
1017
+ return getMarkoOpts().output === "html";
1018
+ }
1019
+ function isOutputDOM() {
1020
+ return getMarkoOpts().output === "dom";
1021
+ }
1022
+ function getMarkoOpts() {
1023
+ return (0, _marko_compiler_babel_utils.getFile)().markoOpts;
1024
+ }
1025
+ function isOptimize() {
1026
+ return getMarkoOpts().optimize;
1027
+ }
1028
+ function getReadyId(file = (0, _marko_compiler_babel_utils.getFile)()) {
1029
+ const { markoOpts } = file;
1030
+ if (!markoOpts.linkAssets) return void 0;
1031
+ return (markoOpts.optimize ? "_" : "ready:") + (0, _marko_compiler_babel_utils.getTemplateId)(markoOpts, file.opts.filename);
1032
+ }
1033
+ //#endregion
1286
1034
  //#region src/translator/util/get-accessor-enums.ts
1287
1035
  function getAccessorPrefix() {
1288
1036
  return isOptimize() ? accessor_prefix_exports : accessor_prefix_debug_exports;
@@ -1425,149 +1173,42 @@ function getPropKey(section, prop, prefix) {
1425
1173
  const keys = binding.serializePropKeys ??= /* @__PURE__ */ new Map();
1426
1174
  let key = keys.get(prefix);
1427
1175
  if (!key) keys.set(prefix, key = Symbol((prefix ? typeof prefix === "symbol" ? `Symbol(${prefix.description})` : prefix : "") + binding.name));
1428
- return key;
1429
- }
1430
- }
1431
- function isStrOrSym(v) {
1432
- switch (typeof v) {
1433
- case "string":
1434
- case "symbol": return true;
1435
- default: return false;
1436
- }
1437
- }
1438
- function setSerializeReason(section, reason) {
1439
- section.serializeReason = reason;
1440
- }
1441
- function setPropSerializeReason(section, key, reason) {
1442
- section.serializeReasons.set(key, reason);
1443
- }
1444
- //#endregion
1445
- //#region src/translator/util/with-comment.ts
1446
- function withLeadingComment(node, value) {
1447
- if (value) {
1448
- const comment = {
1449
- type: "CommentBlock",
1450
- value: ` ${value} `
1451
- };
1452
- node.leadingComments = node.leadingComments ? [...node.leadingComments, comment] : [comment];
1453
- }
1454
- return node;
1455
- }
1456
- //#endregion
1457
- //#region src/translator/util/serialize-guard.ts
1458
- const [getSectionReasonState] = createSectionState("serializeReasonState", (section) => ({
1459
- if: createTypeState(),
1460
- guard: createTypeState(),
1461
- declarators: [_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(getSharedUid(`scope${section.id}_reason`, section)), callRuntime("_scope_reason"))]
1462
- }));
1463
- function buildGroupMask(groups) {
1464
- let mask = 0;
1465
- let maskNames = "";
1466
- let dynamic;
1467
- const props = [];
1468
- let needsObject = false;
1469
- let any = false;
1470
- for (let i = 0; i < groups.length; i++) {
1471
- const { value, names } = groups[i];
1472
- if (value === void 0) continue;
1473
- any = true;
1474
- if (value === 0) continue;
1475
- if (i >= 15) needsObject = true;
1476
- else if (typeof value === "number") {
1477
- mask |= value << 1 + 2 * i;
1478
- if (names) maskNames += maskNames ? ` | ${names}` : names;
1479
- } else {
1480
- const shifted = _marko_compiler.types.binaryExpression("<<", value, withLeadingComment(_marko_compiler.types.numericLiteral(1 + 2 * i), names));
1481
- dynamic = dynamic ? _marko_compiler.types.binaryExpression("|", dynamic, shifted) : shifted;
1482
- }
1483
- props.push(_marko_compiler.types.objectProperty(withLeadingComment(_marko_compiler.types.numericLiteral(i), names), typeof value === "number" ? _marko_compiler.types.numericLiteral(value) : value));
1484
- }
1485
- if (needsObject) return _marko_compiler.types.objectExpression(props);
1486
- if (!any) return;
1487
- const literal = mask ? withLeadingComment(_marko_compiler.types.numericLiteral(mask), maskNames) : void 0;
1488
- return literal && dynamic ? _marko_compiler.types.binaryExpression("|", literal, dynamic) : literal || dynamic || _marko_compiler.types.numericLiteral(0);
1489
- }
1490
- function getScopeReasonDeclaration(section) {
1491
- return _marko_compiler.types.variableDeclaration("const", getSectionReasonState(section).declarators);
1492
- }
1493
- function getSerializeGuard(section, reason, optional) {
1494
- if (!isDynamicSerializeGuard(section, reason)) {
1495
- if (!reason) return _marko_compiler.types.numericLiteral(0);
1496
- return optional ? void 0 : withLeadingComment(_marko_compiler.types.numericLiteral(1), getDebugNames(reason.forced ? void 0 : reason.state));
1497
- }
1498
- return getOrHoist(reason, true);
1499
- }
1500
- function getSerializeGuardForAny(section, reasons, optional) {
1501
- if (!Array.isArray(reasons)) return getSerializeGuard(section, reasons, optional);
1502
- for (const reason of reasons) if (!isReasonDynamic(reason)) return optional ? void 0 : withLeadingComment(_marko_compiler.types.numericLiteral(1), getDebugNames(reason.state));
1503
- let expr;
1504
- for (const reason of reasons) {
1505
- const guard = getSerializeGuard(section, reason, false);
1506
- expr = expr ? _marko_compiler.types.logicalExpression("||", expr, guard) : guard;
1507
- }
1508
- return expr;
1509
- }
1510
- function getExprIfSerialized(section, reason, expr) {
1511
- if (!isDynamicSerializeGuard(section, reason)) return reason && expr;
1512
- const guard = getOrHoist(reason, false);
1513
- return guard ? _marko_compiler.types.logicalExpression("&&", guard, expr) : expr;
1514
- }
1515
- function getOrHoist(reason, isGuard) {
1516
- const onlySection = getOnlySection(reason.param);
1517
- if (onlySection) {
1518
- const state = getSectionReasonState(onlySection);
1519
- const tracking = isGuard ? state.guard : state.if;
1520
- const existingFound = sourcesUtil.find(tracking.hoistedReasons, reason);
1521
- if (existingFound) return _marko_compiler.types.identifier(tracking.names.get(existingFound));
1522
- const guard = buildGuardExpr(onlySection, reason.param, isGuard);
1523
- const seenFound = sourcesUtil.find(tracking.seenReasons, reason);
1524
- if (!seenFound) {
1525
- const expr = _marko_compiler.types.parenthesizedExpression(guard);
1526
- tracking.pending.set(reason, expr);
1527
- tracking.seenReasons = sourcesUtil.add(tracking.seenReasons, reason);
1528
- return expr;
1529
- }
1530
- const name = generateUid(`${isGuard ? "sg" : "si"}__${getDebugNamesAsIdentifier(reason.param)}`);
1531
- tracking.hoistedReasons = sourcesUtil.add(tracking.hoistedReasons, reason);
1532
- tracking.names.set(reason, name);
1533
- state.declarators.push(_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(name), guard));
1534
- const pendingParen = tracking.pending.get(seenFound);
1535
- if (pendingParen) {
1536
- pendingParen.expression = _marko_compiler.types.identifier(name);
1537
- tracking.pending.delete(seenFound);
1538
- }
1539
- return _marko_compiler.types.parenthesizedExpression(_marko_compiler.types.identifier(name));
1540
- }
1541
- let orExpr;
1542
- for (const [paramsSection, params] of groupParamsBySection(reason.param)) {
1543
- const expr = buildGuardExpr(paramsSection, params, isGuard);
1544
- orExpr = orExpr ? _marko_compiler.types.logicalExpression("||", orExpr, expr) : expr;
1176
+ return key;
1545
1177
  }
1546
- return orExpr;
1547
1178
  }
1548
- function buildGuardExpr(paramsSection, params, isGuard) {
1549
- const serializeIdentifier = _marko_compiler.types.identifier(getSharedUid(`scope${paramsSection.id}_reason`, paramsSection));
1550
- return paramsSection.paramReasonGroups ? callRuntime(isGuard ? "_serialize_guard" : "_serialize_if", serializeIdentifier, withLeadingComment(_marko_compiler.types.numericLiteral(getParamReasonGroupIndex(paramsSection, params)), getDebugNames(params))) : serializeIdentifier;
1179
+ function isStrOrSym(v) {
1180
+ switch (typeof v) {
1181
+ case "string":
1182
+ case "symbol": return true;
1183
+ default: return false;
1184
+ }
1551
1185
  }
1552
- function getOnlySection(params) {
1553
- if (params === void 0) return void 0;
1554
- if (!Array.isArray(params)) return params.section;
1555
- const { section } = params[0];
1556
- return section === params[params.length - 1].section ? section : void 0;
1186
+ function setSerializeReason(section, reason) {
1187
+ section.serializeReason = reason;
1557
1188
  }
1558
- function isDynamicSerializeGuard(section, reason) {
1559
- return isReasonDynamic(reason) && !isCrossSection(section, reason);
1189
+ function setPropSerializeReason(section, key, reason) {
1190
+ section.serializeReasons.set(key, reason);
1560
1191
  }
1561
- function isCrossSection(section, reason) {
1562
- return some(reason.param, (param) => !isSameOrChildSection(param.section, section));
1192
+ //#endregion
1193
+ //#region src/translator/util/state.ts
1194
+ function createProgramState(init) {
1195
+ const map = /* @__PURE__ */ new WeakMap();
1196
+ return [() => {
1197
+ let state = map.get((0, _marko_compiler_babel_utils.getProgram)());
1198
+ if (!state) map.set((0, _marko_compiler_babel_utils.getProgram)(), state = init());
1199
+ return state;
1200
+ }, (value) => {
1201
+ map.set((0, _marko_compiler_babel_utils.getProgram)(), value);
1202
+ }];
1563
1203
  }
1564
- function createTypeState() {
1565
- return {
1566
- names: /* @__PURE__ */ new Map(),
1567
- pending: /* @__PURE__ */ new Map(),
1568
- seenReasons: void 0,
1569
- hoistedReasons: void 0
1570
- };
1204
+ function createSectionState(key, init) {
1205
+ return [(section) => {
1206
+ const arrayOfSectionData = (0, _marko_compiler_babel_utils.getProgram)().state[key] ??= {};
1207
+ return arrayOfSectionData[section.id] ??= init && init(section);
1208
+ }, (section, value) => {
1209
+ const arrayOfSectionData = (0, _marko_compiler_babel_utils.getProgram)().state[key] ??= {};
1210
+ arrayOfSectionData[section.id] = value;
1211
+ }];
1571
1212
  }
1572
1213
  //#endregion
1573
1214
  //#region src/translator/util/tag-name-type.ts
@@ -1843,9 +1484,8 @@ function getNodeContentType(path, extraMember, contentInfo) {
1843
1484
  }
1844
1485
  function getSectionRegisterReasons(section) {
1845
1486
  if (section.isBranch) return false;
1487
+ if (section.upstreamExpression?.tagNameType === 0) return false;
1846
1488
  const { downstream } = section;
1847
- const dynamicTagBinding = getDynamicTagNodeBinding(section);
1848
- if (dynamicTagBinding) return getSerializeReason(dynamicTagBinding.section, dynamicTagBinding) || false;
1849
1489
  if (downstream?.binding) {
1850
1490
  const downstreamReasons = reduce(downstream.binding, (reasons, binding) => {
1851
1491
  const reason = getAllSerializeReasonsForBinding(binding, downstream.properties);
@@ -1857,18 +1497,6 @@ function getSectionRegisterReasons(section) {
1857
1497
  } else if (downstream) return false;
1858
1498
  return true;
1859
1499
  }
1860
- function isSectionRegisterDynamic(section, registerReason) {
1861
- const dynamicTagBinding = getDynamicTagNodeBinding(section);
1862
- return !!dynamicTagBinding && registerReason !== true && isDynamicSerializeGuard(dynamicTagBinding.section, registerReason);
1863
- }
1864
- function isSectionRegisterEager(section) {
1865
- const registerReason = getSectionRegisterReasons(section);
1866
- return !!registerReason && !isSectionRegisterDynamic(section, registerReason);
1867
- }
1868
- function getDynamicTagNodeBinding(section) {
1869
- const { upstreamExpression } = section;
1870
- return upstreamExpression?.tagNameType === 0 ? upstreamExpression.nodeBinding : void 0;
1871
- }
1872
1500
  function isImmediateOwner(section, binding) {
1873
1501
  return section.parent?.id === binding.section.id;
1874
1502
  }
@@ -1979,10 +1607,8 @@ var function_default = { analyze(fn) {
1979
1607
  reserveExportRegisterId(fnExtra, fn, markoRoot);
1980
1608
  if (isStaticRoot(markoRoot)) {
1981
1609
  const refs = getStaticDeclRefs(fn);
1982
- if (refs === true) registerFunction(fnExtra, FORCED);
1983
- else if (refs.size) getReferencesByFn().set(fnExtra, refs);
1984
- } else if (shouldAlwaysRegister(markoRoot)) registerFunction(fnExtra, FORCED);
1985
- else getReferencesByFn().set(fnExtra, /* @__PURE__ */ new Set([fnExtra.exprRoot]));
1610
+ if (refs.size) getReferencesByFn().set(fnExtra, refs);
1611
+ } else getReferencesByFn().set(fnExtra, /* @__PURE__ */ new Set([fnExtra.exprRoot]));
1986
1612
  } };
1987
1613
  function finalizeFunctionRegistry() {
1988
1614
  for (const [fnExtra, exprExtras] of getReferencesByFn()) {
@@ -2005,8 +1631,8 @@ function trackImportedFn(importDecl, local, resolved) {
2005
1631
  local
2006
1632
  };
2007
1633
  const refs = /* @__PURE__ */ new Set();
2008
- if (addBindingRefs(binding, refs, /* @__PURE__ */ new Set()) === true) registerImportedFn(importedFn);
2009
- else if (refs.size) getReferencesByImportedFn().set(importedFn, refs);
1634
+ addBindingRefs(binding, refs, /* @__PURE__ */ new Set());
1635
+ if (refs.size) getReferencesByImportedFn().set(importedFn, refs);
2010
1636
  }
2011
1637
  /**
2012
1638
  * Finds the id reserved for an export, following `export ... from` hops. Each
@@ -2099,8 +1725,7 @@ function getStaticDeclRefs(path, refs = /* @__PURE__ */ new Set(), seen = /* @__
2099
1725
  const ids = decl.getOuterBindingIdentifiers();
2100
1726
  if (ids) for (const name in ids) {
2101
1727
  const binding = decl.scope.getBinding(name);
2102
- if (!binding) continue;
2103
- if (addBindingRefs(binding, refs, seen) === true) return true;
1728
+ if (binding) addBindingRefs(binding, refs, seen);
2104
1729
  }
2105
1730
  }
2106
1731
  return refs;
@@ -2111,31 +1736,15 @@ function addBindingRefs(binding, refs, seen) {
2111
1736
  const exprRoot = getExprRoot(ref);
2112
1737
  const markoRoot = getMarkoRoot(exprRoot);
2113
1738
  if (!markoRoot || canIgnoreRegister(markoRoot, exprRoot)) continue;
2114
- if (isStaticRoot(markoRoot)) {
2115
- if (getStaticDeclRefs(ref, refs, seen) === true) return true;
2116
- } else if (shouldAlwaysRegister(markoRoot)) return true;
1739
+ if (isStaticRoot(markoRoot)) getStaticDeclRefs(ref, refs, seen);
2117
1740
  else refs.add(exprRoot.node.extra ??= {});
2118
1741
  }
2119
1742
  }
2120
- function shouldAlwaysRegister(markoRoot) {
2121
- const tag = getTagFromMarkoRoot(markoRoot);
2122
- if (!tag) return false;
2123
- if (isCoreTagName(tag, "let")) return true;
2124
- if (isCoreTagName(tag, "return")) return true;
2125
- return analyzeTagNameType(tag) === 0;
2126
- }
2127
1743
  function hasSpreadAttributeAfter(attr) {
2128
1744
  const attrs = attr.parent.attributes;
2129
1745
  for (let i = attr.key + 1; i < attrs.length; i++) if (attrs[i].type === "MarkoSpreadAttribute") return true;
2130
1746
  return false;
2131
1747
  }
2132
- function getTagFromMarkoRoot(markoRoot) {
2133
- let cur = markoRoot;
2134
- do {
2135
- if (cur.isMarkoTag()) return cur;
2136
- cur = cur.parentPath;
2137
- } while (cur);
2138
- }
2139
1748
  function registerFunction(fnExtra, reason) {
2140
1749
  const { markoOpts, path: program, opts: { filename } } = (0, _marko_compiler_babel_utils.getFile)();
2141
1750
  program.node.extra.isInteractive = true;
@@ -2158,7 +1767,8 @@ function isStaticRoot(path) {
2158
1767
  //#region src/translator/util/analyze-errors.ts
2159
1768
  const [getHasAnalyzeErrors, setHasAnalyzeErrors] = createProgramState(() => false);
2160
1769
  function reportAnalyzeError(path, error) {
2161
- if (!(error instanceof Error)) throw error;
1770
+ const { filename } = error;
1771
+ if (!(error instanceof Error) || filename !== void 0 && filename !== path.hub.file.opts.filename) throw error;
2162
1772
  const { label = error.message, loc } = error;
2163
1773
  setHasAnalyzeErrors(true);
2164
1774
  (0, _marko_compiler_babel_utils.diagnosticError)(path, {
@@ -2319,47 +1929,279 @@ const builder = {
2319
1929
  }
2320
1930
  if (isRoot) state.bundled--;
2321
1931
  }
2322
- };
2323
- //#endregion
2324
- //#region src/translator/util/get-style-file.ts
2325
- function getStyleFile(file) {
2326
- const { filename } = file.opts;
2327
- const fs = file.markoOpts.fileSystem;
2328
- const base = getBase(filename);
2329
- const styleMatch = new RegExp(`^(${escapeRegExp(base)}\\.${"index" === base ? "|" : ""})style\\.\\w+$`);
2330
- let dirFiles;
2331
- try {
2332
- dirFiles = fs.readdirSync(path.default.dirname(filename)).sort();
2333
- } catch {
2334
- return;
1932
+ };
1933
+ //#endregion
1934
+ //#region src/translator/util/get-style-file.ts
1935
+ function getStyleFile(file) {
1936
+ const { filename } = file.opts;
1937
+ const fs = file.markoOpts.fileSystem;
1938
+ const base = getBase(filename);
1939
+ const styleMatch = new RegExp(`^(${escapeRegExp(base)}\\.${"index" === base ? "|" : ""})style\\.\\w+$`);
1940
+ let dirFiles;
1941
+ try {
1942
+ dirFiles = fs.readdirSync(path.default.dirname(filename)).sort();
1943
+ } catch {
1944
+ return;
1945
+ }
1946
+ for (const file of dirFiles) if (styleMatch.test(file)) return `./${file}`;
1947
+ }
1948
+ /**
1949
+ * Given a filename, gets the base name, strips off the file extension
1950
+ * and removes any arc flags (https://github.com/eBay/arc).
1951
+ *
1952
+ * @example
1953
+ * getBase("/dir/foo.marko") // => "foo"
1954
+ * getBase("/dir/foo.bar.marko") // => "foo.bar"
1955
+ * getBase("/dir/foo[bar].marko") // => "foo"
1956
+ * getBase("/dir/foo[bar].baz.marko") // => "foo.baz"
1957
+ */
1958
+ function getBase(filename) {
1959
+ const start = filename.lastIndexOf(path.default.sep) + 1;
1960
+ const leftDot = filename.indexOf(".", start);
1961
+ if (leftDot === -1) return filename.slice(start);
1962
+ const rightDot = filename.lastIndexOf(".");
1963
+ const closeBracket = leftDot - 1;
1964
+ if (filename[closeBracket] === "]") {
1965
+ const openBracket = filename.lastIndexOf("[", closeBracket);
1966
+ if (openBracket > start) return filename.slice(start, openBracket) + filename.slice(leftDot, rightDot);
1967
+ }
1968
+ return filename.slice(start, rightDot);
1969
+ }
1970
+ const regexpCharsReg = /[\\^$.*+?()[\]{}|]/g;
1971
+ function escapeRegExp(str) {
1972
+ return str.replace(regexpCharsReg, "\\$&");
1973
+ }
1974
+ //#endregion
1975
+ //#region src/common/errors.ts
1976
+ function assertExclusiveAttrs(attrs, onError = throwErr) {
1977
+ if (attrs) {
1978
+ let exclusiveAttrs;
1979
+ if (attrs.checkedChange) (exclusiveAttrs ||= []).push("checkedChange");
1980
+ if ("checkedValue" in attrs) {
1981
+ (exclusiveAttrs ||= []).push("checkedValue");
1982
+ if ("checked" in attrs) exclusiveAttrs.push("checked");
1983
+ } else if (attrs.checkedValueChange) {
1984
+ (exclusiveAttrs ||= []).push("checkedValueChange");
1985
+ if ("checked" in attrs) exclusiveAttrs.push("checked");
1986
+ }
1987
+ if (attrs.valueChange) {
1988
+ (exclusiveAttrs ||= []).push("valueChange");
1989
+ if ("checked" in attrs && !exclusiveAttrs.includes("checked")) exclusiveAttrs.push("checked");
1990
+ }
1991
+ if (exclusiveAttrs && exclusiveAttrs.length > 1) onError(`The attributes ${joinWithAnd(exclusiveAttrs)} are mutually exclusive.`);
1992
+ }
1993
+ }
1994
+ function throwErr(msg) {
1995
+ throw new Error(msg);
1996
+ }
1997
+ function joinWithAnd(a) {
1998
+ switch (a.length) {
1999
+ case 0: return "";
2000
+ case 1: return a[0];
2001
+ case 2: return `${a[0]} and ${a[1]}`;
2002
+ default: return `${a.slice(0, -1).join(", ")}, and ${a[a.length - 1]}`;
2003
+ }
2004
+ }
2005
+ //#endregion
2006
+ //#region src/html/content.ts
2007
+ function _unescaped(val) {
2008
+ return val ? val + "" : val === 0 ? "0" : "";
2009
+ }
2010
+ const unsafeXMLReg = /[<&\r]/g;
2011
+ const replaceUnsafeXML = (c) => c === "&" ? "&amp;" : c === "<" ? "&lt;" : "&#13;";
2012
+ const escapeXMLStr = (str) => unsafeXMLReg.test(str) ? str.replace(unsafeXMLReg, replaceUnsafeXML) : str;
2013
+ function _escape(val) {
2014
+ return val ? escapeXMLStr(val + "") : val === 0 ? "0" : "";
2015
+ }
2016
+ const unsafeScriptReg = /<(\/?script|!--)/gi;
2017
+ const escapeScriptStr = (str) => unsafeScriptReg.test(str) ? str.replace(unsafeScriptReg, "\\x3C$1") : str;
2018
+ function _escape_script(val) {
2019
+ return val ? escapeScriptStr(val + "") : val === 0 ? "0" : "";
2020
+ }
2021
+ const unsafeStyleReg = /<(\/style)/gi;
2022
+ const escapeStyleStr = (str) => unsafeStyleReg.test(str) ? str.replace(unsafeStyleReg, "\\3C$1") : str;
2023
+ function _escape_style(val) {
2024
+ return val ? escapeStyleStr(val + "") : val === 0 ? "0" : "";
2025
+ }
2026
+ const unsafeCommentReg = />/g;
2027
+ const escapeCommentStr = (str) => unsafeCommentReg.test(str) ? str.replace(unsafeCommentReg, "&gt;") : str;
2028
+ function _escape_comment(val) {
2029
+ return val ? escapeCommentStr(val + "") : val === 0 ? "0" : "";
2030
+ }
2031
+ globalThis.setImmediate || globalThis.setTimeout || globalThis.queueMicrotask;
2032
+ //#endregion
2033
+ //#region src/html/attrs.ts
2034
+ function _attr_class(value) {
2035
+ return stringAttr("class", toDelimitedString(value, " ", stringifyClassObject));
2036
+ }
2037
+ function _attr_style(value) {
2038
+ return stringAttr("style", toDelimitedString(value, ";", stringifyStyleObject));
2039
+ }
2040
+ function _attr(name, value) {
2041
+ return isVoid(value) ? "" : nonVoidAttr(name, value);
2042
+ }
2043
+ function stringAttr(name, value) {
2044
+ return value && " " + name + attrAssignment(value);
2045
+ }
2046
+ function nonVoidAttr(name, value) {
2047
+ switch (typeof value) {
2048
+ case "string": return " " + name + attrAssignment(value);
2049
+ case "boolean": return " " + name;
2050
+ case "number": return " " + name + "=" + value;
2051
+ }
2052
+ return " " + name + attrAssignment(value + "");
2053
+ }
2054
+ const singleQuoteAttrReplacements = /['\r]|&(?=[#a-zA-Z])/g;
2055
+ const doubleQuoteAttrReplacements = /["\r]|&(?=[#a-zA-Z])/g;
2056
+ const needsQuotedAttr = /["'>\s]|&[#a-zA-Z]|\/$/g;
2057
+ function attrAssignment(value) {
2058
+ return value ? needsQuotedAttr.test(value) ? value[needsQuotedAttr.lastIndex - 1] === (needsQuotedAttr.lastIndex = 0, "\"") ? "='" + escapeSingleQuotedAttrValue(value) + "'" : "=\"" + escapeDoubleQuotedAttrValue(value) + "\"" : "=" + value : "";
2059
+ }
2060
+ function escapeSingleQuotedAttrValue(value) {
2061
+ return singleQuoteAttrReplacements.test(value) ? value.replace(singleQuoteAttrReplacements, replaceUnsafeSingleQuoteAttrChar) : value;
2062
+ }
2063
+ function replaceUnsafeSingleQuoteAttrChar(match) {
2064
+ return match === "'" ? "&#39;" : match === "\r" ? "&#13;" : "&amp;";
2065
+ }
2066
+ function escapeDoubleQuotedAttrValue(value) {
2067
+ return doubleQuoteAttrReplacements.test(value) ? value.replace(doubleQuoteAttrReplacements, replaceUnsafeDoubleQuoteAttrChar) : value;
2068
+ }
2069
+ function replaceUnsafeDoubleQuoteAttrChar(match) {
2070
+ return match === "\"" ? "&#34;" : match === "\r" ? "&#13;" : "&amp;";
2071
+ }
2072
+ //#endregion
2073
+ //#region src/translator/util/to-property-name.ts
2074
+ function getMemberExpressionPropString(expr) {
2075
+ switch (expr.property.type) {
2076
+ case "StringLiteral": return expr.property.value;
2077
+ case "NumericLiteral": return "" + expr.property.value;
2078
+ case "Identifier":
2079
+ if (expr.computed) return;
2080
+ return expr.property.name;
2081
+ }
2082
+ }
2083
+ function isValidPropertyIdentifier(name) {
2084
+ return /^[a-z_$][a-z0-9_$]*$/i.test(name);
2085
+ }
2086
+ function toPropertyName(name) {
2087
+ if (isValidPropertyIdentifier(name)) return _marko_compiler.types.identifier(name);
2088
+ else if (/^(?:0|[1-9][0-9]*)$/.test(name)) return _marko_compiler.types.numericLiteral(parseInt(name, 10));
2089
+ return _marko_compiler.types.stringLiteral(name);
2090
+ }
2091
+ function toObjectProperty(name, value) {
2092
+ return _marko_compiler.types.objectProperty(toPropertyName(name), value);
2093
+ }
2094
+ function toMemberExpression(object, key, optional) {
2095
+ const prop = toPropertyName(key);
2096
+ const computed = prop.type !== "Identifier";
2097
+ return optional ? _marko_compiler.types.optionalMemberExpression(object, prop, computed, true) : _marko_compiler.types.memberExpression(object, prop, computed);
2098
+ }
2099
+ //#endregion
2100
+ //#region src/translator/util/runtime.ts
2101
+ const pureDOMFunctions = /* @__PURE__ */ new Set([
2102
+ "_await_promise",
2103
+ "_await_content",
2104
+ "_child_setup",
2105
+ "_if",
2106
+ "_if_closure",
2107
+ "_show",
2108
+ "_try",
2109
+ "_dynamic_tag",
2110
+ "_dynamic_tag_content",
2111
+ "_content_closures",
2112
+ "_content",
2113
+ "_template",
2114
+ "_closure",
2115
+ "_closure_get",
2116
+ "_or",
2117
+ "_for_closure",
2118
+ "_for_selector",
2119
+ "_for_in",
2120
+ "_for_of",
2121
+ "_for_to",
2122
+ "_for_until",
2123
+ "_hoist",
2124
+ "_let",
2125
+ "_let_change",
2126
+ "_const",
2127
+ "_load_signal",
2128
+ "_load_setup",
2129
+ "_load_template",
2130
+ "_load_visible_trigger",
2131
+ "_load_event_trigger",
2132
+ "_load_idle_trigger",
2133
+ "_load_media_trigger",
2134
+ "_load_race_trigger"
2135
+ ]);
2136
+ const [getRuntimeImports] = createProgramState(() => /* @__PURE__ */ new Map());
2137
+ function importRuntime(name) {
2138
+ if (!isTranslate()) throw new Error(`\`importRuntime(${JSON.stringify(name)})\` may only be called during the translate stage.`);
2139
+ const { output } = getMarkoOpts();
2140
+ const imports = getRuntimeImports();
2141
+ let localName = imports.get(name);
2142
+ if (!localName) {
2143
+ localName = (0, _marko_compiler_babel_utils.importNamed)((0, _marko_compiler_babel_utils.getFile)(), getRuntimePath(output), name).name;
2144
+ imports.set(name, localName);
2145
+ }
2146
+ return _marko_compiler.types.identifier(localName);
2147
+ }
2148
+ function registerRuntimeValue(id, value) {
2149
+ return _marko_compiler.types.assignmentExpression("=", toMemberExpression(importRuntime("_resumed"), id), value);
2150
+ }
2151
+ function callRuntime(name, ...args) {
2152
+ const callExpression = _marko_compiler.types.callExpression(importRuntime(name), filterArguments(args));
2153
+ if (isOutputDOM() && pureDOMFunctions.has(name)) return _marko_compiler.types.addComment(callExpression, "leading", "@__PURE__");
2154
+ return callExpression;
2155
+ }
2156
+ const domRuntimeFeatures = [
2157
+ "catch",
2158
+ "controllable",
2159
+ "controllable-input",
2160
+ "controllable-open",
2161
+ "controllable-select",
2162
+ "controllable-textarea",
2163
+ "dynamic-tag-script",
2164
+ "dynamic-tag-var",
2165
+ "placeholder"
2166
+ ];
2167
+ const importedFeatures = /* @__PURE__ */ new WeakMap();
2168
+ function importRuntimeFeature(feature) {
2169
+ if (!isTranslate()) throw new Error(`\`importRuntimeFeature(${JSON.stringify(feature)})\` may only be called during the translate stage.`);
2170
+ const program = (0, _marko_compiler_babel_utils.getProgram)().node;
2171
+ let features = importedFeatures.get(program);
2172
+ if (!features) importedFeatures.set(program, features = /* @__PURE__ */ new Set());
2173
+ if (!features.has(feature)) {
2174
+ features.add(feature);
2175
+ program.body.push(_marko_compiler.types.importDeclaration([], _marko_compiler.types.stringLiteral(`${getRuntimePath("dom")}/${feature}.feat`)));
2335
2176
  }
2336
- for (const file of dirFiles) if (styleMatch.test(file)) return `./${file}`;
2337
2177
  }
2338
- /**
2339
- * Given a filename, gets the base name, strips off the file extension
2340
- * and removes any arc flags (https://github.com/eBay/arc).
2341
- *
2342
- * @example
2343
- * getBase("/dir/foo.marko") // => "foo"
2344
- * getBase("/dir/foo.bar.marko") // => "foo.bar"
2345
- * getBase("/dir/foo[bar].marko") // => "foo"
2346
- * getBase("/dir/foo[bar].baz.marko") // => "foo.baz"
2347
- */
2348
- function getBase(filename) {
2349
- const start = filename.lastIndexOf(path.default.sep) + 1;
2350
- const leftDot = filename.indexOf(".", start);
2351
- if (leftDot === -1) return filename.slice(start);
2352
- const rightDot = filename.lastIndexOf(".");
2353
- const closeBracket = leftDot - 1;
2354
- if (filename[closeBracket] === "]") {
2355
- const openBracket = filename.lastIndexOf("[", closeBracket);
2356
- if (openBracket > start) return filename.slice(start, openBracket) + filename.slice(leftDot, rightDot);
2178
+ function getHTMLRuntime() {
2179
+ return {
2180
+ _escape,
2181
+ _escape_comment,
2182
+ _unescaped,
2183
+ _attr,
2184
+ _attr_class,
2185
+ _attr_style,
2186
+ _escape_script,
2187
+ _escape_style
2188
+ };
2189
+ }
2190
+ function getRuntimePath(output) {
2191
+ const { optimize } = getMarkoOpts();
2192
+ return `${runtime_info_default.name}/${optimize ? "" : "debug/"}${output === "html" ? "html" : "dom"}`;
2193
+ }
2194
+ function filterArguments(args) {
2195
+ const filteredArgs = [];
2196
+ for (let i = args.length; i--;) {
2197
+ const arg = args[i];
2198
+ if (arg || filteredArgs.length) filteredArgs[i] = arg || _marko_compiler.types.unaryExpression("void", _marko_compiler.types.numericLiteral(0));
2357
2199
  }
2358
- return filename.slice(start, rightDot);
2200
+ return filteredArgs;
2359
2201
  }
2360
- const regexpCharsReg = /[\\^$.*+?()[\]{}|]/g;
2361
- function escapeRegExp(str) {
2362
- return str.replace(regexpCharsReg, "\\$&");
2202
+ function getCompatRuntimeFile() {
2203
+ const markoOpts = getMarkoOpts();
2204
+ return `marko/${markoOpts.optimize ? "dist" : "src"}/runtime/helpers/tags-compat/${isOutputHTML() ? "html" : "dom"}${markoOpts.optimize ? "" : "-debug"}.${markoOpts.modules === "esm" ? "mjs" : "js"}`;
2363
2205
  }
2364
2206
  //#endregion
2365
2207
  //#region src/translator/util/setup-statements.ts
@@ -2561,6 +2403,134 @@ function shiftItems(list, start, offset) {
2561
2403
  for (let i = list.length - 1; i >= start; i--) list[i + offset] = list[i];
2562
2404
  }
2563
2405
  //#endregion
2406
+ //#region src/translator/util/with-comment.ts
2407
+ function withLeadingComment(node, value) {
2408
+ if (value) {
2409
+ const comment = {
2410
+ type: "CommentBlock",
2411
+ value: ` ${value} `
2412
+ };
2413
+ node.leadingComments = node.leadingComments ? [...node.leadingComments, comment] : [comment];
2414
+ }
2415
+ return node;
2416
+ }
2417
+ //#endregion
2418
+ //#region src/translator/util/serialize-guard.ts
2419
+ const [getSectionReasonState] = createSectionState("serializeReasonState", (section) => ({
2420
+ if: createTypeState(),
2421
+ guard: createTypeState(),
2422
+ declarators: [_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(getSharedUid(`scope${section.id}_reason`, section)), callRuntime("_scope_reason"))]
2423
+ }));
2424
+ function buildGroupMask(groups) {
2425
+ let mask = 0;
2426
+ let maskNames = "";
2427
+ let dynamic;
2428
+ const props = [];
2429
+ let needsObject = false;
2430
+ let any = false;
2431
+ for (let i = 0; i < groups.length; i++) {
2432
+ const { value, names } = groups[i];
2433
+ if (value === void 0) continue;
2434
+ any = true;
2435
+ if (value === 0) continue;
2436
+ if (i >= 15) needsObject = true;
2437
+ else if (typeof value === "number") {
2438
+ mask |= value << 1 + 2 * i;
2439
+ if (names) maskNames += maskNames ? ` | ${names}` : names;
2440
+ } else {
2441
+ const shifted = _marko_compiler.types.binaryExpression("<<", value, withLeadingComment(_marko_compiler.types.numericLiteral(1 + 2 * i), names));
2442
+ dynamic = dynamic ? _marko_compiler.types.binaryExpression("|", dynamic, shifted) : shifted;
2443
+ }
2444
+ props.push(_marko_compiler.types.objectProperty(withLeadingComment(_marko_compiler.types.numericLiteral(i), names), typeof value === "number" ? _marko_compiler.types.numericLiteral(value) : value));
2445
+ }
2446
+ if (needsObject) return _marko_compiler.types.objectExpression(props);
2447
+ if (!any) return;
2448
+ const literal = mask ? withLeadingComment(_marko_compiler.types.numericLiteral(mask), maskNames) : void 0;
2449
+ return literal && dynamic ? _marko_compiler.types.binaryExpression("|", literal, dynamic) : literal || dynamic || _marko_compiler.types.numericLiteral(0);
2450
+ }
2451
+ function getScopeReasonDeclaration(section) {
2452
+ return _marko_compiler.types.variableDeclaration("const", getSectionReasonState(section).declarators);
2453
+ }
2454
+ function getSerializeGuard(section, reason, optional) {
2455
+ if (!isDynamicSerializeGuard(section, reason)) {
2456
+ if (!reason) return _marko_compiler.types.numericLiteral(0);
2457
+ return optional ? void 0 : withLeadingComment(_marko_compiler.types.numericLiteral(1), getDebugNames(reason.forced ? void 0 : reason.state));
2458
+ }
2459
+ return getOrHoist(reason, true);
2460
+ }
2461
+ function getSerializeGuardForAny(section, reasons, optional) {
2462
+ if (!Array.isArray(reasons)) return getSerializeGuard(section, reasons, optional);
2463
+ for (const reason of reasons) if (!isReasonDynamic(reason)) return optional ? void 0 : withLeadingComment(_marko_compiler.types.numericLiteral(1), getDebugNames(reason.state));
2464
+ let expr;
2465
+ for (const reason of reasons) {
2466
+ const guard = getSerializeGuard(section, reason, false);
2467
+ expr = expr ? _marko_compiler.types.logicalExpression("||", expr, guard) : guard;
2468
+ }
2469
+ return expr;
2470
+ }
2471
+ function getExprIfSerialized(section, reason, expr) {
2472
+ if (!isDynamicSerializeGuard(section, reason)) return reason && expr;
2473
+ const guard = getOrHoist(reason, false);
2474
+ return guard ? _marko_compiler.types.logicalExpression("&&", guard, expr) : expr;
2475
+ }
2476
+ function getOrHoist(reason, isGuard) {
2477
+ const onlySection = getOnlySection(reason.param);
2478
+ if (onlySection) {
2479
+ const state = getSectionReasonState(onlySection);
2480
+ const tracking = isGuard ? state.guard : state.if;
2481
+ const existingFound = sourcesUtil.find(tracking.hoistedReasons, reason);
2482
+ if (existingFound) return _marko_compiler.types.identifier(tracking.names.get(existingFound));
2483
+ const guard = buildGuardExpr(onlySection, reason.param, isGuard);
2484
+ const seenFound = sourcesUtil.find(tracking.seenReasons, reason);
2485
+ if (!seenFound) {
2486
+ const expr = _marko_compiler.types.parenthesizedExpression(guard);
2487
+ tracking.pending.set(reason, expr);
2488
+ tracking.seenReasons = sourcesUtil.add(tracking.seenReasons, reason);
2489
+ return expr;
2490
+ }
2491
+ const name = generateUid(`${isGuard ? "sg" : "si"}__${getDebugNamesAsIdentifier(reason.param)}`);
2492
+ tracking.hoistedReasons = sourcesUtil.add(tracking.hoistedReasons, reason);
2493
+ tracking.names.set(reason, name);
2494
+ state.declarators.push(_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(name), guard));
2495
+ const pendingParen = tracking.pending.get(seenFound);
2496
+ if (pendingParen) {
2497
+ pendingParen.expression = _marko_compiler.types.identifier(name);
2498
+ tracking.pending.delete(seenFound);
2499
+ }
2500
+ return _marko_compiler.types.parenthesizedExpression(_marko_compiler.types.identifier(name));
2501
+ }
2502
+ let orExpr;
2503
+ for (const [paramsSection, params] of groupParamsBySection(reason.param)) {
2504
+ const expr = buildGuardExpr(paramsSection, params, isGuard);
2505
+ orExpr = orExpr ? _marko_compiler.types.logicalExpression("||", orExpr, expr) : expr;
2506
+ }
2507
+ return orExpr;
2508
+ }
2509
+ function buildGuardExpr(paramsSection, params, isGuard) {
2510
+ const serializeIdentifier = _marko_compiler.types.identifier(getSharedUid(`scope${paramsSection.id}_reason`, paramsSection));
2511
+ return paramsSection.paramReasonGroups ? callRuntime(isGuard ? "_serialize_guard" : "_serialize_if", serializeIdentifier, withLeadingComment(_marko_compiler.types.numericLiteral(getParamReasonGroupIndex(paramsSection, params)), getDebugNames(params))) : serializeIdentifier;
2512
+ }
2513
+ function getOnlySection(params) {
2514
+ if (params === void 0) return void 0;
2515
+ if (!Array.isArray(params)) return params.section;
2516
+ const { section } = params[0];
2517
+ return section === params[params.length - 1].section ? section : void 0;
2518
+ }
2519
+ function isDynamicSerializeGuard(section, reason) {
2520
+ return isReasonDynamic(reason) && !isCrossSection(section, reason);
2521
+ }
2522
+ function isCrossSection(section, reason) {
2523
+ return some(reason.param, (param) => !isSameOrChildSection(param.section, section));
2524
+ }
2525
+ function createTypeState() {
2526
+ return {
2527
+ names: /* @__PURE__ */ new Map(),
2528
+ pending: /* @__PURE__ */ new Map(),
2529
+ seenReasons: void 0,
2530
+ hoistedReasons: void 0
2531
+ };
2532
+ }
2533
+ //#endregion
2564
2534
  //#region src/translator/util/writer.ts
2565
2535
  const [getWrites] = createSectionState("writes", () => [""]);
2566
2536
  const [getTrailerWrites] = createSectionState("trailerWrites", () => [""]);
@@ -3857,15 +3827,13 @@ var dom_default = { translate: {
3857
3827
  tagParamsIdentifier
3858
3828
  ]);
3859
3829
  else {
3860
- const registerReason = getSectionRegisterReasons(childSection);
3861
- let renderer = callRuntime(registerReason ? "_content_resume" : "_content", _marko_compiler.types.stringLiteral(getResumeRegisterId(childSection, "content")), ...replaceNullishAndEmptyFunctionsWith0([
3830
+ let renderer = callRuntime(getSectionRegisterReasons(childSection) ? "_content_resume" : "_content", _marko_compiler.types.stringLiteral(getResumeRegisterId(childSection, "content")), ...replaceNullishAndEmptyFunctionsWith0([
3862
3831
  writes,
3863
3832
  walks,
3864
3833
  setupIdentifier,
3865
3834
  tagParamsIdentifier,
3866
3835
  childSection.hoisted || childSection.isHoistThrough ? getSectionInstancesAccessorLiteral(childSection) : void 0
3867
3836
  ]));
3868
- if (registerReason && isSectionRegisterDynamic(childSection, registerReason)) renderer = _marko_compiler.types.addComment(renderer, "leading", "@__PURE__");
3869
3837
  if (childSection.referencedLocalClosures) {
3870
3838
  const objProps = [];
3871
3839
  forEach(childSection.referencedLocalClosures, (closure) => {
@@ -4747,10 +4715,12 @@ var native_tag_default = {
4747
4715
  hasEventHandlers = true;
4748
4716
  } else {
4749
4717
  assertValidNativeEventHandlerAttr(tag, attr);
4718
+ if (isEventOrChangeHandler(attr.name)) valueExtra.forceRegister = true;
4750
4719
  if (!evaluate(attr.value).confident) hasDynamicAttributes = true;
4751
4720
  }
4752
4721
  } else if (_marko_compiler.types.isMarkoSpreadAttribute(attr)) {
4753
4722
  valueExtra.isEffect = true;
4723
+ valueExtra.forceRegister = true;
4754
4724
  hasEventHandlers = true;
4755
4725
  hasDynamicAttributes = true;
4756
4726
  }
@@ -6110,7 +6080,7 @@ var program_default = {
6110
6080
  if (paramsBinding && !paramsBinding.pruned) programExtra.domExports.params = getBindingPropTree(paramsBinding);
6111
6081
  const section = programExtra.section;
6112
6082
  forEachSection((childSection) => {
6113
- programExtra.hasResumes ||= !!(childSection.serializeReason || childSection.serializeReasons.size || childSection !== section && !isSectionRendererElided(childSection) && isSectionRegisterEager(childSection));
6083
+ programExtra.hasResumes ||= !!(childSection.serializeReason || childSection.serializeReasons.size || childSection !== section && !isSectionRendererElided(childSection) && getSectionRegisterReasons(childSection));
6114
6084
  });
6115
6085
  if (!section.hoistedTo && !sectionHasSetupStatements(section)) programExtra.domExports.setupEmpty = true;
6116
6086
  }
@@ -7144,7 +7114,7 @@ function trackReference(referencePath, binding) {
7144
7114
  let reference = binding;
7145
7115
  while (true) {
7146
7116
  const { parent } = root;
7147
- if (!_marko_compiler.types.isMemberExpression(parent) && !_marko_compiler.types.isOptionalMemberExpression(parent)) break;
7117
+ if (!_marko_compiler.types.isMemberExpression(parent) && !_marko_compiler.types.isOptionalMemberExpression(parent) || isWrittenMember(root.parentPath)) break;
7148
7118
  let prop = getMemberExpressionPropString(parent);
7149
7119
  if (prop === void 0) break;
7150
7120
  if (reference.upstreamAlias && reference.excludeProperties !== void 0) {
@@ -7161,23 +7131,38 @@ function trackReference(referencePath, binding) {
7161
7131
  }
7162
7132
  addReadToExpression(root, reference, void 0);
7163
7133
  }
7134
+ function isWrittenMember(member) {
7135
+ const { node, parent } = member;
7136
+ switch (parent.type) {
7137
+ case "AssignmentExpression":
7138
+ case "AssignmentPattern":
7139
+ case "ForInStatement":
7140
+ case "ForOfStatement": return parent.left === node;
7141
+ case "UnaryExpression": return parent.operator === "delete";
7142
+ case "UpdateExpression":
7143
+ case "ArrayPattern":
7144
+ case "RestElement": return true;
7145
+ case "ObjectProperty": return parent.value === node && _marko_compiler.types.isObjectPattern(member.parentPath.parent);
7146
+ default: return false;
7147
+ }
7148
+ }
7164
7149
  function mergeReferences(section, target, nodes) {
7165
7150
  const targetExtra = target.extra ??= {};
7166
7151
  const readsByExpression = getReadsByExpression();
7167
7152
  const fnReadsByExpression = getFunctionReadsByExpression();
7168
7153
  let reads = readsByExpression.get(targetExtra);
7169
7154
  let exprFnReads = fnReadsByExpression.get(targetExtra);
7170
- let { isEffect, dynamicTagInput } = targetExtra;
7155
+ let { isEffect, forceRegister } = targetExtra;
7171
7156
  for (const node of nodes) {
7172
7157
  if (!node) continue;
7173
7158
  const extra = node.extra ??= {};
7174
7159
  if (extra === targetExtra) continue;
7175
7160
  extra.merged = targetExtra;
7161
+ forceRegister ||= extra.forceRegister;
7176
7162
  if (isReferencedExtra(extra)) {
7177
7163
  const additionalReads = readsByExpression.get(extra);
7178
7164
  const additionalExprFnReads = fnReadsByExpression.get(extra);
7179
7165
  isEffect ||= extra.isEffect;
7180
- dynamicTagInput ||= extra.dynamicTagInput;
7181
7166
  if (additionalReads) {
7182
7167
  forEach(additionalReads, (read) => {
7183
7168
  read.binding.reads.delete(extra);
@@ -7194,7 +7179,7 @@ function mergeReferences(section, target, nodes) {
7194
7179
  }
7195
7180
  readsByExpression.set(targetExtra, reads);
7196
7181
  targetExtra.isEffect = isEffect;
7197
- targetExtra.dynamicTagInput = dynamicTagInput;
7182
+ targetExtra.forceRegister = forceRegister;
7198
7183
  targetExtra.section = section;
7199
7184
  return targetExtra;
7200
7185
  }
@@ -7512,15 +7497,12 @@ function resolveIntersectionSource(intersection, section, resolved) {
7512
7497
  return source && !Array.isArray(source) && source.section === section && !source.scopeOffset ? source : void 0;
7513
7498
  }
7514
7499
  function setBindingDownstream(binding, expr, exprs) {
7515
- setBindingValueExprs(binding, expr);
7500
+ getBindingValueExprs().set(binding, expr || false);
7516
7501
  if (expr && expr !== true) forEach(expr, (expr) => {
7517
7502
  expr.downstream = bindingUtil.add(expr.downstream, binding);
7518
7503
  if (exprs) expr.downstreamExprs = exprs;
7519
7504
  });
7520
7505
  }
7521
- function setBindingValueExprs(binding, expr) {
7522
- getBindingValueExprs().set(binding, expr || false);
7523
- }
7524
7506
  const [getResolvedSources] = createProgramState(() => /* @__PURE__ */ new Set());
7525
7507
  const [getBindingValueExprs] = createProgramState(() => /* @__PURE__ */ new Map());
7526
7508
  function resolveBindingSources(binding) {
@@ -7570,7 +7552,7 @@ function resolveDerivedSources(binding) {
7570
7552
  else if (exprs) {
7571
7553
  let refs;
7572
7554
  forEach(exprs, (expr) => {
7573
- if (isReferencedExtra(expr) && bindingUtil.has(expr.downstream, binding)) refs = bindingUtil.union(refs, expr.referencedBindings);
7555
+ if (isReferencedExtra(expr) && !expr.initialValue) refs = bindingUtil.union(refs, expr.referencedBindings);
7574
7556
  });
7575
7557
  forEach(refs, (ref) => {
7576
7558
  resolveBindingSources(ref);
@@ -8156,11 +8138,12 @@ function getAllSerializeReasonsForBinding(binding, properties) {
8156
8138
  return serializationForBinding(binding, properties).reason;
8157
8139
  }
8158
8140
  function getRegisterReasonForExtra(extra) {
8141
+ if (extra.forceRegister) return FORCED;
8159
8142
  const { reason, reads } = serializationForExtra(extra);
8160
- return some(reads, isDynamicTagInput) ? FORCED : reason;
8143
+ return some(reads, isForceRegisterRead) ? FORCED : reason;
8161
8144
  }
8162
- function isDynamicTagInput(read) {
8163
- return !!read.dynamicTagInput;
8145
+ function isForceRegisterRead(read) {
8146
+ return !!read.forceRegister;
8164
8147
  }
8165
8148
  function serializationForExtra(extra) {
8166
8149
  if (extra.isEffect) return FORCED_SERIALIZATION;
@@ -8865,15 +8848,16 @@ var let_default = {
8865
8848
  const tagSection = getOrCreateSection(tag);
8866
8849
  const binding = trackVarReferences(tag, 1);
8867
8850
  const tagExtra = mergeReferences(tagSection, tag.node, [valueAttr?.value, valueChangeAttr?.value]);
8851
+ setBindingDownstream(binding, tagExtra);
8868
8852
  if (valueChangeAttr) {
8869
8853
  binding.reserveSize = 1;
8870
- setBindingDownstream(binding, tagExtra);
8854
+ tagExtra.forceRegister = true;
8871
8855
  onFinalizeReferences(() => {
8872
8856
  if (binding.assignments) addSerializeReason(tagSection, FORCED, binding, getAccessorPrefix().TagVariableChange);
8873
8857
  });
8874
8858
  } else {
8859
+ tagExtra.initialValue = true;
8875
8860
  tagExtra.pure = !valueAttr || evaluate(valueAttr.value).pure;
8876
- setBindingValueExprs(binding, tagExtra);
8877
8861
  }
8878
8862
  },
8879
8863
  translate: { exit(tag) {
@@ -10162,6 +10146,7 @@ var custom_tag_default = {
10162
10146
  const programSection = programExtra.section;
10163
10147
  const childExtra = childFile.ast.program.extra;
10164
10148
  const childSection = childExtra.section;
10149
+ if (childSection === programSection && getOrCreateSection(tag) === programSection) throw tag.get("name").buildCodeFrameError(`A template that renders itself outside a branch never terminates. Render \`<${getStaticTagName(tag.node)}>\` inside a branch that eventually stops, such as \`<if>\`.`);
10165
10150
  if (childExtra.page) programExtra.page ??= true;
10166
10151
  if (tagExtra.tagNameLoad) tagExtra[kLoadTagBinding] = createBinding("#text", 0, getOrCreateSection(tag));
10167
10152
  if (tagExtra.tagNameLoad || !childExtra.domExports?.setupEmpty) addSetupStatement(getOrCreateSection(tag));
@@ -10359,8 +10344,7 @@ function optionalValueToNode(value) {
10359
10344
  //#endregion
10360
10345
  //#region src/translator/visitors/tag/dynamic-tag.ts
10361
10346
  const kChildOffsetScopeBinding = Symbol("custom tag scope offset");
10362
- const importedDynamicTagResume = /* @__PURE__ */ new WeakSet();
10363
- const importedDynamicTagVarResume = /* @__PURE__ */ new WeakSet();
10347
+ const [getAddedRuntime] = createProgramState(() => /* @__PURE__ */ new Set());
10364
10348
  const [getCompatRegistrations] = createProgramState(() => /* @__PURE__ */ new Set());
10365
10349
  const [getCompatBoundaryCalls] = createProgramState(() => /* @__PURE__ */ new Map());
10366
10350
  function pushCompatRegistration(key, statement) {
@@ -10389,11 +10373,12 @@ var dynamic_tag_default = {
10389
10373
  const tagSection = getOrCreateSection(tag);
10390
10374
  const inputNodes = getAllTagReferenceNodes(node);
10391
10375
  const tagExtra = mergeReferences(tagSection, node, [node.name, ...inputNodes]);
10392
- if (inputNodes.length) tagExtra.dynamicTagInput = true;
10376
+ if (inputNodes.length) tagExtra.forceRegister = true;
10393
10377
  const tagBody = tag.get("body");
10394
10378
  const hasVar = !!tag.node.var;
10379
+ const usesVar = hasVar && isTagVarUsed(tag);
10395
10380
  const nodeBinding = tagExtra.nodeBinding = createBinding("#text", 0, tagSection);
10396
- if (hasVar || tag.node.attributes.some((attr) => _marko_compiler.types.isMarkoSpreadAttribute(attr) || isEventOrChangeHandler(attr.name))) (0, _marko_compiler_babel_utils.getProgram)().node.extra.isInteractive = true;
10381
+ if (usesVar || tag.node.attributes.some((attr) => _marko_compiler.types.isMarkoSpreadAttribute(attr) || isEventOrChangeHandler(attr.name))) (0, _marko_compiler_babel_utils.getProgram)().node.extra.isInteractive = true;
10397
10382
  if (hasVar) {
10398
10383
  trackVarReferences(tag, 5);
10399
10384
  tag.node.var.extra.binding.scopeOffset = tagExtra[kChildOffsetScopeBinding] = createBinding("#scopeOffset", 0, tagSection);
@@ -10404,7 +10389,7 @@ var dynamic_tag_default = {
10404
10389
  if (analyzeTagNameType(tag, true) === 1 && !node.arguments) setTagDownstream(tag, getDynamicTagInputBindings(tagExtra), { value: tagExtra });
10405
10390
  }
10406
10391
  trackParamsReferences(tagBody, 3);
10407
- if (hasVar) addSerializeReason(tagSection, FORCED, nodeBinding);
10392
+ if (usesVar) addSerializeReason(tagSection, FORCED, nodeBinding);
10408
10393
  addSerializeExpr(tagSection, tagExtra, nodeBinding);
10409
10394
  if (!hasVar && !node.arguments && !node.attributes.length && !node.body.body.length) tagExtra[kDirectContent] = true;
10410
10395
  if (tagExtra.featureType !== "class" || (0, _marko_compiler_babel_utils.getTagTemplate)(tag)) {
@@ -10491,12 +10476,13 @@ var dynamic_tag_default = {
10491
10476
  writeHTMLResumeStatements(tag.get("body"));
10492
10477
  const serializeArg = getSerializeGuard(tagSection, serializeReason, true);
10493
10478
  const dynamicTagExpr = hasTagArgs ? callRuntime("_dynamic_tag", getScopeIdIdentifier(tagSection), getScopeAccessorLiteral(nodeBinding), tagExpression, _marko_compiler.types.arrayExpression(args), contentProp ? contentProp.value : _marko_compiler.types.numericLiteral(0), _marko_compiler.types.numericLiteral(1), serializeArg) : callRuntime("_dynamic_tag", getScopeIdIdentifier(tagSection), getScopeAccessorLiteral(nodeBinding), tagExpression, args[0], args[1] || (serializeArg ? _marko_compiler.types.numericLiteral(0) : void 0), serializeArg ? _marko_compiler.types.numericLiteral(0) : void 0, serializeArg);
10494
- if (node.var) {
10479
+ if (node.var && isTagVarResumed(tag)) {
10495
10480
  const dynamicScopeIdentifier = generateUidIdentifier(tag.get("name").toString() + "_scope");
10496
- const mutatesTagVar = !!(tag.node.var.type === "Identifier" && tag.scope.getBinding(tag.node.var.name)?.constantViolations.length);
10481
+ const mutatesTagVar = isTagVarAssigned(tag);
10497
10482
  statements.push(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(dynamicScopeIdentifier, callRuntime("_peek_scope_id"))]));
10498
10483
  statements.push(_marko_compiler.types.variableDeclaration("let", [_marko_compiler.types.variableDeclarator(node.var, dynamicTagExpr)]), _marko_compiler.types.expressionStatement(callRuntime("_var", getScopeIdIdentifier(tagSection), getScopeAccessorLiteral(tag.node.extra[kChildOffsetScopeBinding]), dynamicScopeIdentifier, _marko_compiler.types.stringLiteral(getResumeRegisterId(tagSection, node.var.extra?.binding, "var")), mutatesTagVar ? getScopeAccessorLiteral(nodeBinding) : void 0)));
10499
- } else statements.push(_marko_compiler.types.expressionStatement(dynamicTagExpr));
10484
+ } else if (node.var) statements.push(_marko_compiler.types.variableDeclaration("let", [_marko_compiler.types.variableDeclarator(node.var, dynamicTagExpr)]));
10485
+ else statements.push(_marko_compiler.types.expressionStatement(dynamicTagExpr));
10500
10486
  for (const replacement of tag.replaceWithMultiple(statements)) replacement.skip();
10501
10487
  } else {
10502
10488
  const section = getSection(tag);
@@ -10506,7 +10492,8 @@ var dynamic_tag_default = {
10506
10492
  if (tag.node.var) {
10507
10493
  const varBinding = tag.node.var.extra.binding;
10508
10494
  tagVarSignal = initValue(varBinding);
10509
- tagVarSignal.register = tagVarSignal.referenced = true;
10495
+ tagVarSignal.register = isTagVarResumed(tag);
10496
+ tagVarSignal.referenced = true;
10510
10497
  tagVarSignal.buildAssignment = (valueSection, value) => {
10511
10498
  const changeArgs = [_marko_compiler.types.memberExpression(getScopeExpression(tagVarSignal.section, valueSection), _marko_compiler.types.stringLiteral(getAccessorPrefix().BranchScopes + getScopeAccessor(nodeBinding)), true), value];
10512
10499
  if (!isOptimize()) changeArgs.push(_marko_compiler.types.stringLiteral(varBinding.name));
@@ -10524,7 +10511,7 @@ var dynamic_tag_default = {
10524
10511
  }
10525
10512
  if (!isClassAPI) {
10526
10513
  enableDynamicTagResume(tag);
10527
- enableDynamicTagVarResume(tag);
10514
+ enableDynamicTagVar(tag);
10528
10515
  enableDynamicTagControllables(tag);
10529
10516
  }
10530
10517
  addValue(section, tagExtra.referencedBindings, signal, tagExpression);
@@ -10542,23 +10529,25 @@ function enableDynamicTagControllables(tag) {
10542
10529
  return;
10543
10530
  }
10544
10531
  }
10545
- function enableDynamicTagVarResume(tag) {
10546
- const program = (0, _marko_compiler_babel_utils.getProgram)().node;
10547
- if (tag.node.var && !importedDynamicTagVarResume.has(program) && analyzeTagNameType(tag, true) !== 1) {
10548
- importedDynamicTagVarResume.add(program);
10549
- importRuntimeFeature("dynamic-tag-var");
10532
+ function enableDynamicTagVar(tag) {
10533
+ if (!tag.node.var || !isTagVarResumed(tag) || analyzeTagNameType(tag, true) === 1) return;
10534
+ importRuntimeFeature("dynamic-tag-var");
10535
+ if (!tag.node.var.extra.binding.pruned) {
10536
+ const accessor = getScopeAccessorLiteral(tag.node.extra.nodeBinding, true);
10537
+ if (addRuntimeOnce(`_resume_dynamic_tag_var ${accessor.value}`)) (0, _marko_compiler_babel_utils.getProgram)().node.body.push(_marko_compiler.types.expressionStatement(callRuntime("_resume_dynamic_tag_var", accessor)));
10550
10538
  }
10551
10539
  }
10552
10540
  function enableDynamicTagResume(tag) {
10553
- const program = (0, _marko_compiler_babel_utils.getProgram)().node;
10554
- if (!importedDynamicTagResume.has(program) && analyzeTagNameType(tag, true) !== 1) {
10555
- for (const attr of tag.node.attributes) if (attr.type === "MarkoSpreadAttribute" || attr.type === "MarkoAttribute" && isEventOrChangeHandler(attr.name)) {
10556
- importedDynamicTagResume.add(program);
10557
- program.body.push(_marko_compiler.types.expressionStatement(callRuntime("_resume_dynamic_tag")));
10558
- return;
10559
- }
10541
+ if (analyzeTagNameType(tag, true) === 1) return;
10542
+ for (const attr of tag.node.attributes) if (attr.type === "MarkoSpreadAttribute" || attr.type === "MarkoAttribute" && isEventOrChangeHandler(attr.name)) {
10543
+ importRuntimeFeature("dynamic-tag-script");
10544
+ return;
10560
10545
  }
10561
10546
  }
10547
+ function addRuntimeOnce(key) {
10548
+ const added = getAddedRuntime();
10549
+ return !added.has(key) && !!added.add(key);
10550
+ }
10562
10551
  function getDynamicTagInputBindings(tagExtra) {
10563
10552
  let inputBindings;
10564
10553
  for (const childExtra of tagExtra.tagNameTemplates || []) {
@@ -10568,6 +10557,19 @@ function getDynamicTagInputBindings(tagExtra) {
10568
10557
  }
10569
10558
  return inputBindings;
10570
10559
  }
10560
+ function isTagVarUsed(tag) {
10561
+ for (const name in _marko_compiler.types.getBindingIdentifiers(tag.node.var)) {
10562
+ const binding = tag.scope.getBinding(name);
10563
+ if (binding?.referencePaths.length || binding?.constantViolations.length) return true;
10564
+ }
10565
+ return false;
10566
+ }
10567
+ function isTagVarResumed(tag) {
10568
+ return !tag.node.var.extra.binding.pruned || isTagVarAssigned(tag);
10569
+ }
10570
+ function isTagVarAssigned(tag) {
10571
+ return !!(tag.node.var.type === "Identifier" && tag.scope.getBinding(tag.node.var.name)?.constantViolations.length);
10572
+ }
10571
10573
  //#endregion
10572
10574
  //#region src/translator/visitors/tag/index.ts
10573
10575
  var tag_default = {