marko 6.4.8 → 6.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/constants/closure-signal-prop.d.ts +1 -1
- package/dist/common/constants/closure-signal-prop.debug.d.ts +1 -1
- package/dist/debug/dom/catch.feat.js +1 -1
- package/dist/debug/dom/catch.feat.mjs +1 -1
- package/dist/debug/dom/controllable-input.feat.js +1 -1
- package/dist/debug/dom/controllable-input.feat.mjs +1 -1
- package/dist/debug/dom/controllable-open.feat.js +1 -1
- package/dist/debug/dom/controllable-open.feat.mjs +1 -1
- package/dist/debug/dom/controllable-select.feat.js +1 -1
- package/dist/debug/dom/controllable-select.feat.mjs +1 -1
- package/dist/debug/dom/controllable-textarea.feat.js +1 -1
- package/dist/debug/dom/controllable-textarea.feat.mjs +1 -1
- package/dist/debug/dom/controllable.feat.js +1 -1
- package/dist/debug/dom/controllable.feat.mjs +1 -1
- package/dist/debug/dom/dynamic-tag-script.feat.js +1 -1
- package/dist/debug/dom/dynamic-tag-script.feat.mjs +1 -1
- package/dist/debug/dom/dynamic-tag-var.feat.js +1 -1
- package/dist/debug/dom/dynamic-tag-var.feat.mjs +1 -1
- package/dist/debug/dom/lazy.feat.js +1 -1
- package/dist/debug/dom/lazy.feat.mjs +1 -1
- package/dist/debug/dom/placeholder.feat.js +1 -1
- package/dist/debug/dom/placeholder.feat.mjs +1 -1
- package/dist/debug/{dom-D8znnhpf.js → dom-QkYva5Qx.js} +35 -61
- package/dist/debug/{dom-CFCBDift.mjs → dom-VKjkbuuo.mjs} +36 -50
- package/dist/debug/dom.js +4 -4
- package/dist/debug/dom.mjs +4 -4
- package/dist/debug/html.js +20 -13
- package/dist/debug/html.mjs +18 -11
- package/dist/dom/catch.feat.js +3 -3
- package/dist/dom/catch.feat.mjs +1 -1
- package/dist/dom/compat.d.ts +1 -1
- package/dist/dom/control-flow.d.ts +1 -1
- package/dist/dom/controllable-input.feat.js +1 -1
- package/dist/dom/controllable-input.feat.mjs +1 -1
- package/dist/dom/controllable-open.feat.js +1 -1
- package/dist/dom/controllable-open.feat.mjs +1 -1
- package/dist/dom/controllable-select.feat.js +1 -1
- package/dist/dom/controllable-select.feat.mjs +1 -1
- package/dist/dom/controllable-textarea.feat.js +1 -1
- package/dist/dom/controllable-textarea.feat.mjs +1 -1
- package/dist/dom/controllable.feat.js +1 -1
- package/dist/dom/controllable.feat.mjs +1 -1
- package/dist/dom/dom.d.ts +2 -3
- package/dist/dom/dynamic-tag-script.feat.js +2 -2
- package/dist/dom/dynamic-tag-script.feat.mjs +1 -1
- package/dist/dom/dynamic-tag-var.feat.js +3 -3
- package/dist/dom/dynamic-tag-var.feat.mjs +1 -1
- package/dist/dom/lazy.feat.js +1 -1
- package/dist/dom/lazy.feat.mjs +1 -1
- package/dist/dom/placeholder.feat.js +3 -3
- package/dist/dom/placeholder.feat.mjs +1 -1
- package/dist/dom/resume.d.ts +1 -1
- package/dist/dom/scope.d.ts +1 -1
- package/dist/dom/signals.d.ts +1 -1
- package/dist/{dom-CVAevsbz.mjs → dom-DtKQb840.mjs} +19 -33
- package/dist/{dom-Bpkm72vV.js → dom-IujlfJ6b.js} +82 -106
- package/dist/dom.js +31 -31
- package/dist/dom.mjs +4 -4
- package/dist/html/serializer.d.ts +1 -1
- package/dist/html/writer.d.ts +3 -3
- package/dist/html.d.ts +1 -1
- package/dist/html.js +21 -15
- package/dist/html.mjs +21 -15
- package/dist/translator/core/show.d.ts +3 -4
- package/dist/translator/index.js +998 -967
- package/dist/translator/util/bindings.d.ts +6 -5
- package/dist/translator/util/branch-tag.d.ts +1 -1
- package/dist/translator/util/constants/slot-kind.d.ts +1 -1
- package/dist/translator/util/module-registrations.d.ts +1 -1
- package/dist/translator/util/optional.d.ts +1 -0
- package/dist/translator/util/params-tree.d.ts +3 -3
- package/dist/translator/util/reasons.d.ts +2 -2
- package/dist/translator/util/references.d.ts +13 -10
- package/dist/translator/util/replace-with-statements.d.ts +4 -0
- package/dist/translator/util/runtime.d.ts +1 -0
- package/dist/translator/util/scope-accessor.d.ts +1 -1
- package/dist/translator/util/sections.d.ts +38 -14
- package/dist/translator/util/signals.d.ts +3 -11
- package/dist/translator/util/slots.d.ts +1 -1
- package/dist/translator/util/solve-reasons.d.ts +5 -0
- package/dist/translator/util/static-text.d.ts +1 -0
- package/dist/translator/util/structure.d.ts +3 -2
- package/dist/translator/util/tag-import.d.ts +0 -2
- package/dist/translator/util/write-guard.d.ts +2 -0
- package/dist/translator/visitors/placeholder.d.ts +4 -4
- package/package.json +3 -3
- package/dist/translator/visitors/constants/sibling-text.d.ts +0 -6
package/dist/translator/index.js
CHANGED
|
@@ -429,18 +429,14 @@ function mapToString(data, sep, cb) {
|
|
|
429
429
|
return "";
|
|
430
430
|
}
|
|
431
431
|
function findSorted(compare, data, item) {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
while (pos < max) {
|
|
435
|
-
const mid = pos + max >>> 1;
|
|
436
|
-
const cur = data[mid];
|
|
437
|
-
const compareResult = compare(cur, item);
|
|
438
|
-
if (compareResult === 0) return cur;
|
|
439
|
-
if (compareResult > 0) max = mid;
|
|
440
|
-
else pos = mid + 1;
|
|
441
|
-
}
|
|
432
|
+
const index = searchSorted(compare, data, item);
|
|
433
|
+
if (index >= 0) return data[index];
|
|
442
434
|
}
|
|
443
435
|
function findIndexSorted(compare, data, item) {
|
|
436
|
+
const index = searchSorted(compare, data, item);
|
|
437
|
+
return index < 0 ? -1 : index;
|
|
438
|
+
}
|
|
439
|
+
function searchSorted(compare, data, item) {
|
|
444
440
|
let max = data.length;
|
|
445
441
|
let pos = 0;
|
|
446
442
|
while (pos < max) {
|
|
@@ -450,28 +446,17 @@ function findIndexSorted(compare, data, item) {
|
|
|
450
446
|
if (compareResult > 0) max = mid;
|
|
451
447
|
else pos = mid + 1;
|
|
452
448
|
}
|
|
453
|
-
return
|
|
449
|
+
return ~pos;
|
|
454
450
|
}
|
|
455
451
|
function addSorted(compare, data, item) {
|
|
452
|
+
let pos = searchSorted(compare, data, item);
|
|
453
|
+
if (pos >= 0) return data;
|
|
454
|
+
pos = ~pos;
|
|
456
455
|
const len = data.length;
|
|
457
|
-
let max = len;
|
|
458
|
-
let pos = 0;
|
|
459
|
-
while (pos < max) {
|
|
460
|
-
const mid = pos + max >>> 1;
|
|
461
|
-
const compareResult = compare(data[mid], item);
|
|
462
|
-
if (compareResult === 0) return data;
|
|
463
|
-
if (compareResult > 0) max = mid;
|
|
464
|
-
else pos = mid + 1;
|
|
465
|
-
}
|
|
466
456
|
const result = new Array(len + 1);
|
|
467
457
|
for (let i = 0; i < pos; i++) result[i] = data[i];
|
|
468
|
-
|
|
469
|
-
while (pos < len)
|
|
470
|
-
const next = cur;
|
|
471
|
-
cur = data[pos];
|
|
472
|
-
result[pos++] = next;
|
|
473
|
-
}
|
|
474
|
-
result[len] = cur;
|
|
458
|
+
result[pos] = item;
|
|
459
|
+
while (pos < len) result[pos + 1] = data[pos++];
|
|
475
460
|
return result;
|
|
476
461
|
}
|
|
477
462
|
function partitionPoint(data, key, compareKeys, bound) {
|
|
@@ -651,6 +636,30 @@ function getCompileStage(file = (0, _marko_compiler_babel_utils.getFile)()) {
|
|
|
651
636
|
return file.___compileStage;
|
|
652
637
|
}
|
|
653
638
|
//#endregion
|
|
639
|
+
//#region src/translator/util/replace-with-statements.ts
|
|
640
|
+
const replacements = /* @__PURE__ */ new WeakMap();
|
|
641
|
+
function replaceWithStatements(path, statements) {
|
|
642
|
+
path.skip();
|
|
643
|
+
const inserted = replacements.get(path.node);
|
|
644
|
+
if (inserted) {
|
|
645
|
+
if (statements) for (const statement of statements) inserted.push(statement);
|
|
646
|
+
} else replacements.set(path.node, statements || null);
|
|
647
|
+
}
|
|
648
|
+
function insertStatementBefore(path, statement) {
|
|
649
|
+
const inserted = replacements.get(path.node);
|
|
650
|
+
if (inserted) inserted.push(statement);
|
|
651
|
+
else replacements.set(path.node, [statement]);
|
|
652
|
+
}
|
|
653
|
+
function writeBodyStatements(body) {
|
|
654
|
+
const statements = [];
|
|
655
|
+
for (const child of body.body) {
|
|
656
|
+
const replacement = replacements.get(child);
|
|
657
|
+
if (replacement === void 0) statements.push(child);
|
|
658
|
+
else if (replacement) for (const statement of replacement) statements.push(statement);
|
|
659
|
+
}
|
|
660
|
+
body.body = statements;
|
|
661
|
+
}
|
|
662
|
+
//#endregion
|
|
654
663
|
//#region src/translator/util/state.ts
|
|
655
664
|
function createOutputState(init) {
|
|
656
665
|
return createKeyedState(_marko_compiler_babel_utils.getProgram, init);
|
|
@@ -769,7 +778,7 @@ function generateUidIdentifier(name) {
|
|
|
769
778
|
}
|
|
770
779
|
function declareConstBefore(tag, name, expr) {
|
|
771
780
|
const id = generateUidIdentifier(name);
|
|
772
|
-
tag
|
|
781
|
+
insertStatementBefore(tag, _marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(id, expr)]));
|
|
773
782
|
return id;
|
|
774
783
|
}
|
|
775
784
|
const [getSharedUIDs] = createOutputState(() => /* @__PURE__ */ new Map());
|
|
@@ -958,58 +967,6 @@ const ModuleRead = "moduleRead";
|
|
|
958
967
|
const SectionRef = "sectionRef";
|
|
959
968
|
const ExportRef = "exportRef";
|
|
960
969
|
//#endregion
|
|
961
|
-
//#region src/translator/util/slots.ts
|
|
962
|
-
const slotUtil = new Sorted(compareSlots);
|
|
963
|
-
function ensureSlot(binding, kind = 0, section, group) {
|
|
964
|
-
const owner = getCanonicalBinding(binding);
|
|
965
|
-
return findSlot(owner, kind, section, group) || addSlot(kind, section || owner.section, owner, group);
|
|
966
|
-
}
|
|
967
|
-
function findSlot(binding, kind = 0, section, group) {
|
|
968
|
-
const owner = getCanonicalBinding(binding);
|
|
969
|
-
return findIn((section || owner.section).slots, owner.uid, kind, group);
|
|
970
|
-
}
|
|
971
|
-
function ensureSectionSlot(owner, kind, section = owner) {
|
|
972
|
-
return findSectionSlot(owner, kind, section) || addSlot(kind, section, owner, void 0);
|
|
973
|
-
}
|
|
974
|
-
function findSectionSlot(owner, kind, section = owner) {
|
|
975
|
-
return findIn(section.slots, getOwnerOrder(owner), kind, void 0);
|
|
976
|
-
}
|
|
977
|
-
function addSlot(kind, section, owner, group) {
|
|
978
|
-
const slot = {
|
|
979
|
-
kind,
|
|
980
|
-
section,
|
|
981
|
-
owner,
|
|
982
|
-
group,
|
|
983
|
-
reason: void 0,
|
|
984
|
-
reasonExprs: void 0
|
|
985
|
-
};
|
|
986
|
-
section.slots = slotUtil.add(section.slots, slot);
|
|
987
|
-
return slot;
|
|
988
|
-
}
|
|
989
|
-
function findIn(slots, order, kind, group) {
|
|
990
|
-
if (slots === void 0) return;
|
|
991
|
-
if (!Array.isArray(slots)) return compareSlotTo(slots, order, kind, group) ? void 0 : slots;
|
|
992
|
-
let pos = 0;
|
|
993
|
-
let max = slots.length;
|
|
994
|
-
while (pos < max) {
|
|
995
|
-
const mid = pos + max >>> 1;
|
|
996
|
-
const slot = slots[mid];
|
|
997
|
-
const result = compareSlotTo(slot, order, kind, group);
|
|
998
|
-
if (result === 0) return slot;
|
|
999
|
-
if (result > 0) max = mid;
|
|
1000
|
-
else pos = mid + 1;
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
function compareSlots(a, b) {
|
|
1004
|
-
return compareSlotTo(a, getOwnerOrder(b.owner), b.kind, b.group);
|
|
1005
|
-
}
|
|
1006
|
-
function compareSlotTo(slot, order, kind, group) {
|
|
1007
|
-
return getOwnerOrder(slot.owner) - order || slot.kind - kind || (group ? compareReferences(slot.group, group) : 0);
|
|
1008
|
-
}
|
|
1009
|
-
function getOwnerOrder(owner) {
|
|
1010
|
-
return "uid" in owner ? owner.uid : -1 - owner.id;
|
|
1011
|
-
}
|
|
1012
|
-
//#endregion
|
|
1013
970
|
//#region src/translator/util/cyclic-memo.ts
|
|
1014
971
|
let computations = 0;
|
|
1015
972
|
let provisionalAt = Infinity;
|
|
@@ -1062,11 +1019,64 @@ function createPassPathMemo(compute, cycleAnswer) {
|
|
|
1062
1019
|
};
|
|
1063
1020
|
}
|
|
1064
1021
|
function ensurePropKeys(pathKeys, property) {
|
|
1065
|
-
let next = pathKeys.
|
|
1066
|
-
if (!next) (pathKeys.
|
|
1022
|
+
let next = pathKeys.properties?.get(property);
|
|
1023
|
+
if (!next) (pathKeys.properties ??= /* @__PURE__ */ new Map()).set(property, next = {});
|
|
1067
1024
|
return next;
|
|
1068
1025
|
}
|
|
1069
1026
|
//#endregion
|
|
1027
|
+
//#region src/translator/util/slots.ts
|
|
1028
|
+
function ensureSlot(binding, kind = 0, section, group) {
|
|
1029
|
+
const owner = getCanonicalBinding(binding);
|
|
1030
|
+
return ensureIn(section || owner.section, owner, kind, group);
|
|
1031
|
+
}
|
|
1032
|
+
function findSlot(binding, kind = 0, section, group) {
|
|
1033
|
+
const owner = getCanonicalBinding(binding);
|
|
1034
|
+
return findIn((section || owner.section).slots, owner.uid, kind, group);
|
|
1035
|
+
}
|
|
1036
|
+
function ensureSectionSlot(owner, kind, section = owner) {
|
|
1037
|
+
return ensureIn(section, owner, kind, void 0);
|
|
1038
|
+
}
|
|
1039
|
+
function findSectionSlot(owner, kind, section = owner) {
|
|
1040
|
+
return findIn(section.slots, getOwnerOrder(owner), kind, void 0);
|
|
1041
|
+
}
|
|
1042
|
+
function ensureIn(section, owner, kind, group) {
|
|
1043
|
+
const { slots } = section;
|
|
1044
|
+
const index = searchIn(slots, getOwnerOrder(owner), kind, group);
|
|
1045
|
+
if (index >= 0) return slots[index];
|
|
1046
|
+
const slot = {
|
|
1047
|
+
kind,
|
|
1048
|
+
section,
|
|
1049
|
+
owner,
|
|
1050
|
+
group,
|
|
1051
|
+
reason: void 0,
|
|
1052
|
+
reasonExprs: void 0
|
|
1053
|
+
};
|
|
1054
|
+
slots.splice(~index, 0, slot);
|
|
1055
|
+
return slot;
|
|
1056
|
+
}
|
|
1057
|
+
function findIn(slots, order, kind, group) {
|
|
1058
|
+
const index = searchIn(slots, order, kind, group);
|
|
1059
|
+
if (index >= 0) return slots[index];
|
|
1060
|
+
}
|
|
1061
|
+
function searchIn(slots, order, kind, group) {
|
|
1062
|
+
let pos = 0;
|
|
1063
|
+
let max = slots.length;
|
|
1064
|
+
while (pos < max) {
|
|
1065
|
+
const mid = pos + max >>> 1;
|
|
1066
|
+
const result = compareSlotTo(slots[mid], order, kind, group);
|
|
1067
|
+
if (result === 0) return mid;
|
|
1068
|
+
if (result > 0) max = mid;
|
|
1069
|
+
else pos = mid + 1;
|
|
1070
|
+
}
|
|
1071
|
+
return ~pos;
|
|
1072
|
+
}
|
|
1073
|
+
function compareSlotTo(slot, order, kind, group) {
|
|
1074
|
+
return getOwnerOrder(slot.owner) - order || slot.kind - kind || (group ? compareReferences(slot.group, group) : 0);
|
|
1075
|
+
}
|
|
1076
|
+
function getOwnerOrder(owner) {
|
|
1077
|
+
return "uid" in owner ? owner.uid : -1 - owner.id;
|
|
1078
|
+
}
|
|
1079
|
+
//#endregion
|
|
1070
1080
|
//#region src/translator/util/get-root.ts
|
|
1071
1081
|
function getMarkoRoot(path) {
|
|
1072
1082
|
let curPath = path;
|
|
@@ -1264,13 +1274,21 @@ function compareSources(a, b) {
|
|
|
1264
1274
|
function mergeSources(a, b) {
|
|
1265
1275
|
if (!a) return b;
|
|
1266
1276
|
if (!b) return a;
|
|
1267
|
-
|
|
1268
|
-
|
|
1277
|
+
const state = bindingUtil.union(a.state, b.state);
|
|
1278
|
+
const param = unionParamSources(a.param, b.param);
|
|
1279
|
+
const global = a.global || b.global;
|
|
1280
|
+
const always = a.always || b.always;
|
|
1281
|
+
if (state === a.state && param === a.param && global === a.global && always === a.always) return a;
|
|
1282
|
+
if (state === b.state && param === b.param && global === b.global && always === b.always) return b;
|
|
1283
|
+
return createSources(state, param, global, always);
|
|
1269
1284
|
}
|
|
1270
1285
|
function unionParamSources(a, b) {
|
|
1271
1286
|
const merged = bindingUtil.union(a, b);
|
|
1272
1287
|
if (merged === a || merged === b) return merged;
|
|
1273
|
-
return bindingUtil.
|
|
1288
|
+
return bindingUtil.union(dropCovered(a, b), dropCovered(b, a));
|
|
1289
|
+
}
|
|
1290
|
+
function dropCovered(params, other) {
|
|
1291
|
+
return bindingUtil.filter(params, (binding) => !someUpToAliasRoot(binding.aliasOf, isInParams, other));
|
|
1274
1292
|
}
|
|
1275
1293
|
function isInParams(binding, params) {
|
|
1276
1294
|
return bindingUtil.has(params, binding);
|
|
@@ -1437,11 +1455,10 @@ function trackReferencesForBinding(babelBinding, binding) {
|
|
|
1437
1455
|
}
|
|
1438
1456
|
if (markoRoot?.type === "MarkoAttribute" && markoRoot.parentPath === babelBinding.path && !getFnRoot(ref)) throw ref.buildCodeFrameError(`\`${ref.node.name}\` is the [tag variable](https://markojs.com/docs/reference/language#tag-variables) this tag declares, so its own attributes cannot read it.`);
|
|
1439
1457
|
else if (isReferenceHoisted(babelBinding.path, ref)) {
|
|
1440
|
-
|
|
1441
|
-
if (invoked) setReferencesScope(ref);
|
|
1458
|
+
setReferencesScope(ref);
|
|
1442
1459
|
addReadToExpression(ref, binding, {
|
|
1443
1460
|
hoisted: getCommonSection(refSection, binding.section),
|
|
1444
|
-
invoked
|
|
1461
|
+
invoked: isInvokedFunction(ref)
|
|
1445
1462
|
});
|
|
1446
1463
|
} else if (binding.type !== 3 || refSection !== binding.section) trackReference(ref, binding);
|
|
1447
1464
|
else {
|
|
@@ -1533,7 +1550,7 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, aliased, p
|
|
|
1533
1550
|
if (!prop.computed && prop.key.type === "Identifier") key = prop.key.name;
|
|
1534
1551
|
else if (prop.key.type === "StringLiteral") key = prop.key.value;
|
|
1535
1552
|
else throw scope.path.hub.buildError(prop.key, "Only identifier and string literal keys are supported when destructuring.");
|
|
1536
|
-
if (hasRest) excludeProperties =
|
|
1553
|
+
if (hasRest) excludeProperties = propertiesUtil.add(excludeProperties, key);
|
|
1537
1554
|
if (_marko_compiler.types.isLVal(prop.value)) createBindingsAndTrackReferences(prop.value, type, scope, section, patternBinding, key, void 0, void 0, declaresPattern);
|
|
1538
1555
|
}
|
|
1539
1556
|
break;
|
|
@@ -1599,7 +1616,7 @@ function trackReference(referencePath, binding) {
|
|
|
1599
1616
|
prop = `${+prop + reference.restOffset}`;
|
|
1600
1617
|
reference = reference.aliasOf;
|
|
1601
1618
|
}
|
|
1602
|
-
} else if (!
|
|
1619
|
+
} else if (!propertiesUtil.has(reference.excludeProperties, prop)) reference = reference.aliasOf;
|
|
1603
1620
|
}
|
|
1604
1621
|
if (isInvokedFunction(root.parentPath) && !isEventOrChangeHandler(prop)) break;
|
|
1605
1622
|
root = root.parentPath;
|
|
@@ -1721,20 +1738,20 @@ function addRead(exprExtra, extra, binding, section, getter) {
|
|
|
1721
1738
|
return read;
|
|
1722
1739
|
}
|
|
1723
1740
|
function dropNodes(node) {
|
|
1724
|
-
forEachNodeExtra(node,
|
|
1741
|
+
forEachNodeExtra(node, dropExpr);
|
|
1725
1742
|
}
|
|
1726
1743
|
function untrackNodes(node) {
|
|
1727
|
-
forEachNodeExtra(node,
|
|
1744
|
+
forEachNodeExtra(node, untrackExpr);
|
|
1728
1745
|
}
|
|
1729
1746
|
function forEachNodeExtra(node, fn) {
|
|
1730
1747
|
if (Array.isArray(node)) for (const item of node) fn(item.extra ??= {});
|
|
1731
1748
|
else fn(node.extra ??= {});
|
|
1732
1749
|
}
|
|
1733
|
-
function
|
|
1750
|
+
function dropExpr(exprExtra) {
|
|
1734
1751
|
exprExtra.dropped = true;
|
|
1735
|
-
|
|
1752
|
+
untrackExpr(exprExtra);
|
|
1736
1753
|
}
|
|
1737
|
-
function
|
|
1754
|
+
function untrackExpr(exprExtra) {
|
|
1738
1755
|
/* v8 ignore next 3 -- a merged reference is never dropped */
|
|
1739
1756
|
if (exprExtra.merged) throw new Error("Cannot drop a merged reference");
|
|
1740
1757
|
const readsByExpr = getReadsByExpression();
|
|
@@ -1776,7 +1793,7 @@ function addReadToExpression(root, binding, getter) {
|
|
|
1776
1793
|
const exprRoot = getExprRoot(fnRoot || root);
|
|
1777
1794
|
const section = ensureSection(exprRoot);
|
|
1778
1795
|
const rootExtra = exprRoot.node.extra ??= { section };
|
|
1779
|
-
const exprExtra =
|
|
1796
|
+
const exprExtra = getCanonicalExpr(rootExtra);
|
|
1780
1797
|
if (exprExtra.dropped) return;
|
|
1781
1798
|
const extra = node.extra ??= {};
|
|
1782
1799
|
extra.exprRoot = rootExtra;
|
|
@@ -1812,18 +1829,18 @@ function getAllTagReferenceNodes(tag, referenceNodes = [], collectAttrTag) {
|
|
|
1812
1829
|
}
|
|
1813
1830
|
return referenceNodes;
|
|
1814
1831
|
}
|
|
1815
|
-
function createResolvedRead(binding,
|
|
1832
|
+
function createResolvedRead(binding, properties, inOwnBody = false) {
|
|
1816
1833
|
return {
|
|
1817
1834
|
binding,
|
|
1818
|
-
|
|
1835
|
+
properties,
|
|
1819
1836
|
inOwnBody,
|
|
1820
1837
|
getter: void 0
|
|
1821
1838
|
};
|
|
1822
1839
|
}
|
|
1823
|
-
function createResolvedGetterRead(binding,
|
|
1840
|
+
function createResolvedGetterRead(binding, properties, getter) {
|
|
1824
1841
|
return {
|
|
1825
1842
|
binding,
|
|
1826
|
-
|
|
1843
|
+
properties,
|
|
1827
1844
|
inOwnBody: false,
|
|
1828
1845
|
getter
|
|
1829
1846
|
};
|
|
@@ -1835,16 +1852,16 @@ function hasResumableAssignment(binding) {
|
|
|
1835
1852
|
return some(binding.assignments, isResumableAssignment);
|
|
1836
1853
|
}
|
|
1837
1854
|
function isResumableAssignment({ exprRoot, fnRoot }) {
|
|
1838
|
-
return !!
|
|
1855
|
+
return !!getCanonicalExpr(exprRoot).isEffect || !!fnRoot?.reason;
|
|
1839
1856
|
}
|
|
1840
1857
|
function isAssignedBindingExtra(extra) {
|
|
1841
1858
|
return isReferencedExtra(extra) && extra.assignment !== void 0;
|
|
1842
1859
|
}
|
|
1843
1860
|
function isRegisteredFnExtra(extra) {
|
|
1844
|
-
return isReferencedExtra(extra) && extra.
|
|
1861
|
+
return isReferencedExtra(extra) && extra.registryId !== void 0;
|
|
1845
1862
|
}
|
|
1846
1863
|
function getReferencedBindings(extra) {
|
|
1847
|
-
return extra &&
|
|
1864
|
+
return extra && getCanonicalExpr(extra)[kReferencedBindings];
|
|
1848
1865
|
}
|
|
1849
1866
|
function getBindingsDerivedFrom(binding) {
|
|
1850
1867
|
if (binding.aliasOf) return binding.aliasOf;
|
|
@@ -1854,7 +1871,7 @@ function getValueReferences(exprs) {
|
|
|
1854
1871
|
return reduce(exprs, addValueReferences);
|
|
1855
1872
|
}
|
|
1856
1873
|
function addValueReferences(refs, expr) {
|
|
1857
|
-
return isReferencedExtra(
|
|
1874
|
+
return isReferencedExtra(getCanonicalExpr(expr)) && !expr.initialValue ? bindingUtil.union(refs, getReferencedBindings(expr)) : refs;
|
|
1858
1875
|
}
|
|
1859
1876
|
function getReferencedBindingsInFunction(extra) {
|
|
1860
1877
|
return extra[kReferencedBindingsInFunction];
|
|
@@ -1865,18 +1882,19 @@ function getConstantBindingsInFunction(extra) {
|
|
|
1865
1882
|
function setResolvedFunctionReads(extra, referencedBindings, constantBindings) {
|
|
1866
1883
|
extra[kReferencedBindingsInFunction] = referencedBindings;
|
|
1867
1884
|
extra[kConstantBindingsInFunction] = constantBindings;
|
|
1885
|
+
extra.referencesScope ||= !!(referencedBindings || constantBindings);
|
|
1868
1886
|
}
|
|
1869
1887
|
function setResolvedReads(extra, referencedBindings, lazyBindings) {
|
|
1870
1888
|
extra[kReferencedBindings] = referencedBindings;
|
|
1871
1889
|
extra[kLazyBindings] = lazyBindings;
|
|
1872
1890
|
}
|
|
1873
|
-
function
|
|
1891
|
+
function getCanonicalExpr(extra) {
|
|
1874
1892
|
while (extra.merged) extra = extra.merged;
|
|
1875
1893
|
return extra;
|
|
1876
1894
|
}
|
|
1877
|
-
function addNumericPropertiesUntil(
|
|
1878
|
-
let result =
|
|
1879
|
-
for (let i = len; i--;) result =
|
|
1895
|
+
function addNumericPropertiesUntil(properties, len) {
|
|
1896
|
+
let result = properties;
|
|
1897
|
+
for (let i = len; i--;) result = propertiesUtil.add(result, i + "");
|
|
1880
1898
|
return result;
|
|
1881
1899
|
}
|
|
1882
1900
|
//#endregion
|
|
@@ -1978,11 +1996,18 @@ function getRuntimePath(output) {
|
|
|
1978
1996
|
function assertTranslate(helper, name) {
|
|
1979
1997
|
if (!isTranslate()) throw new Error(`\`${helper}(${JSON.stringify(name)})\` may only be called during the translate stage.`);
|
|
1980
1998
|
}
|
|
1999
|
+
function absentArg(value) {
|
|
2000
|
+
const arg = _marko_compiler.types.numericLiteral(value);
|
|
2001
|
+
absentArgs.add(arg);
|
|
2002
|
+
return arg;
|
|
2003
|
+
}
|
|
2004
|
+
const absentArgs = /* @__PURE__ */ new WeakSet();
|
|
1981
2005
|
function trimFalsyArgs(args) {
|
|
1982
2006
|
const filteredArgs = [];
|
|
1983
2007
|
for (let i = args.length; i--;) {
|
|
1984
2008
|
const arg = args[i];
|
|
1985
|
-
if (
|
|
2009
|
+
if (filteredArgs.length) filteredArgs[i] = arg || _marko_compiler.types.buildUndefinedNode();
|
|
2010
|
+
else if (arg && !absentArgs.has(arg)) filteredArgs[i] = arg;
|
|
1986
2011
|
}
|
|
1987
2012
|
return filteredArgs;
|
|
1988
2013
|
}
|
|
@@ -1996,10 +2021,10 @@ const kRegisteredExports = Symbol("registered exports");
|
|
|
1996
2021
|
const [getReferencesByFn] = createAnalysisState(() => /* @__PURE__ */ new Map());
|
|
1997
2022
|
const [getReferencesByImport] = createAnalysisState(() => /* @__PURE__ */ new Map());
|
|
1998
2023
|
function trackFunction(fn, fnExtra, markoRoot) {
|
|
1999
|
-
|
|
2024
|
+
reserveExportRegistryId(fnExtra, fn, markoRoot);
|
|
2000
2025
|
if (isStatic(markoRoot)) {
|
|
2001
|
-
const
|
|
2002
|
-
if (
|
|
2026
|
+
const exprs = getStaticDeclExprs(fn);
|
|
2027
|
+
if (exprs.size) getReferencesByFn().set(fnExtra, exprs);
|
|
2003
2028
|
} else getReferencesByFn().set(fnExtra, /* @__PURE__ */ new Set([fnExtra.exprRoot]));
|
|
2004
2029
|
}
|
|
2005
2030
|
function canIgnoreRegister(markoRoot, exprRoot) {
|
|
@@ -2035,7 +2060,7 @@ function finalizeRegistrations() {
|
|
|
2035
2060
|
*/
|
|
2036
2061
|
function trackImportedTemplate(importDecl, local, templateFile) {
|
|
2037
2062
|
trackImport(importDecl, local, {
|
|
2038
|
-
|
|
2063
|
+
registryId: templateFile.metadata.marko.id,
|
|
2039
2064
|
exportName: "default",
|
|
2040
2065
|
filename: templateFile.opts.filename
|
|
2041
2066
|
}, /* @__PURE__ */ new Set());
|
|
@@ -2048,14 +2073,14 @@ function trackImportedTemplate(importDecl, local, templateFile) {
|
|
|
2048
2073
|
function trackImport(importDecl, local, registered, fnRoots) {
|
|
2049
2074
|
const binding = registered && importDecl.scope.getBinding(local);
|
|
2050
2075
|
if (!binding) return;
|
|
2051
|
-
const
|
|
2052
|
-
|
|
2053
|
-
if (
|
|
2076
|
+
const exprs = /* @__PURE__ */ new Set();
|
|
2077
|
+
addBindingExprs(binding, exprs, /* @__PURE__ */ new Set(), fnRoots);
|
|
2078
|
+
if (exprs.size) getReferencesByImport().set({
|
|
2054
2079
|
node: importDecl.node,
|
|
2055
2080
|
local,
|
|
2056
2081
|
registered,
|
|
2057
2082
|
fnRoots
|
|
2058
|
-
},
|
|
2083
|
+
}, exprs);
|
|
2059
2084
|
}
|
|
2060
2085
|
/**
|
|
2061
2086
|
* Finds the id reserved for an export, following `export ... from` hops. Each
|
|
@@ -2097,10 +2122,10 @@ function writeModuleRegistrations(program) {
|
|
|
2097
2122
|
for (const child of program.node.body) {
|
|
2098
2123
|
const registeredImports = _marko_compiler.types.isImportDeclaration(child) && child.extra?.registeredImports;
|
|
2099
2124
|
if (registeredImports) for (const [local, registered] of registeredImports) {
|
|
2100
|
-
if (seen.has(registered.
|
|
2101
|
-
seen.add(registered.
|
|
2125
|
+
if (seen.has(registered.registryId)) continue;
|
|
2126
|
+
seen.add(registered.registryId);
|
|
2102
2127
|
if (isOutputHTML()) {
|
|
2103
|
-
if (registered.exportName !== "default") statements.push(buildRegistration(local, registered.
|
|
2128
|
+
if (registered.exportName !== "default") statements.push(buildRegistration(local, registered.registryId));
|
|
2104
2129
|
} else (0, _marko_compiler_babel_utils.importDefault)(file, resolveRegisterModule(file, registered));
|
|
2105
2130
|
}
|
|
2106
2131
|
else if (child.type === "ExportNamedDeclaration") addExportRegistrations(child, seen, statements);
|
|
@@ -2110,7 +2135,7 @@ function writeModuleRegistrations(program) {
|
|
|
2110
2135
|
function resolveReason(exprExtras) {
|
|
2111
2136
|
let reason;
|
|
2112
2137
|
for (const exprExtra of exprExtras) {
|
|
2113
|
-
const extra =
|
|
2138
|
+
const extra = getCanonicalExpr(exprExtra);
|
|
2114
2139
|
if (!exprExtra.consumed || extra.retained) reason = mergeSources(reason, landsRetained(extra) ? ALWAYS : getReasonForExpr(extra));
|
|
2115
2140
|
}
|
|
2116
2141
|
return reason;
|
|
@@ -2118,30 +2143,30 @@ function resolveReason(exprExtras) {
|
|
|
2118
2143
|
function resolveTemplateReason(exprExtras) {
|
|
2119
2144
|
let reason;
|
|
2120
2145
|
for (const exprExtra of exprExtras) {
|
|
2121
|
-
const extra =
|
|
2146
|
+
const extra = getCanonicalExpr(exprExtra);
|
|
2122
2147
|
if (!extra.isEffect) reason = mergeSources(reason, getReasonForExpr(extra));
|
|
2123
2148
|
}
|
|
2124
2149
|
return reason;
|
|
2125
2150
|
}
|
|
2126
2151
|
function isTemplateShipped(fnRoots, exprExtras) {
|
|
2127
2152
|
for (const fnRoot of fnRoots) if (isRegisteredFnExtra(fnRoot)) return true;
|
|
2128
|
-
for (const exprExtra of exprExtras) if (
|
|
2153
|
+
for (const exprExtra of exprExtras) if (getCanonicalExpr(exprExtra).isEffect) return true;
|
|
2129
2154
|
return false;
|
|
2130
2155
|
}
|
|
2131
|
-
function
|
|
2156
|
+
function reserveExportRegistryId(fnExtra, fn, markoRoot) {
|
|
2132
2157
|
if (!isStatic(markoRoot)) return;
|
|
2133
2158
|
const exportNames = getExportNames(fn, markoRoot);
|
|
2134
2159
|
const exportName = exportNames?.find((name) => _marko_compiler.types.isValidIdentifier(name));
|
|
2135
2160
|
if (!exportName) return;
|
|
2136
2161
|
const { markoOpts, opts: { filename } } = (0, _marko_compiler_babel_utils.getFile)();
|
|
2137
2162
|
const programExtra = (0, _marko_compiler_babel_utils.getProgram)().node.extra;
|
|
2138
|
-
const
|
|
2163
|
+
const registryId = (0, _marko_compiler_babel_utils.getTemplateId)(markoOpts, filename, `${fnExtra.section.id}/export/${exportName}`);
|
|
2139
2164
|
const registered = {
|
|
2140
|
-
|
|
2165
|
+
registryId,
|
|
2141
2166
|
exportName,
|
|
2142
2167
|
filename
|
|
2143
2168
|
};
|
|
2144
|
-
fnExtra.
|
|
2169
|
+
fnExtra.exportRegistryId = registryId;
|
|
2145
2170
|
programExtra[kRegisteredExports] ??= /* @__PURE__ */ new Map();
|
|
2146
2171
|
for (const name of exportNames) programExtra[kRegisteredExports].set(name, registered);
|
|
2147
2172
|
}
|
|
@@ -2164,19 +2189,19 @@ function getExportableName(fn) {
|
|
|
2164
2189
|
if (node.type === "FunctionDeclaration") return node.id?.name;
|
|
2165
2190
|
if (_marko_compiler.types.isVariableDeclarator(parent) && parent.init === node && _marko_compiler.types.isIdentifier(parent.id) && _marko_compiler.types.isVariableDeclaration(fn.parentPath.parent, { kind: "const" })) return parent.id.name;
|
|
2166
2191
|
}
|
|
2167
|
-
function
|
|
2168
|
-
const decl = getDeclarationRoot(path$
|
|
2192
|
+
function getStaticDeclExprs(path$10, exprs = /* @__PURE__ */ new Set(), seen = /* @__PURE__ */ new Set(), fnRoots) {
|
|
2193
|
+
const decl = getDeclarationRoot(path$10);
|
|
2169
2194
|
if (decl && !seen.has(decl.node)) {
|
|
2170
2195
|
seen.add(decl.node);
|
|
2171
2196
|
const ids = decl.getOuterBindingIdentifiers();
|
|
2172
2197
|
if (ids) for (const name in ids) {
|
|
2173
2198
|
const binding = decl.scope.getBinding(name);
|
|
2174
|
-
if (binding)
|
|
2199
|
+
if (binding) addBindingExprs(binding, exprs, seen, fnRoots);
|
|
2175
2200
|
}
|
|
2176
2201
|
}
|
|
2177
|
-
return
|
|
2202
|
+
return exprs;
|
|
2178
2203
|
}
|
|
2179
|
-
function
|
|
2204
|
+
function addBindingExprs(binding, exprs, seen, fnRoots) {
|
|
2180
2205
|
for (const ref of binding.referencePaths) {
|
|
2181
2206
|
if (isInvokedFunction(ref) || ref.parentPath.type === "Program") continue;
|
|
2182
2207
|
const exprRoot = getExprRoot(ref);
|
|
@@ -2186,41 +2211,41 @@ function addBindingRefs(binding, refs, seen, fnRoots) {
|
|
|
2186
2211
|
const fnRoot = getFnRoot(ref);
|
|
2187
2212
|
if (fnRoot) fnRoots.add(fnRoot.node.extra ??= {});
|
|
2188
2213
|
}
|
|
2189
|
-
if (isStatic(markoRoot))
|
|
2190
|
-
else
|
|
2214
|
+
if (isStatic(markoRoot)) getStaticDeclExprs(ref, exprs, seen, fnRoots);
|
|
2215
|
+
else exprs.add(exprRoot.node.extra ??= {});
|
|
2191
2216
|
}
|
|
2192
2217
|
}
|
|
2193
2218
|
function registerFunction(fnExtra) {
|
|
2194
2219
|
const { markoOpts, opts: { filename } } = (0, _marko_compiler_babel_utils.getFile)();
|
|
2195
2220
|
fnExtra.name = generateUid(fnExtra.name);
|
|
2196
|
-
fnExtra.
|
|
2221
|
+
fnExtra.registryId = fnExtra.exportRegistryId ?? (0, _marko_compiler_babel_utils.getTemplateId)(markoOpts, filename, `${fnExtra.section.id}/${fnExtra.name.slice(1)}`);
|
|
2197
2222
|
}
|
|
2198
2223
|
function addExportRegistrations(node, seen, statements) {
|
|
2199
2224
|
const { declaration } = node;
|
|
2200
2225
|
if (!declaration) return;
|
|
2201
|
-
const add = (local,
|
|
2202
|
-
if (seen.has(
|
|
2203
|
-
seen.add(
|
|
2204
|
-
statements.push(buildRegistration(local,
|
|
2226
|
+
const add = (local, registryId) => {
|
|
2227
|
+
if (seen.has(registryId)) return;
|
|
2228
|
+
seen.add(registryId);
|
|
2229
|
+
statements.push(buildRegistration(local, registryId));
|
|
2205
2230
|
};
|
|
2206
2231
|
if (declaration.type === "FunctionDeclaration") {
|
|
2207
|
-
if (isRegisteredFnExtra(declaration.extra)) add(declaration.id.name, declaration.extra.
|
|
2232
|
+
if (isRegisteredFnExtra(declaration.extra)) add(declaration.id.name, declaration.extra.registryId);
|
|
2208
2233
|
return;
|
|
2209
2234
|
}
|
|
2210
2235
|
if (isOutputHTML() || declaration.type !== "VariableDeclaration") return;
|
|
2211
2236
|
for (const declarator of declaration.declarations) {
|
|
2212
2237
|
const extra = declarator.init?.extra;
|
|
2213
|
-
if (isRegisteredFnExtra(extra) && _marko_compiler.types.isIdentifier(declarator.id)) add(declarator.id.name, extra.
|
|
2238
|
+
if (isRegisteredFnExtra(extra) && _marko_compiler.types.isIdentifier(declarator.id)) add(declarator.id.name, extra.registryId);
|
|
2214
2239
|
}
|
|
2215
2240
|
}
|
|
2216
|
-
function buildRegistration(local,
|
|
2217
|
-
return _marko_compiler.types.expressionStatement(isOutputHTML() ? callRuntime("_resume", _marko_compiler.types.identifier(local), _marko_compiler.types.stringLiteral(
|
|
2241
|
+
function buildRegistration(local, registryId) {
|
|
2242
|
+
return _marko_compiler.types.expressionStatement(isOutputHTML() ? callRuntime("_resume", _marko_compiler.types.identifier(local), _marko_compiler.types.stringLiteral(registryId)) : registerRuntimeValue(registryId, _marko_compiler.types.identifier(local)));
|
|
2218
2243
|
}
|
|
2219
|
-
function resolveRegisterModule(file, { filename, exportName,
|
|
2244
|
+
function resolveRegisterModule(file, { filename, exportName, registryId }) {
|
|
2220
2245
|
const importer = file.opts.filename;
|
|
2221
2246
|
return getMarkoOpts().resolveVirtualDependency(importer, {
|
|
2222
2247
|
virtualPath: `${relativePath(importer, filename)}.register-${exportName}.js`,
|
|
2223
|
-
code: `import { ${exportName} as value } from "./${path.default.basename(filename)}";\nimport { _resumed } from "${getRuntimePath("dom")}";\n_resumed${isValidPropertyIdentifier(
|
|
2248
|
+
code: `import { ${exportName} as value } from "./${path.default.basename(filename)}";\nimport { _resumed } from "${getRuntimePath("dom")}";\n_resumed${isValidPropertyIdentifier(registryId) ? `.${registryId}` : `[${JSON.stringify(registryId)}]`} = value;\n`
|
|
2224
2249
|
});
|
|
2225
2250
|
}
|
|
2226
2251
|
function relativePath(from, to) {
|
|
@@ -2276,13 +2301,13 @@ function getBranchExprReason(section) {
|
|
|
2276
2301
|
const { derives, branchExpr } = section;
|
|
2277
2302
|
if (derives) {
|
|
2278
2303
|
let reason = mergeSources(getRendererReason(section) || void 0, getSourcesForDerived(derives));
|
|
2279
|
-
forEach(section.
|
|
2304
|
+
forEach(section.renderedBy, (call) => {
|
|
2280
2305
|
const callSection = call.childScopeBinding.section;
|
|
2281
2306
|
reason = mergeSources(reason, getBranchExprReasonUntil(callSection, isSameOrAncestorSection(section, callSection) ? section : section.parent));
|
|
2282
2307
|
});
|
|
2283
2308
|
return reason;
|
|
2284
2309
|
}
|
|
2285
|
-
if (section.branch?.await) return;
|
|
2310
|
+
if (section.branch?.kind === "await") return;
|
|
2286
2311
|
return branchExpr ? getSourcesForExpr(branchExpr) : ALWAYS;
|
|
2287
2312
|
}
|
|
2288
2313
|
function getBranchExprReasonUntil(section, ancestor) {
|
|
@@ -2305,7 +2330,7 @@ function addClosureReasons(section) {
|
|
|
2305
2330
|
});
|
|
2306
2331
|
}
|
|
2307
2332
|
function addCallOwnerReasons(body) {
|
|
2308
|
-
if (body.readsOwner) forEach(body.
|
|
2333
|
+
if (body.readsOwner) forEach(body.renderedBy, (call) => {
|
|
2309
2334
|
const callSection = call.childScopeBinding.section;
|
|
2310
2335
|
addOwnerReason(callSection, body.parent, getBranchExprReasonUntil(callSection, body.parent));
|
|
2311
2336
|
});
|
|
@@ -2324,37 +2349,52 @@ function addRegisteredFnReasons(fnReadsByExpression) {
|
|
|
2324
2349
|
}
|
|
2325
2350
|
}
|
|
2326
2351
|
}
|
|
2352
|
+
const LANDS_RETAINED = 1;
|
|
2353
|
+
const LANDS_RETAINED_INPUT = 2;
|
|
2354
|
+
const LANDS_UNSEEN = 4;
|
|
2327
2355
|
const UNREAD = {
|
|
2328
2356
|
reason: void 0,
|
|
2329
|
-
|
|
2357
|
+
lands: 0
|
|
2330
2358
|
};
|
|
2331
2359
|
const ALWAYS_READ = {
|
|
2332
2360
|
reason: ALWAYS,
|
|
2333
|
-
|
|
2361
|
+
lands: 0
|
|
2362
|
+
};
|
|
2363
|
+
const UNSEEN_READ = {
|
|
2364
|
+
reason: void 0,
|
|
2365
|
+
lands: LANDS_UNSEEN
|
|
2366
|
+
};
|
|
2367
|
+
const RETAINED_TAG_NAME_READ = {
|
|
2368
|
+
reason: void 0,
|
|
2369
|
+
lands: LANDS_RETAINED
|
|
2370
|
+
};
|
|
2371
|
+
const RETAINED_INPUT_READ = {
|
|
2372
|
+
reason: void 0,
|
|
2373
|
+
lands: 3
|
|
2334
2374
|
};
|
|
2335
|
-
const
|
|
2375
|
+
const exprReaders = createPassMemo(computeExprReaders, UNREAD);
|
|
2336
2376
|
const bindingReaders = createPassPathMemo(computeBindingReaders, UNREAD);
|
|
2337
2377
|
function getReasonForBinding(binding, properties) {
|
|
2338
2378
|
return bindingReaders(binding, properties).reason;
|
|
2339
2379
|
}
|
|
2340
2380
|
function getReasonForExpr(extra) {
|
|
2341
|
-
return extra.isEffect ? ALWAYS :
|
|
2381
|
+
return extra.isEffect ? ALWAYS : exprReaders(extra).reason;
|
|
2342
2382
|
}
|
|
2343
2383
|
function bindingLandsRetained(binding, properties) {
|
|
2344
|
-
return
|
|
2384
|
+
return !!(bindingReaders(binding, properties).lands & LANDS_RETAINED_INPUT);
|
|
2345
2385
|
}
|
|
2346
|
-
function
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2386
|
+
function getContentSites({ binding, properties }) {
|
|
2387
|
+
const { lands, sites, deepSites } = reduce(binding, (readers, part) => mergeReaders(readers, bindingReaders(part, properties)), UNREAD);
|
|
2388
|
+
return {
|
|
2389
|
+
unseen: !!(lands & LANDS_UNSEEN),
|
|
2390
|
+
sites,
|
|
2391
|
+
deepSites
|
|
2392
|
+
};
|
|
2350
2393
|
}
|
|
2351
|
-
function
|
|
2352
|
-
|
|
2353
|
-
for (const [read, tagNameOnly] of reads) if (leaf(read, tagNameOnly)) return true;
|
|
2354
|
-
}
|
|
2355
|
-
return false;
|
|
2394
|
+
function landsRetained(extra) {
|
|
2395
|
+
return !!extra.retained || !extra.isEffect && !!(exprReaders(extra).lands & LANDS_RETAINED);
|
|
2356
2396
|
}
|
|
2357
|
-
function
|
|
2397
|
+
function computeExprReaders(extra) {
|
|
2358
2398
|
return readersOfDerives(extra, void 0);
|
|
2359
2399
|
}
|
|
2360
2400
|
function readersOfDerives(extra, part, properties) {
|
|
@@ -2368,9 +2408,10 @@ function readersOfDerives(extra, part, properties) {
|
|
|
2368
2408
|
function readersOfDerived(extra, binding, part, properties) {
|
|
2369
2409
|
const linked = bindingReaders(binding, getDerivedPath(extra, binding, part, properties));
|
|
2370
2410
|
const exprs = extra.callSiteExprs;
|
|
2371
|
-
return linked.reason
|
|
2372
|
-
reason: mapParamReason(binding.section.program, linked.reason, exprs, true),
|
|
2373
|
-
|
|
2411
|
+
return exprs && (linked.reason || linked.sites) ? {
|
|
2412
|
+
reason: linked.reason && mapParamReason(binding.section.program, linked.reason, exprs, true),
|
|
2413
|
+
lands: linked.lands,
|
|
2414
|
+
deepSites: mergeSites(linked.deepSites, linked.sites)
|
|
2374
2415
|
} : linked;
|
|
2375
2416
|
}
|
|
2376
2417
|
function getDerivedPath(extra, binding, part, properties) {
|
|
@@ -2385,7 +2426,7 @@ function getDerivedPath(extra, binding, part, properties) {
|
|
|
2385
2426
|
}
|
|
2386
2427
|
function isReferenceTo(extra, binding) {
|
|
2387
2428
|
const { read } = extra;
|
|
2388
|
-
return !!read && read.
|
|
2429
|
+
return !!read && read.properties === void 0 && getCanonicalBinding(read.binding) === getCanonicalBinding(binding);
|
|
2389
2430
|
}
|
|
2390
2431
|
function isPartOf(binding, value) {
|
|
2391
2432
|
return !!value && binding.aliasOf === value && !isDirectAlias(binding);
|
|
@@ -2395,7 +2436,7 @@ function computeBindingReaders(binding, properties) {
|
|
|
2395
2436
|
const reason = findSlot(binding)?.reason;
|
|
2396
2437
|
let readers = reason ? {
|
|
2397
2438
|
reason,
|
|
2398
|
-
|
|
2439
|
+
lands: 0
|
|
2399
2440
|
} : UNREAD;
|
|
2400
2441
|
const aliased = binding.aliasOf;
|
|
2401
2442
|
if (properties !== true && aliased) readers = mergeReaders(readers, bindingReaders(aliased, properties === void 0 ? binding.property : concat(binding.property, properties)));
|
|
@@ -2404,7 +2445,9 @@ function computeBindingReaders(binding, properties) {
|
|
|
2404
2445
|
if (!(head === "content" && expr.rendersContent && bindingUtil.has(expr.spreadFrom, binding))) readers = mergeReaders(readers, ALWAYS_READ);
|
|
2405
2446
|
continue;
|
|
2406
2447
|
}
|
|
2407
|
-
readers = mergeReaders(
|
|
2448
|
+
readers = mergeReaders(readers, landingReaders(expr, binding));
|
|
2449
|
+
readers = mergeReaders(readers, renderingReaders(expr, binding));
|
|
2450
|
+
readers = mergeReaders(readers, readersOfDerives(expr, binding, properties));
|
|
2408
2451
|
}
|
|
2409
2452
|
for (const alias of binding.aliases) readers = mergeReaders(readers, bindingReaders(alias, properties));
|
|
2410
2453
|
if (properties === void 0) return readers;
|
|
@@ -2413,7 +2456,7 @@ function computeBindingReaders(binding, properties) {
|
|
|
2413
2456
|
return readers;
|
|
2414
2457
|
}
|
|
2415
2458
|
const property = first(properties);
|
|
2416
|
-
if (
|
|
2459
|
+
if (propertiesUtil.has(binding.excludeProperties, property)) return UNREAD;
|
|
2417
2460
|
readers = mergePropertyReaders(readers, binding, property, properties);
|
|
2418
2461
|
for (const alias of binding.aliases) readers = mergePropertyReaders(readers, alias, property, properties);
|
|
2419
2462
|
return readers;
|
|
@@ -2426,40 +2469,35 @@ function mergeReaders(a, b) {
|
|
|
2426
2469
|
if (a === UNREAD) return b;
|
|
2427
2470
|
if (b === UNREAD) return a;
|
|
2428
2471
|
const reason = mergeSources(a.reason, b.reason);
|
|
2429
|
-
const
|
|
2430
|
-
|
|
2431
|
-
|
|
2472
|
+
const lands = a.lands | b.lands;
|
|
2473
|
+
const sites = mergeSites(a.sites, b.sites);
|
|
2474
|
+
const deepSites = mergeSites(a.deepSites, b.deepSites);
|
|
2475
|
+
if (reason === a.reason && lands === a.lands && sites === a.sites && deepSites === a.deepSites) return a;
|
|
2476
|
+
if (reason === b.reason && lands === b.lands && sites === b.sites && deepSites === b.deepSites) return b;
|
|
2432
2477
|
return {
|
|
2433
2478
|
reason,
|
|
2434
|
-
|
|
2479
|
+
lands,
|
|
2480
|
+
sites,
|
|
2481
|
+
deepSites
|
|
2435
2482
|
};
|
|
2436
2483
|
}
|
|
2437
|
-
function
|
|
2438
|
-
|
|
2439
|
-
const tagNameOnly = (had ?? true) && every(binding.reads.get(read), isTagNameRead);
|
|
2440
|
-
return had === tagNameOnly ? readers : {
|
|
2441
|
-
reason: readers.reason,
|
|
2442
|
-
reads: new Map(readers.reads).set(read, tagNameOnly)
|
|
2443
|
-
};
|
|
2444
|
-
}
|
|
2445
|
-
function isRetainedInput(read, tagNameOnly) {
|
|
2446
|
-
return !tagNameOnly && isRetained(read);
|
|
2484
|
+
function mergeSites(a, b) {
|
|
2485
|
+
return reduce(b, (sites, site) => some(sites, (held) => held === site) ? sites : push(sites, site), a);
|
|
2447
2486
|
}
|
|
2448
|
-
function
|
|
2449
|
-
return
|
|
2487
|
+
function landingReaders(read, binding) {
|
|
2488
|
+
return !read.retained ? UNREAD : every(binding.reads.get(read), isTagNameRead) ? RETAINED_TAG_NAME_READ : RETAINED_INPUT_READ;
|
|
2450
2489
|
}
|
|
2451
2490
|
function isTagNameRead({ extra }) {
|
|
2452
2491
|
return !!extra.exprRoot?.tagName;
|
|
2453
2492
|
}
|
|
2454
|
-
function
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
return result || a;
|
|
2493
|
+
function renderingReaders(expr, binding) {
|
|
2494
|
+
const reads = binding.reads.get(expr);
|
|
2495
|
+
if (reads && every(reads, isTagNameRead)) return {
|
|
2496
|
+
reason: void 0,
|
|
2497
|
+
lands: 0,
|
|
2498
|
+
sites: first(reads).extra.exprRoot.tagName
|
|
2499
|
+
};
|
|
2500
|
+
return expr.derives ? UNREAD : UNSEEN_READ;
|
|
2463
2501
|
}
|
|
2464
2502
|
//#endregion
|
|
2465
2503
|
//#region src/common/helpers.ts
|
|
@@ -2502,70 +2540,302 @@ function getWrongAttrSuggestion(name) {
|
|
|
2502
2540
|
}
|
|
2503
2541
|
}
|
|
2504
2542
|
}
|
|
2505
|
-
function stringifyClassEntry(name, value) {
|
|
2506
|
-
return value ? name : "";
|
|
2507
|
-
}
|
|
2508
|
-
function stringifyStyleEntry(name, value) {
|
|
2509
|
-
return value || value === 0 ? escapeStyleAttr(name) + ":" + escapeStyleAttr(value + "") : "";
|
|
2510
|
-
}
|
|
2511
|
-
const unsafeStyleAttrReg = /[\\;]/g;
|
|
2512
|
-
const replaceUnsafeStyleAttr = (c) => c === ";" ? "\\3B " : "\\\\";
|
|
2513
|
-
function escapeStyleAttr(str) {
|
|
2514
|
-
return unsafeStyleAttrReg.test(str) ? str.replace(unsafeStyleAttrReg, replaceUnsafeStyleAttr) : str;
|
|
2515
|
-
}
|
|
2516
|
-
function escapeStyleValue(str) {
|
|
2517
|
-
let closers = "";
|
|
2518
|
-
const result = str.replace(/[\\"'{};<>]|\/(?=\*)/g, (c) => c === "<" ? "\\3C " : c === ";" ? "\\3B " : c === "{" ? "\\7B " : "\\" + c);
|
|
2519
|
-
for (const c of result) if (c === "(") closers = ")" + closers;
|
|
2520
|
-
else if (c === "[") closers = "]" + closers;
|
|
2521
|
-
else if (c === closers[0]) closers = closers.slice(1);
|
|
2522
|
-
return result + closers;
|
|
2523
|
-
}
|
|
2524
|
-
const toDelimitedString = function toDelimitedString(val, delimiter, stringify) {
|
|
2525
|
-
let str = "";
|
|
2526
|
-
let sep = "";
|
|
2527
|
-
let part;
|
|
2528
|
-
if (val) {
|
|
2529
|
-
if (typeof val !== "object") str += val;
|
|
2530
|
-
else if (Array.isArray(val)) for (const v of val) {
|
|
2531
|
-
part = toDelimitedString(v, delimiter, stringify);
|
|
2532
|
-
if (part) {
|
|
2533
|
-
str += sep + part;
|
|
2534
|
-
sep = delimiter;
|
|
2535
|
-
}
|
|
2536
|
-
}
|
|
2537
|
-
else for (const name in val) {
|
|
2538
|
-
part = stringify(name, val[name]);
|
|
2539
|
-
if (part) {
|
|
2540
|
-
str += sep + part;
|
|
2541
|
-
sep = delimiter;
|
|
2542
|
-
}
|
|
2543
|
-
}
|
|
2543
|
+
function stringifyClassEntry(name, value) {
|
|
2544
|
+
return value ? name : "";
|
|
2545
|
+
}
|
|
2546
|
+
function stringifyStyleEntry(name, value) {
|
|
2547
|
+
return value || value === 0 ? escapeStyleAttr(name) + ":" + escapeStyleAttr(value + "") : "";
|
|
2548
|
+
}
|
|
2549
|
+
const unsafeStyleAttrReg = /[\\;]/g;
|
|
2550
|
+
const replaceUnsafeStyleAttr = (c) => c === ";" ? "\\3B " : "\\\\";
|
|
2551
|
+
function escapeStyleAttr(str) {
|
|
2552
|
+
return unsafeStyleAttrReg.test(str) ? str.replace(unsafeStyleAttrReg, replaceUnsafeStyleAttr) : str;
|
|
2553
|
+
}
|
|
2554
|
+
function escapeStyleValue(str) {
|
|
2555
|
+
let closers = "";
|
|
2556
|
+
const result = str.replace(/[\\"'{};<>]|\/(?=\*)/g, (c) => c === "<" ? "\\3C " : c === ";" ? "\\3B " : c === "{" ? "\\7B " : "\\" + c);
|
|
2557
|
+
for (const c of result) if (c === "(") closers = ")" + closers;
|
|
2558
|
+
else if (c === "[") closers = "]" + closers;
|
|
2559
|
+
else if (c === closers[0]) closers = closers.slice(1);
|
|
2560
|
+
return result + closers;
|
|
2561
|
+
}
|
|
2562
|
+
const toDelimitedString = function toDelimitedString(val, delimiter, stringify) {
|
|
2563
|
+
let str = "";
|
|
2564
|
+
let sep = "";
|
|
2565
|
+
let part;
|
|
2566
|
+
if (val) {
|
|
2567
|
+
if (typeof val !== "object") str += val;
|
|
2568
|
+
else if (Array.isArray(val)) for (const v of val) {
|
|
2569
|
+
part = toDelimitedString(v, delimiter, stringify);
|
|
2570
|
+
if (part) {
|
|
2571
|
+
str += sep + part;
|
|
2572
|
+
sep = delimiter;
|
|
2573
|
+
}
|
|
2574
|
+
}
|
|
2575
|
+
else for (const name in val) {
|
|
2576
|
+
part = stringify(name, val[name]);
|
|
2577
|
+
if (part) {
|
|
2578
|
+
str += sep + part;
|
|
2579
|
+
sep = delimiter;
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
return str;
|
|
2584
|
+
};
|
|
2585
|
+
function isEventHandler(name) {
|
|
2586
|
+
return /^on[A-Z-]/.test(name);
|
|
2587
|
+
}
|
|
2588
|
+
function getEventType(name) {
|
|
2589
|
+
return name[2] === "-" ? name.slice(3) : name.slice(2).toLowerCase();
|
|
2590
|
+
}
|
|
2591
|
+
function isNullishOrFalse(value) {
|
|
2592
|
+
return value == null || value === false;
|
|
2593
|
+
}
|
|
2594
|
+
const decodeAccessor = (num) => (num + (num < 26 ? 10 : num < 962 ? 334 : 11998)).toString(36);
|
|
2595
|
+
//#endregion
|
|
2596
|
+
//#region src/common/errors.ts
|
|
2597
|
+
const lowercaseOnAttrReg = /^on[a-z]/;
|
|
2598
|
+
function assertExclusiveAttrs(attrs, onError = throwErr, isSet = isTruthy) {
|
|
2599
|
+
if (attrs) {
|
|
2600
|
+
let exclusiveAttrs;
|
|
2601
|
+
if (isSet(attrs.checkedChange)) (exclusiveAttrs ||= []).push("checkedChange");
|
|
2602
|
+
if ("checkedValue" in attrs) {
|
|
2603
|
+
(exclusiveAttrs ||= []).push("checkedValue");
|
|
2604
|
+
if ("checked" in attrs) exclusiveAttrs.push("checked");
|
|
2605
|
+
} else if (isSet(attrs.checkedValueChange)) {
|
|
2606
|
+
(exclusiveAttrs ||= []).push("checkedValueChange");
|
|
2607
|
+
if ("checked" in attrs) exclusiveAttrs.push("checked");
|
|
2608
|
+
}
|
|
2609
|
+
if (isSet(attrs.valueChange)) {
|
|
2610
|
+
(exclusiveAttrs ||= []).push("valueChange");
|
|
2611
|
+
if ("checked" in attrs && !exclusiveAttrs.includes("checked")) exclusiveAttrs.push("checked");
|
|
2612
|
+
}
|
|
2613
|
+
if (exclusiveAttrs && exclusiveAttrs.length > 1) onError(`The attributes ${joinWithAnd(exclusiveAttrs)} are mutually exclusive.`);
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
function isTruthy(value) {
|
|
2617
|
+
return value;
|
|
2618
|
+
}
|
|
2619
|
+
function throwErr(msg) {
|
|
2620
|
+
throw new Error(msg);
|
|
2621
|
+
}
|
|
2622
|
+
function joinWithAnd(a) {
|
|
2623
|
+
switch (a.length) {
|
|
2624
|
+
case 0: return "";
|
|
2625
|
+
case 1: return a[0];
|
|
2626
|
+
case 2: return `${a[0]} and ${a[1]}`;
|
|
2627
|
+
default: return `${a.slice(0, -1).join(", ")}, and ${a[a.length - 1]}`;
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
//#endregion
|
|
2631
|
+
//#region src/html/attrs.ts
|
|
2632
|
+
function _attr_class(value) {
|
|
2633
|
+
return stringAttr("class", toDelimitedString(value, " ", stringifyClassEntry));
|
|
2634
|
+
}
|
|
2635
|
+
function _attr_style(value) {
|
|
2636
|
+
return stringAttr("style", toDelimitedString(value, ";", stringifyStyleEntry));
|
|
2637
|
+
}
|
|
2638
|
+
function _attr(name, value) {
|
|
2639
|
+
return isNullishOrFalse(value) ? "" : stringifyAttr(name, value);
|
|
2640
|
+
}
|
|
2641
|
+
function stringAttr(name, value) {
|
|
2642
|
+
return value && " " + name + attrAssignment(value);
|
|
2643
|
+
}
|
|
2644
|
+
function stringifyAttr(name, value) {
|
|
2645
|
+
switch (typeof value) {
|
|
2646
|
+
case "string": return " " + name + attrAssignment(value);
|
|
2647
|
+
case "boolean": return " " + name;
|
|
2648
|
+
case "number": return " " + name + "=" + value;
|
|
2649
|
+
}
|
|
2650
|
+
return " " + name + attrAssignment(value + "");
|
|
2651
|
+
}
|
|
2652
|
+
const singleQuoteAttrReplacements = /['\r]|&(?=[#a-zA-Z])/g;
|
|
2653
|
+
const doubleQuoteAttrReplacements = /["\r]|&(?=[#a-zA-Z])/g;
|
|
2654
|
+
const needsQuotedAttr = /["'>\s]|&[#a-zA-Z]|\/$/g;
|
|
2655
|
+
function attrAssignment(value) {
|
|
2656
|
+
return value ? needsQuotedAttr.test(value) ? value[needsQuotedAttr.lastIndex - 1] === (needsQuotedAttr.lastIndex = 0, "\"") ? "='" + escapeSingleQuotedAttrValue(value) + "'" : "=\"" + escapeDoubleQuotedAttrValue(value) + "\"" : "=" + value : "";
|
|
2657
|
+
}
|
|
2658
|
+
function escapeSingleQuotedAttrValue(value) {
|
|
2659
|
+
return singleQuoteAttrReplacements.test(value) ? value.replace(singleQuoteAttrReplacements, replaceUnsafeSingleQuoteAttrChar) : value;
|
|
2660
|
+
}
|
|
2661
|
+
function replaceUnsafeSingleQuoteAttrChar(match) {
|
|
2662
|
+
return match === "'" ? "'" : match === "\r" ? " " : "&";
|
|
2663
|
+
}
|
|
2664
|
+
function escapeDoubleQuotedAttrValue(value) {
|
|
2665
|
+
return doubleQuoteAttrReplacements.test(value) ? value.replace(doubleQuoteAttrReplacements, replaceUnsafeDoubleQuoteAttrChar) : value;
|
|
2666
|
+
}
|
|
2667
|
+
function replaceUnsafeDoubleQuoteAttrChar(match) {
|
|
2668
|
+
return match === "\"" ? """ : match === "\r" ? " " : "&";
|
|
2669
|
+
}
|
|
2670
|
+
//#endregion
|
|
2671
|
+
//#region src/html/writer.ts
|
|
2672
|
+
let $chunk;
|
|
2673
|
+
function getState() {
|
|
2674
|
+
return $chunk.boundary.state;
|
|
2675
|
+
}
|
|
2676
|
+
globalThis.setImmediate || globalThis.setTimeout || globalThis.queueMicrotask;
|
|
2677
|
+
//#endregion
|
|
2678
|
+
//#region src/html/content.ts
|
|
2679
|
+
var content_exports = /* @__PURE__ */ __exportAll({
|
|
2680
|
+
_escape: () => _escape,
|
|
2681
|
+
_escape_comment: () => _escape_comment,
|
|
2682
|
+
_escape_script: () => _escape_script,
|
|
2683
|
+
_escape_style: () => _escape_style,
|
|
2684
|
+
_escape_style_value: () => _escape_style_value,
|
|
2685
|
+
_to_text: () => _to_text,
|
|
2686
|
+
_unescaped: () => _unescaped,
|
|
2687
|
+
quoteScriptTemplateLiteral: () => quoteScriptTemplateLiteral
|
|
2688
|
+
});
|
|
2689
|
+
function _to_text(val) {
|
|
2690
|
+
return val || val === 0 ? val + "" : "";
|
|
2691
|
+
}
|
|
2692
|
+
function _unescaped(val) {
|
|
2693
|
+
return val ? val + "" : val === 0 ? "0" : "";
|
|
2694
|
+
}
|
|
2695
|
+
const unsafeXMLReg = /[<&\r]/g;
|
|
2696
|
+
const replaceUnsafeXML = (c) => c === "&" ? "&" : c === "<" ? "<" : " ";
|
|
2697
|
+
const escapeXMLStr = (str) => unsafeXMLReg.test(str) ? str.replace(unsafeXMLReg, replaceUnsafeXML) : str;
|
|
2698
|
+
function _escape(val) {
|
|
2699
|
+
return val ? escapeXMLStr(val + "") : val === 0 ? "0" : "";
|
|
2700
|
+
}
|
|
2701
|
+
const unsafeScriptReg = /<(\/?script|!--)/gi;
|
|
2702
|
+
const escapeScriptStr = (str) => unsafeScriptReg.test(str) ? str.replace(unsafeScriptReg, "\\u003C$1") : str;
|
|
2703
|
+
function _escape_script(val) {
|
|
2704
|
+
return val ? escapeScriptStr(val + "") : val === 0 ? "0" : "";
|
|
2705
|
+
}
|
|
2706
|
+
const unsafeScriptTemplateLiteralReg = /[`\\\r]|\$\{|<(?=\/?script|!--)/gi;
|
|
2707
|
+
const replaceUnsafeScriptTemplateLiteral = (c) => c === "<" ? "\\x3C" : c === "\r" ? "\\r" : "\\" + c;
|
|
2708
|
+
const quoteScriptTemplateLiteral = (str) => "`" + (unsafeScriptTemplateLiteralReg.test(str) ? str.replace(unsafeScriptTemplateLiteralReg, replaceUnsafeScriptTemplateLiteral) : str) + "`";
|
|
2709
|
+
const unsafeStyleReg = /<(\/style)/gi;
|
|
2710
|
+
const escapeStyleStr = (str) => unsafeStyleReg.test(str) ? str.replace(unsafeStyleReg, "\\3C$1") : str;
|
|
2711
|
+
function _escape_style(val) {
|
|
2712
|
+
return val ? escapeStyleStr(val + "") : val === 0 ? "0" : "";
|
|
2713
|
+
}
|
|
2714
|
+
function _escape_style_value(val) {
|
|
2715
|
+
return val || val === 0 ? escapeStyleValue(val + "") : "";
|
|
2716
|
+
}
|
|
2717
|
+
const unsafeCommentReg = />/g;
|
|
2718
|
+
function escapeCommentStr(str) {
|
|
2719
|
+
if (unsafeCommentReg.test(str)) str = str.replace(unsafeCommentReg, ">");
|
|
2720
|
+
return str.startsWith(getState().commentPrefix) ? "&#" + str.charCodeAt(0) + ";" + str.slice(1) : str;
|
|
2721
|
+
}
|
|
2722
|
+
function _escape_comment(val) {
|
|
2723
|
+
return val ? escapeCommentStr(val + "") : val === 0 ? "0" : "";
|
|
2724
|
+
}
|
|
2725
|
+
//#endregion
|
|
2726
|
+
//#region src/translator/util/evaluate.ts
|
|
2727
|
+
const kEvaluated = Symbol("evaluated");
|
|
2728
|
+
function evaluate(value) {
|
|
2729
|
+
return (value.extra ??= {})[kEvaluated] ??= computeEvaluated(value);
|
|
2730
|
+
}
|
|
2731
|
+
function computeEvaluated(value) {
|
|
2732
|
+
const computed = (0, _marko_compiler_babel_utils.computeNode)(value);
|
|
2733
|
+
return computed ? {
|
|
2734
|
+
confident: true,
|
|
2735
|
+
computed: computed.value,
|
|
2736
|
+
nullable: computed.value == null,
|
|
2737
|
+
pure: true
|
|
2738
|
+
} : {
|
|
2739
|
+
confident: false,
|
|
2740
|
+
computed: void 0,
|
|
2741
|
+
nullable: isNullableExpr(value),
|
|
2742
|
+
pure: !traverseContains(value, isImpure)
|
|
2743
|
+
};
|
|
2744
|
+
}
|
|
2745
|
+
function isImpure(node) {
|
|
2746
|
+
switch (node.type) {
|
|
2747
|
+
case "ArrowFunctionExpression":
|
|
2748
|
+
case "ClassPrivateMethod":
|
|
2749
|
+
case "ClassPrivateProperty":
|
|
2750
|
+
case "FunctionExpression": return skip;
|
|
2751
|
+
case "ClassMethod":
|
|
2752
|
+
case "ObjectMethod": return node.computed && traverseContains(node.key, isImpure) || skip;
|
|
2753
|
+
case "ClassAccessorProperty":
|
|
2754
|
+
case "ClassProperty": return node.static ? void 0 : node.computed && traverseContains(node.key, isImpure) || skip;
|
|
2755
|
+
case "CallExpression": return node.callee.type === "ArrowFunctionExpression" || node.callee.type === "FunctionExpression" ? traverseContains(node.arguments, isImpure) || traverseContains(node.callee.params, isImpure) || traverseContains(node.callee.body, isImpure) || skip : true;
|
|
2756
|
+
case "AssignmentExpression":
|
|
2757
|
+
case "NewExpression":
|
|
2758
|
+
case "OptionalCallExpression":
|
|
2759
|
+
case "TaggedTemplateExpression":
|
|
2760
|
+
case "ThrowStatement":
|
|
2761
|
+
case "UpdateExpression": return true;
|
|
2762
|
+
case "UnaryExpression": return node.operator === "delete";
|
|
2763
|
+
}
|
|
2764
|
+
}
|
|
2765
|
+
function isNullableExpr(expr) {
|
|
2766
|
+
switch (expr.type) {
|
|
2767
|
+
case "ArrayExpression":
|
|
2768
|
+
case "ArrowFunctionExpression":
|
|
2769
|
+
case "BigIntLiteral":
|
|
2770
|
+
case "BinaryExpression":
|
|
2771
|
+
case "BooleanLiteral":
|
|
2772
|
+
case "ClassExpression":
|
|
2773
|
+
case "FunctionExpression":
|
|
2774
|
+
case "NewExpression":
|
|
2775
|
+
case "NumericLiteral":
|
|
2776
|
+
case "ObjectExpression":
|
|
2777
|
+
case "RegExpLiteral":
|
|
2778
|
+
case "StringLiteral":
|
|
2779
|
+
case "TemplateLiteral":
|
|
2780
|
+
case "UpdateExpression": return false;
|
|
2781
|
+
case "AssignmentExpression": switch (expr.operator) {
|
|
2782
|
+
case "=": return isNullableExpr(expr.right);
|
|
2783
|
+
case "*=":
|
|
2784
|
+
case "/=":
|
|
2785
|
+
case "%=":
|
|
2786
|
+
case "+=":
|
|
2787
|
+
case "-=":
|
|
2788
|
+
case "<<=":
|
|
2789
|
+
case ">>=":
|
|
2790
|
+
case ">>>=":
|
|
2791
|
+
case "&=":
|
|
2792
|
+
case "^=":
|
|
2793
|
+
case "|=":
|
|
2794
|
+
case "**=": return false;
|
|
2795
|
+
case "||=":
|
|
2796
|
+
case "??=": return isNullableExpr(expr.right);
|
|
2797
|
+
case "&&=": return isNullableExpr(expr.left) || isNullableExpr(expr.right);
|
|
2798
|
+
default: return true;
|
|
2799
|
+
}
|
|
2800
|
+
case "AwaitExpression": return isNullableExpr(expr.argument);
|
|
2801
|
+
case "ConditionalExpression": return isNullableExpr(expr.consequent) || isNullableExpr(expr.alternate);
|
|
2802
|
+
case "LogicalExpression": switch (expr.operator) {
|
|
2803
|
+
case "||":
|
|
2804
|
+
case "??": return isNullableExpr(expr.right);
|
|
2805
|
+
case "&&": return isNullableExpr(expr.left) || isNullableExpr(expr.right);
|
|
2806
|
+
default: return true;
|
|
2807
|
+
}
|
|
2808
|
+
case "ParenthesizedExpression": return isNullableExpr(expr.expression);
|
|
2809
|
+
case "SequenceExpression": return isNullableExpr(expr.expressions[expr.expressions.length - 1]);
|
|
2810
|
+
case "UnaryExpression": return expr.operator === "void";
|
|
2811
|
+
default: return true;
|
|
2812
|
+
}
|
|
2813
|
+
}
|
|
2814
|
+
//#endregion
|
|
2815
|
+
//#region src/translator/util/static-text.ts
|
|
2816
|
+
function isStaticText(node) {
|
|
2817
|
+
switch (node?.type) {
|
|
2818
|
+
case "MarkoText": return true;
|
|
2819
|
+
case "MarkoPlaceholder": return getPlaceholderContentType(node) === 4;
|
|
2544
2820
|
}
|
|
2545
|
-
return str;
|
|
2546
|
-
};
|
|
2547
|
-
function isEventHandler(name) {
|
|
2548
|
-
return /^on[A-Z-]/.test(name);
|
|
2549
2821
|
}
|
|
2550
|
-
function
|
|
2551
|
-
|
|
2822
|
+
function followsStaticText(path) {
|
|
2823
|
+
let prev = path.getPrevSibling();
|
|
2824
|
+
while (prev.node && getNodeContentType(prev, "endType") === null) prev = prev.getPrevSibling();
|
|
2825
|
+
return isStaticText(prev.node);
|
|
2552
2826
|
}
|
|
2553
|
-
function
|
|
2554
|
-
|
|
2827
|
+
function getPlaceholderContentType(placeholder) {
|
|
2828
|
+
const text = getStaticPlaceholderText(placeholder);
|
|
2829
|
+
return text === "" ? null : text !== void 0 && placeholder.escape ? 4 : 2;
|
|
2830
|
+
}
|
|
2831
|
+
function getStaticPlaceholderText(placeholder) {
|
|
2832
|
+
const { confident, computed } = evaluate(placeholder.value);
|
|
2833
|
+
if (confident) return placeholder.escape ? _escape(computed) : _unescaped(computed);
|
|
2555
2834
|
}
|
|
2556
|
-
const decodeAccessor = (num) => (num + (num < 26 ? 10 : num < 962 ? 334 : 11998)).toString(36);
|
|
2557
2835
|
//#endregion
|
|
2558
2836
|
//#region src/translator/util/tag-import.ts
|
|
2559
2837
|
const triggerRegExp = /\s*([\w-]+)\s*([^?|]+?)?\s*(?:\?([^|]*?))?\s*(?:\||$)/g;
|
|
2560
2838
|
const derivedImports = /* @__PURE__ */ new WeakSet();
|
|
2561
|
-
function importOrSelfReferenceName(file, request, name, nameHint) {
|
|
2562
|
-
if (isCircularRequest(file, request)) return _marko_compiler.types.identifier(name);
|
|
2563
|
-
return (0, _marko_compiler_babel_utils.importNamed)(file, request, name, nameHint);
|
|
2564
|
-
}
|
|
2565
|
-
function isCircularRequest(file, request) {
|
|
2566
|
-
const { filename } = file.opts;
|
|
2567
|
-
return request === filename || request[0] === "." && path.default.resolve(filename, "..", request) === filename;
|
|
2568
|
-
}
|
|
2569
2839
|
function trackTagImport(tagImport) {
|
|
2570
2840
|
const tags = (0, _marko_compiler_babel_utils.getFile)().metadata.marko.tags;
|
|
2571
2841
|
if (!tags.includes(tagImport)) tags.push(tagImport);
|
|
@@ -3043,7 +3313,7 @@ const groupCheckPrefixes = {
|
|
|
3043
3313
|
_write_if: "wi"
|
|
3044
3314
|
};
|
|
3045
3315
|
const [getSectionGuards] = createOutputSectionState((section) => ({
|
|
3046
|
-
|
|
3316
|
+
shares: /* @__PURE__ */ new Map(),
|
|
3047
3317
|
declarators: [_marko_compiler.types.variableDeclarator(scopeReasonIdentifier(section), callRuntime("_scope_reason"))]
|
|
3048
3318
|
}));
|
|
3049
3319
|
function buildGroupMask(groups) {
|
|
@@ -3109,6 +3379,11 @@ function isEverWritten(section, reason) {
|
|
|
3109
3379
|
const ownReason = mapBodyParams(section, reason);
|
|
3110
3380
|
return isGuardedReason(ownReason) ? getGroupsBit(ownReason.param) !== 0 : !!ownReason;
|
|
3111
3381
|
}
|
|
3382
|
+
function isWrittenForCall(section, reason, call, callSection) {
|
|
3383
|
+
if (getWriteBit(section, reason) === 1) return true;
|
|
3384
|
+
const { childScopeBinding, childSection } = call;
|
|
3385
|
+
return !!childScopeBinding && isDynamicWriteGuard(section, reason) && reduceParamGroups(reason.param, (written, groupSection, group) => written || groupSection === childSection && getWriteBit(callSection, findSlot(childScopeBinding, 5, callSection, childSection.paramReasonGroups[getParamReasonGroupIndex(childSection, group)])?.reason) === 1, false);
|
|
3386
|
+
}
|
|
3112
3387
|
function getWriteBit(section, reason) {
|
|
3113
3388
|
return isDynamicWriteGuard(section, reason) ? getGroupsBit(reason.param) : reason ? 1 : 0;
|
|
3114
3389
|
}
|
|
@@ -3127,7 +3402,7 @@ const orGroupChecks = {
|
|
|
3127
3402
|
_write_if: orGroupCheck("_write_if")
|
|
3128
3403
|
};
|
|
3129
3404
|
function orGroupCheck(check) {
|
|
3130
|
-
return (expr, section, group) => getStaticGroupBit(section, group) === 0 ? expr : orGuard(expr,
|
|
3405
|
+
return (expr, section, group) => getStaticGroupBit(section, group) === 0 ? expr : orGuard(expr, getOrShareSectionGuard(section, group, check));
|
|
3131
3406
|
}
|
|
3132
3407
|
function orGuard(guard, other) {
|
|
3133
3408
|
return guard ? _marko_compiler.types.logicalExpression("||", guard, other) : other;
|
|
@@ -3135,11 +3410,11 @@ function orGuard(guard, other) {
|
|
|
3135
3410
|
function andGuard(guard, expr) {
|
|
3136
3411
|
return guard ? _marko_compiler.types.logicalExpression("&&", guard, expr) : expr;
|
|
3137
3412
|
}
|
|
3138
|
-
function
|
|
3413
|
+
function getOrShareSectionGuard(section, params, check) {
|
|
3139
3414
|
if (!section.paramReasonGroups) return scopeReasonIdentifier(section);
|
|
3140
3415
|
const state = getSectionGuards(section);
|
|
3141
|
-
let tracking = state.
|
|
3142
|
-
if (!tracking) state.
|
|
3416
|
+
let tracking = state.shares.get(check);
|
|
3417
|
+
if (!tracking) state.shares.set(check, tracking = createGuardShares());
|
|
3143
3418
|
const index = getParamReasonGroupIndex(section, params);
|
|
3144
3419
|
const name = tracking.names.get(index);
|
|
3145
3420
|
if (name) return _marko_compiler.types.identifier(name);
|
|
@@ -3150,12 +3425,12 @@ function getOrHoistSectionGuard(section, params, check) {
|
|
|
3150
3425
|
tracking.pending.set(index, expr);
|
|
3151
3426
|
return expr;
|
|
3152
3427
|
}
|
|
3153
|
-
const
|
|
3154
|
-
tracking.names.set(index,
|
|
3428
|
+
const shared = generateUid(`${groupCheckPrefixes[check]}__${getDebugNamesAsIdentifier(params)}`);
|
|
3429
|
+
tracking.names.set(index, shared);
|
|
3155
3430
|
tracking.pending.delete(index);
|
|
3156
|
-
state.declarators.push(_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(
|
|
3157
|
-
pending.expression = _marko_compiler.types.identifier(
|
|
3158
|
-
return _marko_compiler.types.parenthesizedExpression(_marko_compiler.types.identifier(
|
|
3431
|
+
state.declarators.push(_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(shared), guard));
|
|
3432
|
+
pending.expression = _marko_compiler.types.identifier(shared);
|
|
3433
|
+
return _marko_compiler.types.parenthesizedExpression(_marko_compiler.types.identifier(shared));
|
|
3159
3434
|
}
|
|
3160
3435
|
function isDynamicWriteGuard(section, reason) {
|
|
3161
3436
|
return isGuardedReason(reason) && !isCrossSection(section, reason);
|
|
@@ -3163,20 +3438,17 @@ function isDynamicWriteGuard(section, reason) {
|
|
|
3163
3438
|
function isCrossSection(section, reason) {
|
|
3164
3439
|
return some(reason.param, (param) => !isSameOrAncestorSection(param.section, section));
|
|
3165
3440
|
}
|
|
3166
|
-
const [getStaticGroupBits] = createAnalysisSectionState(() => /* @__PURE__ */ new Map());
|
|
3167
3441
|
function getStaticGroupBit(body, group) {
|
|
3168
|
-
|
|
3169
|
-
const index = getParamReasonGroupIndex(body, group);
|
|
3170
|
-
if (!bits.has(index)) {
|
|
3171
|
-
bits.set(index, void 0);
|
|
3172
|
-
bits.set(index, isOnlyCalled(body) ? getCallsBit(body, group) : void 0);
|
|
3173
|
-
}
|
|
3174
|
-
return bits.get(index);
|
|
3442
|
+
return getBodyGroupBit(body.paramReasonGroups[getParamReasonGroupIndex(body, group)]);
|
|
3175
3443
|
}
|
|
3444
|
+
const [getBodyGroupBit] = createAnalysisMemo((group) => {
|
|
3445
|
+
const body = first(group).section;
|
|
3446
|
+
return isOnlyCalled(body) ? getCallsBit(body, group) : void 0;
|
|
3447
|
+
}, void 0);
|
|
3176
3448
|
function getCallsBit(body, group) {
|
|
3177
|
-
const
|
|
3449
|
+
const renderedBy = body.renderedBy;
|
|
3178
3450
|
let bit;
|
|
3179
|
-
for (const call of Array.isArray(
|
|
3451
|
+
for (const call of Array.isArray(renderedBy) ? renderedBy : [renderedBy]) {
|
|
3180
3452
|
const callSection = call.childScopeBinding.section;
|
|
3181
3453
|
const callBit = getWriteBit(callSection, findSlot(call.childScopeBinding, 5, callSection, group)?.reason);
|
|
3182
3454
|
if (callBit === void 0 || bit !== void 0 && bit !== callBit) return;
|
|
@@ -3185,12 +3457,12 @@ function getCallsBit(body, group) {
|
|
|
3185
3457
|
return bit;
|
|
3186
3458
|
}
|
|
3187
3459
|
function isOnlyCalled(body) {
|
|
3188
|
-
return !!body.
|
|
3460
|
+
return !!body.renderedBy && !!body.derives && !some(body.derives.binding, isUsed);
|
|
3189
3461
|
}
|
|
3190
3462
|
function isUsed(binding) {
|
|
3191
3463
|
return !!binding.reads.size || !!binding.aliases.size || !!binding.propertyAliases.size;
|
|
3192
3464
|
}
|
|
3193
|
-
function
|
|
3465
|
+
function createGuardShares() {
|
|
3194
3466
|
return {
|
|
3195
3467
|
names: /* @__PURE__ */ new Map(),
|
|
3196
3468
|
pending: /* @__PURE__ */ new Map()
|
|
@@ -3198,7 +3470,7 @@ function createGuardHoists() {
|
|
|
3198
3470
|
}
|
|
3199
3471
|
function hasGuardedReason(section) {
|
|
3200
3472
|
if (section.paramReasonGroups || isGuardedReason(mapBodyParams(section, section.reason))) return true;
|
|
3201
|
-
return
|
|
3473
|
+
return section.slots.some(isConditionalSlot);
|
|
3202
3474
|
}
|
|
3203
3475
|
function isConditionalSlot(slot) {
|
|
3204
3476
|
return isGuardedReason(mapBodyParams(slot.section, slot.reason));
|
|
@@ -3236,13 +3508,13 @@ function ensureBodySection(path) {
|
|
|
3236
3508
|
selector: void 0,
|
|
3237
3509
|
intersections: void 0,
|
|
3238
3510
|
isHoistThrough: void 0,
|
|
3239
|
-
slots:
|
|
3511
|
+
slots: [],
|
|
3240
3512
|
reason: void 0,
|
|
3241
3513
|
paramReasonGroups: void 0,
|
|
3242
3514
|
returnValueExpr: void 0,
|
|
3243
3515
|
content: getContentInfo(path),
|
|
3244
3516
|
branchExpr: void 0,
|
|
3245
|
-
|
|
3517
|
+
renderedBy: void 0,
|
|
3246
3518
|
knownTags: void 0,
|
|
3247
3519
|
derives: void 0,
|
|
3248
3520
|
dropped: !!extra.dropped,
|
|
@@ -3327,8 +3599,8 @@ function getContentInfo(path) {
|
|
|
3327
3599
|
singleChild: false
|
|
3328
3600
|
};
|
|
3329
3601
|
}
|
|
3330
|
-
const
|
|
3331
|
-
return
|
|
3602
|
+
const knownChild = end.type === "MarkoTag" && getKnownChildSection(end);
|
|
3603
|
+
return knownChild ? knownChild.content : {
|
|
3332
3604
|
startType: endType,
|
|
3333
3605
|
endType,
|
|
3334
3606
|
singleChild: endType !== 1
|
|
@@ -3340,7 +3612,7 @@ function getContentInfo(path) {
|
|
|
3340
3612
|
function getNodeContentType(path, edge) {
|
|
3341
3613
|
switch (path.type) {
|
|
3342
3614
|
case "MarkoText": return 4;
|
|
3343
|
-
case "MarkoPlaceholder": return
|
|
3615
|
+
case "MarkoPlaceholder": return getPlaceholderContentType(path.node);
|
|
3344
3616
|
case "MarkoScriptlet":
|
|
3345
3617
|
case "MarkoComment":
|
|
3346
3618
|
case "ImportDeclaration":
|
|
@@ -3349,14 +3621,75 @@ function getNodeContentType(path, edge) {
|
|
|
3349
3621
|
case "ExportDefaultDeclaration": return null;
|
|
3350
3622
|
case "MarkoTag": {
|
|
3351
3623
|
const tag = path;
|
|
3352
|
-
const tagSection =
|
|
3624
|
+
const tagSection = getKnownChildSection(tag);
|
|
3353
3625
|
if (!tagSection) return getTagContentType(tag);
|
|
3354
3626
|
return tagSection.content ? tagSection.content[edge] : null;
|
|
3355
3627
|
}
|
|
3356
3628
|
}
|
|
3357
3629
|
return 1;
|
|
3358
3630
|
}
|
|
3359
|
-
function
|
|
3631
|
+
function isKnownChild(section) {
|
|
3632
|
+
return !section.parent || !!section.renderedBy;
|
|
3633
|
+
}
|
|
3634
|
+
const [getSectionTextBefore] = createAnalysisMemo((section) => getTextBeforeIn(section, void 0), true);
|
|
3635
|
+
function getTextBeforeIn(section, content) {
|
|
3636
|
+
const { branch, derives } = section;
|
|
3637
|
+
if (branch) {
|
|
3638
|
+
const { tag } = branch;
|
|
3639
|
+
const tagSection = tag.nodeBinding.section;
|
|
3640
|
+
return !isStartMarked(branch, section, content) && (branch.kind === "for" && mayEndWithText(section) || (tag.textBefore ?? (content ? getTextBeforeIn(tagSection, content) : getSectionTextBefore(tagSection))));
|
|
3641
|
+
}
|
|
3642
|
+
if (!section.parent) return void 0;
|
|
3643
|
+
return !derives || !!section.renderedBy || mayContentFollowText(section);
|
|
3644
|
+
}
|
|
3645
|
+
function mayContentFollowText(section) {
|
|
3646
|
+
const { tag } = section.derives;
|
|
3647
|
+
const { unseen, sites, deepSites } = getContentSites(section.derives);
|
|
3648
|
+
const tagFollowsText = () => tag.textBefore ?? getSectionTextBefore(section.parent) ?? true;
|
|
3649
|
+
return unseen || !!tag.tagNameNullable && tagFollowsText() || some(sites, (site) => getSiteTextBefore(site, section) ?? tagFollowsText()) || some(deepSites, (site) => getSiteTextBefore(site, void 0) ?? true);
|
|
3650
|
+
}
|
|
3651
|
+
function getSiteTextBefore(site, content) {
|
|
3652
|
+
return site.textBefore ?? getTextBeforeIn(site.nodeBinding.section, content);
|
|
3653
|
+
}
|
|
3654
|
+
function isStartMarked(branch, section, content) {
|
|
3655
|
+
const { nodeBinding } = branch.tag;
|
|
3656
|
+
const tagSection = nodeBinding.section;
|
|
3657
|
+
return branch.kind === "try" || (branch.kind === "await" ? isAlwaysWritten(tagSection, section.reason, content) : isAlwaysWritten(tagSection, getBranchWriteReason(section), content) && isAlwaysWritten(tagSection, getWriteReason(nodeBinding), content));
|
|
3658
|
+
}
|
|
3659
|
+
function isAlwaysWritten(section, reason, content) {
|
|
3660
|
+
return content ? isWrittenForCall(section, reason, content.derives.tag, content.parent) : getWriteBit(section, reason) === 1;
|
|
3661
|
+
}
|
|
3662
|
+
function mayEndWithText(section) {
|
|
3663
|
+
return !!section.content && mayRenderText(section.content.endType);
|
|
3664
|
+
}
|
|
3665
|
+
function mayMergeWithText(path, before) {
|
|
3666
|
+
let sibling = getSibling(path, before);
|
|
3667
|
+
let parent = path.parentPath;
|
|
3668
|
+
for (;;) if (!sibling.node) {
|
|
3669
|
+
const inlinedTag = getInlinedBodyTag(parent);
|
|
3670
|
+
if (!inlinedTag) return getSectionForBody(parent) ? void 0 : false;
|
|
3671
|
+
sibling = getSibling(inlinedTag, before);
|
|
3672
|
+
parent = inlinedTag.parentPath;
|
|
3673
|
+
} else {
|
|
3674
|
+
const contentType = getNodeContentType(sibling, before ? "endType" : "startType");
|
|
3675
|
+
if (contentType !== null) return mayRenderText(contentType);
|
|
3676
|
+
sibling = getSibling(sibling, before);
|
|
3677
|
+
}
|
|
3678
|
+
}
|
|
3679
|
+
function getSibling(path, before) {
|
|
3680
|
+
return before ? path.getPrevSibling() : path.getNextSibling();
|
|
3681
|
+
}
|
|
3682
|
+
function getInlinedBodyTag(parent) {
|
|
3683
|
+
if (parent.isMarkoTagBody()) {
|
|
3684
|
+
const tag = parent.parentPath;
|
|
3685
|
+
const facts = getTagFacts(tag);
|
|
3686
|
+
if (facts.controlFlow && facts.inlineBody) return tag;
|
|
3687
|
+
}
|
|
3688
|
+
}
|
|
3689
|
+
function mayRenderText(contentType) {
|
|
3690
|
+
return contentType === 4 || contentType === 1 || contentType === 2;
|
|
3691
|
+
}
|
|
3692
|
+
function getKnownChildSection(tag) {
|
|
3360
3693
|
return tag.node.extra?.defineBodySection || !isCoreTag(tag) && analyzeTagNameType(tag) === 1 && !tag.node.extra.tagNameLoad && (0, _marko_compiler_babel_utils.loadFileForTag)(tag).ast.program.extra.section;
|
|
3361
3694
|
}
|
|
3362
3695
|
function getRendererReason(section) {
|
|
@@ -3370,7 +3703,8 @@ function getRendererReason(section) {
|
|
|
3370
3703
|
return ALWAYS;
|
|
3371
3704
|
}
|
|
3372
3705
|
function isOptionalBranch(section) {
|
|
3373
|
-
|
|
3706
|
+
const kind = section.branch?.kind;
|
|
3707
|
+
return kind === "if" || kind === "for";
|
|
3374
3708
|
}
|
|
3375
3709
|
function isInParentSection(binding, section) {
|
|
3376
3710
|
return section.parent?.id === binding.section.id;
|
|
@@ -3408,10 +3742,7 @@ function getCommonSection(section, other) {
|
|
|
3408
3742
|
}
|
|
3409
3743
|
function ensureSectionReasonGroups(section) {
|
|
3410
3744
|
ensureReasonGroups(section, section.reason);
|
|
3411
|
-
|
|
3412
|
-
}
|
|
3413
|
-
function ensureSlotReasonGroups(slot) {
|
|
3414
|
-
ensureReasonGroups(slot.section, slot.reason);
|
|
3745
|
+
for (const slot of section.slots) ensureReasonGroups(slot.section, slot.reason);
|
|
3415
3746
|
}
|
|
3416
3747
|
function ensureReasonGroups(section, reason) {
|
|
3417
3748
|
const ownReason = mapBodyParams(section, reason);
|
|
@@ -3478,9 +3809,9 @@ function setContentDerives(tag, tagExtra, binding, exprs, properties, skip) {
|
|
|
3478
3809
|
//#region src/translator/util/params-tree.ts
|
|
3479
3810
|
function exposeParamsTree(binding, bodyAnalyzed) {
|
|
3480
3811
|
binding.exposed = true;
|
|
3481
|
-
const
|
|
3812
|
+
const tree = {
|
|
3482
3813
|
binding,
|
|
3483
|
-
|
|
3814
|
+
properties: void 0,
|
|
3484
3815
|
rest: void 0
|
|
3485
3816
|
};
|
|
3486
3817
|
if (!binding.reads.size) {
|
|
@@ -3491,15 +3822,15 @@ function exposeParamsTree(binding, bodyAnalyzed) {
|
|
|
3491
3822
|
if (++aliasCount > 1) break;
|
|
3492
3823
|
}
|
|
3493
3824
|
if (!restAlias) {
|
|
3494
|
-
|
|
3495
|
-
for (const [property, alias] of binding.propertyAliases)
|
|
3825
|
+
tree.properties = Object.create(null);
|
|
3826
|
+
for (const [property, alias] of binding.propertyAliases) tree.properties[property] = exposeParamsTree(alias, bodyAnalyzed);
|
|
3496
3827
|
} else if (aliasCount === 1) {
|
|
3497
3828
|
if (hasSupersetExcludeProperties(binding, restAlias.excludeProperties)) {
|
|
3498
|
-
|
|
3499
|
-
|
|
3829
|
+
tree.rest = exposeParamsTree(restAlias, bodyAnalyzed);
|
|
3830
|
+
tree.properties = Object.create(null);
|
|
3500
3831
|
forEach(restAlias.excludeProperties, (property) => {
|
|
3501
3832
|
const propAlias = binding.propertyAliases.get(property);
|
|
3502
|
-
if (propAlias)
|
|
3833
|
+
if (propAlias) tree.properties[property] = exposeParamsTree(propAlias, bodyAnalyzed);
|
|
3503
3834
|
});
|
|
3504
3835
|
}
|
|
3505
3836
|
}
|
|
@@ -3507,7 +3838,7 @@ function exposeParamsTree(binding, bodyAnalyzed) {
|
|
|
3507
3838
|
const exportNames = (0, _marko_compiler_babel_utils.getProgram)().node.extra.exportNames;
|
|
3508
3839
|
if (isTemplateParam(binding) && !exportNames.params.has(binding)) exportNames.params.set(binding, generateUid(binding.name));
|
|
3509
3840
|
if (isDirectContentBinding(binding) && !exportNames.directContent.has(binding)) exportNames.directContent.set(binding, generateUid(`${binding.name}_direct`));
|
|
3510
|
-
return
|
|
3841
|
+
return tree;
|
|
3511
3842
|
}
|
|
3512
3843
|
function isDirectContentBinding(binding) {
|
|
3513
3844
|
if (binding.reads.size !== 1) return false;
|
|
@@ -3522,33 +3853,33 @@ function isPossiblyRead(alias) {
|
|
|
3522
3853
|
}
|
|
3523
3854
|
function hasSupersetExcludeProperties(binding, excludeProperties) {
|
|
3524
3855
|
if (excludeProperties === void 0) return false;
|
|
3525
|
-
for (const prop of binding.propertyAliases.keys()) if (!
|
|
3856
|
+
for (const prop of binding.propertyAliases.keys()) if (!propertiesUtil.has(excludeProperties, prop)) return false;
|
|
3526
3857
|
return true;
|
|
3527
3858
|
}
|
|
3528
3859
|
function getSettledParamsTree(paramsTree) {
|
|
3529
3860
|
if (!paramsTree || paramsTree.binding.pruned) return;
|
|
3530
|
-
if (!paramsTree.
|
|
3531
|
-
const
|
|
3532
|
-
for (const name in paramsTree.
|
|
3533
|
-
const prop = getSettledParamsTree(paramsTree.
|
|
3534
|
-
if (prop)
|
|
3861
|
+
if (!paramsTree.properties) return paramsTree;
|
|
3862
|
+
const properties = Object.create(null);
|
|
3863
|
+
for (const name in paramsTree.properties) {
|
|
3864
|
+
const prop = getSettledParamsTree(paramsTree.properties[name]);
|
|
3865
|
+
if (prop) properties[name] = prop;
|
|
3535
3866
|
}
|
|
3536
3867
|
return {
|
|
3537
3868
|
binding: paramsTree.binding,
|
|
3538
|
-
|
|
3869
|
+
properties,
|
|
3539
3870
|
rest: getSettledParamsTree(paramsTree.rest)
|
|
3540
3871
|
};
|
|
3541
3872
|
}
|
|
3542
3873
|
function getParamsTreeAt(paramsTree, name) {
|
|
3543
|
-
return paramsTree === true ? true : paramsTree.
|
|
3874
|
+
return paramsTree === true ? true : paramsTree.properties ? paramsTree.properties[name] || (paramsTree.rest ? getParamsTreeAt(paramsTree.rest, name) : void 0) : propertiesUtil.has(paramsTree.binding.excludeProperties, name) ? void 0 : true;
|
|
3544
3875
|
}
|
|
3545
|
-
function
|
|
3546
|
-
const keys = paramsTree.
|
|
3547
|
-
if (paramsTree.rest?.
|
|
3876
|
+
function getAllKnownPropertyNames(paramsTree) {
|
|
3877
|
+
const keys = paramsTree.properties ? Object.keys(paramsTree.properties) : [];
|
|
3878
|
+
if (paramsTree.rest?.properties) for (const key of Object.keys(paramsTree.rest.properties)) keys.push(key);
|
|
3548
3879
|
return keys;
|
|
3549
3880
|
}
|
|
3550
|
-
function
|
|
3551
|
-
return paramsTree.
|
|
3881
|
+
function hasAllKnownProperties(paramsTree) {
|
|
3882
|
+
return paramsTree.properties && (!paramsTree.rest || !!paramsTree.rest.properties);
|
|
3552
3883
|
}
|
|
3553
3884
|
//#endregion
|
|
3554
3885
|
//#region src/common/constants/accessor-prefix.ts
|
|
@@ -3677,9 +4008,9 @@ function getClosureAccessorId(binding) {
|
|
|
3677
4008
|
return id;
|
|
3678
4009
|
}
|
|
3679
4010
|
function getSectionInstancesAccessor(section) {
|
|
3680
|
-
return isOptionalBranch(section) ? getAccessorPrefix().BranchScopes + getScopeAccessor(section.branch.nodeBinding) : getAccessorPrefix().ClosureScopes + section.id;
|
|
4011
|
+
return isOptionalBranch(section) ? getAccessorPrefix().BranchScopes + getScopeAccessor(section.branch.tag.nodeBinding) : getAccessorPrefix().ClosureScopes + section.id;
|
|
3681
4012
|
}
|
|
3682
|
-
function
|
|
4013
|
+
function getSectionScopesAccessorLiteral(section) {
|
|
3683
4014
|
return _marko_compiler.types.stringLiteral(getSectionInstancesAccessor(section));
|
|
3684
4015
|
}
|
|
3685
4016
|
//#endregion
|
|
@@ -3745,7 +4076,7 @@ function finalizeSetupWork() {
|
|
|
3745
4076
|
});
|
|
3746
4077
|
}
|
|
3747
4078
|
function setCallSectionsSetup(body) {
|
|
3748
|
-
forEach(body.
|
|
4079
|
+
forEach(body.renderedBy, (call) => {
|
|
3749
4080
|
const callSection = call.childScopeBinding.section;
|
|
3750
4081
|
if (!callSection.hasSetupWork) {
|
|
3751
4082
|
callSection.hasSetupWork = true;
|
|
@@ -3757,7 +4088,7 @@ function hasOwnSetupWork(section) {
|
|
|
3757
4088
|
const info = getSetupInfo(section);
|
|
3758
4089
|
if (info.always || section.referencedClosures || callsOtherTemplateSetup(section)) return true;
|
|
3759
4090
|
for (const expr of info.exprs) {
|
|
3760
|
-
const extra =
|
|
4091
|
+
const extra = getCanonicalExpr(expr);
|
|
3761
4092
|
if (!extra.dropped && !getReferencedBindings(extra)) return true;
|
|
3762
4093
|
}
|
|
3763
4094
|
return false;
|
|
@@ -3800,13 +4131,13 @@ function onlyComparesKey(closure, canonical, bodySection, keyBinding) {
|
|
|
3800
4131
|
return found;
|
|
3801
4132
|
}
|
|
3802
4133
|
function resolvesTo(read, canonical) {
|
|
3803
|
-
const binding = getPropertyAlias(read.binding, read.
|
|
4134
|
+
const binding = getPropertyAlias(read.binding, read.properties);
|
|
3804
4135
|
return !!binding && getCanonicalBinding(binding) === canonical;
|
|
3805
4136
|
}
|
|
3806
4137
|
function resolvesThrough(read, canonical) {
|
|
3807
4138
|
let binding = read.binding;
|
|
3808
4139
|
let through = false;
|
|
3809
|
-
forEach(read.
|
|
4140
|
+
forEach(read.properties, (prop) => {
|
|
3810
4141
|
if (binding) {
|
|
3811
4142
|
through ||= getCanonicalBinding(binding) === canonical;
|
|
3812
4143
|
binding = binding.propertyAliases.get(prop);
|
|
@@ -3816,7 +4147,7 @@ function resolvesThrough(read, canonical) {
|
|
|
3816
4147
|
}
|
|
3817
4148
|
function readsKey(read, keyBinding) {
|
|
3818
4149
|
if (!read || read.getter) return false;
|
|
3819
|
-
const binding = getPropertyAlias(read.binding, read.
|
|
4150
|
+
const binding = getPropertyAlias(read.binding, read.properties);
|
|
3820
4151
|
return !!binding && getCanonicalBinding(binding) === getCanonicalBinding(keyBinding);
|
|
3821
4152
|
}
|
|
3822
4153
|
//#endregion
|
|
@@ -3831,7 +4162,7 @@ function getDeclaredBindingExpression(binding, inPlace = false) {
|
|
|
3831
4162
|
if (!aliased) return _marko_compiler.types.identifier(canonicalBinding.name);
|
|
3832
4163
|
if (property !== void 0) {
|
|
3833
4164
|
const alias = getDeclaredAlias(aliased);
|
|
3834
|
-
if (alias && !
|
|
4165
|
+
if (alias && !propertiesUtil.has(alias.excludeProperties, property)) return toMemberExpression(_marko_compiler.types.identifier(alias.name), alias.restOffset ? `${+property - alias.restOffset}` : property, !inPlace && alias.nullable);
|
|
3835
4166
|
return toMemberExpression(getDeclaredBindingExpression(aliased, inPlace), property, !inPlace && aliased.nullable);
|
|
3836
4167
|
}
|
|
3837
4168
|
return getDeclaredBindingExpression(aliased, inPlace);
|
|
@@ -3847,33 +4178,42 @@ function withPreviousLocation(newNode, originalNode) {
|
|
|
3847
4178
|
//#endregion
|
|
3848
4179
|
//#region src/translator/util/read-replacement.ts
|
|
3849
4180
|
function getReadReplacement(node, signal) {
|
|
4181
|
+
if (isOutputDOM() && !isOptimize() && node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier" && node.object.extra?.binding?.type === 6 && getReferencedBindings(node.object.extra.exprRoot)) return callRuntime("_global_read", node.object, _marko_compiler.types.stringLiteral(node.property.name));
|
|
3850
4182
|
const { extra } = node;
|
|
3851
4183
|
if (!extra || extra.assignment) return;
|
|
3852
4184
|
const { read, binding } = extra;
|
|
3853
4185
|
if (!read) {
|
|
3854
|
-
if (binding
|
|
4186
|
+
if (binding) {
|
|
4187
|
+
if (binding.type === 6) {
|
|
4188
|
+
if (isOutputDOM()) {
|
|
4189
|
+
const globals = toMemberExpression(scopeIdentifier, getAccessorProp().Global);
|
|
4190
|
+
globals.extra = extra;
|
|
4191
|
+
return globals;
|
|
4192
|
+
}
|
|
4193
|
+
} else if (node.type === "Identifier" && node.name !== binding.name) node.name = binding.name;
|
|
4194
|
+
}
|
|
3855
4195
|
return;
|
|
3856
4196
|
}
|
|
3857
4197
|
if (read.getter?.invoked) return;
|
|
3858
4198
|
const base = isOutputDOM() ? getDOMReadBase(read, extra.section, signal) : getHTMLReadBase(node, read);
|
|
3859
4199
|
if (!base) return;
|
|
3860
|
-
const expr = reduce(read.
|
|
4200
|
+
const expr = reduce(read.properties, addMember, base);
|
|
3861
4201
|
if (node.type === "Identifier" && expr.type === "Identifier") {
|
|
3862
4202
|
node.name = expr.name;
|
|
3863
4203
|
return;
|
|
3864
4204
|
}
|
|
3865
|
-
return getChainReplacement(node, expr, isOutputDOM() ? size(read.
|
|
4205
|
+
return getChainReplacement(node, expr, isOutputDOM() ? size(read.properties) : Infinity);
|
|
3866
4206
|
}
|
|
3867
4207
|
function getDOMReadBase(read, section, signal) {
|
|
3868
|
-
const { binding,
|
|
4208
|
+
const { binding, properties, getter } = read;
|
|
3869
4209
|
if (read.localFn) return isRegisteredFnExtra(read.localFn) ? toMemberExpression(localsIdentifier, getLocalsScopeAccessor(binding)) : _marko_compiler.types.identifier(binding.name);
|
|
3870
|
-
if (
|
|
4210
|
+
if (properties === void 0) {
|
|
3871
4211
|
const inlined = getSignals(section).get(binding)?.inline?.value;
|
|
3872
4212
|
if (inlined) return _marko_compiler.types.cloneNode(inlined, true);
|
|
3873
4213
|
}
|
|
3874
4214
|
if (signal?.referencedBindings === binding && !signal.storesValue) return getSignalValueIdentifier(signal);
|
|
3875
4215
|
if (getter?.hoisted) return binding.aliasOf ? callRuntime("_hoist_read_error") : _marko_compiler.types.callExpression(getBindingGetterIdentifier(binding, getter.hoisted), [getScopeExpression(section, getter.hoisted)]);
|
|
3876
|
-
if (
|
|
4216
|
+
if (properties === void 0 && binding.type === 0) return getter && _marko_compiler.types.callExpression(getBindingGetterIdentifier(binding, binding.section), [getScopeExpression(section, binding.section)]);
|
|
3877
4217
|
if (!isOptimize() && read.inOwnBody && isChildReturnVar(binding)) return callRuntime("_assert_init", section ? getScopeExpression(section, binding.section) : scopeIdentifier, getScopeAccessorLiteral(binding));
|
|
3878
4218
|
return createScopeReadExpression(binding, section);
|
|
3879
4219
|
}
|
|
@@ -3975,7 +4315,7 @@ function translateVar(tag, initialValue, kind = "const", statements) {
|
|
|
3975
4315
|
});
|
|
3976
4316
|
const declaration = _marko_compiler.types.variableDeclaration(kind, [_marko_compiler.types.variableDeclarator(tagVar, initialValue)]);
|
|
3977
4317
|
if (statements) statements.push(declaration);
|
|
3978
|
-
else tag
|
|
4318
|
+
else insertStatementBefore(tag, declaration);
|
|
3979
4319
|
}
|
|
3980
4320
|
function isTagVarAssigned(tag) {
|
|
3981
4321
|
return !!(tag.node.var.type === "Identifier" && tag.scope.getBinding(tag.node.var.name)?.constantViolations.length);
|
|
@@ -4012,7 +4352,7 @@ function removeUndeclared(pattern, section) {
|
|
|
4012
4352
|
function translateAliasInSection(tag, id, alias, kind) {
|
|
4013
4353
|
const aliased = alias.aliasOf;
|
|
4014
4354
|
const value = getDeclaredBindingExpression(aliased);
|
|
4015
|
-
getSectionTarget(tag, alias.section)
|
|
4355
|
+
insertStatementBefore(getSectionTarget(tag, alias.section), _marko_compiler.types.variableDeclaration(kind, [_marko_compiler.types.variableDeclarator(id, alias.property === void 0 ? value : toMemberExpression(value, alias.property, aliased.nullable))]));
|
|
4016
4356
|
}
|
|
4017
4357
|
function translateRest(tag, id, rest, kind) {
|
|
4018
4358
|
const source = getCanonicalBinding(rest.aliasOf);
|
|
@@ -4024,7 +4364,7 @@ function translateRest(tag, id, rest, kind) {
|
|
|
4024
4364
|
inPlace = false;
|
|
4025
4365
|
}
|
|
4026
4366
|
const value = getDeclaredBindingExpression(from, inPlace);
|
|
4027
|
-
target
|
|
4367
|
+
insertStatementBefore(target, _marko_compiler.types.variableDeclaration(kind, [_marko_compiler.types.variableDeclarator(getRestPattern(rest, id, from, false), inPlace ? value : withRestFallback(rest, from, value))]));
|
|
4028
4368
|
}
|
|
4029
4369
|
function getRestPattern(rest, id, from, shorthand) {
|
|
4030
4370
|
const restElement = _marko_compiler.types.restElement(id);
|
|
@@ -4140,7 +4480,7 @@ function consumeHTML(path) {
|
|
|
4140
4480
|
}
|
|
4141
4481
|
function flushBefore(path) {
|
|
4142
4482
|
const expr = consumeHTML(path);
|
|
4143
|
-
if (expr) path
|
|
4483
|
+
if (expr) insertStatementBefore(path, expr);
|
|
4144
4484
|
}
|
|
4145
4485
|
function flushInto(path) {
|
|
4146
4486
|
const target = path.isProgram() ? path : path.get("body");
|
|
@@ -4153,7 +4493,7 @@ function markNode(path, nodeBinding, reason, deferred) {
|
|
|
4153
4493
|
if (isOutputHTML()) {
|
|
4154
4494
|
if (reason) {
|
|
4155
4495
|
const section = getSection(path);
|
|
4156
|
-
writeTo$1(path, deferred)`${callRuntime("
|
|
4496
|
+
writeTo$1(path, deferred)`${callRuntime("_el_mark", getScopeIdIdentifier(section), getScopeAccessorLiteral(nodeBinding), getWriteGuard(section, reason, true))}`;
|
|
4157
4497
|
}
|
|
4158
4498
|
}
|
|
4159
4499
|
}
|
|
@@ -4164,12 +4504,14 @@ function unwrapWrite(write) {
|
|
|
4164
4504
|
//#region src/translator/util/signals.ts
|
|
4165
4505
|
const [getSignals] = createOutputSectionState(() => /* @__PURE__ */ new Map());
|
|
4166
4506
|
const [getClosureSignalBuilder, _setClosureSignalBuilder] = createOutputSectionState();
|
|
4167
|
-
function setClosureSignalBuilder(tag,
|
|
4168
|
-
|
|
4507
|
+
function setClosureSignalBuilder(tag, build) {
|
|
4508
|
+
const section = getSectionForBody(tag.get("body"));
|
|
4509
|
+
_setClosureSignalBuilder(section, build || ((_closure, render) => buildClosureHop(section, render)));
|
|
4169
4510
|
}
|
|
4170
|
-
function buildClosureHop(
|
|
4171
|
-
const
|
|
4172
|
-
|
|
4511
|
+
function buildClosureHop(section, render) {
|
|
4512
|
+
const branch = section.branch;
|
|
4513
|
+
const accessor = getScopeAccessorLiteral(branch.tag.nodeBinding, true);
|
|
4514
|
+
return branch.kind === "if" ? callRuntime("_if_closure", accessor, _marko_compiler.types.numericLiteral(branch.index), render) : callRuntime("_for_closure", accessor, render);
|
|
4173
4515
|
}
|
|
4174
4516
|
const [getOwnerResumedByMarker, setOwnerResumedByMarker] = createOutputSectionState();
|
|
4175
4517
|
function setSectionOwnerResumedByMarker(section) {
|
|
@@ -4281,7 +4623,7 @@ function getSignal(section, referencedBindings, name) {
|
|
|
4281
4623
|
const render = buildSignalFn(signal);
|
|
4282
4624
|
const closureSignalBuilder = getClosureSignalBuilder(section);
|
|
4283
4625
|
if (closureSignalBuilder && !isDynamicClosure(section, closure)) return closureSignalBuilder(closure, render);
|
|
4284
|
-
return callRuntime("_closure_get", getClosureAccessorLiteral(closure), render, isInParentSection(closure, section) ? void 0 : _marko_compiler.types.arrowFunctionExpression([scopeIdentifier], getScopeExpression(section, closure.section)), isChangeableDynamicClosure(section, closure) ? _marko_compiler.types.stringLiteral(
|
|
4626
|
+
return callRuntime("_closure_get", getClosureAccessorLiteral(closure), render, isInParentSection(closure, section) ? void 0 : _marko_compiler.types.arrowFunctionExpression([scopeIdentifier], getScopeExpression(section, closure.section)), isChangeableDynamicClosure(section, closure) ? _marko_compiler.types.stringLiteral(getResumeRegistryId(section, closure, "subscribe")) : void 0);
|
|
4285
4627
|
};
|
|
4286
4628
|
}
|
|
4287
4629
|
return signal;
|
|
@@ -4434,7 +4776,7 @@ function getSignalValueIdentifier(signal) {
|
|
|
4434
4776
|
function isOwnValueRead(node, binding) {
|
|
4435
4777
|
const extra = node.extra;
|
|
4436
4778
|
const read = extra?.read;
|
|
4437
|
-
return !!read && !extra.assignment && read.binding === binding && read.
|
|
4779
|
+
return !!read && !extra.assignment && read.binding === binding && read.properties === void 0 && !read.getter?.invoked;
|
|
4438
4780
|
}
|
|
4439
4781
|
function subscribe(references, intersection) {
|
|
4440
4782
|
if (references) forEach(references, (binding) => {
|
|
@@ -4480,9 +4822,11 @@ function addStatement(type, targetSection, expr, statement, isPure) {
|
|
|
4480
4822
|
if (!isPure || type === "effect") signal.storesValue = true;
|
|
4481
4823
|
}
|
|
4482
4824
|
function addTagStatement(tag, statement) {
|
|
4483
|
-
if (isOutputHTML()) tag
|
|
4484
|
-
else
|
|
4485
|
-
|
|
4825
|
+
if (isOutputHTML()) insertStatementBefore(tag, statement);
|
|
4826
|
+
else {
|
|
4827
|
+
addStatement("render", getSection(tag), tag.node.attributes[0]?.value.extra, statement);
|
|
4828
|
+
replaceWithStatements(tag);
|
|
4829
|
+
}
|
|
4486
4830
|
}
|
|
4487
4831
|
function addValue(targetSection, expr, signal, value) {
|
|
4488
4832
|
const parentSignal = getSignal(targetSection, getReferencedBindings(expr));
|
|
@@ -4500,7 +4844,7 @@ function buildResumeRegisterKey(section, referencedBindings, type) {
|
|
|
4500
4844
|
}
|
|
4501
4845
|
return `${section.id}${name}${type ? "/" + type : ""}`;
|
|
4502
4846
|
}
|
|
4503
|
-
function
|
|
4847
|
+
function getResumeRegistryId(section, referencedBindings, type) {
|
|
4504
4848
|
const { markoOpts, opts: { filename } } = (0, _marko_compiler_babel_utils.getFile)();
|
|
4505
4849
|
const key = buildResumeRegisterKey(section, referencedBindings, type);
|
|
4506
4850
|
return (0, _marko_compiler_babel_utils.getTemplateId)(markoOpts, filename, key);
|
|
@@ -4523,7 +4867,7 @@ function writeSignals(section) {
|
|
|
4523
4867
|
traverseReplace(signal, "effect", replaceEffectNode);
|
|
4524
4868
|
const effectIdentifier = getSignalEffectIdentifier(signal);
|
|
4525
4869
|
const effectFn = _marko_compiler.types.arrowFunctionExpression([scopeIdentifier], toOnlyExpressionOrBlock(signal.effect));
|
|
4526
|
-
effectDeclarator = _marko_compiler.types.variableDeclarator(effectIdentifier, callRuntime("_script", _marko_compiler.types.stringLiteral(
|
|
4870
|
+
effectDeclarator = _marko_compiler.types.variableDeclarator(effectIdentifier, callRuntime("_script", _marko_compiler.types.stringLiteral(getResumeRegistryId(section, signal.referencedBindings)), effectFn));
|
|
4527
4871
|
}
|
|
4528
4872
|
let signalDeclaration;
|
|
4529
4873
|
if (signal.build) {
|
|
@@ -4531,7 +4875,7 @@ function writeSignals(section) {
|
|
|
4531
4875
|
const buildsEagerForward = _marko_compiler.types.isIdentifier(value) || _marko_compiler.types.isCallExpression(value) && _marko_compiler.types.isIdentifier(value.arguments.at(-1));
|
|
4532
4876
|
if (!value || !signal.register && !signal.referenced && _marko_compiler.types.isFunction(value) && _marko_compiler.types.isBlockStatement(value.body) && !value.body.body.length) return;
|
|
4533
4877
|
if (_marko_compiler.types.isCallExpression(value)) trimEmptyArgs(value.arguments);
|
|
4534
|
-
if (signal.register) value = callRuntime("_var_resume", _marko_compiler.types.stringLiteral(
|
|
4878
|
+
if (signal.register) value = callRuntime("_var_resume", _marko_compiler.types.stringLiteral(getResumeRegistryId(section, signal.referencedBindings, "var")), value);
|
|
4535
4879
|
if (buildsEagerForward) forEach(signal.forwards, writeSignal);
|
|
4536
4880
|
const signalDeclarator = _marko_compiler.types.variableDeclarator(signal.identifier, value);
|
|
4537
4881
|
signalDeclaration = !section.parent && !signal.referencedBindings && (_marko_compiler.types.isFunctionExpression(value) || _marko_compiler.types.isArrowFunctionExpression(value)) ? _marko_compiler.types.functionDeclaration(signal.identifier, value.params, _marko_compiler.types.isExpression(value.body) ? _marko_compiler.types.blockStatement([_marko_compiler.types.expressionStatement(value.body)]) : value.body) : _marko_compiler.types.variableDeclaration("const", [signalDeclarator]);
|
|
@@ -4552,16 +4896,16 @@ function writeGetters(section) {
|
|
|
4552
4896
|
const getterIdentifier = getBindingGetterIdentifier(binding, hoistSection);
|
|
4553
4897
|
const accessors = [getScopeAccessorLiteral(binding, true)];
|
|
4554
4898
|
if (hoistSection) forEachAncestorSection(binding.section, hoistSection, pushInstancesAccessor, accessors);
|
|
4555
|
-
(0, _marko_compiler_babel_utils.getProgram)().node.body.push(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(getterIdentifier, hoistSection ? hasReference ? callRuntime("_hoist_resume", _marko_compiler.types.stringLiteral(
|
|
4899
|
+
(0, _marko_compiler_babel_utils.getProgram)().node.body.push(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(getterIdentifier, hoistSection ? hasReference ? callRuntime("_hoist_resume", _marko_compiler.types.stringLiteral(getResumeRegistryId(hoistSection, binding, "hoist")), ...accessors) : callRuntime("_hoist", ...accessors) : callRuntime("_el", _marko_compiler.types.stringLiteral(getResumeRegistryId(section, binding)), ...accessors))]));
|
|
4556
4900
|
}
|
|
4557
4901
|
});
|
|
4558
4902
|
}
|
|
4559
4903
|
function pushInstancesAccessor(section, accessors) {
|
|
4560
|
-
const instancesAccessor =
|
|
4904
|
+
const instancesAccessor = getSectionScopesAccessorLiteral(section);
|
|
4561
4905
|
const { branch } = section;
|
|
4562
|
-
accessors.push(branch?.
|
|
4906
|
+
accessors.push(branch?.kind === "if" && Array.isArray(branch.tag.nodeBinding.branchBodies) ? _marko_compiler.types.arrayExpression([
|
|
4563
4907
|
instancesAccessor,
|
|
4564
|
-
_marko_compiler.types.stringLiteral(getAccessorPrefix().ConditionalRenderer + getScopeAccessor(branch.nodeBinding)),
|
|
4908
|
+
_marko_compiler.types.stringLiteral(getAccessorPrefix().ConditionalRenderer + getScopeAccessor(branch.tag.nodeBinding)),
|
|
4565
4909
|
_marko_compiler.types.numericLiteral(branch.index)
|
|
4566
4910
|
]) : instancesAccessor);
|
|
4567
4911
|
}
|
|
@@ -4570,12 +4914,12 @@ function writeRegisteredFns() {
|
|
|
4570
4914
|
const statements = [];
|
|
4571
4915
|
for (const registeredFn of registeredFns) {
|
|
4572
4916
|
let fn;
|
|
4573
|
-
if (registeredFn.
|
|
4917
|
+
if (registeredFn.referencesScope || registeredFn.referencedLocals) {
|
|
4574
4918
|
let params;
|
|
4575
4919
|
let prologue;
|
|
4576
4920
|
if (registeredFn.referencedLocals) {
|
|
4577
4921
|
params = [localsIdentifier];
|
|
4578
|
-
if (registeredFn.
|
|
4922
|
+
if (registeredFn.referencesScope) prologue = [_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(scopeIdentifier, _marko_compiler.types.memberExpression(localsIdentifier, _marko_compiler.types.identifier(getAccessorProp().Owner)))])];
|
|
4579
4923
|
} else params = [scopeIdentifier];
|
|
4580
4924
|
const body = toReturnedFunction(registeredFn.node, prologue);
|
|
4581
4925
|
fn = _marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(registeredFn.id), _marko_compiler.types.arrowFunctionExpression(params, body.length === 1 && body[0].type === "ReturnStatement" ? body[0].argument : _marko_compiler.types.blockStatement(body)))]);
|
|
@@ -4583,7 +4927,7 @@ function writeRegisteredFns() {
|
|
|
4583
4927
|
else fn = _marko_compiler.types.functionDeclaration(_marko_compiler.types.identifier(registeredFn.id), registeredFn.node.params, registeredFn.node.body.type === "BlockStatement" ? registeredFn.node.body : _marko_compiler.types.blockStatement([_marko_compiler.types.returnStatement(registeredFn.node.body)]), registeredFn.node.generator, registeredFn.node.async);
|
|
4584
4928
|
statements.push(fn);
|
|
4585
4929
|
}
|
|
4586
|
-
for (const registeredFn of registeredFns) statements.push(_marko_compiler.types.expressionStatement(registerRuntimeValue(registeredFn.
|
|
4930
|
+
for (const registeredFn of registeredFns) statements.push(_marko_compiler.types.expressionStatement(registerRuntimeValue(registeredFn.registryId, _marko_compiler.types.identifier(registeredFn.id))));
|
|
4587
4931
|
(0, _marko_compiler_babel_utils.getProgram)().node.body.push(...statements);
|
|
4588
4932
|
}
|
|
4589
4933
|
function toReturnedFunction(rawFn, prologue) {
|
|
@@ -4623,7 +4967,7 @@ function writeHTMLResumeStatements(path) {
|
|
|
4623
4967
|
const subscribeArg = isGuardedReason(closureScopesReason) && !isSameReason(closureScopesReason, sectionReason) ? getExprIfWritten(closure.section, closureScopesReason, identifier) : identifier;
|
|
4624
4968
|
const changeable = isChangeableDynamicClosure(section, closure);
|
|
4625
4969
|
if (subscribeArg) addWriteScopeBuilder(section, (expr) => {
|
|
4626
|
-
const resumeId = changeable && _marko_compiler.types.stringLiteral(
|
|
4970
|
+
const resumeId = changeable && _marko_compiler.types.stringLiteral(getResumeRegistryId(section, closure, "subscribe"));
|
|
4627
4971
|
return callRuntime("_subscribe", subscribeArg, expr, resumeId, resumeId && markerGuard);
|
|
4628
4972
|
});
|
|
4629
4973
|
}
|
|
@@ -4631,7 +4975,7 @@ function writeHTMLResumeStatements(path) {
|
|
|
4631
4975
|
});
|
|
4632
4976
|
for (let i = allSignals.length; i--;) if (allSignals[i].hasHTMLEffect) {
|
|
4633
4977
|
const signalRefs = allSignals[i].referencedBindings;
|
|
4634
|
-
body.push(_marko_compiler.types.expressionStatement(callRuntime("_script", scopeIdIdentifier, _marko_compiler.types.stringLiteral(
|
|
4978
|
+
body.push(_marko_compiler.types.expressionStatement(callRuntime("_script", scopeIdIdentifier, _marko_compiler.types.stringLiteral(getResumeRegistryId(section, signalRefs)), markerGuard)));
|
|
4635
4979
|
}
|
|
4636
4980
|
const debug = !isOptimize();
|
|
4637
4981
|
const writeScopeBuilder = getSectionWriteScopeBuilder(section);
|
|
@@ -4827,25 +5171,23 @@ function registerFnExpression(node) {
|
|
|
4827
5171
|
if (isRegisteredFnExtra(extra)) {
|
|
4828
5172
|
const id = extra.name;
|
|
4829
5173
|
const referencesScope = extra.referencesScope;
|
|
4830
|
-
const referencedBindings = getReferencedBindingsInFunction(extra);
|
|
4831
5174
|
const referencedLocals = extra.referencedLocalBindingsInFunction;
|
|
4832
5175
|
getRegisteredFns().push({
|
|
4833
5176
|
id,
|
|
4834
5177
|
node,
|
|
4835
|
-
|
|
5178
|
+
registryId: extra.registryId,
|
|
4836
5179
|
section: extra.section,
|
|
4837
5180
|
referencesScope,
|
|
4838
|
-
referencedBindings,
|
|
4839
5181
|
referencedLocals
|
|
4840
5182
|
});
|
|
4841
5183
|
if (referencedLocals) {
|
|
4842
5184
|
const properties = [];
|
|
4843
|
-
if (referencesScope
|
|
5185
|
+
if (referencesScope) properties.push(_marko_compiler.types.objectProperty(_marko_compiler.types.identifier(getAccessorProp().Owner), scopeIdentifier));
|
|
4844
5186
|
forEach(referencedLocals, (binding) => {
|
|
4845
5187
|
properties.push(toObjectProperty(getLocalsScopeAccessor(binding), getDeclaredBindingExpression(binding)));
|
|
4846
5188
|
});
|
|
4847
5189
|
return _marko_compiler.types.callExpression(_marko_compiler.types.identifier(id), [_marko_compiler.types.objectExpression(properties)]);
|
|
4848
|
-
} else if (referencesScope
|
|
5190
|
+
} else if (referencesScope) return _marko_compiler.types.callExpression(_marko_compiler.types.identifier(id), [scopeIdentifier]);
|
|
4849
5191
|
else return _marko_compiler.types.identifier(id);
|
|
4850
5192
|
}
|
|
4851
5193
|
}
|
|
@@ -4889,7 +5231,7 @@ function translateAttrs(tag, paramsTree = true, skip, statements = [], contentKe
|
|
|
4889
5231
|
if (child.isMarkoTag()) {
|
|
4890
5232
|
if ((0, _marko_compiler_babel_utils.isAttributeTag)(child)) {
|
|
4891
5233
|
const attrTagMeta = attrTagLookup[getTagName(child)];
|
|
4892
|
-
if (
|
|
5234
|
+
if (propertiesUtil.has(skip, attrTagMeta.name)) continue;
|
|
4893
5235
|
if (attrTagMeta.dynamic) i = addDynamicAttrTagStatements(attrTags, i, attrTagLookup, statements, paramsTree, contentKey);
|
|
4894
5236
|
else {
|
|
4895
5237
|
const translatedAttrTag = translateAttrs(child, getParamsTreeAt(paramsTree, attrTagMeta.name), void 0, statements, contentKey);
|
|
@@ -5020,7 +5362,7 @@ function buildContent$1(body) {
|
|
|
5020
5362
|
if (isOutputHTML()) {
|
|
5021
5363
|
const serialized = getRendererReason(bodySection);
|
|
5022
5364
|
body.node.body.unshift(getScopeReasonStatement(bodySection));
|
|
5023
|
-
return callRuntime(serialized ? "_content_resume" : "_content", _marko_compiler.types.stringLiteral(
|
|
5365
|
+
return callRuntime(serialized ? "_content_resume" : "_content", _marko_compiler.types.stringLiteral(getResumeRegistryId(bodySection, "content")), _marko_compiler.types.arrowFunctionExpression(body.node.params, _marko_compiler.types.blockStatement(body.node.body)), getScopeIdIdentifier(getSection(getAttributeTagParent(body.parentPath))), serialized && getRegisteredLocals(bodySection));
|
|
5024
5366
|
} else {
|
|
5025
5367
|
const renderer = getSectionRendererIdentifier(bodySection);
|
|
5026
5368
|
if (renderer) {
|
|
@@ -5039,7 +5381,7 @@ function getLocalClosureValues(bodySection) {
|
|
|
5039
5381
|
if (bodySection.localClosures) return _marko_compiler.types.objectExpression(toArray(bodySection.localClosures, (closure) => toObjectProperty(getScopeAccessor(closure, true), getDeclaredBindingExpression(closure))));
|
|
5040
5382
|
}
|
|
5041
5383
|
function getSingleKnownSpread(paramsTree, attributes) {
|
|
5042
|
-
if (paramsTree === true || !
|
|
5384
|
+
if (paramsTree === true || !hasAllKnownProperties(paramsTree)) return;
|
|
5043
5385
|
let binding;
|
|
5044
5386
|
for (let i = attributes.length; i--;) {
|
|
5045
5387
|
const attr = attributes[i];
|
|
@@ -5047,7 +5389,7 @@ function getSingleKnownSpread(paramsTree, attributes) {
|
|
|
5047
5389
|
const spreadFrom = attr.value.extra?.spreadFrom;
|
|
5048
5390
|
if (binding || !spreadFrom || Array.isArray(spreadFrom)) return;
|
|
5049
5391
|
binding = spreadFrom;
|
|
5050
|
-
} else if (binding && !
|
|
5392
|
+
} else if (binding && !propertiesUtil.has(binding.excludeProperties, attr.name)) return;
|
|
5051
5393
|
}
|
|
5052
5394
|
return binding;
|
|
5053
5395
|
}
|
|
@@ -5063,6 +5405,7 @@ function knownTagAnalyze(tag, childSection, childParamsTree) {
|
|
|
5063
5405
|
const section = ensureSection(tag);
|
|
5064
5406
|
const tagBody = tag.get("body");
|
|
5065
5407
|
const tagExtra = tag.node.extra ??= {};
|
|
5408
|
+
tagExtra.textBefore = mayMergeWithText(tag, true);
|
|
5066
5409
|
tagExtra.childScopeBinding = createBinding("#childScope", 0, section);
|
|
5067
5410
|
tagExtra.childSection = childSection;
|
|
5068
5411
|
ensureBodySection(tagBody);
|
|
@@ -5072,7 +5415,7 @@ function knownTagAnalyze(tag, childSection, childParamsTree) {
|
|
|
5072
5415
|
const recursive = isSameOrAncestorSection(childSection, section);
|
|
5073
5416
|
let exprs;
|
|
5074
5417
|
if (childSection.program === section.program) {
|
|
5075
|
-
childSection.
|
|
5418
|
+
childSection.renderedBy = push(childSection.renderedBy, tagExtra);
|
|
5076
5419
|
if (recursive) getRecursiveTags().push(tag);
|
|
5077
5420
|
else exprs = analyzeKnownTagParams(tag, exposeChildParamsTree(childSection));
|
|
5078
5421
|
} else exprs = analyzeKnownTagParams(tag, childParamsTree);
|
|
@@ -5111,7 +5454,7 @@ function assertTerminates(tag, childSection) {
|
|
|
5111
5454
|
const callers = /* @__PURE__ */ new Set([getSection(tag)]);
|
|
5112
5455
|
for (const caller of callers) {
|
|
5113
5456
|
if (caller === childSection) throw tag.get("name").buildCodeFrameError(`A ${childSection === (0, _marko_compiler_babel_utils.getProgram)().node.extra.section ? "template" : "`<define>`"} that renders itself outside a branch never terminates. Render \`<${getTagNameHint(tag.node)}>\` inside a branch that eventually stops, such as \`<if>\`.`);
|
|
5114
|
-
forEach(caller.
|
|
5457
|
+
forEach(caller.renderedBy, (call) => {
|
|
5115
5458
|
callers.add(call.childScopeBinding.section);
|
|
5116
5459
|
});
|
|
5117
5460
|
}
|
|
@@ -5124,7 +5467,7 @@ function analyzeKnownTagParams(tag, paramsTree) {
|
|
|
5124
5467
|
const attrExprs = /* @__PURE__ */ new Set([tagExtra]);
|
|
5125
5468
|
tagExtra[kParamsTree] = paramsTree;
|
|
5126
5469
|
const exprs = tagExtra[kKnownExprs] = analyzeParams(tagExtra, getSection(tag), tag, paramsTree, attrExprs);
|
|
5127
|
-
setTagContentDerives(tag, paramsTree?.
|
|
5470
|
+
setTagContentDerives(tag, paramsTree?.properties?.[tag.node.arguments?.length ?? 0]?.binding, exprs);
|
|
5128
5471
|
addReasonExprs(ensureSlot(tagExtra.childScopeBinding), fromIter(attrExprs));
|
|
5129
5472
|
return exprs;
|
|
5130
5473
|
}
|
|
@@ -5140,7 +5483,7 @@ function isChildScopeResumed(section, tagExtra) {
|
|
|
5140
5483
|
}
|
|
5141
5484
|
function getRenderArgs(tag, properties) {
|
|
5142
5485
|
const args = tag.node.arguments;
|
|
5143
|
-
const renderArgs = args?.length && !args.every(isDroppedNode) ? args.map(toRenderArg) : [];
|
|
5486
|
+
const renderArgs = args?.length && (properties.length || !args.every(isDroppedNode)) ? args.map(toRenderArg) : [];
|
|
5144
5487
|
if (!renderArgs.length || properties.length) renderArgs.push(propsToExpression(properties));
|
|
5145
5488
|
return renderArgs;
|
|
5146
5489
|
}
|
|
@@ -5148,7 +5491,7 @@ function isDroppedNode(node) {
|
|
|
5148
5491
|
return !!node.extra?.dropped;
|
|
5149
5492
|
}
|
|
5150
5493
|
function toRenderArg(arg) {
|
|
5151
|
-
return isDroppedNode(arg) ?
|
|
5494
|
+
return isDroppedNode(arg) ? absentArg(0) : arg;
|
|
5152
5495
|
}
|
|
5153
5496
|
function knownTagTranslateHTML(tag, tagIdentifier) {
|
|
5154
5497
|
const { node } = tag;
|
|
@@ -5158,8 +5501,8 @@ function knownTagTranslateHTML(tag, tagIdentifier) {
|
|
|
5158
5501
|
writeHTMLResumeStatements(tag);
|
|
5159
5502
|
const tagVar = node.var;
|
|
5160
5503
|
const section = getSection(tag);
|
|
5161
|
-
const attrsTree = paramsTree?.
|
|
5162
|
-
const { properties, statements } = paramsTree && !paramsTree.
|
|
5504
|
+
const attrsTree = paramsTree?.properties?.[tag.node.arguments?.length || 0];
|
|
5505
|
+
const { properties, statements } = paramsTree && !paramsTree.properties || attrsTree ? translateAttrs(tag, attrsTree) : {
|
|
5163
5506
|
properties: [],
|
|
5164
5507
|
statements: []
|
|
5165
5508
|
};
|
|
@@ -5170,17 +5513,17 @@ function knownTagTranslateHTML(tag, tagIdentifier) {
|
|
|
5170
5513
|
statements.push(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(peekScopeId, callRuntime("_peek_scope_id"))]));
|
|
5171
5514
|
const childScopeSlot = findSlot(childScopeBinding);
|
|
5172
5515
|
writeSlot(childScopeSlot, callRuntime("_existing_scope", peekScopeId));
|
|
5173
|
-
if (tagVar) varStatement = _marko_compiler.types.expressionStatement(getExprIfWritten(section, childScopeSlot.reason, callRuntime("_var", getScopeIdIdentifier(section), getScopeOffsetAccessorLiteral(childScopeBinding), peekScopeId, _marko_compiler.types.stringLiteral(
|
|
5516
|
+
if (tagVar) varStatement = _marko_compiler.types.expressionStatement(getExprIfWritten(section, childScopeSlot.reason, callRuntime("_var", getScopeIdIdentifier(section), getScopeOffsetAccessorLiteral(childScopeBinding), peekScopeId, _marko_compiler.types.stringLiteral(getResumeRegistryId(section, tagVar.extra?.binding, "var")))));
|
|
5174
5517
|
}
|
|
5175
5518
|
if (childSection.paramReasonGroups) {
|
|
5176
5519
|
const childGroupMask = buildChildGroupMask(section, childScopeBinding, childSection.paramReasonGroups);
|
|
5177
|
-
if (childGroupMask)
|
|
5520
|
+
if (childGroupMask) statements.unshift(_marko_compiler.types.expressionStatement(callRuntime("_set_scope_reason", childGroupMask)));
|
|
5178
5521
|
}
|
|
5179
5522
|
if (tagVar) {
|
|
5180
5523
|
translateVar(tag, _marko_compiler.types.callExpression(tagIdentifier, getRenderArgs(tag, properties)), "let", statements);
|
|
5181
5524
|
if (varStatement) statements.push(varStatement);
|
|
5182
5525
|
} else statements.push(_marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(tagIdentifier, getRenderArgs(tag, properties))));
|
|
5183
|
-
|
|
5526
|
+
replaceWithStatements(tag, statements);
|
|
5184
5527
|
}
|
|
5185
5528
|
function knownTagTranslateDOM(tag, getBindingIdentifier, callSetup) {
|
|
5186
5529
|
const tagSection = getSection(tag);
|
|
@@ -5209,7 +5552,7 @@ function getCallSiteSources(param) {
|
|
|
5209
5552
|
if (sourcesByParam.has(param)) return sourcesByParam.get(param);
|
|
5210
5553
|
const body = param.section;
|
|
5211
5554
|
let sources;
|
|
5212
|
-
forEach(body.
|
|
5555
|
+
forEach(body.renderedBy, (call) => {
|
|
5213
5556
|
sources = mergeSources(sources, getSourcesForExprs(mapParamBindingToExpr(call[kKnownExprs], param)));
|
|
5214
5557
|
});
|
|
5215
5558
|
sourcesByParam.set(param, sources);
|
|
@@ -5263,7 +5606,7 @@ function analyzeParams(rootTagExtra, section, tag, paramsTree, rootAttrExprs) {
|
|
|
5263
5606
|
const known = paramsExpr.known = {};
|
|
5264
5607
|
let i = 0;
|
|
5265
5608
|
if (tag.node.arguments) for (const arg of tag.node.arguments) {
|
|
5266
|
-
const argTree = paramsTree.
|
|
5609
|
+
const argTree = paramsTree.properties[i];
|
|
5267
5610
|
if (argTree) {
|
|
5268
5611
|
const argValueExtra = arg.extra ??= {};
|
|
5269
5612
|
known[i] = { value: argValueExtra };
|
|
@@ -5273,7 +5616,7 @@ function analyzeParams(rootTagExtra, section, tag, paramsTree, rootAttrExprs) {
|
|
|
5273
5616
|
} else dropNodes(arg);
|
|
5274
5617
|
i++;
|
|
5275
5618
|
}
|
|
5276
|
-
const attrsTree = paramsTree.
|
|
5619
|
+
const attrsTree = paramsTree.properties[i];
|
|
5277
5620
|
if (attrsTree) known[i] = analyzeAttrs(rootTagExtra, section, tag, attrsTree, rootAttrExprs, paramsExpr);
|
|
5278
5621
|
else {
|
|
5279
5622
|
const args = tag.node.arguments;
|
|
@@ -5285,14 +5628,14 @@ function analyzeParams(rootTagExtra, section, tag, paramsTree, rootAttrExprs) {
|
|
|
5285
5628
|
}
|
|
5286
5629
|
function analyzeAttrs(rootTagExtra, section, tag, paramsTree, rootAttrExprs, rootExprs) {
|
|
5287
5630
|
const inputExpr = {};
|
|
5288
|
-
if (!paramsTree.
|
|
5631
|
+
if (!paramsTree.properties) {
|
|
5289
5632
|
inputExpr.value = setDerivedFromTag(section, tag, paramsTree.binding, rootExprs);
|
|
5290
5633
|
return inputExpr;
|
|
5291
5634
|
}
|
|
5292
5635
|
const known = inputExpr.known = {};
|
|
5293
5636
|
const attrTagLookup = analyzeAttributeTags(tag);
|
|
5294
5637
|
const seen = /* @__PURE__ */ new Set();
|
|
5295
|
-
const remaining = new Set(
|
|
5638
|
+
const remaining = new Set(getAllKnownPropertyNames(paramsTree));
|
|
5296
5639
|
const dropReferenceNodes = [];
|
|
5297
5640
|
let restReferenceNodes;
|
|
5298
5641
|
if (attrTagLookup) {
|
|
@@ -5320,7 +5663,7 @@ function analyzeAttrs(rootTagExtra, section, tag, paramsTree, rootAttrExprs, roo
|
|
|
5320
5663
|
else if (childAttrTree === true) {
|
|
5321
5664
|
getAllTagReferenceNodes(child.node, restReferenceNodes ||= []);
|
|
5322
5665
|
known[attrTagMeta.name] = { value: rootTagExtra };
|
|
5323
|
-
} else if (childAttrTree.
|
|
5666
|
+
} else if (childAttrTree.properties && !(attrTagMeta.repeated && childAttrTree.rest)) {
|
|
5324
5667
|
if (remaining.delete(attrTagMeta.name)) known[attrTagMeta.name] = analyzeAttrs(rootTagExtra, section, child, childAttrTree, rootAttrExprs, rootExprs);
|
|
5325
5668
|
else dropAttrTag(child.node, dropReferenceNodes);
|
|
5326
5669
|
} else analyzeDynamicAttrTagChildGroup(attrTagMeta.group, child);
|
|
@@ -5418,7 +5761,7 @@ function analyzeAttrs(rootTagExtra, section, tag, paramsTree, rootAttrExprs, roo
|
|
|
5418
5761
|
setDerivedFrom(attrTree === true ? paramsTree.rest.binding : attrTree.binding, propExtra, rootExprs);
|
|
5419
5762
|
}
|
|
5420
5763
|
else if (spreadReferenceNodes) {
|
|
5421
|
-
if (remaining.size || paramsTree.rest && !paramsTree.rest.
|
|
5764
|
+
if (remaining.size || paramsTree.rest && !paramsTree.rest.properties) {
|
|
5422
5765
|
inputExpr.value = mergeReferences(section, tag.node, spreadReferenceNodes);
|
|
5423
5766
|
setDerivedFrom(paramsTree.rest?.binding || paramsTree.binding, inputExpr.value, rootExprs);
|
|
5424
5767
|
} else dropNodes(spreadReferenceNodes);
|
|
@@ -5428,13 +5771,13 @@ function analyzeAttrs(rootTagExtra, section, tag, paramsTree, rootAttrExprs, roo
|
|
|
5428
5771
|
setDerivedFrom(paramsTree.rest.binding, inputExpr.value, rootExprs);
|
|
5429
5772
|
}
|
|
5430
5773
|
if (remaining.size) addSetupWork(section);
|
|
5431
|
-
if (paramsTree.rest && !paramsTree.rest.
|
|
5774
|
+
if (paramsTree.rest && !paramsTree.rest.properties) addSetupExpr(section, tag.node);
|
|
5432
5775
|
}
|
|
5433
5776
|
dropNodes(dropReferenceNodes);
|
|
5434
5777
|
return inputExpr;
|
|
5435
5778
|
}
|
|
5436
5779
|
function readsParamsByName(tag, paramsTree) {
|
|
5437
|
-
return !!paramsTree.
|
|
5780
|
+
return !!paramsTree.properties && !paramsTree.rest && !tag.node.arguments?.some(isSpreadArgument);
|
|
5438
5781
|
}
|
|
5439
5782
|
function isSpreadArgument(arg) {
|
|
5440
5783
|
return arg.type === "SpreadElement";
|
|
@@ -5472,11 +5815,11 @@ function writeParamsToSignals(tag, paramsTree, hint, info) {
|
|
|
5472
5815
|
}
|
|
5473
5816
|
let i = 0;
|
|
5474
5817
|
if (tag.node.arguments) for (const arg of tag.node.arguments) {
|
|
5475
|
-
const argTree = paramsTree.
|
|
5818
|
+
const argTree = paramsTree.properties[i];
|
|
5476
5819
|
if (argTree) writeToSignal(info, info.getBindingIdentifier(argTree.binding, `${hint}_param_${i}`), arg.extra, arg, true);
|
|
5477
5820
|
i++;
|
|
5478
5821
|
}
|
|
5479
|
-
const attrsTree = paramsTree.
|
|
5822
|
+
const attrsTree = paramsTree.properties[i];
|
|
5480
5823
|
if (attrsTree) writeAttrsToSignals(tag, attrsTree, `${hint}_input`, info);
|
|
5481
5824
|
}
|
|
5482
5825
|
function applyAttrObject(tag, paramsTree, tagInputIdentifier, info) {
|
|
@@ -5491,14 +5834,14 @@ function applyAttrObject(tag, paramsTree, tagInputIdentifier, info) {
|
|
|
5491
5834
|
writeToSignal(info, tagInputIdentifier, tagExtra, translatedProps, true);
|
|
5492
5835
|
}
|
|
5493
5836
|
function writeAttrsToSignals(tag, paramsTree, hint, info) {
|
|
5494
|
-
if (!paramsTree.
|
|
5837
|
+
if (!paramsTree.properties) {
|
|
5495
5838
|
applyAttrObject(tag, paramsTree, info.getBindingIdentifier(paramsTree.binding, hint), info);
|
|
5496
5839
|
return;
|
|
5497
5840
|
}
|
|
5498
5841
|
const attrTagLookup = analyzeAttributeTags(tag);
|
|
5499
5842
|
const seen = /* @__PURE__ */ new Set();
|
|
5500
5843
|
const tagExtra = tag.node.extra;
|
|
5501
|
-
const remaining = new Set(
|
|
5844
|
+
const remaining = new Set(getAllKnownPropertyNames(paramsTree));
|
|
5502
5845
|
const contentProps = [];
|
|
5503
5846
|
if (attrTagLookup) {
|
|
5504
5847
|
const attrTags = tag.get("attributeTags");
|
|
@@ -5532,7 +5875,7 @@ function writeAttrsToSignals(tag, paramsTree, hint, info) {
|
|
|
5532
5875
|
const translatedAttrs = translateAttrs(child, true, void 0, statements);
|
|
5533
5876
|
addStatement("render", info.tagSection, tagExtra, statements);
|
|
5534
5877
|
addAttrTag(contentProps, attrTagMeta, _marko_compiler.types.objectExpression(translatedAttrs.properties));
|
|
5535
|
-
} else if (attrTagMeta.repeated && (!childAttrTree.
|
|
5878
|
+
} else if (attrTagMeta.repeated && (!childAttrTree.properties || childAttrTree.rest)) {
|
|
5536
5879
|
if (remaining.delete(attrTagMeta.name)) applyAttrObject(child, childAttrTree, info.getBindingIdentifier(childAttrTree.binding, `${hint}_${attrTagMeta.name}`), info);
|
|
5537
5880
|
} else {
|
|
5538
5881
|
remaining.delete(attrTagMeta.name);
|
|
@@ -5611,7 +5954,7 @@ function writeAttrsToSignals(tag, paramsTree, hint, info) {
|
|
|
5611
5954
|
const propBinding = getPropertyAlias(knownSpread, prop);
|
|
5612
5955
|
writeToSignal(info, propSignal, getKnownExprsAt(info.knownExprs, getParamsTreeAt(paramsTree, prop).binding).value, createScopeReadExpression(propBinding, info.tagSection), true);
|
|
5613
5956
|
}
|
|
5614
|
-
else if (hasSpread && (remaining.size || paramsTree.rest && !paramsTree.rest.
|
|
5957
|
+
else if (hasSpread && (remaining.size || paramsTree.rest && !paramsTree.rest.properties)) {
|
|
5615
5958
|
const spreadExpr = propsToExpression(inputProps);
|
|
5616
5959
|
let spreadId = spreadExpr;
|
|
5617
5960
|
if (!isSimpleReference(spreadExpr)) {
|
|
@@ -5619,7 +5962,7 @@ function writeAttrsToSignals(tag, paramsTree, hint, info) {
|
|
|
5619
5962
|
addStatement("render", info.tagSection, tagExtra, [_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(spreadId, spreadExpr)])]);
|
|
5620
5963
|
}
|
|
5621
5964
|
for (const name of remaining) writeToSignal(info, getSignalIdentifier(info, paramsTree, hint, name), tagExtra, toMemberExpression(_marko_compiler.types.cloneNode(spreadId, true), name));
|
|
5622
|
-
if (paramsTree.rest && !paramsTree.rest.
|
|
5965
|
+
if (paramsTree.rest && !paramsTree.rest.properties) {
|
|
5623
5966
|
const props = [];
|
|
5624
5967
|
const restId = _marko_compiler.types.identifier(paramsTree.rest.binding.name);
|
|
5625
5968
|
forEach(paramsTree.rest.binding.excludeProperties, (name) => {
|
|
@@ -5632,7 +5975,7 @@ function writeAttrsToSignals(tag, paramsTree, hint, info) {
|
|
|
5632
5975
|
}
|
|
5633
5976
|
} else {
|
|
5634
5977
|
for (const name of remaining) writeToSignal(info, getSignalIdentifier(info, paramsTree, hint, name), void 0);
|
|
5635
|
-
if (paramsTree.rest && !paramsTree.rest.
|
|
5978
|
+
if (paramsTree.rest && !paramsTree.rest.properties) writeToSignal(info, info.getBindingIdentifier(paramsTree.rest.binding, hint + "_$rest"), tagExtra, _marko_compiler.types.objectExpression(inputProps), true);
|
|
5636
5979
|
}
|
|
5637
5980
|
}
|
|
5638
5981
|
function writeToSignal(info, signal, expr, value, isPure) {
|
|
@@ -5665,9 +6008,11 @@ function getGroupParamsTrees(group, attrTagLookup, paramsTree) {
|
|
|
5665
6008
|
//#region src/translator/util/reasons.ts
|
|
5666
6009
|
function addReason(slot, reason) {
|
|
5667
6010
|
if (reason) {
|
|
5668
|
-
const
|
|
5669
|
-
|
|
5670
|
-
|
|
6011
|
+
const newReason = mergeSources(slot.reason, reason);
|
|
6012
|
+
if (slot.reason !== newReason) {
|
|
6013
|
+
reasonsVersion++;
|
|
6014
|
+
slot.reason = newReason;
|
|
6015
|
+
}
|
|
5671
6016
|
}
|
|
5672
6017
|
}
|
|
5673
6018
|
function addAlwaysReason(binding) {
|
|
@@ -5703,8 +6048,8 @@ function isStateReason(reason) {
|
|
|
5703
6048
|
return !!reason && !reason.always && !!reason.state;
|
|
5704
6049
|
}
|
|
5705
6050
|
function getSourcesForExpr(expr) {
|
|
5706
|
-
const root =
|
|
5707
|
-
return isReferencedExtra(root) ?
|
|
6051
|
+
const root = getCanonicalExpr(expr);
|
|
6052
|
+
return isReferencedExtra(root) ? getSourcesForReferencedBindings(getReferencedBindings(root)) : void 0;
|
|
5708
6053
|
}
|
|
5709
6054
|
function getSourcesForExprs(exprs) {
|
|
5710
6055
|
if (exprs) {
|
|
@@ -5712,8 +6057,8 @@ function getSourcesForExprs(exprs) {
|
|
|
5712
6057
|
return reduce(exprs, mergeExprSources);
|
|
5713
6058
|
}
|
|
5714
6059
|
}
|
|
5715
|
-
function
|
|
5716
|
-
return reduce(
|
|
6060
|
+
function getSourcesForReferencedBindings(bindings) {
|
|
6061
|
+
return reduce(bindings, mergeBindingSources);
|
|
5717
6062
|
}
|
|
5718
6063
|
function getSourcesForDerived({ binding, exprs, properties }) {
|
|
5719
6064
|
if (exprs) return reduce(binding, (sources, binding) => mergeSources(sources, getSourcesForExprs(mapParamBindingToExpr(exprs, getDeepestPropertyAlias(binding, properties)))));
|
|
@@ -5754,7 +6099,7 @@ function mapParamBindingToExpr(exprs, binding) {
|
|
|
5754
6099
|
if (isWholeAlias) {
|
|
5755
6100
|
let result = curExpr.value;
|
|
5756
6101
|
if (curExpr.known) {
|
|
5757
|
-
for (const key in curExpr.known) if (!
|
|
6102
|
+
for (const key in curExpr.known) if (!propertiesUtil.has(binding.excludeProperties, key)) result = concat(result, curExpr.known[key].value);
|
|
5758
6103
|
}
|
|
5759
6104
|
return result;
|
|
5760
6105
|
}
|
|
@@ -5767,19 +6112,16 @@ function getKnownExprsAt(exprs, binding) {
|
|
|
5767
6112
|
return binding.property === void 0 || !known.known ? known : known.known[binding.property] ?? { value: known.value };
|
|
5768
6113
|
}
|
|
5769
6114
|
function applyReasonExprs(section) {
|
|
5770
|
-
|
|
5771
|
-
}
|
|
5772
|
-
function applySlotExprs(slot) {
|
|
5773
|
-
addReason(slot, getSourcesForExprs(slot.reasonExprs));
|
|
6115
|
+
for (const slot of section.slots) addReason(slot, getSourcesForExprs(slot.reasonExprs));
|
|
5774
6116
|
}
|
|
5775
6117
|
function mergeSlotReasons(section) {
|
|
5776
|
-
section.reason =
|
|
6118
|
+
section.reason = section.slots.reduce(mergeSlotReason, section.reason);
|
|
5777
6119
|
}
|
|
5778
6120
|
function mergeSlotReason(sectionReason, slot) {
|
|
5779
6121
|
return mergeSources(sectionReason, slot.reason);
|
|
5780
6122
|
}
|
|
5781
6123
|
function getNodeReasons(section) {
|
|
5782
|
-
return
|
|
6124
|
+
return section.slots.reduce(addNodeReason, void 0);
|
|
5783
6125
|
}
|
|
5784
6126
|
function addNodeReason(reasons, slot) {
|
|
5785
6127
|
return slot.reason && slot.kind === 0 && slot.owner.type === 0 ? sourcesUtil.add(reasons, slot.reason) : reasons;
|
|
@@ -5788,17 +6130,10 @@ let reasonsVersion = 0;
|
|
|
5788
6130
|
function getReasonsVersion() {
|
|
5789
6131
|
return reasonsVersion;
|
|
5790
6132
|
}
|
|
5791
|
-
function setSlotReason(slot, reason) {
|
|
5792
|
-
if (!isSameSources(slot.reason, reason)) reasonsVersion++;
|
|
5793
|
-
slot.reason = reason;
|
|
5794
|
-
}
|
|
5795
6133
|
function setParamReasonGroups(section, groups) {
|
|
5796
6134
|
reasonsVersion++;
|
|
5797
6135
|
section.paramReasonGroups = groups;
|
|
5798
6136
|
}
|
|
5799
|
-
function isSameSources(a, b) {
|
|
5800
|
-
return !!a && compareSources(a, b) === 0;
|
|
5801
|
-
}
|
|
5802
6137
|
//#endregion
|
|
5803
6138
|
//#region src/translator/util/bindings.ts
|
|
5804
6139
|
const [getBindings] = createAnalysisState(() => /* @__PURE__ */ new Set());
|
|
@@ -5869,13 +6204,13 @@ function ensurePropertyAlias(binding, property) {
|
|
|
5869
6204
|
return canonical.propertyAliases.get(property) || createBinding(canonical.name + toIdentifierAccess(property), canonical.type, canonical.section, canonical, property);
|
|
5870
6205
|
}
|
|
5871
6206
|
function addAssignedProperty(binding, property) {
|
|
5872
|
-
if (binding.assignedProperties !== true) binding.assignedProperties = property === void 0 ||
|
|
6207
|
+
if (binding.assignedProperties !== true) binding.assignedProperties = property === void 0 || propertiesUtil.add(binding.assignedProperties, property);
|
|
5873
6208
|
}
|
|
5874
6209
|
function getAssignedObject(binding) {
|
|
5875
6210
|
let object;
|
|
5876
6211
|
for (let alias = binding; alias.aliasOf && !isRest(alias); alias = alias.aliasOf) if (alias.property !== void 0) {
|
|
5877
6212
|
const parent = getCanonicalBinding(alias.aliasOf);
|
|
5878
|
-
if (parent.assignedProperties === true ||
|
|
6213
|
+
if (parent.assignedProperties === true || propertiesUtil.has(parent.assignedProperties, alias.property)) object = alias.aliasOf;
|
|
5879
6214
|
}
|
|
5880
6215
|
return object;
|
|
5881
6216
|
}
|
|
@@ -5920,7 +6255,7 @@ function getAliasRoot(binding) {
|
|
|
5920
6255
|
const bindingUtil = new Sorted(function compareBindings(a, b) {
|
|
5921
6256
|
return a === b ? 0 : a.section.id - b.section.id || +(b.type === 0) - +(a.type === 0) || a.uid - b.uid;
|
|
5922
6257
|
});
|
|
5923
|
-
const
|
|
6258
|
+
const propertiesUtil = new Sorted(function compareProperties(a, b) {
|
|
5924
6259
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
5925
6260
|
});
|
|
5926
6261
|
function getCanonicalBinding(binding) {
|
|
@@ -5968,11 +6303,11 @@ function getDebugName(binding) {
|
|
|
5968
6303
|
const { root, access } = getDebugAccess(binding, isTemplateParam(binding), toAccess);
|
|
5969
6304
|
return root.name + access;
|
|
5970
6305
|
}
|
|
5971
|
-
function getDebugNames(
|
|
5972
|
-
return mapToString(
|
|
6306
|
+
function getDebugNames(bindings) {
|
|
6307
|
+
return mapToString(bindings, ", ", getDebugName);
|
|
5973
6308
|
}
|
|
5974
|
-
function getDebugNamesAsIdentifier(
|
|
5975
|
-
return mapToString(
|
|
6309
|
+
function getDebugNamesAsIdentifier(bindings) {
|
|
6310
|
+
return mapToString(bindings, "__OR__", getDebugNameAsIdentifier);
|
|
5976
6311
|
}
|
|
5977
6312
|
function getDebugNameAsIdentifier(binding) {
|
|
5978
6313
|
const { root, access } = getDebugAccess(binding, isTemplateParam(binding), toIdentifierAccess);
|
|
@@ -5992,8 +6327,8 @@ function isReadBeyondInvoking(binding) {
|
|
|
5992
6327
|
function isOwnBinding(binding) {
|
|
5993
6328
|
return binding.section.program === (0, _marko_compiler_babel_utils.getProgram)().node.extra.section;
|
|
5994
6329
|
}
|
|
5995
|
-
function hasNonConstantPropertyAlias(
|
|
5996
|
-
for (const alias of
|
|
6330
|
+
function hasNonConstantPropertyAlias(binding) {
|
|
6331
|
+
for (const alias of binding.propertyAliases.values()) if (alias.type !== 5) return true;
|
|
5997
6332
|
return false;
|
|
5998
6333
|
}
|
|
5999
6334
|
function getPropertyPath(binding, ancestor) {
|
|
@@ -6022,7 +6357,8 @@ function isOnlyChild(tag) {
|
|
|
6022
6357
|
function initBranchSection(bodySection, branchExpr, branch) {
|
|
6023
6358
|
bodySection.branchExpr = branchExpr;
|
|
6024
6359
|
bodySection.branch = branch;
|
|
6025
|
-
|
|
6360
|
+
const { nodeBinding } = branch.tag;
|
|
6361
|
+
nodeBinding.branchBodies = push(nodeBinding.branchBodies, bodySection);
|
|
6026
6362
|
}
|
|
6027
6363
|
function resumeOwnerByMarkerWhenUnconditional(bodySection, nodeBinding) {
|
|
6028
6364
|
const branchExprReason = findSlot(nodeBinding, 4)?.reason;
|
|
@@ -6060,8 +6396,8 @@ const [getBranchEndTags] = createOutputState(() => /* @__PURE__ */ new Set());
|
|
|
6060
6396
|
function isEndTagWrittenByBranch(nodeBinding) {
|
|
6061
6397
|
return !!nodeBinding && getBranchEndTags().has(nodeBinding);
|
|
6062
6398
|
}
|
|
6063
|
-
function
|
|
6064
|
-
return !!(
|
|
6399
|
+
function isSingleNodeContent(content) {
|
|
6400
|
+
return !!(content?.singleChild && content.startType === 3);
|
|
6065
6401
|
}
|
|
6066
6402
|
function buildForRuntimeCall(type, attrs, params, statements) {
|
|
6067
6403
|
return _marko_compiler.types.expressionStatement(callRuntime(forTypeToRuntime(type), ...getBaseArgsInForTag(type, attrs), _marko_compiler.types.arrowFunctionExpression(params, _marko_compiler.types.blockStatement(statements))));
|
|
@@ -6162,189 +6498,59 @@ function assertNoBodyContent(tag) {
|
|
|
6162
6498
|
function buildAttrsError(tag, attrs, msg) {
|
|
6163
6499
|
return buildRangeError(tag, attrs[0].loc?.start, attrs[attrs.length - 1].loc?.end, msg);
|
|
6164
6500
|
}
|
|
6165
|
-
function buildAttrNameError(tag, attr, msg) {
|
|
6166
|
-
const start = attr.loc?.start;
|
|
6167
|
-
return buildRangeError(tag, start, start && {
|
|
6168
|
-
line: start.line,
|
|
6169
|
-
column: start.column + attr.name.length
|
|
6170
|
-
}, msg);
|
|
6171
|
-
}
|
|
6172
|
-
function buildUnsupportedAttrsError(tag, change, hint) {
|
|
6173
|
-
const { attributes } = tag.node;
|
|
6174
|
-
const valueAttr = attributes.find(isValueAttr);
|
|
6175
|
-
const changeAttr = change ? attributes.find(isValueChangeAttr) : void 0;
|
|
6176
|
-
const unsupported = attributes.filter((attr) => attr !== valueAttr && attr !== changeAttr);
|
|
6177
|
-
const [attr] = unsupported;
|
|
6178
|
-
return buildAttrsError(tag, unsupported, withHint(`The ${coreTagLink(tag)} only supports the ${valueAttrLink}${change ? " and its change handler" : ""}.`, attr.type === "MarkoAttribute" ? hint?.(attr) : void 0));
|
|
6179
|
-
}
|
|
6180
|
-
function buildRangeError(tag, start, end, msg) {
|
|
6181
|
-
return start && end ? tag.hub.buildError({ loc: {
|
|
6182
|
-
start,
|
|
6183
|
-
end
|
|
6184
|
-
} }, msg, Error) : tag.get("name").buildCodeFrameError(msg);
|
|
6185
|
-
}
|
|
6186
|
-
/** The loop a `<for>` tag's attributes run, which it requires. */
|
|
6187
|
-
function assertForType(tag) {
|
|
6188
|
-
const type = getForType(tag.node);
|
|
6189
|
-
if (!type) throw tag.buildCodeFrameError(`The ${coreTagLink(tag)} requires an \`of=\`, \`in=\`, \`to=\`, or \`until=\` attribute.`);
|
|
6190
|
-
return type;
|
|
6191
|
-
}
|
|
6192
|
-
/** The attributes a loop of `type` takes, besides `by=`. */
|
|
6193
|
-
function getForAttrs(type) {
|
|
6194
|
-
return type === "of" || type === "in" ? [type] : [
|
|
6195
|
-
type,
|
|
6196
|
-
"from",
|
|
6197
|
-
"step"
|
|
6198
|
-
];
|
|
6199
|
-
}
|
|
6200
|
-
/** Throws for a param that a loop of `type` never supplies. */
|
|
6201
|
-
function assertForParams(tag, type) {
|
|
6202
|
-
const extraParam = tag.node.body.params[type === "of" || type === "in" ? 2 : 1];
|
|
6203
|
-
if (extraParam && extraParam.type !== "RestElement") throw tag.hub.buildError(extraParam, `The ${coreTagLink(tag)} only provides \`|${type === "of" ? "item, index" : type === "in" ? "key, value" : "num"}|\` with \`${type}=\`, so this parameter is never supplied.`);
|
|
6204
|
-
}
|
|
6205
|
-
function coreTagLink(tag) {
|
|
6206
|
-
const tagName = getTagName(tag);
|
|
6207
|
-
const anchor = docsAnchors[tagName] ?? tagName;
|
|
6208
|
-
return `[\`<${tagName}>\` tag](https://markojs.com/docs/reference/core-tag${anchor && "#" + anchor})`;
|
|
6209
|
-
}
|
|
6210
|
-
function withHint(msg, hint) {
|
|
6211
|
-
return hint ? `${msg} ${hint}` : msg;
|
|
6212
|
-
}
|
|
6213
|
-
function isValueAttr(attr) {
|
|
6214
|
-
return attr.type === "MarkoAttribute" && attr.name === "value";
|
|
6215
|
-
}
|
|
6216
|
-
function isValueChangeAttr(attr) {
|
|
6217
|
-
return attr.type === "MarkoAttribute" && attr.name === "valueChange";
|
|
6218
|
-
}
|
|
6219
|
-
//#endregion
|
|
6220
|
-
//#region src/common/errors.ts
|
|
6221
|
-
const lowercaseOnAttrReg = /^on[a-z]/;
|
|
6222
|
-
function assertExclusiveAttrs(attrs, onError = throwErr, isSet = isTruthy) {
|
|
6223
|
-
if (attrs) {
|
|
6224
|
-
let exclusiveAttrs;
|
|
6225
|
-
if (isSet(attrs.checkedChange)) (exclusiveAttrs ||= []).push("checkedChange");
|
|
6226
|
-
if ("checkedValue" in attrs) {
|
|
6227
|
-
(exclusiveAttrs ||= []).push("checkedValue");
|
|
6228
|
-
if ("checked" in attrs) exclusiveAttrs.push("checked");
|
|
6229
|
-
} else if (isSet(attrs.checkedValueChange)) {
|
|
6230
|
-
(exclusiveAttrs ||= []).push("checkedValueChange");
|
|
6231
|
-
if ("checked" in attrs) exclusiveAttrs.push("checked");
|
|
6232
|
-
}
|
|
6233
|
-
if (isSet(attrs.valueChange)) {
|
|
6234
|
-
(exclusiveAttrs ||= []).push("valueChange");
|
|
6235
|
-
if ("checked" in attrs && !exclusiveAttrs.includes("checked")) exclusiveAttrs.push("checked");
|
|
6236
|
-
}
|
|
6237
|
-
if (exclusiveAttrs && exclusiveAttrs.length > 1) onError(`The attributes ${joinWithAnd(exclusiveAttrs)} are mutually exclusive.`);
|
|
6238
|
-
}
|
|
6239
|
-
}
|
|
6240
|
-
function isTruthy(value) {
|
|
6241
|
-
return value;
|
|
6242
|
-
}
|
|
6243
|
-
function throwErr(msg) {
|
|
6244
|
-
throw new Error(msg);
|
|
6245
|
-
}
|
|
6246
|
-
function joinWithAnd(a) {
|
|
6247
|
-
switch (a.length) {
|
|
6248
|
-
case 0: return "";
|
|
6249
|
-
case 1: return a[0];
|
|
6250
|
-
case 2: return `${a[0]} and ${a[1]}`;
|
|
6251
|
-
default: return `${a.slice(0, -1).join(", ")}, and ${a[a.length - 1]}`;
|
|
6252
|
-
}
|
|
6253
|
-
}
|
|
6254
|
-
//#endregion
|
|
6255
|
-
//#region src/html/attrs.ts
|
|
6256
|
-
function _attr_class(value) {
|
|
6257
|
-
return stringAttr("class", toDelimitedString(value, " ", stringifyClassEntry));
|
|
6258
|
-
}
|
|
6259
|
-
function _attr_style(value) {
|
|
6260
|
-
return stringAttr("style", toDelimitedString(value, ";", stringifyStyleEntry));
|
|
6261
|
-
}
|
|
6262
|
-
function _attr(name, value) {
|
|
6263
|
-
return isNullishOrFalse(value) ? "" : stringifyAttr(name, value);
|
|
6264
|
-
}
|
|
6265
|
-
function stringAttr(name, value) {
|
|
6266
|
-
return value && " " + name + attrAssignment(value);
|
|
6267
|
-
}
|
|
6268
|
-
function stringifyAttr(name, value) {
|
|
6269
|
-
switch (typeof value) {
|
|
6270
|
-
case "string": return " " + name + attrAssignment(value);
|
|
6271
|
-
case "boolean": return " " + name;
|
|
6272
|
-
case "number": return " " + name + "=" + value;
|
|
6273
|
-
}
|
|
6274
|
-
return " " + name + attrAssignment(value + "");
|
|
6275
|
-
}
|
|
6276
|
-
const singleQuoteAttrReplacements = /['\r]|&(?=[#a-zA-Z])/g;
|
|
6277
|
-
const doubleQuoteAttrReplacements = /["\r]|&(?=[#a-zA-Z])/g;
|
|
6278
|
-
const needsQuotedAttr = /["'>\s]|&[#a-zA-Z]|\/$/g;
|
|
6279
|
-
function attrAssignment(value) {
|
|
6280
|
-
return value ? needsQuotedAttr.test(value) ? value[needsQuotedAttr.lastIndex - 1] === (needsQuotedAttr.lastIndex = 0, "\"") ? "='" + escapeSingleQuotedAttrValue(value) + "'" : "=\"" + escapeDoubleQuotedAttrValue(value) + "\"" : "=" + value : "";
|
|
6281
|
-
}
|
|
6282
|
-
function escapeSingleQuotedAttrValue(value) {
|
|
6283
|
-
return singleQuoteAttrReplacements.test(value) ? value.replace(singleQuoteAttrReplacements, replaceUnsafeSingleQuoteAttrChar) : value;
|
|
6284
|
-
}
|
|
6285
|
-
function replaceUnsafeSingleQuoteAttrChar(match) {
|
|
6286
|
-
return match === "'" ? "'" : match === "\r" ? " " : "&";
|
|
6287
|
-
}
|
|
6288
|
-
function escapeDoubleQuotedAttrValue(value) {
|
|
6289
|
-
return doubleQuoteAttrReplacements.test(value) ? value.replace(doubleQuoteAttrReplacements, replaceUnsafeDoubleQuoteAttrChar) : value;
|
|
6290
|
-
}
|
|
6291
|
-
function replaceUnsafeDoubleQuoteAttrChar(match) {
|
|
6292
|
-
return match === "\"" ? """ : match === "\r" ? " " : "&";
|
|
6293
|
-
}
|
|
6294
|
-
//#endregion
|
|
6295
|
-
//#region src/html/writer.ts
|
|
6296
|
-
let $chunk;
|
|
6297
|
-
function getState() {
|
|
6298
|
-
return $chunk.boundary.state;
|
|
6501
|
+
function buildAttrNameError(tag, attr, msg) {
|
|
6502
|
+
const start = attr.loc?.start;
|
|
6503
|
+
return buildRangeError(tag, start, start && {
|
|
6504
|
+
line: start.line,
|
|
6505
|
+
column: start.column + attr.name.length
|
|
6506
|
+
}, msg);
|
|
6299
6507
|
}
|
|
6300
|
-
|
|
6301
|
-
|
|
6302
|
-
|
|
6303
|
-
|
|
6304
|
-
|
|
6305
|
-
|
|
6306
|
-
|
|
6307
|
-
_escape_style: () => _escape_style,
|
|
6308
|
-
_escape_style_value: () => _escape_style_value,
|
|
6309
|
-
_to_text: () => _to_text,
|
|
6310
|
-
_unescaped: () => _unescaped,
|
|
6311
|
-
quoteScriptTemplateLiteral: () => quoteScriptTemplateLiteral
|
|
6312
|
-
});
|
|
6313
|
-
function _to_text(val) {
|
|
6314
|
-
return val || val === 0 ? val + "" : "";
|
|
6508
|
+
function buildUnsupportedAttrsError(tag, change, hint) {
|
|
6509
|
+
const { attributes } = tag.node;
|
|
6510
|
+
const valueAttr = attributes.find(isValueAttr);
|
|
6511
|
+
const changeAttr = change ? attributes.find(isValueChangeAttr) : void 0;
|
|
6512
|
+
const unsupported = attributes.filter((attr) => attr !== valueAttr && attr !== changeAttr);
|
|
6513
|
+
const [attr] = unsupported;
|
|
6514
|
+
return buildAttrsError(tag, unsupported, withHint(`The ${coreTagLink(tag)} only supports the ${valueAttrLink}${change ? " and its change handler" : ""}.`, attr.type === "MarkoAttribute" ? hint?.(attr) : void 0));
|
|
6315
6515
|
}
|
|
6316
|
-
function
|
|
6317
|
-
return
|
|
6516
|
+
function buildRangeError(tag, start, end, msg) {
|
|
6517
|
+
return start && end ? tag.hub.buildError({ loc: {
|
|
6518
|
+
start,
|
|
6519
|
+
end
|
|
6520
|
+
} }, msg, Error) : tag.get("name").buildCodeFrameError(msg);
|
|
6318
6521
|
}
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
const
|
|
6322
|
-
|
|
6323
|
-
return
|
|
6522
|
+
/** The loop a `<for>` tag's attributes run, which it requires. */
|
|
6523
|
+
function assertForType(tag) {
|
|
6524
|
+
const type = getForType(tag.node);
|
|
6525
|
+
if (!type) throw tag.buildCodeFrameError(`The ${coreTagLink(tag)} requires an \`of=\`, \`in=\`, \`to=\`, or \`until=\` attribute.`);
|
|
6526
|
+
return type;
|
|
6324
6527
|
}
|
|
6325
|
-
|
|
6326
|
-
|
|
6327
|
-
|
|
6328
|
-
|
|
6528
|
+
/** The attributes a loop of `type` takes, besides `by=`. */
|
|
6529
|
+
function getForAttrs(type) {
|
|
6530
|
+
return type === "of" || type === "in" ? [type] : [
|
|
6531
|
+
type,
|
|
6532
|
+
"from",
|
|
6533
|
+
"step"
|
|
6534
|
+
];
|
|
6329
6535
|
}
|
|
6330
|
-
|
|
6331
|
-
|
|
6332
|
-
const
|
|
6333
|
-
|
|
6334
|
-
const escapeStyleStr = (str) => unsafeStyleReg.test(str) ? str.replace(unsafeStyleReg, "\\3C$1") : str;
|
|
6335
|
-
function _escape_style(val) {
|
|
6336
|
-
return val ? escapeStyleStr(val + "") : val === 0 ? "0" : "";
|
|
6536
|
+
/** Throws for a param that a loop of `type` never supplies. */
|
|
6537
|
+
function assertForParams(tag, type) {
|
|
6538
|
+
const extraParam = tag.node.body.params[type === "of" || type === "in" ? 2 : 1];
|
|
6539
|
+
if (extraParam && extraParam.type !== "RestElement") throw tag.hub.buildError(extraParam, `The ${coreTagLink(tag)} only provides \`|${type === "of" ? "item, index" : type === "in" ? "key, value" : "num"}|\` with \`${type}=\`, so this parameter is never supplied.`);
|
|
6337
6540
|
}
|
|
6338
|
-
function
|
|
6339
|
-
|
|
6541
|
+
function coreTagLink(tag) {
|
|
6542
|
+
const tagName = getTagName(tag);
|
|
6543
|
+
const anchor = docsAnchors[tagName] ?? tagName;
|
|
6544
|
+
return `[\`<${tagName}>\` tag](https://markojs.com/docs/reference/core-tag${anchor && "#" + anchor})`;
|
|
6340
6545
|
}
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
if (unsafeCommentReg.test(str)) str = str.replace(unsafeCommentReg, ">");
|
|
6344
|
-
return str.startsWith(getState().commentPrefix) ? "&#" + str.charCodeAt(0) + ";" + str.slice(1) : str;
|
|
6546
|
+
function withHint(msg, hint) {
|
|
6547
|
+
return hint ? `${msg} ${hint}` : msg;
|
|
6345
6548
|
}
|
|
6346
|
-
function
|
|
6347
|
-
return
|
|
6549
|
+
function isValueAttr(attr) {
|
|
6550
|
+
return attr.type === "MarkoAttribute" && attr.name === "value";
|
|
6551
|
+
}
|
|
6552
|
+
function isValueChangeAttr(attr) {
|
|
6553
|
+
return attr.type === "MarkoAttribute" && attr.name === "valueChange";
|
|
6348
6554
|
}
|
|
6349
6555
|
//#endregion
|
|
6350
6556
|
//#region src/translator/util/body-to-text.ts
|
|
@@ -6387,7 +6593,7 @@ function buildText(body, coerce, decodeEntities = false) {
|
|
|
6387
6593
|
if (templateExpressions.length === 1 && !currentQuasi && !templateQuasis[0].value.cooked && !_marko_compiler.types.isStringLiteral(singleValue)) return singleValue;
|
|
6388
6594
|
templateQuasis.push(toTemplateElement(currentQuasi, true));
|
|
6389
6595
|
const literal = _marko_compiler.types.templateLiteral(templateQuasis, templateExpressions);
|
|
6390
|
-
literal.extra = placeholderExtra &&
|
|
6596
|
+
literal.extra = placeholderExtra && getCanonicalExpr(placeholderExtra);
|
|
6391
6597
|
return literal;
|
|
6392
6598
|
}
|
|
6393
6599
|
return _marko_compiler.types.stringLiteral(currentQuasi);
|
|
@@ -6506,6 +6712,14 @@ function pushMarkup(structure, str) {
|
|
|
6506
6712
|
function node(path, binding) {
|
|
6507
6713
|
return addNode(path, binding, false);
|
|
6508
6714
|
}
|
|
6715
|
+
function text(path, binding, marker) {
|
|
6716
|
+
getSection(path).structure?.push({
|
|
6717
|
+
kind: Node,
|
|
6718
|
+
binding,
|
|
6719
|
+
marker,
|
|
6720
|
+
text: true
|
|
6721
|
+
});
|
|
6722
|
+
}
|
|
6509
6723
|
function marker(path, binding) {
|
|
6510
6724
|
addNode(path, binding, true);
|
|
6511
6725
|
}
|
|
@@ -6541,15 +6755,18 @@ function resolveStructure(section) {
|
|
|
6541
6755
|
};
|
|
6542
6756
|
if (section.content?.startType === 1) separate(resolved);
|
|
6543
6757
|
let textEdge;
|
|
6758
|
+
const writeText = (value) => {
|
|
6759
|
+
if (textEdge === "child") separate(resolved);
|
|
6760
|
+
appendLiteral(resolved.writes, value);
|
|
6761
|
+
textEdge = "own";
|
|
6762
|
+
};
|
|
6544
6763
|
for (const op of section.structure) if (typeof op === "string") {
|
|
6545
6764
|
appendLiteral(resolved.writes, op);
|
|
6546
6765
|
textEdge = void 0;
|
|
6547
6766
|
} else if (typeof op === "number") resolved.steps.push(op);
|
|
6548
6767
|
else switch (op.kind) {
|
|
6549
6768
|
case Text:
|
|
6550
|
-
|
|
6551
|
-
appendLiteral(resolved.writes, op.value);
|
|
6552
|
-
textEdge = "own";
|
|
6769
|
+
writeText(op.value);
|
|
6553
6770
|
break;
|
|
6554
6771
|
case ModuleRead:
|
|
6555
6772
|
resolved.writes.push(toModuleReadExpression(op.read), "");
|
|
@@ -6557,12 +6774,14 @@ function resolveStructure(section) {
|
|
|
6557
6774
|
break;
|
|
6558
6775
|
case Node: {
|
|
6559
6776
|
if (!op.binding) continue;
|
|
6777
|
+
const marker = op.marker ?? isKnownChild(section);
|
|
6778
|
+
if (op.text && !marker) writeText(" ");
|
|
6560
6779
|
const withVar = hasScopeOffset(op.binding);
|
|
6561
|
-
const code =
|
|
6780
|
+
const code = marker ? withVar ? 49 : 37 : 32;
|
|
6562
6781
|
flushSteps(resolved);
|
|
6563
6782
|
resolved.walkComment.push(walkCodeToName[code]);
|
|
6564
6783
|
appendLiteral(resolved.walks, String.fromCharCode(code));
|
|
6565
|
-
if (
|
|
6784
|
+
if (marker) {
|
|
6566
6785
|
appendLiteral(resolved.writes, "<!>");
|
|
6567
6786
|
textEdge = void 0;
|
|
6568
6787
|
}
|
|
@@ -6607,7 +6826,7 @@ function resolveRef(ref, part) {
|
|
|
6607
6826
|
declareOwnExports();
|
|
6608
6827
|
return _marko_compiler.types.identifier(name);
|
|
6609
6828
|
}
|
|
6610
|
-
return
|
|
6829
|
+
return (0, _marko_compiler_babel_utils.importNamed)((0, _marko_compiler_babel_utils.getFile)(), ref.path, name, `${ref.hint}_${part}`);
|
|
6611
6830
|
}
|
|
6612
6831
|
const [getSectionMeta] = createOutputSectionState((section) => {
|
|
6613
6832
|
if (!section.structure || section.dropped) return {
|
|
@@ -6787,11 +7006,12 @@ const IfTag = {
|
|
|
6787
7006
|
const ifTagExtra = ifTag.node.extra ??= {};
|
|
6788
7007
|
const mergeReferenceNodes = [];
|
|
6789
7008
|
const nodeBinding = controlFlowNode(ifTag, ifTagSection);
|
|
7009
|
+
ifTagExtra.textBefore = mayMergeWithText(ifTag, true);
|
|
6790
7010
|
for (let index = 0; index < branches.length; index++) {
|
|
6791
7011
|
const [branchTag, branchBodySection] = branches[index];
|
|
6792
7012
|
if (branchBodySection) initBranchSection(branchBodySection, ifTagExtra, {
|
|
6793
|
-
|
|
6794
|
-
|
|
7013
|
+
kind: "if",
|
|
7014
|
+
tag: ifTagExtra,
|
|
6795
7015
|
index
|
|
6796
7016
|
});
|
|
6797
7017
|
if (branchTag.node.attributes.length) mergeReferenceNodes.push(branchTag.node.attributes[0].value);
|
|
@@ -6817,7 +7037,6 @@ const IfTag = {
|
|
|
6817
7037
|
if (isLastBranch(tag)) {
|
|
6818
7038
|
const branches = getBranches(tag);
|
|
6819
7039
|
const [ifTag] = branches[0];
|
|
6820
|
-
const nextTag = tag.getNextSibling();
|
|
6821
7040
|
let branchReasons;
|
|
6822
7041
|
let statement;
|
|
6823
7042
|
for (let i = branches.length; i--;) {
|
|
@@ -6837,10 +7056,10 @@ const IfTag = {
|
|
|
6837
7056
|
}
|
|
6838
7057
|
if (branchReasons) {
|
|
6839
7058
|
const cbNode = _marko_compiler.types.arrowFunctionExpression([], _marko_compiler.types.blockStatement([statement]));
|
|
6840
|
-
statement = _marko_compiler.types.expressionStatement(callRuntime("_if", cbNode, ...getBranchResumeArgs(ifTag, branchReasons, branches.every(([, branchBody]) =>
|
|
7059
|
+
statement = _marko_compiler.types.expressionStatement(callRuntime("_if", cbNode, ...getBranchResumeArgs(ifTag, branchReasons, branches.every(([, branchBody]) => isSingleNodeContent(branchBody?.content)))));
|
|
6841
7060
|
}
|
|
6842
|
-
for (const [branchTag] of branches) branchTag
|
|
6843
|
-
|
|
7061
|
+
for (const [branchTag] of branches) replaceWithStatements(branchTag);
|
|
7062
|
+
replaceWithStatements(tag, [statement]);
|
|
6844
7063
|
}
|
|
6845
7064
|
}
|
|
6846
7065
|
},
|
|
@@ -6857,12 +7076,8 @@ const IfTag = {
|
|
|
6857
7076
|
const [branchTag, branchBodySection] = branches[i];
|
|
6858
7077
|
const [testAttr] = branchTag.node.attributes;
|
|
6859
7078
|
const consequent = _marko_compiler.types.numericLiteral(branchBodySection ? i : -1);
|
|
6860
|
-
if (branchBodySection) setClosureSignalBuilder(branchTag
|
|
6861
|
-
|
|
6862
|
-
nodeBinding,
|
|
6863
|
-
index: i
|
|
6864
|
-
});
|
|
6865
|
-
branchTag.remove();
|
|
7079
|
+
if (branchBodySection) setClosureSignalBuilder(branchTag);
|
|
7080
|
+
replaceWithStatements(branchTag);
|
|
6866
7081
|
expr = testAttr ? _marko_compiler.types.conditionalExpression(testAttr.value, consequent, expr) : consequent;
|
|
6867
7082
|
}
|
|
6868
7083
|
const signal = getSignal(ifTagSection, nodeBinding, "if");
|
|
@@ -7102,7 +7317,7 @@ function getStaticNativeTagDef(tag) {
|
|
|
7102
7317
|
}
|
|
7103
7318
|
function buildChangeHandlerAttr(tag, attr) {
|
|
7104
7319
|
const changeAttrName = attr.name + "Change";
|
|
7105
|
-
let
|
|
7320
|
+
let refiningFn;
|
|
7106
7321
|
if (attr.modifier != null) {
|
|
7107
7322
|
if (!_marko_compiler.types.isValidIdentifier(attr.modifier)) throw tag.hub.buildError(attr.value.loc?.end && { loc: {
|
|
7108
7323
|
start: {
|
|
@@ -7114,22 +7329,22 @@ function buildChangeHandlerAttr(tag, attr) {
|
|
|
7114
7329
|
column: attr.value.loc.start.column - 2
|
|
7115
7330
|
}
|
|
7116
7331
|
} }, "Bound attribute refinement shorthand must be a valid JavaScript identifier.");
|
|
7117
|
-
|
|
7332
|
+
refiningFn = withPreviousLocation(_marko_compiler.types.identifier(attr.modifier), attr);
|
|
7118
7333
|
}
|
|
7119
7334
|
if (_marko_compiler.types.isIdentifier(attr.value)) {
|
|
7120
7335
|
const binding = tag.scope.getBinding(attr.value.name);
|
|
7121
|
-
if (!binding) return _marko_compiler.types.markoAttribute(changeAttrName, buildChangeHandlerFunction(attr.value,
|
|
7122
|
-
const
|
|
7123
|
-
let
|
|
7124
|
-
if (!
|
|
7125
|
-
const existingChangedAttr =
|
|
7336
|
+
if (!binding) return _marko_compiler.types.markoAttribute(changeAttrName, buildChangeHandlerFunction(attr.value, refiningFn));
|
|
7337
|
+
const refiningFnKey = refiningFn?.name ?? "";
|
|
7338
|
+
let handlerByRefiningFn = BINDING_CHANGE_HANDLER.get(binding.identifier);
|
|
7339
|
+
if (!handlerByRefiningFn) BINDING_CHANGE_HANDLER.set(binding.identifier, handlerByRefiningFn = /* @__PURE__ */ new Map());
|
|
7340
|
+
const existingChangedAttr = handlerByRefiningFn.get(refiningFnKey);
|
|
7126
7341
|
if (!existingChangedAttr) {
|
|
7127
7342
|
const bindingIdentifierPath = binding.path.getOuterBindingIdentifierPaths()[binding.identifier.name];
|
|
7128
|
-
let changeAttrExpr = bindingIdentifierPath ? bindingIdentifierPath.parentPath === binding.path ? buildChangeHandlerFunction(attr.value,
|
|
7343
|
+
let changeAttrExpr = bindingIdentifierPath ? bindingIdentifierPath.parentPath === binding.path ? buildChangeHandlerFunction(attr.value, refiningFn) : bindingIdentifierPath.parentPath.isObjectProperty() ? ensureDestructuredChangeHandler(bindingIdentifierPath.parentPath) : void 0 : void 0;
|
|
7129
7344
|
if (!changeAttrExpr) throw tag.hub.buildError(attr.value, bindingIdentifierPath?.parentPath?.isArrayPattern() ? `Cannot two-way bind to \`${attr.value.name}\` because it comes from array destructuring, which has no change handler. Use object destructuring or pass an explicit \`${changeAttrName}\` attribute.` : bindingIdentifierPath?.parentPath?.isObjectProperty({ computed: true }) ? `Cannot two-way bind to \`${attr.value.name}\` because it is destructured with a dynamically computed key, so its change handler cannot be derived. Use a static key or pass an explicit \`${changeAttrName}\` attribute.` : "Unable to bind to value.");
|
|
7130
|
-
if (
|
|
7345
|
+
if (refiningFn && _marko_compiler.types.isIdentifier(changeAttrExpr)) changeAttrExpr = _marko_compiler.types.logicalExpression("&&", changeAttrExpr, buildRefiningFnForwarder(_marko_compiler.types.cloneNode(changeAttrExpr), refiningFn));
|
|
7131
7346
|
const changeHandlerAttr = _marko_compiler.types.markoAttribute(changeAttrName, changeAttrExpr);
|
|
7132
|
-
|
|
7347
|
+
handlerByRefiningFn.set(refiningFnKey, changeHandlerAttr);
|
|
7133
7348
|
return changeHandlerAttr;
|
|
7134
7349
|
}
|
|
7135
7350
|
if (existingChangedAttr.type === "Identifier") return _marko_compiler.types.markoAttribute(changeAttrName, withPreviousLocation(_marko_compiler.types.identifier(existingChangedAttr.name), attr.value));
|
|
@@ -7137,7 +7352,7 @@ function buildChangeHandlerAttr(tag, attr) {
|
|
|
7137
7352
|
if (!(markoRoot?.isMarkoTag() || markoRoot?.isMarkoTagBody())) throw tag.hub.buildError(attr.value, "Unable to bind to value.");
|
|
7138
7353
|
const changeHandlerId = generateUid(changeAttrName);
|
|
7139
7354
|
const changeHandlerConst = toConstTag(_marko_compiler.types.identifier(changeHandlerId), existingChangedAttr.value);
|
|
7140
|
-
|
|
7355
|
+
handlerByRefiningFn.set(refiningFnKey, existingChangedAttr.value = _marko_compiler.types.identifier(changeHandlerId));
|
|
7141
7356
|
if (markoRoot.isMarkoTag()) markoRoot.insertAfter(changeHandlerConst);
|
|
7142
7357
|
else markoRoot.unshiftContainer("body", changeHandlerConst);
|
|
7143
7358
|
return _marko_compiler.types.markoAttribute(changeAttrName, withPreviousLocation(_marko_compiler.types.identifier(changeHandlerId), attr.value));
|
|
@@ -7148,20 +7363,20 @@ function buildChangeHandlerAttr(tag, attr) {
|
|
|
7148
7363
|
const memberProp = !attr.value.computed && prop.type === "Identifier" ? withPreviousLocation(_marko_compiler.types.identifier(prop.name + "Change"), prop) : _marko_compiler.types.binaryExpression("+", _marko_compiler.types.cloneNode(prop), _marko_compiler.types.stringLiteral("Change"));
|
|
7149
7364
|
const computed = memberProp.type !== "Identifier";
|
|
7150
7365
|
let changeAttrExpr = attr.value.optional ? _marko_compiler.types.optionalMemberExpression(memberObj, memberProp, computed, true) : _marko_compiler.types.memberExpression(memberObj, memberProp, computed);
|
|
7151
|
-
if (
|
|
7366
|
+
if (refiningFn) changeAttrExpr = _marko_compiler.types.logicalExpression("&&", changeAttrExpr, buildRefiningFnForwarder(_marko_compiler.types.memberExpression(memberObj, memberProp, computed), refiningFn));
|
|
7152
7367
|
return _marko_compiler.types.markoAttribute(changeAttrName, changeAttrExpr);
|
|
7153
7368
|
}
|
|
7154
7369
|
}
|
|
7155
7370
|
throw tag.hub.buildError(attr.value, "Attributes may only be bound to identifiers or member expressions");
|
|
7156
7371
|
}
|
|
7157
|
-
function
|
|
7372
|
+
function buildRefiningFnForwarder(changeHandler, refiningFn) {
|
|
7158
7373
|
const newValueId = generateUid("next");
|
|
7159
|
-
return _marko_compiler.types.arrowFunctionExpression([_marko_compiler.types.identifier(newValueId)], _marko_compiler.types.blockStatement([_marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(changeHandler, [_marko_compiler.types.callExpression(_marko_compiler.types.cloneNode(
|
|
7374
|
+
return _marko_compiler.types.arrowFunctionExpression([_marko_compiler.types.identifier(newValueId)], _marko_compiler.types.blockStatement([_marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(changeHandler, [_marko_compiler.types.callExpression(_marko_compiler.types.cloneNode(refiningFn), [_marko_compiler.types.identifier(newValueId)])]))]));
|
|
7160
7375
|
}
|
|
7161
|
-
function buildChangeHandlerFunction(id,
|
|
7376
|
+
function buildChangeHandlerFunction(id, refiningFn) {
|
|
7162
7377
|
const newId = "_new_" + id.name;
|
|
7163
7378
|
let newValue = withPreviousLocation(_marko_compiler.types.identifier(newId), id);
|
|
7164
|
-
if (
|
|
7379
|
+
if (refiningFn) newValue = _marko_compiler.types.callExpression(refiningFn, [newValue]);
|
|
7165
7380
|
return _marko_compiler.types.arrowFunctionExpression([withPreviousLocation(_marko_compiler.types.identifier(newId), id)], _marko_compiler.types.blockStatement([_marko_compiler.types.expressionStatement(_marko_compiler.types.assignmentExpression("=", withPreviousLocation(_marko_compiler.types.identifier(id.name), id), newValue))]));
|
|
7166
7381
|
}
|
|
7167
7382
|
function ensureDestructuredChangeHandler(parent) {
|
|
@@ -7271,10 +7486,10 @@ var await_default = {
|
|
|
7271
7486
|
valueExtra.pure = false;
|
|
7272
7487
|
setDerivedFrom(paramsBinding, valueExtra);
|
|
7273
7488
|
}
|
|
7489
|
+
tagExtra.textBefore = mayMergeWithText(tag, true);
|
|
7274
7490
|
initBranchSection(bodySection, valueExtra, {
|
|
7275
|
-
|
|
7276
|
-
|
|
7277
|
-
await: true
|
|
7491
|
+
kind: "await",
|
|
7492
|
+
tag: tagExtra
|
|
7278
7493
|
});
|
|
7279
7494
|
addSetupWork(section);
|
|
7280
7495
|
marker(tag, nodeBinding);
|
|
@@ -7294,7 +7509,7 @@ var await_default = {
|
|
|
7294
7509
|
const bodySection = getSectionForBody(tagBody);
|
|
7295
7510
|
setSectionOwnerResumedByMarker(bodySection);
|
|
7296
7511
|
writeHTMLResumeStatements(tag);
|
|
7297
|
-
tag
|
|
7512
|
+
replaceWithStatements(tag, [_marko_compiler.types.expressionStatement(callRuntime("_await", getScopeIdIdentifier(section), getScopeAccessorLiteral(nodeBinding), valueAttr.value, _marko_compiler.types.arrowFunctionExpression(node.body.params, toOnlyExpressionOrBlock(node.body.body)), getWriteGuard(section, bodySection.reason, true)))]);
|
|
7298
7513
|
}
|
|
7299
7514
|
},
|
|
7300
7515
|
dom: { exit(tag) {
|
|
@@ -7313,7 +7528,7 @@ var await_default = {
|
|
|
7313
7528
|
};
|
|
7314
7529
|
addStatement("render", section, void 0, _marko_compiler.types.callExpression(_marko_compiler.types.identifier(bodySection.name), [scopeIdentifier]));
|
|
7315
7530
|
addValue(section, valueExpr.extra, signal, valueExpr);
|
|
7316
|
-
tag
|
|
7531
|
+
replaceWithStatements(tag);
|
|
7317
7532
|
} }
|
|
7318
7533
|
}),
|
|
7319
7534
|
attributes: {},
|
|
@@ -7373,95 +7588,6 @@ function createStatementTag(keyword) {
|
|
|
7373
7588
|
//#region src/translator/core/client.ts
|
|
7374
7589
|
var client_default = createStatementTag("client");
|
|
7375
7590
|
//#endregion
|
|
7376
|
-
//#region src/translator/util/evaluate.ts
|
|
7377
|
-
const kEvaluated = Symbol("evaluated");
|
|
7378
|
-
function evaluate(value) {
|
|
7379
|
-
return (value.extra ??= {})[kEvaluated] ??= computeEvaluated(value);
|
|
7380
|
-
}
|
|
7381
|
-
function computeEvaluated(value) {
|
|
7382
|
-
const computed = (0, _marko_compiler_babel_utils.computeNode)(value);
|
|
7383
|
-
return computed ? {
|
|
7384
|
-
confident: true,
|
|
7385
|
-
computed: computed.value,
|
|
7386
|
-
nullable: computed.value == null,
|
|
7387
|
-
pure: true
|
|
7388
|
-
} : {
|
|
7389
|
-
confident: false,
|
|
7390
|
-
computed: void 0,
|
|
7391
|
-
nullable: isNullableExpr(value),
|
|
7392
|
-
pure: !traverseContains(value, isImpure)
|
|
7393
|
-
};
|
|
7394
|
-
}
|
|
7395
|
-
function isImpure(node) {
|
|
7396
|
-
switch (node.type) {
|
|
7397
|
-
case "ArrowFunctionExpression":
|
|
7398
|
-
case "ClassPrivateMethod":
|
|
7399
|
-
case "ClassPrivateProperty":
|
|
7400
|
-
case "FunctionExpression": return skip;
|
|
7401
|
-
case "ClassMethod":
|
|
7402
|
-
case "ObjectMethod": return node.computed && traverseContains(node.key, isImpure) || skip;
|
|
7403
|
-
case "ClassAccessorProperty":
|
|
7404
|
-
case "ClassProperty": return node.static ? void 0 : node.computed && traverseContains(node.key, isImpure) || skip;
|
|
7405
|
-
case "CallExpression": return node.callee.type === "ArrowFunctionExpression" || node.callee.type === "FunctionExpression" ? traverseContains(node.arguments, isImpure) || traverseContains(node.callee.params, isImpure) || traverseContains(node.callee.body, isImpure) || skip : true;
|
|
7406
|
-
case "AssignmentExpression":
|
|
7407
|
-
case "NewExpression":
|
|
7408
|
-
case "OptionalCallExpression":
|
|
7409
|
-
case "TaggedTemplateExpression":
|
|
7410
|
-
case "ThrowStatement":
|
|
7411
|
-
case "UpdateExpression": return true;
|
|
7412
|
-
case "UnaryExpression": return node.operator === "delete";
|
|
7413
|
-
}
|
|
7414
|
-
}
|
|
7415
|
-
function isNullableExpr(expr) {
|
|
7416
|
-
switch (expr.type) {
|
|
7417
|
-
case "ArrayExpression":
|
|
7418
|
-
case "ArrowFunctionExpression":
|
|
7419
|
-
case "BigIntLiteral":
|
|
7420
|
-
case "BinaryExpression":
|
|
7421
|
-
case "BooleanLiteral":
|
|
7422
|
-
case "ClassExpression":
|
|
7423
|
-
case "FunctionExpression":
|
|
7424
|
-
case "NewExpression":
|
|
7425
|
-
case "NumericLiteral":
|
|
7426
|
-
case "ObjectExpression":
|
|
7427
|
-
case "RegExpLiteral":
|
|
7428
|
-
case "StringLiteral":
|
|
7429
|
-
case "TemplateLiteral":
|
|
7430
|
-
case "UpdateExpression": return false;
|
|
7431
|
-
case "AssignmentExpression": switch (expr.operator) {
|
|
7432
|
-
case "=": return isNullableExpr(expr.right);
|
|
7433
|
-
case "*=":
|
|
7434
|
-
case "/=":
|
|
7435
|
-
case "%=":
|
|
7436
|
-
case "+=":
|
|
7437
|
-
case "-=":
|
|
7438
|
-
case "<<=":
|
|
7439
|
-
case ">>=":
|
|
7440
|
-
case ">>>=":
|
|
7441
|
-
case "&=":
|
|
7442
|
-
case "^=":
|
|
7443
|
-
case "|=":
|
|
7444
|
-
case "**=": return false;
|
|
7445
|
-
case "||=":
|
|
7446
|
-
case "??=": return isNullableExpr(expr.right);
|
|
7447
|
-
case "&&=": return isNullableExpr(expr.left) || isNullableExpr(expr.right);
|
|
7448
|
-
default: return true;
|
|
7449
|
-
}
|
|
7450
|
-
case "AwaitExpression": return isNullableExpr(expr.argument);
|
|
7451
|
-
case "ConditionalExpression": return isNullableExpr(expr.consequent) || isNullableExpr(expr.alternate);
|
|
7452
|
-
case "LogicalExpression": switch (expr.operator) {
|
|
7453
|
-
case "||":
|
|
7454
|
-
case "??": return isNullableExpr(expr.right);
|
|
7455
|
-
case "&&": return isNullableExpr(expr.left) || isNullableExpr(expr.right);
|
|
7456
|
-
default: return true;
|
|
7457
|
-
}
|
|
7458
|
-
case "ParenthesizedExpression": return isNullableExpr(expr.expression);
|
|
7459
|
-
case "SequenceExpression": return isNullableExpr(expr.expressions[expr.expressions.length - 1]);
|
|
7460
|
-
case "UnaryExpression": return expr.operator === "void";
|
|
7461
|
-
default: return true;
|
|
7462
|
-
}
|
|
7463
|
-
}
|
|
7464
|
-
//#endregion
|
|
7465
7591
|
//#region src/translator/core/const.ts
|
|
7466
7592
|
var const_default = {
|
|
7467
7593
|
analyze(tag) {
|
|
@@ -7499,7 +7625,7 @@ var const_default = {
|
|
|
7499
7625
|
addValue(section, value.extra, signal, value);
|
|
7500
7626
|
}
|
|
7501
7627
|
} else if (!varBinding?.pruned || !value.extra?.dropped) translateVar(tag, value);
|
|
7502
|
-
tag
|
|
7628
|
+
replaceWithStatements(tag);
|
|
7503
7629
|
} },
|
|
7504
7630
|
parseOptions: { openTagOnly: true },
|
|
7505
7631
|
attributes: {},
|
|
@@ -7589,7 +7715,7 @@ var define_default = {
|
|
|
7589
7715
|
translate: {
|
|
7590
7716
|
enter(tag) {
|
|
7591
7717
|
if (!tag.node.var || tag.node.body.extra?.dropped) {
|
|
7592
|
-
tag
|
|
7718
|
+
replaceWithStatements(tag);
|
|
7593
7719
|
return;
|
|
7594
7720
|
}
|
|
7595
7721
|
if (isOutputHTML()) flushBefore(tag);
|
|
@@ -7600,7 +7726,7 @@ var define_default = {
|
|
|
7600
7726
|
if (isOutputHTML()) {
|
|
7601
7727
|
writeHTMLResumeStatements(tag);
|
|
7602
7728
|
translateVar(tag, propsToExpression(translatedAttrs.properties), "const", translatedAttrs.statements);
|
|
7603
|
-
tag
|
|
7729
|
+
replaceWithStatements(tag, translatedAttrs.statements);
|
|
7604
7730
|
} else {
|
|
7605
7731
|
if (_marko_compiler.types.isIdentifier(node.var)) {
|
|
7606
7732
|
const babelBinding = tag.scope.getBinding(node.var.name);
|
|
@@ -7618,15 +7744,15 @@ var define_default = {
|
|
|
7618
7744
|
};
|
|
7619
7745
|
}
|
|
7620
7746
|
if (bodySection && allDirectReferences) {
|
|
7621
|
-
tag
|
|
7747
|
+
replaceWithStatements(tag);
|
|
7622
7748
|
return;
|
|
7623
7749
|
}
|
|
7624
7750
|
}
|
|
7625
7751
|
const section = getSection(tag);
|
|
7626
7752
|
if (translatedAttrs.statements.length) addStatement("render", section, node.extra, translatedAttrs.statements);
|
|
7627
7753
|
addValue(section, node.extra, initValue(tag.get("var").node.extra.binding), propsToExpression(translatedAttrs.properties));
|
|
7754
|
+
replaceWithStatements(tag);
|
|
7628
7755
|
}
|
|
7629
|
-
tag.remove();
|
|
7630
7756
|
}
|
|
7631
7757
|
},
|
|
7632
7758
|
attributes: {},
|
|
@@ -7726,9 +7852,10 @@ var for_default = {
|
|
|
7726
7852
|
onFinalizeReferences(() => detectForSelector(bodySection, keyBinding));
|
|
7727
7853
|
}
|
|
7728
7854
|
}
|
|
7855
|
+
tagExtra.textBefore = mayMergeWithText(tag, true);
|
|
7729
7856
|
initBranchSection(bodySection, tagExtra, {
|
|
7730
|
-
|
|
7731
|
-
|
|
7857
|
+
kind: "for",
|
|
7858
|
+
tag: tagExtra
|
|
7732
7859
|
});
|
|
7733
7860
|
},
|
|
7734
7861
|
translate: translateByTarget({
|
|
@@ -7736,7 +7863,7 @@ var for_default = {
|
|
|
7736
7863
|
enter(tag) {
|
|
7737
7864
|
if (tag.node.body.attributeTags) return;
|
|
7738
7865
|
if (!getSectionForBody(tag.get("body"))) {
|
|
7739
|
-
tag
|
|
7866
|
+
replaceWithStatements(tag);
|
|
7740
7867
|
return;
|
|
7741
7868
|
}
|
|
7742
7869
|
flushBefore(tag);
|
|
@@ -7757,15 +7884,15 @@ var for_default = {
|
|
|
7757
7884
|
const forTagArgs = getBaseArgsInForTag(forType, forAttrs);
|
|
7758
7885
|
const forTagHTMLRuntime = branchReason ? forTypeToBranchRuntime(forType) : forTypeToRuntime(forType);
|
|
7759
7886
|
forTagArgs.push(_marko_compiler.types.arrowFunctionExpression(params, _marko_compiler.types.blockStatement(bodyStatements)));
|
|
7760
|
-
if (branchReason) forTagArgs.push(forAttrs.by || _marko_compiler.types.numericLiteral(0), ...getBranchResumeArgs(tag, branchReason,
|
|
7887
|
+
if (branchReason) forTagArgs.push(forAttrs.by || _marko_compiler.types.numericLiteral(0), ...getBranchResumeArgs(tag, branchReason, isSingleNodeContent(bodySection?.content)));
|
|
7761
7888
|
statements.push(_marko_compiler.types.expressionStatement(callRuntime(forTagHTMLRuntime, ...forTagArgs)));
|
|
7762
|
-
|
|
7889
|
+
replaceWithStatements(tag, statements);
|
|
7763
7890
|
}
|
|
7764
7891
|
},
|
|
7765
7892
|
dom: {
|
|
7766
7893
|
enter(tag) {
|
|
7767
7894
|
if (tag.node.body.attributeTags) return;
|
|
7768
|
-
if (!getSectionForBody(tag.get("body"))) tag
|
|
7895
|
+
if (!getSectionForBody(tag.get("body"))) replaceWithStatements(tag);
|
|
7769
7896
|
},
|
|
7770
7897
|
exit(tag) {
|
|
7771
7898
|
if (tag.node.body.attributeTags) return;
|
|
@@ -7775,12 +7902,8 @@ var for_default = {
|
|
|
7775
7902
|
const { node } = tag;
|
|
7776
7903
|
const tagExtra = node.extra;
|
|
7777
7904
|
const nodeBinding = tagExtra.nodeBinding;
|
|
7778
|
-
|
|
7779
|
-
|
|
7780
|
-
nodeBinding
|
|
7781
|
-
};
|
|
7782
|
-
setClosureSignalBuilder(tag, hop, (closure, render) => {
|
|
7783
|
-
if (!isForSelectorClosure(bodySection, closure)) return buildClosureHop(hop, render);
|
|
7905
|
+
setClosureSignalBuilder(tag, (closure, render) => {
|
|
7906
|
+
if (!isForSelectorClosure(bodySection, closure)) return buildClosureHop(bodySection, render);
|
|
7784
7907
|
return callRuntime("_for_selector", getScopeAccessorLiteral(nodeBinding, true), getScopeAccessorLiteral(closure, true), render);
|
|
7785
7908
|
});
|
|
7786
7909
|
const forType = getForType(node);
|
|
@@ -7792,7 +7915,7 @@ var for_default = {
|
|
|
7792
7915
|
const loopArgs = getBaseArgsInForTag(forType, forAttrs);
|
|
7793
7916
|
if (forAttrs.by) loopArgs.push(forAttrs.by);
|
|
7794
7917
|
addValue(tagSection, tagExtra, signal, _marko_compiler.types.arrayExpression(loopArgs));
|
|
7795
|
-
tag
|
|
7918
|
+
replaceWithStatements(tag);
|
|
7796
7919
|
}
|
|
7797
7920
|
}
|
|
7798
7921
|
}),
|
|
@@ -7938,7 +8061,7 @@ var html_comment_default = {
|
|
|
7938
8061
|
if (!_marko_compiler.types.isStringLiteral(textLiteral)) addStatement("render", tagSection, tagExtra, callRuntime("_text", createScopeReadExpression(nodeBinding), textLiteral));
|
|
7939
8062
|
}
|
|
7940
8063
|
if (nodeBinding) markNode(tag, nodeBinding, getWriteReason(nodeBinding));
|
|
7941
|
-
tag
|
|
8064
|
+
replaceWithStatements(tag);
|
|
7942
8065
|
} },
|
|
7943
8066
|
parseOptions: { text: true },
|
|
7944
8067
|
types: runtime_info_default.name + "/tags/html-comment.d.marko",
|
|
@@ -8015,11 +8138,11 @@ var id_default = {
|
|
|
8015
8138
|
const { node } = tag;
|
|
8016
8139
|
const [valueAttr] = node.attributes;
|
|
8017
8140
|
if ((valueAttr ? valueAttr.value : node).extra?.dropped) {
|
|
8018
|
-
tag
|
|
8141
|
+
replaceWithStatements(tag);
|
|
8019
8142
|
return;
|
|
8020
8143
|
}
|
|
8021
8144
|
const id = isOutputHTML() ? callRuntime("_id") : callRuntime("_id", scopeIdentifier);
|
|
8022
|
-
if (isOutputHTML()) tag
|
|
8145
|
+
if (isOutputHTML()) replaceWithStatements(tag, [_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(node.var, valueAttr ? _marko_compiler.types.logicalExpression("||", valueAttr.value, id) : id)])]);
|
|
8023
8146
|
else {
|
|
8024
8147
|
const section = getSection(tag);
|
|
8025
8148
|
const signal = initValue(node.var.extra.binding);
|
|
@@ -8027,7 +8150,7 @@ var id_default = {
|
|
|
8027
8150
|
const { value } = valueAttr;
|
|
8028
8151
|
addValue(section, value.extra, signal, _marko_compiler.types.logicalExpression("||", value, evaluate(value).confident ? id : callRuntime("_id", scopeIdentifier, _marko_compiler.types.stringLiteral(getPrefixedScopeAccessor(node.var.extra.binding, getAccessorPrefix().IdFallback)))));
|
|
8029
8152
|
} else addValue(section, void 0, signal, id);
|
|
8030
|
-
tag
|
|
8153
|
+
replaceWithStatements(tag);
|
|
8031
8154
|
}
|
|
8032
8155
|
} },
|
|
8033
8156
|
parseOptions: { openTagOnly: true },
|
|
@@ -8096,7 +8219,7 @@ function excludeAssignedChangeHandlers() {
|
|
|
8096
8219
|
const excluded = /* @__PURE__ */ new Set();
|
|
8097
8220
|
for (const { assignment: binding } of getAssignments()) if (binding.assignments && binding.aliasOf && binding.property !== void 0 && !excluded.has(binding)) {
|
|
8098
8221
|
excluded.add(binding);
|
|
8099
|
-
for (const alias of binding.aliasOf.aliases) if (
|
|
8222
|
+
for (const alias of binding.aliasOf.aliases) if (propertiesUtil.has(alias.excludeProperties, binding.property)) alias.excludeProperties = propertiesUtil.add(alias.excludeProperties, binding.property + "Change");
|
|
8100
8223
|
}
|
|
8101
8224
|
}
|
|
8102
8225
|
function resolveReads(intersectionsBySection) {
|
|
@@ -8165,13 +8288,13 @@ function resolveBindings() {
|
|
|
8165
8288
|
}
|
|
8166
8289
|
}
|
|
8167
8290
|
const canonicalBinding = getCanonicalBinding(binding);
|
|
8168
|
-
section.bindings = bindingUtil.add(section.bindings,
|
|
8291
|
+
if (canonicalBinding === binding) section.bindings = bindingUtil.add(section.bindings, binding);
|
|
8169
8292
|
bindingNamesBySection.get(section)?.add(canonicalBinding.name);
|
|
8170
8293
|
if (binding.localOf) section.localClosures = bindingUtil.add(section.localClosures, binding);
|
|
8171
8294
|
}
|
|
8172
8295
|
}
|
|
8173
8296
|
function addSectionReasons(section) {
|
|
8174
|
-
if (section.readsOwner) forEach(section.
|
|
8297
|
+
if (section.readsOwner) forEach(section.renderedBy, (call) => {
|
|
8175
8298
|
setReadsOwner(call.childScopeBinding.section, section.parent);
|
|
8176
8299
|
});
|
|
8177
8300
|
if (section.isHoistThrough) addReason(ensureSectionSlot(section, 6), ALWAYS);
|
|
@@ -8180,11 +8303,11 @@ function addSectionReasons(section) {
|
|
|
8180
8303
|
addOwnerReason(section, closure.section, closure.sources);
|
|
8181
8304
|
});
|
|
8182
8305
|
if (isOptionalBranch(section)) {
|
|
8183
|
-
const closureSources =
|
|
8306
|
+
const closureSources = getSourcesForReferencedBindings(getDirectClosures(section));
|
|
8184
8307
|
const branchSlot = ensureSectionSlot(section, 9);
|
|
8185
8308
|
addReason(branchSlot, section.isHoistThrough || section.hoisted ? mergeSources(ALWAYS, closureSources) : closureSources);
|
|
8186
8309
|
addReasonExprs(branchSlot, section.branchExpr);
|
|
8187
|
-
addReasonExprs(ensureSlot(section.branch.nodeBinding), section.branchExpr);
|
|
8310
|
+
addReasonExprs(ensureSlot(section.branch.tag.nodeBinding), section.branchExpr);
|
|
8188
8311
|
}
|
|
8189
8312
|
}
|
|
8190
8313
|
function allocateIds(intersectionsBySection) {
|
|
@@ -8362,7 +8485,7 @@ function readsValuesOnResume(expr) {
|
|
|
8362
8485
|
return !!expr.isEffect && !expr.retained;
|
|
8363
8486
|
}
|
|
8364
8487
|
function isEmitted(exprExtra) {
|
|
8365
|
-
return !
|
|
8488
|
+
return !getCanonicalExpr(exprExtra).dropped;
|
|
8366
8489
|
}
|
|
8367
8490
|
function inEmittedExpr({ exprRoot, section }) {
|
|
8368
8491
|
return !section.dropped && isEmitted(exprRoot);
|
|
@@ -8371,7 +8494,7 @@ function isDroppableValue(expr) {
|
|
|
8371
8494
|
return (!!expr.pure || !!expr.callSiteExprs) && !expr.merged && !expr.dropped;
|
|
8372
8495
|
}
|
|
8373
8496
|
function dropUnreadValue(expr) {
|
|
8374
|
-
if (isDroppableValue(expr) && every(expr.derives, isPrunedBinding))
|
|
8497
|
+
if (isDroppableValue(expr) && every(expr.derives, isPrunedBinding)) dropExpr(expr);
|
|
8375
8498
|
}
|
|
8376
8499
|
function isPrunedBinding(binding) {
|
|
8377
8500
|
return !!binding.pruned;
|
|
@@ -8429,7 +8552,7 @@ function getNearestReadBy(binding, expr) {
|
|
|
8429
8552
|
for (let cur = binding; cur; cur = cur.aliasOf) if (cur.reads.has(expr)) return cur;
|
|
8430
8553
|
}
|
|
8431
8554
|
function markLazyRead(binding) {
|
|
8432
|
-
binding.hasLazyReads = true;
|
|
8555
|
+
getCanonicalBinding(binding).hasLazyReads = true;
|
|
8433
8556
|
}
|
|
8434
8557
|
function addBindingGetter(binding, { invoked, hoisted }) {
|
|
8435
8558
|
if (!invoked || !binding.getters.has(hoisted)) {
|
|
@@ -8438,11 +8561,7 @@ function addBindingGetter(binding, { invoked, hoisted }) {
|
|
|
8438
8561
|
}
|
|
8439
8562
|
}
|
|
8440
8563
|
function isLazyRead(expr, read, binding, isChangeHandlerRead) {
|
|
8441
|
-
return !!(expr.invokeOnly && read.deferred && !isChangeHandlerRead &&
|
|
8442
|
-
}
|
|
8443
|
-
function isParamBinding(binding) {
|
|
8444
|
-
const root = getAliasRoot(binding);
|
|
8445
|
-
return root === root.section.params;
|
|
8564
|
+
return !!(expr.invokeOnly && read.deferred && !isChangeHandlerRead && binding.type !== 5);
|
|
8446
8565
|
}
|
|
8447
8566
|
function resolveReferencedBindings(expr, reads, intersectionsBySection) {
|
|
8448
8567
|
let referencedBindings;
|
|
@@ -8503,10 +8622,13 @@ function resolveReferencedBindings(expr, reads, intersectionsBySection) {
|
|
|
8503
8622
|
};
|
|
8504
8623
|
}
|
|
8505
8624
|
function getCanonicalIntersection(intersectionsBySection, section, intersection) {
|
|
8506
|
-
const intersections = intersectionsBySection.get(section)
|
|
8507
|
-
|
|
8508
|
-
|
|
8509
|
-
|
|
8625
|
+
const intersections = intersectionsBySection.get(section);
|
|
8626
|
+
if (!intersections) intersectionsBySection.set(section, [intersection]);
|
|
8627
|
+
else {
|
|
8628
|
+
const index = searchSorted(compareIntersections, intersections, intersection);
|
|
8629
|
+
if (index >= 0) return intersections[index];
|
|
8630
|
+
intersections.splice(~index, 0, intersection);
|
|
8631
|
+
}
|
|
8510
8632
|
return intersection;
|
|
8511
8633
|
}
|
|
8512
8634
|
function resolveConstantReference(binding) {
|
|
@@ -8570,7 +8692,7 @@ var let_default = {
|
|
|
8570
8692
|
translate: { exit(tag) {
|
|
8571
8693
|
const { node } = tag;
|
|
8572
8694
|
if (node.extra?.dropped) {
|
|
8573
|
-
tag
|
|
8695
|
+
replaceWithStatements(tag);
|
|
8574
8696
|
return;
|
|
8575
8697
|
}
|
|
8576
8698
|
const tagVar = node.var;
|
|
@@ -8583,7 +8705,7 @@ var let_default = {
|
|
|
8583
8705
|
const tagExtra = tag.node.extra;
|
|
8584
8706
|
if (unused) {
|
|
8585
8707
|
for (const attr of [valueAttr, valueChangeAttr]) if (attr && !evaluate(attr.value).pure) addValue(section, tagExtra, initValue(binding), attr.value);
|
|
8586
|
-
tag
|
|
8708
|
+
replaceWithStatements(tag);
|
|
8587
8709
|
return;
|
|
8588
8710
|
}
|
|
8589
8711
|
const signal = initValue(binding, true);
|
|
@@ -8595,7 +8717,7 @@ var let_default = {
|
|
|
8595
8717
|
} else {
|
|
8596
8718
|
translateVar(tag, valueAttr.value, "let");
|
|
8597
8719
|
if (unused) {
|
|
8598
|
-
if (valueChangeAttr && !evaluate(valueChangeAttr.value).pure) tag
|
|
8720
|
+
if (valueChangeAttr && !evaluate(valueChangeAttr.value).pure) replaceWithStatements(tag, [_marko_compiler.types.expressionStatement(valueChangeAttr.value)]);
|
|
8599
8721
|
} else if (valueChangeAttr) {
|
|
8600
8722
|
const accessor = writeSlot(findSlot(binding, 1), _marko_compiler.types.logicalExpression("||", valueChangeAttr.value, _marko_compiler.types.buildUndefinedNode()));
|
|
8601
8723
|
if (accessor && !isOptimize()) {
|
|
@@ -8604,7 +8726,7 @@ var let_default = {
|
|
|
8604
8726
|
}
|
|
8605
8727
|
}
|
|
8606
8728
|
}
|
|
8607
|
-
tag
|
|
8729
|
+
replaceWithStatements(tag);
|
|
8608
8730
|
} },
|
|
8609
8731
|
parseOptions: { openTagOnly: true },
|
|
8610
8732
|
attributes: {},
|
|
@@ -8647,7 +8769,7 @@ var lifecycle_default = {
|
|
|
8647
8769
|
translatedAttrs.statements.push(_marko_compiler.types.expressionStatement(callRuntime("_lifecycle", scopeIdentifier, propsToExpression(translatedAttrs.properties), index > 0 ? _marko_compiler.types.numericLiteral(index) : void 0)));
|
|
8648
8770
|
addStatement("effect", section, tagExtra, translatedAttrs.statements);
|
|
8649
8771
|
} else addHTMLEffectCall(section, tagExtra);
|
|
8650
|
-
tag
|
|
8772
|
+
replaceWithStatements(tag);
|
|
8651
8773
|
} },
|
|
8652
8774
|
parseOptions: { openTagOnly: true },
|
|
8653
8775
|
attributes: {},
|
|
@@ -8725,7 +8847,7 @@ var return_default = {
|
|
|
8725
8847
|
if (attrs.value) {
|
|
8726
8848
|
const returnId = generateUidIdentifier("return");
|
|
8727
8849
|
setReturnValueIdentifier(section, returnId);
|
|
8728
|
-
tag
|
|
8850
|
+
replaceWithStatements(tag, [_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(returnId, attrs.value)])]);
|
|
8729
8851
|
}
|
|
8730
8852
|
} },
|
|
8731
8853
|
dom: { exit(tag) {
|
|
@@ -8733,7 +8855,7 @@ var return_default = {
|
|
|
8733
8855
|
const attrs = getKnownAttrValues(tag.node);
|
|
8734
8856
|
if (attrs.value) addStatement("render", section, attrs.value.extra, callRuntime("_return", scopeIdentifier, attrs.value));
|
|
8735
8857
|
if (attrs.valueChange) addStatement("render", section, attrs.valueChange.extra, callRuntime("_return_change", scopeIdentifier, attrs.valueChange));
|
|
8736
|
-
tag
|
|
8858
|
+
replaceWithStatements(tag);
|
|
8737
8859
|
} }
|
|
8738
8860
|
}),
|
|
8739
8861
|
parseOptions: { openTagOnly: true },
|
|
@@ -8792,7 +8914,7 @@ var script_default = {
|
|
|
8792
8914
|
const { node } = tag;
|
|
8793
8915
|
const [valueAttr] = node.attributes;
|
|
8794
8916
|
if (!valueAttr?.value.extra?.isEffect) {
|
|
8795
|
-
tag
|
|
8917
|
+
replaceWithStatements(tag);
|
|
8796
8918
|
return;
|
|
8797
8919
|
}
|
|
8798
8920
|
const section = getSection(tag);
|
|
@@ -8815,7 +8937,7 @@ var script_default = {
|
|
|
8815
8937
|
}
|
|
8816
8938
|
addStatement("effect", section, value.extra, inlineBody || _marko_compiler.types.callExpression(value, []));
|
|
8817
8939
|
} else addHTMLEffectCall(section, value.extra);
|
|
8818
|
-
tag
|
|
8940
|
+
replaceWithStatements(tag);
|
|
8819
8941
|
} },
|
|
8820
8942
|
parseOptions: {
|
|
8821
8943
|
text: true,
|
|
@@ -8860,9 +8982,8 @@ var server_default = createStatementTag("server");
|
|
|
8860
8982
|
//#endregion
|
|
8861
8983
|
//#region src/translator/core/show.ts
|
|
8862
8984
|
const kStartBinding = Symbol("<show> range start binding");
|
|
8863
|
-
const kEndBinding = Symbol("<show> range end binding");
|
|
8864
8985
|
const kStaticDisplay = Symbol("<show> static display");
|
|
8865
|
-
const
|
|
8986
|
+
const kBodyContent = Symbol("<show> body content");
|
|
8866
8987
|
const htmlDisplayRefs = /* @__PURE__ */ new WeakMap();
|
|
8867
8988
|
var show_default = {
|
|
8868
8989
|
analyze: {
|
|
@@ -8871,13 +8992,13 @@ var show_default = {
|
|
|
8871
8992
|
const tagExtra = tag.node.extra ??= {};
|
|
8872
8993
|
const display = tag.node.attributes[0].value;
|
|
8873
8994
|
const displayEval = evaluate(display);
|
|
8874
|
-
tagExtra[kSingleNodeBody] = isSingleNodeBody(tag);
|
|
8875
8995
|
if (displayEval.confident) tagExtra[kStaticDisplay] = !!displayEval.computed;
|
|
8876
8996
|
if (tagExtra[kStaticDisplay] === true) return;
|
|
8877
8997
|
assertLegalHiddenContext(tag);
|
|
8878
8998
|
const tagSection = ensureSection(tag);
|
|
8999
|
+
const content = tagExtra[kBodyContent] = getContentInfo(tag.get("body"));
|
|
8879
9000
|
if (getOnlyChildParentTagName(tag)) controlFlowNode(tag, tagSection);
|
|
8880
|
-
else {
|
|
9001
|
+
else if (!isSingleNodeContent(content)) {
|
|
8881
9002
|
tagExtra[kStartBinding] = createBinding("#text", 0, tagSection);
|
|
8882
9003
|
marker(tag, tagExtra[kStartBinding]);
|
|
8883
9004
|
enterShallow(tag);
|
|
@@ -8889,14 +9010,7 @@ var show_default = {
|
|
|
8889
9010
|
const tagExtra = tag.node.extra;
|
|
8890
9011
|
if (tagExtra[kStaticDisplay] === true) return;
|
|
8891
9012
|
const tagSection = getSection(tag);
|
|
8892
|
-
if (
|
|
8893
|
-
if (!tagExtra[kSingleNodeBody]) {
|
|
8894
|
-
tagExtra[kEndBinding] = createBinding("#text", 0, tagSection);
|
|
8895
|
-
marker(tag, tagExtra[kEndBinding]);
|
|
8896
|
-
enterShallow(tag);
|
|
8897
|
-
}
|
|
8898
|
-
controlFlowNode(tag, tagSection);
|
|
8899
|
-
}
|
|
9013
|
+
if (!getOnlyChildParentTagName(tag)) controlFlowNode(tag, tagSection);
|
|
8900
9014
|
const nodeBinding = tagExtra.nodeBinding;
|
|
8901
9015
|
if (tagExtra[kStaticDisplay] === void 0) {
|
|
8902
9016
|
addReasonExprs(ensureSlot(nodeBinding), tagExtra);
|
|
@@ -8925,41 +9039,39 @@ var show_default = {
|
|
|
8925
9039
|
flushInto(tag);
|
|
8926
9040
|
const bodyStatements = tag.node.body.body;
|
|
8927
9041
|
if (staticDisplay !== void 0) {
|
|
8928
|
-
|
|
9042
|
+
replaceWithStatements(tag, bodyStatements);
|
|
8929
9043
|
return;
|
|
8930
9044
|
}
|
|
8931
9045
|
const tagSection = getSection(tag);
|
|
8932
9046
|
const display = htmlDisplayRefs.get(tag.node) || tag.node.attributes[0].value;
|
|
8933
9047
|
const nodeBinding = tagExtra.nodeBinding;
|
|
8934
9048
|
const onlyChildParentTagName = getOnlyChildParentTagName(tag);
|
|
8935
|
-
const singleNode = tagExtra[
|
|
9049
|
+
const singleNode = isSingleNodeContent(tagExtra[kBodyContent]);
|
|
8936
9050
|
const endArgs = buildBranchEndArgs(tagSection, nodeBinding, onlyChildParentTagName, singleNode);
|
|
8937
9051
|
const showStart = singleNode ? callRuntime("_show_start", _marko_compiler.types.cloneNode(display, true), _marko_compiler.types.numericLiteral(0)) : callRuntime("_show_start", _marko_compiler.types.cloneNode(display, true), ...buildBranchEndArgs(tagSection, nodeBinding, onlyChildParentTagName, singleNode));
|
|
8938
|
-
|
|
9052
|
+
replaceWithStatements(tag, [
|
|
8939
9053
|
_marko_compiler.types.expressionStatement(showStart),
|
|
8940
9054
|
...bodyStatements,
|
|
8941
9055
|
_marko_compiler.types.expressionStatement(callRuntime("_show_end", getScopeIdIdentifier(tagSection), getScopeAccessorLiteral(nodeBinding), display, ...endArgs))
|
|
8942
|
-
];
|
|
8943
|
-
for (const replacement of tag.replaceWithMultiple(statements)) replacement.skip();
|
|
9056
|
+
]);
|
|
8944
9057
|
}
|
|
8945
9058
|
},
|
|
8946
9059
|
dom: { exit(tag) {
|
|
8947
9060
|
const tagExtra = tag.node.extra;
|
|
8948
9061
|
if (tagExtra[kStaticDisplay] === true) {
|
|
8949
|
-
tag
|
|
9062
|
+
replaceWithStatements(tag);
|
|
8950
9063
|
return;
|
|
8951
9064
|
}
|
|
8952
9065
|
const tagSection = getSection(tag);
|
|
8953
|
-
const endBinding = tagExtra[kEndBinding];
|
|
8954
9066
|
const nodeBinding = tagExtra.nodeBinding;
|
|
8955
9067
|
const startBinding = tagExtra[kStartBinding];
|
|
8956
9068
|
const display = tagExtra[kStaticDisplay] === false ? _marko_compiler.types.booleanLiteral(false) : tag.node.attributes[0].value;
|
|
8957
9069
|
const signal = getSignal(tagSection, nodeBinding, "show");
|
|
8958
9070
|
signal.build = () => {
|
|
8959
|
-
return callRuntime("_show", getScopeAccessorLiteral(nodeBinding, true), startBinding
|
|
9071
|
+
return callRuntime("_show", getScopeAccessorLiteral(nodeBinding, true), startBinding && getScopeAccessorLiteral(startBinding, true));
|
|
8960
9072
|
};
|
|
8961
9073
|
addValue(tagSection, tagExtra, signal, display);
|
|
8962
|
-
tag
|
|
9074
|
+
replaceWithStatements(tag);
|
|
8963
9075
|
} }
|
|
8964
9076
|
}),
|
|
8965
9077
|
parseOptions: { controlFlow: true },
|
|
@@ -8970,15 +9082,6 @@ var show_default = {
|
|
|
8970
9082
|
}],
|
|
8971
9083
|
types: runtime_info_default.name + "/tags/show.d.marko"
|
|
8972
9084
|
};
|
|
8973
|
-
function isSingleNodeBody(tag) {
|
|
8974
|
-
let elements = 0;
|
|
8975
|
-
for (const child of tag.get("body").get("body")) {
|
|
8976
|
-
if (child.isMarkoComment()) continue;
|
|
8977
|
-
if (child.isMarkoTag() && analyzeTagNameType(child) === 0 && _marko_compiler.types.isStringLiteral(child.node.name)) elements++;
|
|
8978
|
-
else return false;
|
|
8979
|
-
}
|
|
8980
|
-
return elements === 1;
|
|
8981
|
-
}
|
|
8982
9085
|
function assertValidShow(tag) {
|
|
8983
9086
|
(0, _marko_compiler_babel_utils.assertNoVar)(tag);
|
|
8984
9087
|
(0, _marko_compiler_babel_utils.assertNoArgs)(tag, "Write the condition as a value attribute instead: `<show=condition>`.");
|
|
@@ -9111,15 +9214,15 @@ var style_default = {
|
|
|
9111
9214
|
(0, _marko_compiler_babel_utils.assertNoArgs)(tag);
|
|
9112
9215
|
(0, _marko_compiler_babel_utils.assertNoParams)(tag);
|
|
9113
9216
|
(0, _marko_compiler_babel_utils.assertNoAttributeTags)(tag);
|
|
9114
|
-
const { node: node$
|
|
9217
|
+
const { node: node$2 } = tag;
|
|
9115
9218
|
assertNoStyleAttributes(tag);
|
|
9116
9219
|
const names = createCustomPropertyNames(tag);
|
|
9117
9220
|
if (names) {
|
|
9118
9221
|
checkStyleInterpolations(tag);
|
|
9119
9222
|
checkDynamicStylePlacement(tag);
|
|
9120
9223
|
}
|
|
9121
|
-
const importPath = createStyleDependency((0, _marko_compiler_babel_utils.getFile)(), node$
|
|
9122
|
-
(node$
|
|
9224
|
+
const importPath = createStyleDependency((0, _marko_compiler_babel_utils.getFile)(), node$2, names);
|
|
9225
|
+
(node$2.extra ??= {})[kStyleImportPath] = importPath;
|
|
9123
9226
|
if (importPath) addAssetImport(importPath);
|
|
9124
9227
|
if (names) {
|
|
9125
9228
|
analyzeDynamicStyle(tag, names);
|
|
@@ -9191,7 +9294,7 @@ function translateHTML$1(tag) {
|
|
|
9191
9294
|
markNode(tag, binding, getWriteReason(binding));
|
|
9192
9295
|
}
|
|
9193
9296
|
emitStyleImport(tag);
|
|
9194
|
-
tag
|
|
9297
|
+
replaceWithStatements(tag);
|
|
9195
9298
|
}
|
|
9196
9299
|
function translateDOM$1(tag) {
|
|
9197
9300
|
const { node } = tag;
|
|
@@ -9206,7 +9309,7 @@ function translateDOM$1(tag) {
|
|
|
9206
9309
|
});
|
|
9207
9310
|
}
|
|
9208
9311
|
emitStyleImport(tag);
|
|
9209
|
-
tag
|
|
9312
|
+
replaceWithStatements(tag);
|
|
9210
9313
|
}
|
|
9211
9314
|
function dynamicStyleValues(node) {
|
|
9212
9315
|
const values = [];
|
|
@@ -9309,9 +9412,10 @@ var try_default = {
|
|
|
9309
9412
|
const nodeBinding = tagExtra.nodeBinding = createBinding("#text", 0, section);
|
|
9310
9413
|
assertHasBody(tag);
|
|
9311
9414
|
if (!attrTags) throw tag.get("name").buildCodeFrameError("The [`<try>` tag](https://markojs.com/docs/reference/core-tag#try) needs a `<@catch>` to handle errors or a `<@placeholder>` to show while its content is pending. Without either it has no effect, so render its content directly.");
|
|
9415
|
+
tagExtra.textBefore = mayMergeWithText(tag, true);
|
|
9312
9416
|
initBranchSection(ensureBodySection(tag.get("body")), tagExtra, {
|
|
9313
|
-
|
|
9314
|
-
|
|
9417
|
+
kind: "try",
|
|
9418
|
+
tag: tagExtra
|
|
9315
9419
|
});
|
|
9316
9420
|
marker(tag, nodeBinding);
|
|
9317
9421
|
enterShallow(tag);
|
|
@@ -9333,10 +9437,10 @@ var try_default = {
|
|
|
9333
9437
|
buildContent(tagBody),
|
|
9334
9438
|
placeholderSection && buildContent(placeholderTag.get("body")),
|
|
9335
9439
|
catchTag && (catchSection ? buildContent(catchTag.get("body")) : _marko_compiler.types.arrowFunctionExpression([], _marko_compiler.types.blockStatement([]))),
|
|
9336
|
-
placeholderSection && _marko_compiler.types.stringLiteral(
|
|
9337
|
-
catchTag && _marko_compiler.types.stringLiteral(catchSection ?
|
|
9440
|
+
placeholderSection && _marko_compiler.types.stringLiteral(getResumeRegistryId(placeholderSection, "content")) || absentArg(0),
|
|
9441
|
+
catchTag && _marko_compiler.types.stringLiteral(catchSection ? getResumeRegistryId(catchSection, "content") : getResumeRegistryId(section, nodeBinding, "catch"))
|
|
9338
9442
|
];
|
|
9339
|
-
tag
|
|
9443
|
+
replaceWithStatements(tag, [_marko_compiler.types.expressionStatement(callRuntime("_try", ...tryArgs))]);
|
|
9340
9444
|
}
|
|
9341
9445
|
},
|
|
9342
9446
|
dom: { exit(tag) {
|
|
@@ -9344,7 +9448,7 @@ var try_default = {
|
|
|
9344
9448
|
const section = getSection(tag);
|
|
9345
9449
|
const bodySection = getSectionForBody(tag.get("body"));
|
|
9346
9450
|
const { catchTag, catchSection, placeholderSection } = getTryParts(tag);
|
|
9347
|
-
const emptyCatchId = catchTag && !catchSection &&
|
|
9451
|
+
const emptyCatchId = catchTag && !catchSection && getResumeRegistryId(section, nodeBinding, "catch");
|
|
9348
9452
|
const signal = getSignal(section, nodeBinding, "try");
|
|
9349
9453
|
signal.build = () => {
|
|
9350
9454
|
importRuntimeFeature("catch");
|
|
@@ -9364,7 +9468,7 @@ var try_default = {
|
|
|
9364
9468
|
]));
|
|
9365
9469
|
};
|
|
9366
9470
|
addValue(section, void 0, signal);
|
|
9367
|
-
tag
|
|
9471
|
+
replaceWithStatements(tag);
|
|
9368
9472
|
} }
|
|
9369
9473
|
}),
|
|
9370
9474
|
attributes: {},
|
|
@@ -9431,7 +9535,7 @@ var cdata_default = { translate: { enter(cdata) {
|
|
|
9431
9535
|
//#endregion
|
|
9432
9536
|
//#region src/translator/visitors/comment.ts
|
|
9433
9537
|
var comment_default = { translate: { exit(comment) {
|
|
9434
|
-
comment
|
|
9538
|
+
replaceWithStatements(comment);
|
|
9435
9539
|
} } };
|
|
9436
9540
|
//#endregion
|
|
9437
9541
|
//#region src/translator/visitors/declaration.ts
|
|
@@ -9445,7 +9549,7 @@ var document_type_default = { translate: { exit(documentType) {
|
|
|
9445
9549
|
writeTo$1(documentType)`<!${documentType.node.value}>`;
|
|
9446
9550
|
if (getMarkoOpts().linkAssets && !isBeforeHtmlOrHead(documentType)) writeTo$1(documentType)`${callRuntime("_flush_head")}`;
|
|
9447
9551
|
}
|
|
9448
|
-
documentType
|
|
9552
|
+
replaceWithStatements(documentType);
|
|
9449
9553
|
} } };
|
|
9450
9554
|
function isBeforeHtmlOrHead(documentType) {
|
|
9451
9555
|
let next = documentType.getNextSibling();
|
|
@@ -9594,33 +9698,15 @@ function trackRegisteredImports(importDecl) {
|
|
|
9594
9698
|
}
|
|
9595
9699
|
}
|
|
9596
9700
|
//#endregion
|
|
9597
|
-
//#region src/translator/util/static-text.ts
|
|
9598
|
-
function isStaticText(node) {
|
|
9599
|
-
switch (node?.type) {
|
|
9600
|
-
case "MarkoText": return true;
|
|
9601
|
-
case "MarkoPlaceholder": return node.escape && !!getStaticPlaceholderText(node);
|
|
9602
|
-
}
|
|
9603
|
-
}
|
|
9604
|
-
function followsStaticText(path) {
|
|
9605
|
-
let prev = path.getPrevSibling();
|
|
9606
|
-
while (prev.node && (getNodeContentType(prev, "endType") === null || prev.isMarkoPlaceholder() && getStaticPlaceholderText(prev.node) === "")) prev = prev.getPrevSibling();
|
|
9607
|
-
return isStaticText(prev.node);
|
|
9608
|
-
}
|
|
9609
|
-
function getStaticPlaceholderText(placeholder) {
|
|
9610
|
-
const { confident, computed } = evaluate(placeholder.value);
|
|
9611
|
-
if (confident) return placeholder.escape ? _escape(computed) : _unescaped(computed);
|
|
9612
|
-
}
|
|
9613
|
-
//#endregion
|
|
9614
9701
|
//#region src/translator/visitors/placeholder.ts
|
|
9615
|
-
const
|
|
9702
|
+
const kTextAfter = Symbol("text may merge after the placeholder");
|
|
9616
9703
|
var placeholder_default = {
|
|
9617
9704
|
analyze: {
|
|
9618
9705
|
enter(placeholder) {
|
|
9619
9706
|
if (isInTextBody(placeholder)) return;
|
|
9620
9707
|
const { node } = placeholder;
|
|
9621
9708
|
const valueExtra = node.value.extra ??= {};
|
|
9622
|
-
if (
|
|
9623
|
-
if (!isStaticText(node)) {
|
|
9709
|
+
if (getPlaceholderContentType(node) === 2) {
|
|
9624
9710
|
const section = ensureSection(placeholder);
|
|
9625
9711
|
const nodeBinding = (node.extra ??= {}).nodeBinding = createBinding("#text", 0, section);
|
|
9626
9712
|
analyzeSiblingText(placeholder);
|
|
@@ -9630,22 +9716,18 @@ var placeholder_default = {
|
|
|
9630
9716
|
},
|
|
9631
9717
|
exit(placeholder) {
|
|
9632
9718
|
if (isInTextBody(placeholder)) return;
|
|
9633
|
-
const { node
|
|
9634
|
-
const
|
|
9635
|
-
if (
|
|
9636
|
-
const extra = node
|
|
9637
|
-
if (
|
|
9719
|
+
const { node } = placeholder;
|
|
9720
|
+
const contentType = getPlaceholderContentType(node);
|
|
9721
|
+
if (contentType === null) return;
|
|
9722
|
+
const extra = node.extra || {};
|
|
9723
|
+
if (contentType === 4) writeTextTo(placeholder, getStaticPlaceholderText(node));
|
|
9638
9724
|
else {
|
|
9639
|
-
const
|
|
9640
|
-
const
|
|
9725
|
+
const before = extra.textBefore;
|
|
9726
|
+
const after = extra[kTextAfter];
|
|
9641
9727
|
const { content } = getSection(placeholder);
|
|
9642
|
-
|
|
9643
|
-
else {
|
|
9644
|
-
writeTextTo(placeholder, " ");
|
|
9645
|
-
node(placeholder, nodeBinding);
|
|
9646
|
-
}
|
|
9728
|
+
text(placeholder, extra.nodeBinding, before || after || !node.escape && content.singleChild && content.startType === 2 || (before === false && after === false ? false : void 0));
|
|
9647
9729
|
}
|
|
9648
|
-
if (
|
|
9730
|
+
if (contentType !== 4 || !followsStaticText(placeholder)) enterShallow(placeholder);
|
|
9649
9731
|
}
|
|
9650
9732
|
},
|
|
9651
9733
|
translate: { exit: translateExit }
|
|
@@ -9655,8 +9737,8 @@ function translateExit(placeholder) {
|
|
|
9655
9737
|
const { node } = placeholder;
|
|
9656
9738
|
const { value } = node;
|
|
9657
9739
|
if (node.extra?.needsTextCoercion) injectTextCoercion(value);
|
|
9658
|
-
if (
|
|
9659
|
-
placeholder
|
|
9740
|
+
if (getPlaceholderContentType(node) === null) {
|
|
9741
|
+
replaceWithStatements(placeholder);
|
|
9660
9742
|
return;
|
|
9661
9743
|
}
|
|
9662
9744
|
const { confident, computed } = evaluate(value);
|
|
@@ -9670,16 +9752,15 @@ function translateExit(placeholder) {
|
|
|
9670
9752
|
if (isHTML) write`${node.escape ? _escape(computed) : _unescaped(computed)}`;
|
|
9671
9753
|
} else {
|
|
9672
9754
|
const section = getSection(placeholder);
|
|
9673
|
-
const siblingText = extra[kSiblingText];
|
|
9674
9755
|
const markerReason = nodeBinding && getWriteReason(nodeBinding);
|
|
9675
9756
|
if (isHTML) {
|
|
9676
9757
|
if (markerReason) {
|
|
9677
9758
|
const guard = getWriteGuard(section, markerReason, true);
|
|
9678
|
-
write`${callRuntime(node.escape ? "
|
|
9759
|
+
write`${callRuntime(node.escape ? "_text_mark" : "_html_mark", getScopeIdIdentifier(section), getScopeAccessorLiteral(nodeBinding), value, extra.textBefore ?? getSectionTextBefore(section) ?? true ? guard ? _marko_compiler.types.binaryExpression("*", guard, _marko_compiler.types.numericLiteral(2)) : _marko_compiler.types.numericLiteral(2) : guard)}`;
|
|
9679
9760
|
} else write`${method === "_escape" ? buildEscapedTextExpression(value) : callRuntime(method, value)}`;
|
|
9680
9761
|
} else addStatement("render", section, value.extra, method === "_text" ? callRuntime("_text", createScopeReadExpression(nodeBinding), value) : callRuntime("_html", scopeIdentifier, value, getScopeAccessorLiteral(nodeBinding)), true);
|
|
9681
9762
|
}
|
|
9682
|
-
placeholder
|
|
9763
|
+
replaceWithStatements(placeholder);
|
|
9683
9764
|
}
|
|
9684
9765
|
function buildEscapedTextExpression(value) {
|
|
9685
9766
|
switch (value.type) {
|
|
@@ -9701,31 +9782,9 @@ function buildEscapedTextExpression(value) {
|
|
|
9701
9782
|
}
|
|
9702
9783
|
}
|
|
9703
9784
|
function analyzeSiblingText(placeholder) {
|
|
9704
|
-
placeholder.node.extra
|
|
9705
|
-
|
|
9706
|
-
|
|
9707
|
-
let sibling = getSibling(placeholder, before);
|
|
9708
|
-
let parent = placeholder.parentPath;
|
|
9709
|
-
for (;;) if (!sibling.node) {
|
|
9710
|
-
const inlinedTag = getInlinedBodyTag(parent);
|
|
9711
|
-
if (!inlinedTag) return parent.isProgram();
|
|
9712
|
-
sibling = getSibling(inlinedTag, before);
|
|
9713
|
-
parent = inlinedTag.parentPath;
|
|
9714
|
-
} else {
|
|
9715
|
-
const contentType = getNodeContentType(sibling, before ? "endType" : "startType");
|
|
9716
|
-
if (contentType !== null) return contentType === 4 || contentType === 1 || contentType === 2;
|
|
9717
|
-
sibling = getSibling(sibling, before);
|
|
9718
|
-
}
|
|
9719
|
-
}
|
|
9720
|
-
function getSibling(path, before) {
|
|
9721
|
-
return before ? path.getPrevSibling() : path.getNextSibling();
|
|
9722
|
-
}
|
|
9723
|
-
function getInlinedBodyTag(parent) {
|
|
9724
|
-
if (parent.isMarkoTagBody()) {
|
|
9725
|
-
const tag = parent.parentPath;
|
|
9726
|
-
const facts = getTagFacts(tag);
|
|
9727
|
-
if (facts.controlFlow && facts.inlineBody) return tag;
|
|
9728
|
-
}
|
|
9785
|
+
const extra = placeholder.node.extra;
|
|
9786
|
+
extra.textBefore = mayMergeWithText(placeholder, true);
|
|
9787
|
+
extra[kTextAfter] = mayMergeWithText(placeholder, false);
|
|
9729
9788
|
}
|
|
9730
9789
|
//#endregion
|
|
9731
9790
|
//#region src/translator/util/analyze-errors.ts
|
|
@@ -9817,7 +9876,7 @@ const builder = {
|
|
|
9817
9876
|
}
|
|
9818
9877
|
};
|
|
9819
9878
|
function assertVisited(entryFile, state) {
|
|
9820
|
-
if (!state) throw entryFile.path.buildCodeFrameError("Unable to build
|
|
9879
|
+
if (!state) throw entryFile.path.buildCodeFrameError("Unable to build resume code, no files were visited before finalizing the build");
|
|
9821
9880
|
}
|
|
9822
9881
|
function createVisited(entryFile) {
|
|
9823
9882
|
return /* @__PURE__ */ new Map([[(0, _marko_compiler_babel_utils.resolveRelativePath)(entryFile, entryFile.opts.filename), 0]]);
|
|
@@ -9902,8 +9961,9 @@ var dynamic_tag_default = {
|
|
|
9902
9961
|
analyzeAttributeTags(tag);
|
|
9903
9962
|
const tagSection = ensureSection(tag);
|
|
9904
9963
|
const inputNodes = getAllTagReferenceNodes(node);
|
|
9905
|
-
(node.name.extra ??= {}).tagName =
|
|
9964
|
+
(node.name.extra ??= {}).tagName = node.extra ??= {};
|
|
9906
9965
|
const tagExtra = mergeReferences(tagSection, node, [node.name, ...inputNodes]);
|
|
9966
|
+
tagExtra.textBefore = mayMergeWithText(tag, true);
|
|
9907
9967
|
if (inputNodes.length) tagExtra.retained = true;
|
|
9908
9968
|
const tagBody = tag.get("body");
|
|
9909
9969
|
const hasVar = !!tag.node.var;
|
|
@@ -9936,7 +9996,7 @@ var dynamic_tag_default = {
|
|
|
9936
9996
|
translate: {
|
|
9937
9997
|
enter(tag) {
|
|
9938
9998
|
if (tag.node.extra?.featureType === "class" && !isOutputHTML() && !(0, _marko_compiler_babel_utils.getTagTemplate)(tag)) {
|
|
9939
|
-
tag
|
|
9999
|
+
replaceWithStatements(tag);
|
|
9940
10000
|
return;
|
|
9941
10001
|
}
|
|
9942
10002
|
removeDroppedContent(tag);
|
|
@@ -9957,7 +10017,7 @@ var dynamic_tag_default = {
|
|
|
9957
10017
|
if (definedBodySection.readsOwner) addStatement("render", section, void 0, _marko_compiler.types.assignmentExpression("=", toMemberExpression(createScopeReadExpression(childBinding, section), getAccessorProp().Owner), getScopeExpression(section, definedBodySection.parent)));
|
|
9958
10018
|
if (definedBodySection.hasSetupWork) addStatement("render", section, void 0, _marko_compiler.types.callExpression(getSignal(definedBodySection, void 0).identifier, [createScopeReadExpression(childBinding, section)]));
|
|
9959
10019
|
});
|
|
9960
|
-
tag
|
|
10020
|
+
replaceWithStatements(tag);
|
|
9961
10021
|
}
|
|
9962
10022
|
return;
|
|
9963
10023
|
}
|
|
@@ -9971,7 +10031,7 @@ var dynamic_tag_default = {
|
|
|
9971
10031
|
const classFile = classTagTemplate ? (0, _marko_compiler_babel_utils.loadFileForTag)(tag) : void 0;
|
|
9972
10032
|
const classHydration = classFile?.metadata.marko.classHydration;
|
|
9973
10033
|
if (!isOutputHTML() && isOptimize() && classTagTemplate && !markerReason && !classHydration) {
|
|
9974
|
-
tag
|
|
10034
|
+
replaceWithStatements(tag);
|
|
9975
10035
|
return;
|
|
9976
10036
|
}
|
|
9977
10037
|
setNeedsCompat(true);
|
|
@@ -10012,16 +10072,16 @@ var dynamic_tag_default = {
|
|
|
10012
10072
|
writeHTMLResumeStatements(tag);
|
|
10013
10073
|
const markerGuard = getWriteGuard(tagSection, markerReason, true);
|
|
10014
10074
|
const debugTagVar = !isOptimize() && node.var && _marko_compiler.types.numericLiteral(1);
|
|
10015
|
-
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), markerGuard, debugTagVar) : callRuntime("_dynamic_tag", getScopeIdIdentifier(tagSection), getScopeAccessorLiteral(nodeBinding), tagExpression, args[0], args[1] || (
|
|
10075
|
+
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), markerGuard || absentArg(1), debugTagVar) : callRuntime("_dynamic_tag", getScopeIdIdentifier(tagSection), getScopeAccessorLiteral(nodeBinding), tagExpression, args[0], args[1] || absentArg(0), absentArg(0), markerGuard || absentArg(1), debugTagVar);
|
|
10016
10076
|
if (node.var && isTagVarResumed(tag)) {
|
|
10017
10077
|
const dynamicScopeIdentifier = generateUidIdentifier(tag.get("name").toString() + "_scope");
|
|
10018
10078
|
const mutatesTagVar = isTagVarAssigned(tag);
|
|
10019
10079
|
statements.push(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(dynamicScopeIdentifier, callRuntime("_peek_scope_id"))]));
|
|
10020
10080
|
translateVar(tag, dynamicTagExpr, "let", statements);
|
|
10021
|
-
statements.push(_marko_compiler.types.expressionStatement(callRuntime("_var", getScopeIdIdentifier(tagSection), getScopeOffsetAccessorLiteral(nodeBinding), dynamicScopeIdentifier, _marko_compiler.types.stringLiteral(
|
|
10081
|
+
statements.push(_marko_compiler.types.expressionStatement(callRuntime("_var", getScopeIdIdentifier(tagSection), getScopeOffsetAccessorLiteral(nodeBinding), dynamicScopeIdentifier, _marko_compiler.types.stringLiteral(getResumeRegistryId(tagSection, node.var.extra?.binding, "var")), mutatesTagVar ? getScopeAccessorLiteral(nodeBinding) : void 0)));
|
|
10022
10082
|
} else if (node.var) translateVar(tag, dynamicTagExpr, "let", statements);
|
|
10023
10083
|
else statements.push(_marko_compiler.types.expressionStatement(dynamicTagExpr));
|
|
10024
|
-
|
|
10084
|
+
replaceWithStatements(tag, statements);
|
|
10025
10085
|
} else {
|
|
10026
10086
|
const section = getSection(tag);
|
|
10027
10087
|
const bodySection = getSectionForBody(tag.get("body"));
|
|
@@ -10050,7 +10110,7 @@ var dynamic_tag_default = {
|
|
|
10050
10110
|
if (mayHaveNativeAttr(tag, isControllableAttr)) importRuntimeFeature("controllable");
|
|
10051
10111
|
}
|
|
10052
10112
|
addValue(section, tagExtra, signal, tagExpression);
|
|
10053
|
-
tag
|
|
10113
|
+
replaceWithStatements(tag);
|
|
10054
10114
|
}
|
|
10055
10115
|
}
|
|
10056
10116
|
}
|
|
@@ -10072,7 +10132,7 @@ function getDynamicTagInputBindings(tagExtra) {
|
|
|
10072
10132
|
let inputBindings;
|
|
10073
10133
|
for (const childExtra of tagExtra.tagNameTemplates || []) {
|
|
10074
10134
|
if (childExtra.featureType === "class") return;
|
|
10075
|
-
const inputBinding = childExtra.paramsTree?.
|
|
10135
|
+
const inputBinding = childExtra.paramsTree?.properties?.[0]?.binding;
|
|
10076
10136
|
if (inputBinding) inputBindings = concat(inputBindings, inputBinding);
|
|
10077
10137
|
}
|
|
10078
10138
|
return inputBindings;
|
|
@@ -10127,7 +10187,7 @@ var dom_default = { translate: {
|
|
|
10127
10187
|
]);
|
|
10128
10188
|
else {
|
|
10129
10189
|
const registerReason = getRendererReason(childSection);
|
|
10130
|
-
const
|
|
10190
|
+
const registryId = getResumeRegistryId(childSection, "content");
|
|
10131
10191
|
const objProps = [];
|
|
10132
10192
|
forEach(childSection.localClosures, (closure) => {
|
|
10133
10193
|
const closureSignal = getSignal(childSection, closure);
|
|
@@ -10140,17 +10200,17 @@ var dom_default = { translate: {
|
|
|
10140
10200
|
}
|
|
10141
10201
|
});
|
|
10142
10202
|
const registerWrapper = !!(registerReason && objProps.length);
|
|
10143
|
-
let renderer = callRuntime("_content", _marko_compiler.types.stringLiteral(
|
|
10203
|
+
let renderer = callRuntime("_content", _marko_compiler.types.stringLiteral(registryId), ...trimEmptyArgs([
|
|
10144
10204
|
writes,
|
|
10145
10205
|
walks,
|
|
10146
10206
|
...markReturn(childSection, setupIdentifier, tagParamsIdentifier),
|
|
10147
|
-
childSection.hoisted || childSection.isHoistThrough ?
|
|
10207
|
+
childSection.hoisted || childSection.isHoistThrough ? getSectionScopesAccessorLiteral(childSection) : void 0
|
|
10148
10208
|
]));
|
|
10149
10209
|
if (!registerReason || registerWrapper) renderer = _marko_compiler.types.addComment(renderer, "leading", "@__PURE__");
|
|
10150
10210
|
if (objProps.length) renderer = callRuntime("_content_closures", renderer, _marko_compiler.types.objectExpression(objProps));
|
|
10151
10211
|
program.node.body.push(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(childSection.name), renderer)]));
|
|
10152
10212
|
if (registerReason && getDynamicTagContentClosures(childSection)) program.node.body.push(_marko_compiler.types.expressionStatement(callRuntime("_content_resume", _marko_compiler.types.identifier(childSection.name), registerWrapper && _marko_compiler.types.numericLiteral(1))));
|
|
10153
|
-
else if (registerWrapper) program.node.body.push(_marko_compiler.types.expressionStatement(registerRuntimeValue(
|
|
10213
|
+
else if (registerWrapper) program.node.body.push(_marko_compiler.types.expressionStatement(registerRuntimeValue(registryId, _marko_compiler.types.identifier(childSection.name))));
|
|
10154
10214
|
}
|
|
10155
10215
|
}
|
|
10156
10216
|
}
|
|
@@ -10185,7 +10245,7 @@ var html_default = { translate: {
|
|
|
10185
10245
|
const sectionDynamicSubscribers = /* @__PURE__ */ new Set();
|
|
10186
10246
|
forEachSection((section) => {
|
|
10187
10247
|
forEach(section.bindings, (binding) => {
|
|
10188
|
-
for (const [hoistSection, hasReference] of binding.getters) if (hasReference) getHTMLSectionStatements(hoistSection || section).push(_marko_compiler.types.variableDeclaration("const", [hoistSection ? _marko_compiler.types.variableDeclarator(getBindingGetterIdentifier(binding, hoistSection), callRuntime("_hoist", getScopeIdIdentifier(hoistSection), _marko_compiler.types.stringLiteral(
|
|
10248
|
+
for (const [hoistSection, hasReference] of binding.getters) if (hasReference) getHTMLSectionStatements(hoistSection || section).push(_marko_compiler.types.variableDeclaration("const", [hoistSection ? _marko_compiler.types.variableDeclarator(getBindingGetterIdentifier(binding, hoistSection), callRuntime("_hoist", getScopeIdIdentifier(hoistSection), _marko_compiler.types.stringLiteral(getResumeRegistryId(hoistSection, binding, "hoist")))) : _marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(binding.originalName), callRuntime("_el", getScopeIdIdentifier(section), _marko_compiler.types.stringLiteral(getResumeRegistryId(section, binding))))]));
|
|
10189
10249
|
});
|
|
10190
10250
|
forEach(section.hoisted, (binding) => {
|
|
10191
10251
|
const highestHoistSection = first(binding.hoists);
|
|
@@ -10208,16 +10268,12 @@ var html_default = { translate: {
|
|
|
10208
10268
|
if (program.node.extra.hasGlobalRead) getHTMLSectionStatements(getSection(program)).push(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier("$global"), callRuntime("$global"))]));
|
|
10209
10269
|
writeHTMLResumeStatements(program);
|
|
10210
10270
|
traverseReplace(program.node, "body", replaceNode);
|
|
10211
|
-
const
|
|
10212
|
-
const
|
|
10213
|
-
renderContent.push(
|
|
10214
|
-
|
|
10215
|
-
|
|
10216
|
-
|
|
10217
|
-
} else if (child.isMarkoScriptlet()) {
|
|
10218
|
-
if (child.node.target && child.node.target !== "server") child.remove();
|
|
10219
|
-
else child.replaceWithMultiple(child.node.body);
|
|
10220
|
-
}
|
|
10271
|
+
const statics = [];
|
|
10272
|
+
const renderContent = [getScopeReasonStatement(getSection(program))];
|
|
10273
|
+
for (const child of program.get("body")) if (!isStatic(child)) renderContent.push(child.node);
|
|
10274
|
+
else if (child.isMarkoScriptlet()) statics.push(...child.node.body);
|
|
10275
|
+
else statics.push(child.node);
|
|
10276
|
+
program.node.body = statics;
|
|
10221
10277
|
writeModuleRegistrations(program);
|
|
10222
10278
|
const contentId = hasSharedUid("content") && ensureSharedUid("content");
|
|
10223
10279
|
const contentFn = _marko_compiler.types.arrowFunctionExpression([_marko_compiler.types.identifier("input")], _marko_compiler.types.blockStatement(renderContent));
|
|
@@ -10260,7 +10316,7 @@ function registerFunctionDeclarations(body) {
|
|
|
10260
10316
|
const len = body.length;
|
|
10261
10317
|
for (let i = 0; i < len; i++) {
|
|
10262
10318
|
const child = body[i];
|
|
10263
|
-
if (child.type === "FunctionDeclaration" && isRegisteredFnExtra(child.extra)) body.push(_marko_compiler.types.expressionStatement(callRuntime("_resume", _marko_compiler.types.identifier(child.id.name), _marko_compiler.types.stringLiteral(child.extra.
|
|
10319
|
+
if (child.type === "FunctionDeclaration" && isRegisteredFnExtra(child.extra)) body.push(_marko_compiler.types.expressionStatement(callRuntime("_resume", _marko_compiler.types.identifier(child.id.name), _marko_compiler.types.stringLiteral(child.extra.registryId))));
|
|
10264
10320
|
}
|
|
10265
10321
|
}
|
|
10266
10322
|
function buildResumeCall(node) {
|
|
@@ -10272,9 +10328,9 @@ function buildResumeCall(node) {
|
|
|
10272
10328
|
forEach(referencedLocals, (binding) => {
|
|
10273
10329
|
localProperties.push(toObjectProperty(getLocalsScopeAccessor(binding), getDeclaredBindingExpression(binding)));
|
|
10274
10330
|
});
|
|
10275
|
-
return callRuntime("_resume_locals", simplifyFunction(node), _marko_compiler.types.stringLiteral(extra.
|
|
10331
|
+
return callRuntime("_resume_locals", simplifyFunction(node), _marko_compiler.types.stringLiteral(extra.registryId), _marko_compiler.types.objectExpression(localProperties), extra.referencesScope && getScopeIdIdentifier(extra.section));
|
|
10276
10332
|
}
|
|
10277
|
-
return callRuntime("_resume", simplifyFunction(node), _marko_compiler.types.stringLiteral(extra.
|
|
10333
|
+
return callRuntime("_resume", simplifyFunction(node), _marko_compiler.types.stringLiteral(extra.registryId), extra.referencesScope && getScopeIdIdentifier(extra.section));
|
|
10278
10334
|
}
|
|
10279
10335
|
}
|
|
10280
10336
|
//#endregion
|
|
@@ -10381,6 +10437,7 @@ var program_default = {
|
|
|
10381
10437
|
else dom_default.translate.enter(program);
|
|
10382
10438
|
},
|
|
10383
10439
|
exit(program) {
|
|
10440
|
+
writeBodyStatements(program.node);
|
|
10384
10441
|
if (isOutputHTML()) html_default.translate.exit(program);
|
|
10385
10442
|
else dom_default.translate.exit(program);
|
|
10386
10443
|
if (needsCompat()) {
|
|
@@ -10410,36 +10467,27 @@ var referenced_identifier_default = {
|
|
|
10410
10467
|
analyze(identifier) {
|
|
10411
10468
|
const { name } = identifier.node;
|
|
10412
10469
|
if (identifier.scope.hasBinding(name)) return;
|
|
10413
|
-
if (name === "$global") {
|
|
10470
|
+
if (name === "$global" || name === "$signal") {
|
|
10414
10471
|
assertReferencedInRender(identifier, name);
|
|
10415
10472
|
setReferencesScope(identifier);
|
|
10416
|
-
trackGlobalReference(identifier);
|
|
10417
|
-
} else if (name === "$signal") {
|
|
10418
|
-
assertReferencedInRender(identifier, name);
|
|
10419
10473
|
const section = ensureSection(identifier);
|
|
10420
|
-
section.hasAbortSignal = true;
|
|
10421
|
-
setReferencesScope(identifier);
|
|
10422
10474
|
const rootExtra = getExprRoot(identifier).node.extra ??= { section };
|
|
10423
10475
|
(identifier.node.extra ??= {}).exprRoot = rootExtra;
|
|
10424
|
-
if (
|
|
10476
|
+
if (name === "$global") trackGlobalReference(identifier);
|
|
10477
|
+
else {
|
|
10478
|
+
section.hasAbortSignal = true;
|
|
10479
|
+
if (rootExtra[kAbortId] === void 0) rootExtra[kAbortId] = section.abortSignalExprs++;
|
|
10480
|
+
}
|
|
10425
10481
|
}
|
|
10426
10482
|
},
|
|
10427
10483
|
translate(identifier) {
|
|
10428
10484
|
const { name } = identifier.node;
|
|
10429
10485
|
if (identifier.scope.hasBinding(name)) return;
|
|
10430
10486
|
switch (name) {
|
|
10431
|
-
case "$global": {
|
|
10432
|
-
if (isOutputHTML()) break;
|
|
10433
|
-
const globalRead = _marko_compiler.types.memberExpression(scopeIdentifier, _marko_compiler.types.identifier(getAccessorProp().Global));
|
|
10434
|
-
const key = !isOptimize() && getSignalGlobalKey(identifier);
|
|
10435
|
-
if (key) identifier.parentPath.replaceWith(callRuntime("_global_read", globalRead, _marko_compiler.types.stringLiteral(key)));
|
|
10436
|
-
else replaceWithExtra(identifier, globalRead);
|
|
10437
|
-
break;
|
|
10438
|
-
}
|
|
10439
10487
|
case "$signal": if (isOutputHTML()) replaceWithExtra(identifier, callRuntime("_signal_read_error"));
|
|
10440
10488
|
else {
|
|
10441
10489
|
const exprRoot = identifier.node.extra.exprRoot;
|
|
10442
|
-
const canonicalExtra =
|
|
10490
|
+
const canonicalExtra = getCanonicalExpr(exprRoot);
|
|
10443
10491
|
if (canonicalExtra.dropped) break;
|
|
10444
10492
|
const section = getSection(identifier);
|
|
10445
10493
|
const exprId = exprRoot[kAbortId];
|
|
@@ -10457,13 +10505,6 @@ function replaceWithExtra(path, replacement) {
|
|
|
10457
10505
|
replacement.extra = path.node.extra;
|
|
10458
10506
|
path.replaceWith(replacement);
|
|
10459
10507
|
}
|
|
10460
|
-
function getSignalGlobalKey(identifier) {
|
|
10461
|
-
const { parent } = identifier;
|
|
10462
|
-
if (!_marko_compiler.types.isMemberExpression(parent) || parent.computed || !_marko_compiler.types.isIdentifier(parent.property) || parent.object !== identifier.node) return;
|
|
10463
|
-
const { name } = parent.property;
|
|
10464
|
-
if (name === "runtimeId" || name === "renderId") return;
|
|
10465
|
-
return getReferencedBindings(getExprRoot(identifier).node.extra) ? name : void 0;
|
|
10466
|
-
}
|
|
10467
10508
|
//#endregion
|
|
10468
10509
|
//#region src/translator/visitors/scriptlet.ts
|
|
10469
10510
|
var scriptlet_default = {
|
|
@@ -10481,19 +10522,9 @@ var scriptlet_default = {
|
|
|
10481
10522
|
const isHTML = isOutputHTML();
|
|
10482
10523
|
if (node.target && node.target !== (isHTML ? "server" : "client")) {
|
|
10483
10524
|
const ids = Object.keys(scriptlet.getOuterBindingIdentifiers());
|
|
10484
|
-
|
|
10485
|
-
|
|
10486
|
-
|
|
10487
|
-
scriptlet.node.target = null;
|
|
10488
|
-
scriptlet.node.body = [decl];
|
|
10489
|
-
} else scriptlet.replaceWith(decl);
|
|
10490
|
-
} else scriptlet.remove();
|
|
10491
|
-
return;
|
|
10492
|
-
}
|
|
10493
|
-
if (isHTML) {} else {
|
|
10494
|
-
traverseReplace(node, "body", replaceRegisteredFunctionNode$1);
|
|
10495
|
-
scriptlet.replaceWithMultiple(node.body);
|
|
10496
|
-
}
|
|
10525
|
+
node.body = ids.length ? [_marko_compiler.types.variableDeclaration("var", ids.map((key) => _marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(key))))] : [];
|
|
10526
|
+
} else if (!isHTML) traverseReplace(node, "body", replaceRegisteredFunctionNode$1);
|
|
10527
|
+
if (!isHTML) replaceWithStatements(scriptlet, node.body);
|
|
10497
10528
|
} }
|
|
10498
10529
|
};
|
|
10499
10530
|
//#endregion
|
|
@@ -10545,7 +10576,7 @@ var custom_tag_default = {
|
|
|
10545
10576
|
if (tag.node.var) throw tag.get("var").buildCodeFrameError(`The \`${getTagNameHint(tag.node)}\` tag is lazily loaded, so it does not support a [tag variable](https://markojs.com/docs/reference/language#tag-variables). Remove the variable, or import the tag without \`load\`.`);
|
|
10546
10577
|
tagExtra.nodeBinding = createBinding("#text", 0, ensureSection(tag));
|
|
10547
10578
|
}
|
|
10548
|
-
if (!isTemplateImport(tag)) dropNodes(tag.node.name);
|
|
10579
|
+
if (childSection === programExtra.section || !isTemplateImport(tag)) dropNodes(tag.node.name);
|
|
10549
10580
|
knownTagAnalyze(tag, childSection, childExtra.paramsTree);
|
|
10550
10581
|
const tagName = getTagNameHint(tag.node);
|
|
10551
10582
|
if (tagExtra.tagNameLoad) {
|
|
@@ -10572,28 +10603,29 @@ var custom_tag_default = {
|
|
|
10572
10603
|
};
|
|
10573
10604
|
function translateHTML(tag) {
|
|
10574
10605
|
const { node } = tag;
|
|
10606
|
+
const tagExtra = node.extra;
|
|
10575
10607
|
let tagIdentifier;
|
|
10576
10608
|
if (node.name.extra?.dropped) {
|
|
10577
10609
|
const relativePath = getTagRelativePath(tag);
|
|
10578
|
-
const loadConfig =
|
|
10610
|
+
const loadConfig = tagExtra.tagNameLoad;
|
|
10579
10611
|
const importTemplate = () => (0, _marko_compiler_babel_utils.importDefault)((0, _marko_compiler_babel_utils.getFile)(), relativePath, getTagNameHint(node));
|
|
10580
10612
|
if (loadConfig) {
|
|
10581
10613
|
const childFile = (0, _marko_compiler_babel_utils.loadFileForTag)(tag);
|
|
10582
10614
|
tagIdentifier = _marko_compiler.types.identifier(ensureHtmlLoadWrapped(childFile, importTemplate, loadConfig.render ? void 0 : loadConfig.triggers));
|
|
10583
|
-
} else tagIdentifier =
|
|
10615
|
+
} else tagIdentifier = tagExtra.childSection === (0, _marko_compiler_babel_utils.getProgram)().node.extra.section ? _marko_compiler.types.identifier(ensureSharedUid("content")) : importTemplate();
|
|
10584
10616
|
} else tagIdentifier = node.name;
|
|
10585
10617
|
knownTagTranslateHTML(tag, tagIdentifier);
|
|
10586
10618
|
}
|
|
10587
10619
|
function translateDOM(tag) {
|
|
10588
10620
|
const { node } = tag;
|
|
10621
|
+
const tagExtra = node.extra;
|
|
10589
10622
|
const file = (0, _marko_compiler_babel_utils.getFile)();
|
|
10590
10623
|
const relativePath = getTagRelativePath(tag);
|
|
10591
10624
|
const programSection = (0, _marko_compiler_babel_utils.getProgram)().node.extra.section;
|
|
10592
10625
|
const childFile = (0, _marko_compiler_babel_utils.loadFileForTag)(tag);
|
|
10593
|
-
const
|
|
10594
|
-
const
|
|
10595
|
-
const
|
|
10596
|
-
const loadConfig = node.extra?.tagNameLoad;
|
|
10626
|
+
const childExports = childFile.ast.program.extra.exportNames;
|
|
10627
|
+
const { childSection } = tagExtra;
|
|
10628
|
+
const loadConfig = tagExtra.tagNameLoad;
|
|
10597
10629
|
const isLoad = !!loadConfig;
|
|
10598
10630
|
const tagName = getTagNameHint(node);
|
|
10599
10631
|
if (isLoad) {
|
|
@@ -10621,20 +10653,20 @@ function translateDOM(tag) {
|
|
|
10621
10653
|
addStatement("render", section, void 0, _marko_compiler.types.callExpression(setupIdent, [
|
|
10622
10654
|
scopeIdentifier,
|
|
10623
10655
|
createScopeReadExpression(childBinding, section),
|
|
10624
|
-
createScopeReadExpression(
|
|
10656
|
+
createScopeReadExpression(tagExtra.nodeBinding, section)
|
|
10625
10657
|
]));
|
|
10626
10658
|
});
|
|
10627
10659
|
} else if (programSection === childSection) knownTagTranslateDOM(tag, (binding, preferredName) => getSignal(programSection, binding, preferredName).identifier, childSection.hasSetupWork ? (section, childBinding) => {
|
|
10628
10660
|
addStatement("render", section, void 0, _marko_compiler.types.callExpression(_marko_compiler.types.identifier(childExports.setup), [createScopeReadExpression(childBinding, section)]));
|
|
10629
10661
|
} : void 0);
|
|
10630
10662
|
else {
|
|
10631
|
-
knownTagTranslateDOM(tag, (binding, preferredName, directContent) =>
|
|
10632
|
-
addStatement("render", section, void 0, _marko_compiler.types.callExpression(
|
|
10663
|
+
knownTagTranslateDOM(tag, (binding, preferredName, directContent) => (0, _marko_compiler_babel_utils.importNamed)(file, relativePath, directContent && childExports.directContent.get(binding) || childExports.params.get(binding), preferredName), childSection.hasSetupWork ? (section, childBinding) => {
|
|
10664
|
+
addStatement("render", section, void 0, _marko_compiler.types.callExpression((0, _marko_compiler_babel_utils.importNamed)(file, relativePath, childExports.setup, tagName), [createScopeReadExpression(childBinding, section)]));
|
|
10633
10665
|
} : void 0);
|
|
10634
10666
|
(0, _marko_compiler_babel_utils.importNamed)(file, relativePath, childExports.template, `${tagName}_template`);
|
|
10635
10667
|
(0, _marko_compiler_babel_utils.importNamed)(file, relativePath, childExports.walks, `${tagName}_walks`);
|
|
10636
10668
|
}
|
|
10637
|
-
tag
|
|
10669
|
+
replaceWithStatements(tag);
|
|
10638
10670
|
}
|
|
10639
10671
|
function createLoadIdentifier(cache, key, name, runtime, request, trigger) {
|
|
10640
10672
|
const id = generateUidIdentifier(name);
|
|
@@ -10905,7 +10937,7 @@ var native_tag_default = {
|
|
|
10905
10937
|
write`<${tagName}`;
|
|
10906
10938
|
if (injectsNonce && !spread) write`${callRuntime("_attr_nonce")}`;
|
|
10907
10939
|
if (controllable) {
|
|
10908
|
-
if (tagName !== "select" && tagName !== "textarea") write`${callRuntime(getControllableHelper(tagName, controllable.state), getScopeIdIdentifier(tagSection), nodeAccessor, ...controllable.attrs.map((index) => attrAt(attributes, index)?.value))}`;
|
|
10940
|
+
if (tagName !== "select" && tagName !== "textarea") write`${callRuntime(getControllableHelper(tagName, controllable.state), getScopeIdIdentifier(tagSection), nodeAccessor, ...controllable.attrs.map((index, i) => attrAt(attributes, index)?.value || i === 1 && absentArg(0)))}`;
|
|
10909
10941
|
if (controllable.attrs[1] !== void 0) addHTMLEffectCall(tagSection, void 0);
|
|
10910
10942
|
}
|
|
10911
10943
|
let writeAtStartOfBody;
|
|
@@ -10913,7 +10945,7 @@ var native_tag_default = {
|
|
|
10913
10945
|
if (tagName === "select") {
|
|
10914
10946
|
if (controllable) htmlSelectArgs.set(tag.node, {
|
|
10915
10947
|
helper: "_attr_select_value",
|
|
10916
|
-
args: [attrAt(attributes, controllable.attrs[0])?.value || _marko_compiler.types.buildUndefinedNode(), attrAt(attributes, controllable.attrs[1])?.value ||
|
|
10948
|
+
args: [attrAt(attributes, controllable.attrs[0])?.value || _marko_compiler.types.buildUndefinedNode(), attrAt(attributes, controllable.attrs[1])?.value || absentArg(0)]
|
|
10917
10949
|
});
|
|
10918
10950
|
else if (spreadExpression) {
|
|
10919
10951
|
const spreadIdentifier = declareConstBefore(tag, "select_input", spreadExpression);
|
|
@@ -10977,10 +11009,11 @@ var native_tag_default = {
|
|
|
10977
11009
|
const markerReason = !skipEndTag && nodeBinding && getWriteReason(nodeBinding);
|
|
10978
11010
|
const write = writeTo$1(tag, tagName === "html" || !markerReason && tagName === "body");
|
|
10979
11011
|
if (htmlContentAttrTags.has(tag.node)) flushBefore(tag);
|
|
11012
|
+
let statements = [];
|
|
10980
11013
|
if (selectArgs) {
|
|
10981
11014
|
if (!skipEndTag) write`</${tagName}>`;
|
|
10982
11015
|
flushInto(tag);
|
|
10983
|
-
|
|
11016
|
+
statements = [_marko_compiler.types.expressionStatement(callRuntime(selectArgs.helper, getScopeIdIdentifier(tagSection), nodeBinding && getScopeAccessorLiteral(nodeBinding), ...selectArgs.args, _marko_compiler.types.arrowFunctionExpression([], _marko_compiler.types.blockStatement(tag.node.body.body))))];
|
|
10984
11017
|
} else if (isTextOnly) {
|
|
10985
11018
|
const rawTextHelper = getRawTextEscapeHelper(tagName);
|
|
10986
11019
|
if (rawTextHelper) {
|
|
@@ -10988,13 +11021,13 @@ var native_tag_default = {
|
|
|
10988
11021
|
write`${_marko_compiler.types.isStringLiteral(body) ? content_exports[rawTextHelper](body.value) : callRuntime(rawTextHelper, body)}`;
|
|
10989
11022
|
} else for (const child of tag.node.body.body) if (_marko_compiler.types.isMarkoText(child)) write`${child.value}`;
|
|
10990
11023
|
else if (_marko_compiler.types.isMarkoPlaceholder(child)) write`${callRuntime("_escape", child.value)}`;
|
|
10991
|
-
} else tag.
|
|
11024
|
+
} else statements = tag.node.body.body;
|
|
10992
11025
|
if (!skipEndTag && !isOpenOnly && !selectArgs) {
|
|
10993
11026
|
if (tagName === "head" && getMarkoOpts().linkAssets) write`${callRuntime("_flush_head")}`;
|
|
10994
11027
|
write`</${tagName}>`;
|
|
10995
11028
|
}
|
|
10996
11029
|
if (markerReason) markNode(tag, nodeBinding, markerReason, tagName === "html");
|
|
10997
|
-
tag
|
|
11030
|
+
replaceWithStatements(tag, statements);
|
|
10998
11031
|
}
|
|
10999
11032
|
},
|
|
11000
11033
|
dom: {
|
|
@@ -11072,15 +11105,12 @@ var native_tag_default = {
|
|
|
11072
11105
|
},
|
|
11073
11106
|
exit(tag) {
|
|
11074
11107
|
const nodeBinding = tag.node.extra.nodeBinding;
|
|
11075
|
-
const openTagOnly = (0, _marko_compiler_babel_utils.getTagDef)(tag)?.parseOptions?.openTagOnly;
|
|
11076
11108
|
const tagName = getCanonicalTagName(tag);
|
|
11077
|
-
if (
|
|
11078
|
-
|
|
11079
|
-
|
|
11080
|
-
if (!_marko_compiler.types.isStringLiteral(textLiteral)) addStatement("render", getSection(tag), textLiteral.extra, callRuntime("_text_content", createScopeReadExpression(nodeBinding), textLiteral), true);
|
|
11081
|
-
} else tag.insertBefore(tag.node.body.body).forEach((child) => child.skip());
|
|
11109
|
+
if (tagName !== "textarea" && getTagFacts(tag).textBody) {
|
|
11110
|
+
const textLiteral = bodyToText(tag.node.body, tagName === "title");
|
|
11111
|
+
if (!_marko_compiler.types.isStringLiteral(textLiteral)) addStatement("render", getSection(tag), textLiteral.extra, callRuntime("_text_content", createScopeReadExpression(nodeBinding), textLiteral), true);
|
|
11082
11112
|
}
|
|
11083
|
-
tag
|
|
11113
|
+
replaceWithStatements(tag);
|
|
11084
11114
|
}
|
|
11085
11115
|
}
|
|
11086
11116
|
})
|
|
@@ -11586,6 +11616,7 @@ var tag_default = {
|
|
|
11586
11616
|
}
|
|
11587
11617
|
},
|
|
11588
11618
|
exit(tag) {
|
|
11619
|
+
writeBodyStatements(tag.node.body);
|
|
11589
11620
|
const translator = (0, _marko_compiler_babel_utils.getTagDef)(tag)?.translator;
|
|
11590
11621
|
if (translator) {
|
|
11591
11622
|
exitHook(translator.hook, tag);
|
|
@@ -11617,7 +11648,7 @@ var text_default = {
|
|
|
11617
11648
|
translate: { exit(text) {
|
|
11618
11649
|
if (isInTextBody(text)) return;
|
|
11619
11650
|
if (isOutputHTML()) writeTo$1(text)`${text.node.value}`;
|
|
11620
|
-
text
|
|
11651
|
+
replaceWithStatements(text);
|
|
11621
11652
|
} }
|
|
11622
11653
|
};
|
|
11623
11654
|
//#endregion
|
|
@@ -11625,7 +11656,7 @@ var text_default = {
|
|
|
11625
11656
|
function buildAggregateError(file, rootMsg, ...paths) {
|
|
11626
11657
|
const err = /* @__PURE__ */ new SyntaxError();
|
|
11627
11658
|
const fileName = path.default.relative(_marko_compiler_modules.cwd, file.opts.filename);
|
|
11628
|
-
const finalMsg = `${rootMsg}:\n\n${paths.map(([msg, path$
|
|
11659
|
+
const finalMsg = `${rootMsg}:\n\n${paths.map(([msg, path$9]) => `\x1b[90m${msg} at ${getFileNameWithLoc(fileName, path$9)}:\x1b[0m\n${getFrame(file, path$9)}`).join("\n\n")}`;
|
|
11629
11660
|
if (!("MARKO_DEBUG" in process.env)) err.stack = finalMsg;
|
|
11630
11661
|
Object.defineProperty(err, "message", {
|
|
11631
11662
|
get() {
|
|
@@ -11850,8 +11881,8 @@ function mergeVisit(visit5, visit6) {
|
|
|
11850
11881
|
} : { exit } : enter;
|
|
11851
11882
|
}
|
|
11852
11883
|
function mergeHook(hook5, hook6) {
|
|
11853
|
-
return (hook5 || hook6) && function(path$
|
|
11854
|
-
return (isTagsAPI() ? hook6 : hook5)?.call(this, path$
|
|
11884
|
+
return (hook5 || hook6) && function(path$8, state) {
|
|
11885
|
+
return (isTagsAPI() ? hook6 : hook5)?.call(this, path$8, state);
|
|
11855
11886
|
};
|
|
11856
11887
|
}
|
|
11857
11888
|
function mergeTaglibs(libs5, libs6) {
|