marko 6.4.16 → 6.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cheatsheet.md +12 -1
- package/dist/debug/dom/catch.feat.js +2 -2
- package/dist/debug/dom/catch.feat.mjs +2 -2
- package/dist/debug/dom/compat.feat.js +1 -1
- package/dist/debug/dom/compat.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-BLoTKI2r.js → dom-BiJ_UKJV.js} +9 -9
- package/dist/debug/{dom-DlBA4dCe.mjs → dom-D3A8gh_D.mjs} +4 -4
- package/dist/debug/dom.js +1 -1
- package/dist/debug/dom.mjs +1 -1
- package/dist/debug/html/compat.feat.js +1 -1
- package/dist/debug/html/compat.feat.mjs +1 -1
- package/dist/debug/{html-DM7X2D_b.mjs → html-Bfl3MJP9.mjs} +27 -24
- package/dist/debug/{html-Du0z056z.js → html-shBfuhlc.js} +27 -24
- package/dist/debug/html.js +1 -1
- package/dist/debug/html.mjs +1 -1
- package/dist/dom/catch.feat.js +3 -3
- package/dist/dom/catch.feat.mjs +2 -2
- package/dist/dom/compat.feat.js +1 -1
- package/dist/dom/compat.feat.mjs +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/dynamic-tag-script.feat.js +1 -1
- package/dist/dom/dynamic-tag-script.feat.mjs +1 -1
- package/dist/dom/dynamic-tag-var.feat.js +1 -1
- 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 +1 -1
- package/dist/dom/placeholder.feat.mjs +1 -1
- package/dist/{dom-BRtFOIF-.js → dom-B3piR0q1.js} +5 -5
- package/dist/{dom-Cqajrs_w.mjs → dom-CPk_8CMB.mjs} +4 -4
- package/dist/dom.js +2 -2
- package/dist/dom.mjs +1 -1
- package/dist/html/compat.feat.js +1 -1
- package/dist/html/compat.feat.mjs +1 -1
- package/dist/html/writer.d.ts +0 -1
- package/dist/{html-C3dQGQ2x.mjs → html-BD-y50wS.mjs} +25 -22
- package/dist/{html-4A3vJpIT.js → html-aFBpTKdf.js} +25 -22
- package/dist/html.js +1 -1
- package/dist/html.mjs +1 -1
- package/dist/translator/core/define.d.ts +6 -0
- package/dist/translator/core/show.d.ts +1 -1
- package/dist/translator/index.js +577 -611
- package/dist/translator/util/assert.d.ts +2 -0
- package/dist/translator/util/bindings.d.ts +15 -8
- package/dist/translator/util/cyclic-memo.d.ts +0 -1
- package/dist/translator/util/entry-builder.d.ts +2 -3
- package/dist/translator/util/finalize-references.d.ts +0 -1
- package/dist/translator/util/for-selector.d.ts +0 -1
- package/dist/translator/util/module-registrations.d.ts +1 -0
- package/dist/translator/util/optional.d.ts +7 -5
- package/dist/translator/util/reasons.d.ts +1 -2
- package/dist/translator/util/references.d.ts +6 -5
- package/dist/translator/util/sections.d.ts +4 -1
- package/dist/translator/util/signals.d.ts +1 -1
- package/dist/translator/util/slots.d.ts +1 -2
- package/dist/translator/util/solve-reasons.d.ts +2 -2
- package/dist/translator/util/structure.d.ts +1 -0
- package/dist/translator/visitors/tag/native-tag.d.ts +2 -0
- package/index.d.ts +11 -0
- package/package.json +4 -4
package/dist/translator/index.js
CHANGED
|
@@ -149,26 +149,14 @@ const TagVariable$1 = "#TagVariable";
|
|
|
149
149
|
const TagVariableChange$2 = "#TagVariableChange";
|
|
150
150
|
const TryBranch$2 = "#TryBranch";
|
|
151
151
|
// src/html/serializer.ts
|
|
152
|
-
const kTouchedIterator = /* @__PURE__ */ Symbol.for("marko.touchedIterator");
|
|
153
152
|
const { hasOwnProperty } = {};
|
|
154
153
|
Array.prototype;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
patchIteratorNext(Generator.prototype);
|
|
158
|
-
patchIteratorNext(AsyncGenerator.prototype);
|
|
154
|
+
(/* @__PURE__ */ (function* () {})()).constructor;
|
|
155
|
+
(/* @__PURE__ */ (async function* () {})()).constructor;
|
|
159
156
|
function toAccess(accessor) {
|
|
160
157
|
const start = accessor[0];
|
|
161
158
|
return start === "[" ? accessor : start === "\"" || start >= "0" && start <= "9" ? "[" + accessor + "]" : "." + accessor;
|
|
162
159
|
}
|
|
163
|
-
function patchIteratorNext(proto) {
|
|
164
|
-
if (proto.next[kTouchedIterator]) return;
|
|
165
|
-
const { next } = proto;
|
|
166
|
-
proto.next = function(value) {
|
|
167
|
-
this[kTouchedIterator] = 1;
|
|
168
|
-
return next.call(this, value);
|
|
169
|
-
};
|
|
170
|
-
proto.next[kTouchedIterator] = true;
|
|
171
|
-
}
|
|
172
160
|
// src/translator/util/optional.ts
|
|
173
161
|
var Sorted = class {
|
|
174
162
|
compare;
|
|
@@ -195,12 +183,12 @@ var Sorted = class {
|
|
|
195
183
|
}
|
|
196
184
|
return b;
|
|
197
185
|
}
|
|
198
|
-
filter(data, cb) {
|
|
199
|
-
if (!Array.isArray(data)) return data !== void 0 && cb(data) ? data : void 0;
|
|
200
|
-
for (let i = 0; i < data.length; i++) if (!cb(data[i])) {
|
|
186
|
+
filter(data, cb, context) {
|
|
187
|
+
if (!Array.isArray(data)) return data !== void 0 && cb(data, context) ? data : void 0;
|
|
188
|
+
for (let i = 0; i < data.length; i++) if (!cb(data[i], context)) {
|
|
201
189
|
const kept = [];
|
|
202
190
|
for (let j = 0; j < i; j++) kept.push(data[j]);
|
|
203
|
-
while (++i < data.length) if (cb(data[i])) kept.push(data[i]);
|
|
191
|
+
while (++i < data.length) if (cb(data[i], context)) kept.push(data[i]);
|
|
204
192
|
return kept.length > 1 ? kept : kept[0];
|
|
205
193
|
}
|
|
206
194
|
return data;
|
|
@@ -234,12 +222,6 @@ var Sorted = class {
|
|
|
234
222
|
}
|
|
235
223
|
return acc;
|
|
236
224
|
}
|
|
237
|
-
find(data, item) {
|
|
238
|
-
if (data !== void 0) {
|
|
239
|
-
if (Array.isArray(data)) return findSorted(this.compare, data, item);
|
|
240
|
-
else if (this.compare(data, item) === 0) return data;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
225
|
has(data, item) {
|
|
244
226
|
return this.findIndex(data, item) !== -1;
|
|
245
227
|
}
|
|
@@ -358,12 +340,10 @@ function filter(data, cb) {
|
|
|
358
340
|
if (cb(data)) return data;
|
|
359
341
|
}
|
|
360
342
|
}
|
|
361
|
-
function forEach(data, cb) {
|
|
343
|
+
function forEach(data, cb, context) {
|
|
362
344
|
if (data !== void 0) {
|
|
363
|
-
if (Array.isArray(data))
|
|
364
|
-
|
|
365
|
-
for (const item of data) cb(item, i++);
|
|
366
|
-
} else cb(data, 0);
|
|
345
|
+
if (Array.isArray(data)) for (const item of data) cb(item, context);
|
|
346
|
+
else cb(data, context);
|
|
367
347
|
}
|
|
368
348
|
}
|
|
369
349
|
function fromIter(data) {
|
|
@@ -380,11 +360,19 @@ function find(data, cb) {
|
|
|
380
360
|
if (cb(data, 0)) return data;
|
|
381
361
|
}
|
|
382
362
|
}
|
|
383
|
-
function some(data, cb) {
|
|
384
|
-
|
|
363
|
+
function some(data, cb, context) {
|
|
364
|
+
if (Array.isArray(data)) {
|
|
365
|
+
for (const item of data) if (cb(item, context)) return true;
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
return data !== void 0 && !!cb(data, context);
|
|
385
369
|
}
|
|
386
|
-
function every(data, cb) {
|
|
387
|
-
|
|
370
|
+
function every(data, cb, context) {
|
|
371
|
+
if (Array.isArray(data)) {
|
|
372
|
+
for (const item of data) if (!cb(item, context)) return false;
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
375
|
+
return data === void 0 || cb(data, context);
|
|
388
376
|
}
|
|
389
377
|
function reduce(data, cb, initial) {
|
|
390
378
|
return data !== void 0 ? Array.isArray(data) ? data.reduce(cb, initial) : cb(initial, data, 0) : initial;
|
|
@@ -419,10 +407,6 @@ function mapToString(data, sep, cb) {
|
|
|
419
407
|
}
|
|
420
408
|
return "";
|
|
421
409
|
}
|
|
422
|
-
function findSorted(compare, data, item) {
|
|
423
|
-
const index = searchSorted(compare, data, item);
|
|
424
|
-
if (index >= 0) return data[index];
|
|
425
|
-
}
|
|
426
410
|
function findIndexSorted(compare, data, item) {
|
|
427
411
|
const index = searchSorted(compare, data, item);
|
|
428
412
|
return index < 0 ? -1 : index;
|
|
@@ -984,49 +968,78 @@ const SectionRef = "sectionRef";
|
|
|
984
968
|
const ExportRef = "exportRef";
|
|
985
969
|
// src/translator/util/cyclic-memo.ts
|
|
986
970
|
let computations = 0;
|
|
971
|
+
const running = [];
|
|
987
972
|
let provisionalAt = Infinity;
|
|
973
|
+
let provisionalTo = -1;
|
|
988
974
|
function createCyclicMemo(compute, cycleAnswer) {
|
|
989
975
|
const cache = /* @__PURE__ */ new WeakMap();
|
|
990
976
|
const computing = /* @__PURE__ */ new Map();
|
|
977
|
+
const provisional = /* @__PURE__ */ new WeakMap();
|
|
991
978
|
return (key) => {
|
|
992
979
|
if (cache.has(key)) return cache.get(key);
|
|
993
980
|
const at = computing.get(key);
|
|
994
981
|
if (at !== void 0) {
|
|
995
|
-
|
|
982
|
+
takeCycleAnswers(at, at);
|
|
996
983
|
return cycleAnswer;
|
|
997
984
|
}
|
|
998
|
-
const
|
|
999
|
-
|
|
985
|
+
const answer = provisional.get(key);
|
|
986
|
+
if (answer && running[answer.to] === answer.computation) {
|
|
987
|
+
takeCycleAnswers(answer.at, answer.to);
|
|
988
|
+
return answer.result;
|
|
989
|
+
}
|
|
990
|
+
const depth = running.push(computations++) - 1;
|
|
991
|
+
computing.set(key, depth);
|
|
1000
992
|
const outerProvisionalAt = provisionalAt;
|
|
993
|
+
const outerProvisionalTo = provisionalTo;
|
|
1001
994
|
provisionalAt = Infinity;
|
|
995
|
+
provisionalTo = -1;
|
|
1002
996
|
try {
|
|
1003
997
|
const result = compute(key);
|
|
1004
|
-
if (provisionalAt >=
|
|
998
|
+
if (provisionalAt >= depth) cache.set(key, result);
|
|
999
|
+
else if (provisionalTo < depth) provisional.set(key, {
|
|
1000
|
+
result,
|
|
1001
|
+
at: provisionalAt,
|
|
1002
|
+
to: provisionalTo,
|
|
1003
|
+
computation: running[provisionalTo]
|
|
1004
|
+
});
|
|
1005
1005
|
return result;
|
|
1006
1006
|
} finally {
|
|
1007
1007
|
computing.delete(key);
|
|
1008
|
-
|
|
1008
|
+
running.pop();
|
|
1009
|
+
if (provisionalAt >= depth) {
|
|
1010
|
+
provisionalAt = outerProvisionalAt;
|
|
1011
|
+
provisionalTo = outerProvisionalTo;
|
|
1012
|
+
} else takeCycleAnswers(outerProvisionalAt, outerProvisionalTo);
|
|
1009
1013
|
}
|
|
1010
1014
|
};
|
|
1011
1015
|
}
|
|
1016
|
+
function takeCycleAnswers(at, to) {
|
|
1017
|
+
if (at < provisionalAt) provisionalAt = at;
|
|
1018
|
+
if (to > provisionalTo) provisionalTo = to;
|
|
1019
|
+
}
|
|
1012
1020
|
function createAnalysisMemo(compute, cycleAnswer) {
|
|
1013
1021
|
const create = () => createCyclicMemo(compute, cycleAnswer);
|
|
1014
1022
|
const [getMemo, setMemo] = createAnalysisState(create);
|
|
1015
|
-
return [(key) =>
|
|
1016
|
-
|
|
1017
|
-
|
|
1023
|
+
return [(key) => {
|
|
1024
|
+
let memo = getMemo();
|
|
1025
|
+
if (!memo) setMemo(memo = create());
|
|
1026
|
+
return memo(key);
|
|
1027
|
+
}, () => setMemo(null)];
|
|
1028
|
+
}
|
|
1029
|
+
let passMemoCount = 0;
|
|
1030
|
+
const [getPassMemos] = createAnalysisState(() => new Array(passMemoCount).fill(void 0));
|
|
1018
1031
|
function createPassMemo(compute, cycleAnswer) {
|
|
1019
|
-
const
|
|
1020
|
-
|
|
1021
|
-
|
|
1032
|
+
const index = passMemoCount++;
|
|
1033
|
+
return (key) => {
|
|
1034
|
+
const memos = getPassMemos();
|
|
1035
|
+
let memo = memos[index];
|
|
1036
|
+
if (!memo) memos[index] = memo = createCyclicMemo(compute, cycleAnswer);
|
|
1037
|
+
return memo(key);
|
|
1038
|
+
};
|
|
1022
1039
|
}
|
|
1023
1040
|
function resetPassMemos() {
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
function createPassPathMemo(compute, cycleAnswer) {
|
|
1027
|
-
const getKey = createPathKeys();
|
|
1028
|
-
const memo = createPassMemo(([key, path]) => compute(key, path), cycleAnswer);
|
|
1029
|
-
return (key, path) => memo(getKey(key, path));
|
|
1041
|
+
const memos = getPassMemos();
|
|
1042
|
+
for (let i = 0; i < memos.length; i++) memos[i] = void 0;
|
|
1030
1043
|
}
|
|
1031
1044
|
function createPathKeys() {
|
|
1032
1045
|
const keys = /* @__PURE__ */ new WeakMap();
|
|
@@ -1188,7 +1201,7 @@ const globalSources = {
|
|
|
1188
1201
|
always: void 0
|
|
1189
1202
|
};
|
|
1190
1203
|
function sharesSources(a, b) {
|
|
1191
|
-
return !!a.sources && !!b.sources && (bindingUtil.intersects(a.sources.state, b.sources.state) || some(a.sources.param,
|
|
1204
|
+
return !!a.sources && !!b.sources && (bindingUtil.intersects(a.sources.state, b.sources.state) || some(a.sources.param, isCoveredParam, b.sources.param) || some(b.sources.param, isCoveredParam, a.sources.param));
|
|
1192
1205
|
}
|
|
1193
1206
|
function createSources(state, param, global, always) {
|
|
1194
1207
|
/* v8 ignore next 6 -- every caller passes at least one source */
|
|
@@ -1232,10 +1245,10 @@ function mergeSources(a, b) {
|
|
|
1232
1245
|
function unionParamSources(a, b) {
|
|
1233
1246
|
const merged = bindingUtil.union(a, b);
|
|
1234
1247
|
if (merged === a || merged === b) return merged;
|
|
1235
|
-
return bindingUtil.union(
|
|
1248
|
+
return bindingUtil.union(bindingUtil.filter(a, isUncoveredAlias, b), bindingUtil.filter(b, isUncoveredAlias, a));
|
|
1236
1249
|
}
|
|
1237
|
-
function
|
|
1238
|
-
return
|
|
1250
|
+
function isUncoveredAlias(binding, params) {
|
|
1251
|
+
return !isCoveredParam(binding.aliasOf, params);
|
|
1239
1252
|
}
|
|
1240
1253
|
function isInParams(binding, params) {
|
|
1241
1254
|
return bindingUtil.has(params, binding);
|
|
@@ -1243,7 +1256,7 @@ function isInParams(binding, params) {
|
|
|
1243
1256
|
function isSupersetSources(a, b) {
|
|
1244
1257
|
if (!b.sources) return true;
|
|
1245
1258
|
if (!a.sources) return false;
|
|
1246
|
-
return bindingUtil.isSuperset(a.sources.state, b.sources.state) && every(b.sources.param,
|
|
1259
|
+
return bindingUtil.isSuperset(a.sources.state, b.sources.state) && every(b.sources.param, isCoveredParam, a.sources.param);
|
|
1247
1260
|
}
|
|
1248
1261
|
function isCoveredParam(binding, params) {
|
|
1249
1262
|
return someUpToAliasRoot(binding, isInParams, params);
|
|
@@ -1299,7 +1312,7 @@ function trackVarReferences(tag, type, aliased) {
|
|
|
1299
1312
|
const tagVar = tag.node.var;
|
|
1300
1313
|
if (tagVar) {
|
|
1301
1314
|
const section = ensureSection(tag);
|
|
1302
|
-
let target = aliased
|
|
1315
|
+
let target = aliased?.canonical;
|
|
1303
1316
|
if (target) {
|
|
1304
1317
|
const { excludeProperties, restOffset } = target;
|
|
1305
1318
|
if (isRest(target)) target = target.aliasOf;
|
|
@@ -1407,7 +1420,7 @@ function trackAssignment(assignment, binding) {
|
|
|
1407
1420
|
const fnParent = getFnParent(assignment);
|
|
1408
1421
|
if (!fnParent) throw assignment.buildCodeFrameError(`\`${binding.name}\` is a tag ${binding.type === 2 ? "parameter" : "variable"} and can only be assigned within a script or function.`);
|
|
1409
1422
|
if (binding.type === 3) throw assignment.buildCodeFrameError(`\`${binding.name}\` is a tag parameter and cannot be assigned to.`);
|
|
1410
|
-
const assigned =
|
|
1423
|
+
const assigned = binding.canonical;
|
|
1411
1424
|
const fnRoot = getFnRoot(fnParent);
|
|
1412
1425
|
const fnExtra = fnRoot && (fnRoot.node.extra ??= {});
|
|
1413
1426
|
const section = ensureSection(assignment);
|
|
@@ -1427,7 +1440,7 @@ function trackAssignment(assignment, binding) {
|
|
|
1427
1440
|
if (assigned.aliasOf && assigned.property !== void 0) {
|
|
1428
1441
|
if (assigned.aliasOf === assigned.section.params) throw assignment.buildCodeFrameError(`\`${binding.name}\` is a tag parameter and cannot be assigned to.`);
|
|
1429
1442
|
const changePropName = assigned.property + "Change";
|
|
1430
|
-
const changeBinding = assigned.aliasOf.propertyAliases
|
|
1443
|
+
const changeBinding = assigned.aliasOf.propertyAliases?.get(changePropName) || createBinding(generateUid(changePropName), assigned.type, assigned.section, assigned.aliasOf, changePropName, void 0, id.node.loc, assigned.declared);
|
|
1431
1444
|
idExtra.assignmentTo = changeBinding;
|
|
1432
1445
|
addReadToExpression(id, changeBinding, void 0);
|
|
1433
1446
|
}
|
|
@@ -1496,7 +1509,7 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, aliased, p
|
|
|
1496
1509
|
}
|
|
1497
1510
|
}
|
|
1498
1511
|
function ensurePatternBinding(lVal, type, section, aliased, property, excludeProperties) {
|
|
1499
|
-
const patternBinding = (property ? aliased.propertyAliases
|
|
1512
|
+
const patternBinding = (property ? aliased.propertyAliases?.get(property) : aliased) || ((lVal.extra ??= {}).binding = createBinding(generateUid(property || "pattern"), type, section, aliased, property, excludeProperties, lVal.loc));
|
|
1500
1513
|
if (patternBinding.section === section) patternBinding.nullable = false;
|
|
1501
1514
|
return patternBinding;
|
|
1502
1515
|
}
|
|
@@ -1521,13 +1534,13 @@ function trackReference(referencePath, binding) {
|
|
|
1521
1534
|
if (parent.object !== root.node) break;
|
|
1522
1535
|
let prop = getMemberExpressionPropString(parent);
|
|
1523
1536
|
if (isAssignedMember(root.parentPath)) {
|
|
1524
|
-
const object =
|
|
1537
|
+
const object = reference.canonical;
|
|
1525
1538
|
if (isRest(object)) throw root.parentPath.buildCodeFrameError(`\`${referencePath.node.name}\` is a rest element, a copy rebuilt from the value it is destructured from whenever that changes, so assigning its members would be lost. Assign the property on that value instead, or keep your own copy in a \`<let>\`.`);
|
|
1526
1539
|
addAssignedProperty(object, prop);
|
|
1527
1540
|
break;
|
|
1528
1541
|
}
|
|
1529
1542
|
if (prop === void 0) break;
|
|
1530
|
-
if (
|
|
1543
|
+
if (isRest(reference)) {
|
|
1531
1544
|
if (reference.restOffset !== void 0) {
|
|
1532
1545
|
if (isIndexProperty(prop)) {
|
|
1533
1546
|
prop = `${+prop + reference.restOffset}`;
|
|
@@ -1570,9 +1583,7 @@ function mergeReferenceGroup(section, nodes) {
|
|
|
1570
1583
|
function mergeInto(section, extra, nodes) {
|
|
1571
1584
|
const targetExtra = extra;
|
|
1572
1585
|
const readsByExpression = getReadsByExpression();
|
|
1573
|
-
const fnReadsByExpression = getFunctionReadsByExpression();
|
|
1574
1586
|
let reads = readsByExpression.get(targetExtra);
|
|
1575
|
-
let exprFnReads = fnReadsByExpression.get(targetExtra);
|
|
1576
1587
|
let { isEffect, retained } = targetExtra;
|
|
1577
1588
|
for (const node of nodes) {
|
|
1578
1589
|
if (!node) continue;
|
|
@@ -1581,7 +1592,6 @@ function mergeInto(section, extra, nodes) {
|
|
|
1581
1592
|
retained ||= extra.retained;
|
|
1582
1593
|
if (isReferencedExtra(extra)) {
|
|
1583
1594
|
const additionalReads = readsByExpression.get(extra);
|
|
1584
|
-
const additionalExprFnReads = fnReadsByExpression.get(extra);
|
|
1585
1595
|
isEffect ||= extra.isEffect;
|
|
1586
1596
|
if (additionalReads) {
|
|
1587
1597
|
forEach(additionalReads, (read) => {
|
|
@@ -1592,10 +1602,6 @@ function mergeInto(section, extra, nodes) {
|
|
|
1592
1602
|
reads = concat(reads, additionalReads);
|
|
1593
1603
|
readsByExpression.delete(extra);
|
|
1594
1604
|
}
|
|
1595
|
-
if (additionalExprFnReads) {
|
|
1596
|
-
if (exprFnReads) for (const [key, value] of additionalExprFnReads) exprFnReads.set(key, value);
|
|
1597
|
-
else fnReadsByExpression.set(targetExtra, exprFnReads = new Map(additionalExprFnReads));
|
|
1598
|
-
}
|
|
1599
1605
|
} else if (extra.dropped)
|
|
1600
1606
|
/* v8 ignore next -- a dropped reference is never merged into another */
|
|
1601
1607
|
throw new Error("Cannot merge a dropped reference.");
|
|
@@ -1632,7 +1638,6 @@ function setDerivedFrom(binding, expr, exprs) {
|
|
|
1632
1638
|
}
|
|
1633
1639
|
const [getAssignments] = createAnalysisState(() => []);
|
|
1634
1640
|
const [getReadsByExpression] = createAnalysisState(() => /* @__PURE__ */ new Map());
|
|
1635
|
-
const [getFunctionReadsByExpression] = createAnalysisState(() => /* @__PURE__ */ new Map());
|
|
1636
1641
|
const [getReferenceFinalizers] = createAnalysisState(() => []);
|
|
1637
1642
|
function onFinalizeReferences(finalize) {
|
|
1638
1643
|
getReferenceFinalizers().push(finalize);
|
|
@@ -1642,6 +1647,7 @@ function addRead(exprExtra, extra, exprRoot, binding, section, getter) {
|
|
|
1642
1647
|
const readsByExpression = getReadsByExpression();
|
|
1643
1648
|
const read = {
|
|
1644
1649
|
binding,
|
|
1650
|
+
holder: binding,
|
|
1645
1651
|
extra,
|
|
1646
1652
|
getter,
|
|
1647
1653
|
inOwnBody: false,
|
|
@@ -1650,7 +1656,8 @@ function addRead(exprExtra, extra, exprRoot, binding, section, getter) {
|
|
|
1650
1656
|
fnRoot: void 0
|
|
1651
1657
|
};
|
|
1652
1658
|
if (section.dropped) return read;
|
|
1653
|
-
binding.reads
|
|
1659
|
+
const bindingReads = binding.reads ??= /* @__PURE__ */ new Map();
|
|
1660
|
+
bindingReads.set(exprExtra, push(bindingReads.get(exprExtra), read));
|
|
1654
1661
|
exprExtra.section = section;
|
|
1655
1662
|
readsByExpression.set(exprExtra, push(readsByExpression.get(exprExtra), read));
|
|
1656
1663
|
return read;
|
|
@@ -1679,12 +1686,12 @@ function untrackExpr(exprExtra) {
|
|
|
1679
1686
|
const reads = readsByExpr.get(exprExtra);
|
|
1680
1687
|
if (reads) {
|
|
1681
1688
|
readsByExpr.delete(exprExtra);
|
|
1682
|
-
|
|
1683
|
-
forEach(reads, (read) => {
|
|
1684
|
-
for (let cur = read.binding; cur; cur = cur.aliasOf) cur.reads.delete(exprExtra);
|
|
1685
|
-
});
|
|
1689
|
+
forEach(reads, untrackRead, exprExtra);
|
|
1686
1690
|
}
|
|
1687
1691
|
}
|
|
1692
|
+
function untrackRead({ holder }, exprExtra) {
|
|
1693
|
+
if (holder.reads?.delete(exprExtra) && !holder.reads.size) holder.reads = void 0;
|
|
1694
|
+
}
|
|
1688
1695
|
function dropContent(body) {
|
|
1689
1696
|
const bodyExtra = body.extra ??= {};
|
|
1690
1697
|
bodyExtra.dropped = true;
|
|
@@ -1727,14 +1734,10 @@ function addReadToExpression(root, binding, getter) {
|
|
|
1727
1734
|
if (!getter && root.parent.type === "MarkoSpreadAttribute") extra.spreadFrom = binding;
|
|
1728
1735
|
if (fnRoot) {
|
|
1729
1736
|
read.deferred = fnRoot.node.type !== "ObjectMethod" || fnRoot.node.kind === "method";
|
|
1730
|
-
const fnReadsByExpr = getFunctionReadsByExpression();
|
|
1731
|
-
let exprFnReads = fnReadsByExpr.get(exprExtra);
|
|
1732
|
-
if (!exprFnReads) fnReadsByExpr.set(exprExtra, exprFnReads = /* @__PURE__ */ new Map());
|
|
1733
1737
|
const fnExtra = fnRoot.node.extra ??= {};
|
|
1734
1738
|
fnExtra.section = section;
|
|
1735
1739
|
fnExtra.exprRoot = rootExtra;
|
|
1736
1740
|
read.fnRoot = fnExtra;
|
|
1737
|
-
exprFnReads.set(fnExtra, push(exprFnReads.get(fnExtra), read));
|
|
1738
1741
|
}
|
|
1739
1742
|
}
|
|
1740
1743
|
function getAllTagReferenceNodes(tag, referenceNodes = [], collectAttrTag) {
|
|
@@ -1752,19 +1755,11 @@ function getChildTagReferenceNodes(tag, referenceNodes, collectAttrTag) {
|
|
|
1752
1755
|
}
|
|
1753
1756
|
return referenceNodes;
|
|
1754
1757
|
}
|
|
1755
|
-
function createResolvedRead(binding, properties, inOwnBody = false) {
|
|
1758
|
+
function createResolvedRead(binding, properties, inOwnBody = false, getter) {
|
|
1756
1759
|
return {
|
|
1757
1760
|
binding,
|
|
1758
1761
|
properties,
|
|
1759
1762
|
inOwnBody,
|
|
1760
|
-
getter: void 0
|
|
1761
|
-
};
|
|
1762
|
-
}
|
|
1763
|
-
function createResolvedGetterRead(binding, properties, getter) {
|
|
1764
|
-
return {
|
|
1765
|
-
binding,
|
|
1766
|
-
properties,
|
|
1767
|
-
inOwnBody: false,
|
|
1768
1763
|
getter
|
|
1769
1764
|
};
|
|
1770
1765
|
}
|
|
@@ -1828,18 +1823,16 @@ function addNumericPropertiesUntil(properties, len) {
|
|
|
1828
1823
|
}
|
|
1829
1824
|
// src/translator/util/for-selector.ts
|
|
1830
1825
|
function isForSelectorClosure(bodySection, closure) {
|
|
1831
|
-
return !!bodySection.selector?.has(
|
|
1832
|
-
}
|
|
1833
|
-
function isForSelectorValue(binding) {
|
|
1834
|
-
return some(binding.closureSections, (section) => !!section.selector?.has(binding));
|
|
1826
|
+
return !!bodySection.selector?.has(closure.canonical);
|
|
1835
1827
|
}
|
|
1836
1828
|
function detectForSelector(bodySection, keyBinding) {
|
|
1829
|
+
if (!keyBinding.reads) return;
|
|
1837
1830
|
const parentSection = bodySection.parent;
|
|
1838
1831
|
let closures;
|
|
1839
1832
|
for (const expr of keyBinding.reads.keys()) {
|
|
1840
1833
|
if (expr.section !== bodySection) continue;
|
|
1841
1834
|
forEach(getReferencedBindings(expr), (closure) => {
|
|
1842
|
-
const canonical =
|
|
1835
|
+
const canonical = closure.canonical;
|
|
1843
1836
|
if (!closures?.has(canonical) && bindingUtil.has(bodySection.referencedClosures, canonical) && !parentSection.selector?.has(canonical) && onlyComparesKey(closure, canonical, bodySection, keyBinding)) {
|
|
1844
1837
|
(closures ||= /* @__PURE__ */ new Set()).add(canonical);
|
|
1845
1838
|
if (canonical.section !== parentSection) parentSection.referencedClosures = bindingUtil.add(parentSection.referencedClosures, canonical);
|
|
@@ -1850,47 +1843,50 @@ function detectForSelector(bodySection, keyBinding) {
|
|
|
1850
1843
|
}
|
|
1851
1844
|
function onlyComparesKey(closure, canonical, bodySection, keyBinding) {
|
|
1852
1845
|
let found = false;
|
|
1853
|
-
for (let chain = closure; chain; chain = chain.aliasOf)
|
|
1854
|
-
if (
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
if (resolved
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1846
|
+
for (let chain = closure; chain; chain = chain.aliasOf) {
|
|
1847
|
+
if (!chain.reads) continue;
|
|
1848
|
+
for (const [expr, reads] of chain.reads) {
|
|
1849
|
+
if (expr.section !== bodySection) continue;
|
|
1850
|
+
let other = false;
|
|
1851
|
+
forEach(reads, (read) => {
|
|
1852
|
+
const resolved = read.extra.read;
|
|
1853
|
+
if (!resolved) return;
|
|
1854
|
+
if (resolvesTo(resolved, canonical)) {
|
|
1855
|
+
const keyRead = read.comparedTo?.extra?.read;
|
|
1856
|
+
if (resolved.getter || !readsKey(keyRead, keyBinding)) other = true;
|
|
1857
|
+
else found = true;
|
|
1858
|
+
} else other ||= resolvesThrough(resolved, canonical);
|
|
1859
|
+
});
|
|
1860
|
+
if (other) return false;
|
|
1861
|
+
}
|
|
1866
1862
|
}
|
|
1867
1863
|
return found;
|
|
1868
1864
|
}
|
|
1869
1865
|
function resolvesTo(read, canonical) {
|
|
1870
1866
|
const binding = getPropertyAlias(read.binding, read.properties);
|
|
1871
|
-
return !!binding &&
|
|
1867
|
+
return !!binding && binding.canonical === canonical;
|
|
1872
1868
|
}
|
|
1873
1869
|
function resolvesThrough(read, canonical) {
|
|
1874
1870
|
let binding = read.binding;
|
|
1875
1871
|
let through = false;
|
|
1876
1872
|
forEach(read.properties, (prop) => {
|
|
1877
1873
|
if (binding) {
|
|
1878
|
-
through ||=
|
|
1879
|
-
binding = binding.propertyAliases
|
|
1874
|
+
through ||= binding.canonical === canonical;
|
|
1875
|
+
binding = binding.propertyAliases?.get(prop);
|
|
1880
1876
|
}
|
|
1881
1877
|
});
|
|
1882
1878
|
return through;
|
|
1883
1879
|
}
|
|
1884
1880
|
function readsKey(read, keyBinding) {
|
|
1885
|
-
return !!read && !read.getter && resolvesTo(read,
|
|
1881
|
+
return !!read && !read.getter && resolvesTo(read, keyBinding);
|
|
1886
1882
|
}
|
|
1887
1883
|
// src/translator/util/slots.ts
|
|
1888
1884
|
function ensureSlot(binding, kind = 0, section, group) {
|
|
1889
|
-
const owner =
|
|
1885
|
+
const owner = binding.canonical;
|
|
1890
1886
|
return ensureIn(section || owner.section, owner, kind, group);
|
|
1891
1887
|
}
|
|
1892
1888
|
function findSlot(binding, kind = 0, section, group) {
|
|
1893
|
-
const owner =
|
|
1889
|
+
const owner = binding.canonical;
|
|
1894
1890
|
return findIn((section || owner.section).slots, owner.uid, kind, group);
|
|
1895
1891
|
}
|
|
1896
1892
|
function ensureSectionSlot(owner, kind, section = owner) {
|
|
@@ -2220,10 +2216,10 @@ function getOrShareSectionGuard(section, params, check) {
|
|
|
2220
2216
|
return _marko_compiler.types.parenthesizedExpression(_marko_compiler.types.identifier(shared));
|
|
2221
2217
|
}
|
|
2222
2218
|
function isDynamicWriteGuard(section, reason) {
|
|
2223
|
-
return isGuardedReason(reason) && !
|
|
2219
|
+
return isGuardedReason(reason) && !some(reason.param, isOutsideSection, section);
|
|
2224
2220
|
}
|
|
2225
|
-
function
|
|
2226
|
-
return
|
|
2221
|
+
function isOutsideSection(param, section) {
|
|
2222
|
+
return !isSameOrAncestorSection(param.section, section);
|
|
2227
2223
|
}
|
|
2228
2224
|
function getStaticGroupBit(body, group) {
|
|
2229
2225
|
const index = findParamReasonGroupIndex(body, group);
|
|
@@ -2238,7 +2234,9 @@ function getCallsBit(body, group) {
|
|
|
2238
2234
|
let bit;
|
|
2239
2235
|
for (const call of Array.isArray(renderedBy) ? renderedBy : [renderedBy]) {
|
|
2240
2236
|
const callSection = call.childScopeBinding.section;
|
|
2241
|
-
const
|
|
2237
|
+
const reason = findSlot(call.childScopeBinding, 5, callSection, group)?.reason;
|
|
2238
|
+
if (isGuardedReason(reason) && !compareReferences(reason.param, group)) continue;
|
|
2239
|
+
const callBit = getWriteBit(callSection, reason);
|
|
2242
2240
|
if (callBit === void 0 || bit !== void 0 && bit !== callBit) return;
|
|
2243
2241
|
bit = callBit;
|
|
2244
2242
|
}
|
|
@@ -2248,7 +2246,7 @@ function isOnlyCalled(body) {
|
|
|
2248
2246
|
return !!body.renderedBy && !!body.derives && !some(body.derives.binding, isUsed);
|
|
2249
2247
|
}
|
|
2250
2248
|
function isUsed(binding) {
|
|
2251
|
-
return !!binding.reads
|
|
2249
|
+
return !!(binding.reads || binding.aliases || binding.propertyAliases);
|
|
2252
2250
|
}
|
|
2253
2251
|
function createGuardShares() {
|
|
2254
2252
|
return {
|
|
@@ -2509,15 +2507,21 @@ function solveReasons(intersectionsBySection) {
|
|
|
2509
2507
|
forEachSection((section) => addIntersectionReasons(section, intersectionsBySection.get(section)));
|
|
2510
2508
|
forEachSection(addClosureReasons);
|
|
2511
2509
|
forEachSection(addCallOwnerReasons);
|
|
2512
|
-
addRegisteredFnReasons(
|
|
2510
|
+
addRegisteredFnReasons();
|
|
2511
|
+
} while (reasonsVersion !== getReasonsVersion());
|
|
2512
|
+
do {
|
|
2513
|
+
reasonsVersion = getReasonsVersion();
|
|
2513
2514
|
forEachSectionReverse(solveSectionReasons);
|
|
2514
2515
|
} while (reasonsVersion !== getReasonsVersion());
|
|
2515
|
-
getFunctionReadsByExpression().clear();
|
|
2516
2516
|
}
|
|
2517
2517
|
function solveSectionReasons(section) {
|
|
2518
2518
|
addKnownTagReasons(section);
|
|
2519
|
-
|
|
2520
|
-
|
|
2519
|
+
let { reason } = section;
|
|
2520
|
+
for (const slot of section.slots) {
|
|
2521
|
+
reason = mergeSources(reason, slot.reason);
|
|
2522
|
+
ensureReasonGroups(section, slot.reason);
|
|
2523
|
+
}
|
|
2524
|
+
ensureReasonGroups(section, section.reason = reason);
|
|
2521
2525
|
}
|
|
2522
2526
|
function addIntersectionReasons(section, intersections) {
|
|
2523
2527
|
if (intersections) for (const intersection of intersections) for (let i = 0; i < intersection.length - 1; i++) for (let j = i + 1; j < intersection.length; j++) {
|
|
@@ -2535,14 +2539,17 @@ function hasReadIntermediate(member, partner, seen) {
|
|
|
2535
2539
|
return some(getBindingsDerivedFrom(member), (from) => {
|
|
2536
2540
|
if (seen.has(from) || !sharesSources(from, partner)) return false;
|
|
2537
2541
|
seen.add(from);
|
|
2538
|
-
if (bindingUtil.has(partner.sources.state, from) || some(partner.sources.param,
|
|
2542
|
+
if (bindingUtil.has(partner.sources.state, from) || some(partner.sources.param, isCoveredParam, from)) return false;
|
|
2539
2543
|
return !!findSlot(from)?.reason || hasReadIntermediate(from, partner, seen);
|
|
2540
2544
|
});
|
|
2541
2545
|
}
|
|
2542
2546
|
function withoutOwnSources(closure, sources) {
|
|
2543
2547
|
const own = closure.sources;
|
|
2544
2548
|
if (!sources || !own || hasReadIntermediate(closure, closure, /* @__PURE__ */ new Set())) return sources;
|
|
2545
|
-
return withSources(sources, bindingUtil.difference(sources.state, own.state), bindingUtil.filter(sources.param,
|
|
2549
|
+
return withSources(sources, bindingUtil.difference(sources.state, own.state), bindingUtil.filter(sources.param, isUncoveredParam, own.param));
|
|
2550
|
+
}
|
|
2551
|
+
function isUncoveredParam(binding, params) {
|
|
2552
|
+
return !isCoveredParam(binding, params);
|
|
2546
2553
|
}
|
|
2547
2554
|
function getBranchExprReason(section) {
|
|
2548
2555
|
const { derives, branchExpr } = section;
|
|
@@ -2563,30 +2570,32 @@ function getBranchExprReasonUntil(section, ancestor) {
|
|
|
2563
2570
|
return reason;
|
|
2564
2571
|
}
|
|
2565
2572
|
function addClosureReasons(section) {
|
|
2566
|
-
forEach(section.referencedConstants,
|
|
2567
|
-
forEach(section.referencedClosures,
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2573
|
+
forEach(section.referencedConstants, addClosureReason, section);
|
|
2574
|
+
forEach(section.referencedClosures, addReferencedClosureReasons, section);
|
|
2575
|
+
}
|
|
2576
|
+
function addReferencedClosureReasons(closure, section) {
|
|
2577
|
+
addClosureReason(closure, section);
|
|
2578
|
+
if (closure.sources && isDynamicClosure(section, closure)) {
|
|
2579
|
+
addReason(ensureSlot(closure, 2), closure.sources);
|
|
2580
|
+
if (getDynamicClosureIndex(closure, section)) addReason(ensureSlot(closure, 3, section), closure.sources);
|
|
2581
|
+
}
|
|
2574
2582
|
}
|
|
2575
|
-
function addClosureReason(
|
|
2583
|
+
function addClosureReason(binding, section) {
|
|
2576
2584
|
const sourceSection = binding.section;
|
|
2577
2585
|
const branchesReason = getBranchExprReasonUntil(section, sourceSection);
|
|
2578
2586
|
addReason(ensureSlot(binding), branchesReason?.always ? branchesReason : withoutOwnSources(binding, branchesReason));
|
|
2579
2587
|
if (isDynamicClosure(section, binding)) addOwnerReason(section, sourceSection, branchesReason);
|
|
2580
2588
|
}
|
|
2581
2589
|
function addCallOwnerReasons(body) {
|
|
2582
|
-
if (body.readsOwner) forEach(body.renderedBy,
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2590
|
+
if (body.readsOwner) forEach(body.renderedBy, addCallOwnerReason, body.parent);
|
|
2591
|
+
}
|
|
2592
|
+
function addCallOwnerReason(call, owner) {
|
|
2593
|
+
const callSection = call.childScopeBinding.section;
|
|
2594
|
+
addOwnerReason(callSection, owner, getBranchExprReasonUntil(callSection, owner));
|
|
2586
2595
|
}
|
|
2587
|
-
function addRegisteredFnReasons(
|
|
2596
|
+
function addRegisteredFnReasons() {
|
|
2588
2597
|
addFunctionReasons();
|
|
2589
|
-
for (const
|
|
2598
|
+
for (const fn of getReferencesByFn().keys()) {
|
|
2590
2599
|
const reason = fn.reason;
|
|
2591
2600
|
if (reason) {
|
|
2592
2601
|
const addReadReason = (binding) => {
|
|
@@ -2609,15 +2618,16 @@ const ALWAYS_READ = {
|
|
|
2609
2618
|
lands: 0
|
|
2610
2619
|
};
|
|
2611
2620
|
const exprReaders = createPassMemo(computeExprReaders, UNREAD);
|
|
2612
|
-
const bindingReaders =
|
|
2613
|
-
|
|
2614
|
-
|
|
2621
|
+
const bindingReaders = createPassMemo(computeBindingReaders, UNREAD);
|
|
2622
|
+
const getWalkKey = createPathKeys();
|
|
2623
|
+
function getReasonForBinding(binding, properties, exprs) {
|
|
2624
|
+
return readersOf(binding, properties, exprs).reason;
|
|
2615
2625
|
}
|
|
2616
2626
|
function getReasonForExpr(extra) {
|
|
2617
2627
|
return extra.isEffect ? ALWAYS : exprReaders(extra).reason;
|
|
2618
2628
|
}
|
|
2619
2629
|
function bindingLandsRetained(binding, properties) {
|
|
2620
|
-
return !!(bindingReaders(binding, properties).lands & LANDS_RETAINED_INPUT);
|
|
2630
|
+
return !!(bindingReaders(getWalkKey(binding, properties)).lands & LANDS_RETAINED_INPUT);
|
|
2621
2631
|
}
|
|
2622
2632
|
function getContentSites({ binding, properties }) {
|
|
2623
2633
|
return reduce(binding, (sites, part) => joinSites(sites, getSitesAt(getWalkKey(part, properties))), NO_SITES);
|
|
@@ -2659,7 +2669,7 @@ function computeExprReaders(extra) {
|
|
|
2659
2669
|
return folding.readers;
|
|
2660
2670
|
}
|
|
2661
2671
|
function readersOf(binding, path, exprs) {
|
|
2662
|
-
const linked = bindingReaders(binding, path);
|
|
2672
|
+
const linked = bindingReaders(getWalkKey(binding, path));
|
|
2663
2673
|
return exprs && linked.reason ? {
|
|
2664
2674
|
reason: mapParamReason(binding.section.program, linked.reason, exprs, true),
|
|
2665
2675
|
lands: linked.lands
|
|
@@ -2677,12 +2687,12 @@ function getDerivedPath(extra, binding, part, properties) {
|
|
|
2677
2687
|
}
|
|
2678
2688
|
function isReferenceTo(extra, binding) {
|
|
2679
2689
|
const { read } = extra;
|
|
2680
|
-
return !!read && read.properties === void 0 &&
|
|
2690
|
+
return !!read && read.properties === void 0 && read.binding.canonical === binding.canonical;
|
|
2681
2691
|
}
|
|
2682
2692
|
function isPartOf(binding, value) {
|
|
2683
2693
|
return !!value && binding.aliasOf === value && !isDirectAlias(binding);
|
|
2684
2694
|
}
|
|
2685
|
-
function computeBindingReaders(binding, properties) {
|
|
2695
|
+
function computeBindingReaders([binding, properties]) {
|
|
2686
2696
|
if (isLeftOut(binding, properties)) return UNREAD;
|
|
2687
2697
|
const head = properties === true || properties === void 0 ? void 0 : first(properties);
|
|
2688
2698
|
const reason = findSlot(binding)?.reason;
|
|
@@ -2730,7 +2740,7 @@ function getLandingBits(read, binding) {
|
|
|
2730
2740
|
return read.retained ? isNamedBy(read, binding) ? LANDS_RETAINED : 3 : 0;
|
|
2731
2741
|
}
|
|
2732
2742
|
function isNamedBy(read, binding) {
|
|
2733
|
-
return every(binding.reads
|
|
2743
|
+
return every(binding.reads?.get(read), isTagNameRead);
|
|
2734
2744
|
}
|
|
2735
2745
|
function isTagNameRead({ extra }) {
|
|
2736
2746
|
return !!extra.exprRoot?.tagName;
|
|
@@ -2741,18 +2751,19 @@ function isLeftOut(binding, properties) {
|
|
|
2741
2751
|
function forEachStep(binding, properties, step, state) {
|
|
2742
2752
|
const aliased = binding.aliasOf;
|
|
2743
2753
|
if (properties !== true && aliased) step.reach(state, aliased, concat(binding.property, properties), void 0);
|
|
2744
|
-
for (const read of binding.reads.keys()) {
|
|
2754
|
+
if (binding.reads) for (const read of binding.reads.keys()) {
|
|
2745
2755
|
step.land(state, read, binding);
|
|
2746
2756
|
if (!read.isEffect) forEachDerivedStep(read, binding, properties, step, state);
|
|
2747
2757
|
}
|
|
2748
|
-
for (const alias of binding.aliases) step.reach(state, alias, properties, void 0);
|
|
2749
|
-
if (properties === true)
|
|
2750
|
-
|
|
2758
|
+
if (binding.aliases) for (const alias of binding.aliases) step.reach(state, alias, properties, void 0);
|
|
2759
|
+
if (properties === true) {
|
|
2760
|
+
if (binding.propertyAliases) for (const part of binding.propertyAliases.values()) step.reach(state, part, true, void 0);
|
|
2761
|
+
} else if (properties !== void 0) {
|
|
2751
2762
|
const property = first(properties);
|
|
2752
|
-
let part = binding.propertyAliases
|
|
2763
|
+
let part = binding.propertyAliases?.get(property);
|
|
2753
2764
|
if (part) step.reach(state, part, rest(properties), void 0);
|
|
2754
|
-
for (const alias of binding.aliases) {
|
|
2755
|
-
part = alias.propertyAliases
|
|
2765
|
+
if (binding.aliases) for (const alias of binding.aliases) {
|
|
2766
|
+
part = alias.propertyAliases?.get(property);
|
|
2756
2767
|
if (part) step.reach(state, part, rest(properties), void 0);
|
|
2757
2768
|
}
|
|
2758
2769
|
}
|
|
@@ -2767,7 +2778,6 @@ function forEachDerivedStep(read, part, properties, step, state) {
|
|
|
2767
2778
|
function isReturned(extra) {
|
|
2768
2779
|
return extra === (0, _marko_compiler_babel_utils.getProgram)().node.extra.section.returnValueExpr;
|
|
2769
2780
|
}
|
|
2770
|
-
const getWalkKey = createPathKeys();
|
|
2771
2781
|
function someReachedRead(binding, properties, test) {
|
|
2772
2782
|
const walk = {
|
|
2773
2783
|
test,
|
|
@@ -3640,6 +3650,7 @@ function ensureBodySection(path) {
|
|
|
3640
3650
|
abortSignalExprs: 0,
|
|
3641
3651
|
readsOwner: false,
|
|
3642
3652
|
hasSetupWork: false,
|
|
3653
|
+
hasReturnedVar: false,
|
|
3643
3654
|
branch: void 0,
|
|
3644
3655
|
structure: parentSection && !parentSection.structure ? null : []
|
|
3645
3656
|
};
|
|
@@ -3678,7 +3689,7 @@ function forEachSection(fn) {
|
|
|
3678
3689
|
}
|
|
3679
3690
|
function getDynamicTagContentClosures(section) {
|
|
3680
3691
|
const { derives } = section;
|
|
3681
|
-
if (section.branchExpr?.tagNameType === 2 || derives && some(derives.binding,
|
|
3692
|
+
if (section.branchExpr?.tagNameType === 2 || derives && some(derives.binding, bindingLandsRetained, derives.properties)) return bindingUtil.filter(getClosuresFromAbove(section, section, /* @__PURE__ */ new Set()), mayBeUnwritten);
|
|
3682
3693
|
}
|
|
3683
3694
|
function mayBeUnwritten(closure) {
|
|
3684
3695
|
const reason = getWriteReason(closure);
|
|
@@ -3781,9 +3792,9 @@ function getSiteTextBefore(site, content) {
|
|
|
3781
3792
|
function isStartMarked(branch, section, content) {
|
|
3782
3793
|
const { nodeBinding } = branch.tag;
|
|
3783
3794
|
const tagSection = nodeBinding.section;
|
|
3784
|
-
return branch.kind === "try" || (branch.kind === "await" ? isAlwaysWritten(tagSection, section.reason, content) : isAlwaysWritten(tagSection, getBranchWriteReason(section), content) && isAlwaysWritten(tagSection, getWriteReason(nodeBinding), content));
|
|
3795
|
+
return branch.kind === "try" || (branch.kind === "await" ? isAlwaysWritten$1(tagSection, section.reason, content) : isAlwaysWritten$1(tagSection, getBranchWriteReason(section), content) && isAlwaysWritten$1(tagSection, getWriteReason(nodeBinding), content));
|
|
3785
3796
|
}
|
|
3786
|
-
function isAlwaysWritten(section, reason, content) {
|
|
3797
|
+
function isAlwaysWritten$1(section, reason, content) {
|
|
3787
3798
|
return content ? isWrittenForCall(section, reason, content.derives.tag, content.parent) : getWriteBit(section, reason) === 1;
|
|
3788
3799
|
}
|
|
3789
3800
|
function mayEndWithText(section) {
|
|
@@ -3830,10 +3841,13 @@ function getRendererReason(section) {
|
|
|
3830
3841
|
if (isOptionalBranch(section)) return false;
|
|
3831
3842
|
if (section.branchExpr?.tagNameType === 0) return false;
|
|
3832
3843
|
const { derives } = section;
|
|
3833
|
-
if (derives)
|
|
3834
|
-
const
|
|
3835
|
-
return
|
|
3836
|
-
|
|
3844
|
+
if (derives) {
|
|
3845
|
+
const { properties, exprs } = derives;
|
|
3846
|
+
return reduce(derives.binding, (reasons, binding) => {
|
|
3847
|
+
const reason = getReasonForBinding(binding, properties, exprs);
|
|
3848
|
+
return mergeSources(reasons, reason && !exprs ? mapParamReason(section.program, reason, void 0, false) : reason);
|
|
3849
|
+
}) || false;
|
|
3850
|
+
}
|
|
3837
3851
|
return ALWAYS;
|
|
3838
3852
|
}
|
|
3839
3853
|
function isOptionalBranch(section) {
|
|
@@ -3886,10 +3900,6 @@ function getCommonSection(section, other) {
|
|
|
3886
3900
|
else b = b.parent;
|
|
3887
3901
|
return a;
|
|
3888
3902
|
}
|
|
3889
|
-
function ensureSectionReasonGroups(section) {
|
|
3890
|
-
ensureReasonGroups(section, section.reason);
|
|
3891
|
-
for (const slot of section.slots) ensureReasonGroups(slot.section, slot.reason);
|
|
3892
|
-
}
|
|
3893
3903
|
function ensureReasonGroups(section, reason) {
|
|
3894
3904
|
const ownReason = mapBodyParams(section, reason);
|
|
3895
3905
|
if (isGuardedReason(ownReason)) forEachParamGroup(ownReason.param, ensureParamReasonGroup);
|
|
@@ -3961,22 +3971,24 @@ function exposeParamsTree(binding, bodyAnalyzed) {
|
|
|
3961
3971
|
properties: void 0,
|
|
3962
3972
|
rest: void 0
|
|
3963
3973
|
};
|
|
3964
|
-
if (!binding.reads
|
|
3974
|
+
if (!binding.reads) {
|
|
3965
3975
|
let restAlias;
|
|
3966
3976
|
let aliasCount = 0;
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3977
|
+
if (binding.aliases) {
|
|
3978
|
+
for (const alias of binding.aliases) if (!bodyAnalyzed || isPossiblyRead(alias)) {
|
|
3979
|
+
restAlias = alias;
|
|
3980
|
+
if (++aliasCount > 1) break;
|
|
3981
|
+
}
|
|
3970
3982
|
}
|
|
3971
3983
|
if (!restAlias) {
|
|
3972
3984
|
tree.properties = Object.create(null);
|
|
3973
|
-
for (const [property, alias] of binding.propertyAliases) tree.properties[property] = exposeParamsTree(alias, bodyAnalyzed);
|
|
3985
|
+
if (binding.propertyAliases) for (const [property, alias] of binding.propertyAliases) tree.properties[property] = exposeParamsTree(alias, bodyAnalyzed);
|
|
3974
3986
|
} else if (aliasCount === 1) {
|
|
3975
3987
|
if (hasSupersetExcludeProperties(binding, restAlias.excludeProperties)) {
|
|
3976
3988
|
tree.rest = exposeParamsTree(restAlias, bodyAnalyzed);
|
|
3977
3989
|
tree.properties = Object.create(null);
|
|
3978
3990
|
forEach(restAlias.excludeProperties, (property) => {
|
|
3979
|
-
const propAlias = binding.propertyAliases
|
|
3991
|
+
const propAlias = binding.propertyAliases?.get(property);
|
|
3980
3992
|
if (propAlias) tree.properties[property] = exposeParamsTree(propAlias, bodyAnalyzed);
|
|
3981
3993
|
});
|
|
3982
3994
|
}
|
|
@@ -3988,19 +4000,25 @@ function exposeParamsTree(binding, bodyAnalyzed) {
|
|
|
3988
4000
|
return tree;
|
|
3989
4001
|
}
|
|
3990
4002
|
function isDirectContentBinding(binding) {
|
|
3991
|
-
if (binding.reads
|
|
4003
|
+
if (binding.reads?.size !== 1) return false;
|
|
3992
4004
|
const [[expr, read]] = binding.reads;
|
|
3993
4005
|
return expr.nameOnly && expr.section === binding.section && !Array.isArray(read) && !!read.extra.tagName;
|
|
3994
4006
|
}
|
|
3995
4007
|
function isPossiblyRead(alias) {
|
|
3996
|
-
if (alias.reads
|
|
3997
|
-
|
|
3998
|
-
|
|
4008
|
+
if (alias.reads) return true;
|
|
4009
|
+
if (alias.aliases) {
|
|
4010
|
+
for (const nested of alias.aliases) if (isPossiblyRead(nested)) return true;
|
|
4011
|
+
}
|
|
4012
|
+
if (alias.propertyAliases) {
|
|
4013
|
+
for (const prop of alias.propertyAliases.values()) if (isPossiblyRead(prop)) return true;
|
|
4014
|
+
}
|
|
3999
4015
|
return false;
|
|
4000
4016
|
}
|
|
4001
4017
|
function hasSupersetExcludeProperties(binding, excludeProperties) {
|
|
4002
4018
|
if (excludeProperties === void 0) return false;
|
|
4003
|
-
|
|
4019
|
+
if (binding.propertyAliases) {
|
|
4020
|
+
for (const prop of binding.propertyAliases.keys()) if (!propertiesUtil.has(excludeProperties, prop)) return false;
|
|
4021
|
+
}
|
|
4004
4022
|
return true;
|
|
4005
4023
|
}
|
|
4006
4024
|
function getSettledParamsTree(paramsTree) {
|
|
@@ -4110,14 +4128,14 @@ function getScopeOffsetAccessor(nodeBinding) {
|
|
|
4110
4128
|
return isOptimize() ? decodeAccessor(id) : `#scopeOffset/${id}`;
|
|
4111
4129
|
}
|
|
4112
4130
|
function getReservedId(binding, offset) {
|
|
4113
|
-
return
|
|
4131
|
+
return binding.canonical.id + offset;
|
|
4114
4132
|
}
|
|
4115
4133
|
function getScopeAccessorLiteral(binding, encoded, includeId) {
|
|
4116
|
-
const canonicalBinding =
|
|
4134
|
+
const canonicalBinding = binding.canonical;
|
|
4117
4135
|
return encoded && isOptimize() && canonicalBinding.type !== 5 ? _marko_compiler.types.numericLiteral(canonicalBinding.id) : _marko_compiler.types.stringLiteral(getScopeAccessor(binding, encoded, includeId));
|
|
4118
4136
|
}
|
|
4119
4137
|
function getScopeAccessor(binding, encoded, includeId) {
|
|
4120
|
-
const canonicalBinding =
|
|
4138
|
+
const canonicalBinding = binding.canonical;
|
|
4121
4139
|
if (canonicalBinding.type === 5) return canonicalBinding.scopeAccessor ?? canonicalBinding.name;
|
|
4122
4140
|
else if (isOptimize()) return encoded ? canonicalBinding.id + "" : decodeAccessor(canonicalBinding.id);
|
|
4123
4141
|
const name = reservedDebugAccessors.has(canonicalBinding.name) ? `${canonicalBinding.name}/${canonicalBinding.id}` : canonicalBinding.name;
|
|
@@ -4129,7 +4147,7 @@ function getLocalsScopeAccessor(binding) {
|
|
|
4129
4147
|
return getScopeAccessor(binding, false, true);
|
|
4130
4148
|
}
|
|
4131
4149
|
function getPrefixedScopeAccessor(binding, prefix) {
|
|
4132
|
-
const canonicalBinding =
|
|
4150
|
+
const canonicalBinding = binding.canonical;
|
|
4133
4151
|
if (isOptimize()) switch (prefix) {
|
|
4134
4152
|
case getAccessorPrefix().TagVariableChange: return decodeAccessor(getReservedId(canonicalBinding, 1));
|
|
4135
4153
|
case getAccessorPrefix().ClosureScopes: return decodeAccessor(getClosureAccessorId(canonicalBinding));
|
|
@@ -4145,7 +4163,7 @@ function getDebugClosureAccessor(binding) {
|
|
|
4145
4163
|
return `${getScopeAccessor(binding)}/${getClosureAccessorId(binding)}`;
|
|
4146
4164
|
}
|
|
4147
4165
|
function getClosureAccessorId(binding) {
|
|
4148
|
-
const id =
|
|
4166
|
+
const id = binding.canonical.closureId;
|
|
4149
4167
|
/* v8 ignore next 5 -- analyze reserves an id for every closure binding */
|
|
4150
4168
|
if (id === void 0) throw new Error(`No closure accessor id was reserved for "${binding.name}".`);
|
|
4151
4169
|
return id;
|
|
@@ -4183,16 +4201,18 @@ function getSectionRendererIdentifier(section) {
|
|
|
4183
4201
|
return isSectionRendererElided(section) ? void 0 : _marko_compiler.types.identifier(section.name);
|
|
4184
4202
|
}
|
|
4185
4203
|
function isSectionRendererElided(section) {
|
|
4186
|
-
return section.dropped || !!section.derives && !(section.derives.tag.tagNameNullable && section.derives.properties === "content") && !some(section.derives.binding,
|
|
4204
|
+
return section.dropped || !!section.derives && !(section.derives.tag.tagNameNullable && section.derives.properties === "content") && !some(section.derives.binding, isPropertyPathRead, section.derives.properties);
|
|
4187
4205
|
}
|
|
4188
4206
|
function isPropertyPathRead(binding, properties) {
|
|
4189
4207
|
if (binding.pruned) return false;
|
|
4190
4208
|
else if (binding.pruned === void 0) throw new Error("Binding must be pruned before checking properties");
|
|
4191
|
-
if (binding.reads
|
|
4209
|
+
if (binding.reads || !properties) return true;
|
|
4192
4210
|
const property = first(properties);
|
|
4193
|
-
const propBinding = binding.propertyAliases
|
|
4211
|
+
const propBinding = binding.propertyAliases?.get(property);
|
|
4194
4212
|
if (propBinding && isPropertyPathRead(propBinding, rest(properties))) return true;
|
|
4195
|
-
|
|
4213
|
+
if (binding.aliases) {
|
|
4214
|
+
for (const alias of binding.aliases) if (isPropertyPathRead(alias, properties)) return true;
|
|
4215
|
+
}
|
|
4196
4216
|
return false;
|
|
4197
4217
|
}
|
|
4198
4218
|
// src/translator/util/setup-work.ts
|
|
@@ -4270,11 +4290,12 @@ function excludeAssignedChangeHandlers() {
|
|
|
4270
4290
|
const excluded = /* @__PURE__ */ new Set();
|
|
4271
4291
|
for (const { assignment: binding } of getAssignments()) if (binding.assignments && binding.aliasOf && binding.property !== void 0 && !excluded.has(binding)) {
|
|
4272
4292
|
excluded.add(binding);
|
|
4273
|
-
|
|
4293
|
+
if (binding.aliasOf.aliases) {
|
|
4294
|
+
for (const alias of binding.aliasOf.aliases) if (propertiesUtil.has(alias.excludeProperties, binding.property)) alias.excludeProperties = propertiesUtil.add(alias.excludeProperties, binding.property + "Change");
|
|
4295
|
+
}
|
|
4274
4296
|
}
|
|
4275
4297
|
}
|
|
4276
4298
|
function resolveReads(intersectionsBySection) {
|
|
4277
|
-
const fnReadsByExpression = getFunctionReadsByExpression();
|
|
4278
4299
|
for (const [expr, reads] of getReadsByExpression()) if (isReferencedExtra(expr)) {
|
|
4279
4300
|
const exprBindings = resolveReferencedBindings(expr, reads, intersectionsBySection);
|
|
4280
4301
|
setResolvedReads(expr, exprBindings.referencedBindings, exprBindings.lazyBindings);
|
|
@@ -4297,18 +4318,42 @@ function resolveReads(intersectionsBySection) {
|
|
|
4297
4318
|
forEach(exprBindings.constantBindings, addAlwaysReason);
|
|
4298
4319
|
}
|
|
4299
4320
|
forEach(exprBindings.lazyBindings, addAlwaysReason);
|
|
4300
|
-
} else forEach(reads,
|
|
4301
|
-
|
|
4302
|
-
});
|
|
4303
|
-
if (exprBindings.allBindings) {
|
|
4304
|
-
const exprFnReads = fnReadsByExpression.get(expr);
|
|
4305
|
-
if (exprFnReads) for (const [fn, fnReads] of exprFnReads) {
|
|
4306
|
-
const fnBindings = fn === expr ? exprBindings : resolveReferencedBindingsInFunction(expr, exprBindings.allBindings, fnReads);
|
|
4307
|
-
setResolvedFunctionReads(fn, fn === expr ? bindingUtil.union(fnBindings.referencedBindings, exprBindings.lazyBindings) : fnBindings.referencedBindings, fnBindings.constantBindings);
|
|
4308
|
-
}
|
|
4309
|
-
}
|
|
4321
|
+
} else forEach(reads, addRetainedReadReason, expr);
|
|
4322
|
+
if (exprBindings.allBindings) resolveFunctionReads(expr, exprBindings, exprBindings.allBindings, reads);
|
|
4310
4323
|
}
|
|
4311
4324
|
}
|
|
4325
|
+
function resolveFunctionReads(expr, exprBindings, allBindings, reads) {
|
|
4326
|
+
const exprFnReads = reduce(reads, addReadByFunction);
|
|
4327
|
+
if (exprFnReads) for (const [fn, fnReads] of exprFnReads) {
|
|
4328
|
+
const fnBindings = fn === expr ? exprBindings : resolveReferencedBindingsInFunction(allBindings, fnReads);
|
|
4329
|
+
setResolvedFunctionReads(fn, fn === expr ? bindingUtil.union(fnBindings.referencedBindings, exprBindings.lazyBindings) : fnBindings.referencedBindings, fnBindings.constantBindings);
|
|
4330
|
+
}
|
|
4331
|
+
}
|
|
4332
|
+
function addReadByFunction(byFn, read) {
|
|
4333
|
+
const fn = read.fnRoot;
|
|
4334
|
+
if (fn) (byFn ??= /* @__PURE__ */ new Map()).set(fn, push(byFn.get(fn), read));
|
|
4335
|
+
return byFn;
|
|
4336
|
+
}
|
|
4337
|
+
function addRetainedReadReason(read, expr) {
|
|
4338
|
+
if (!read.fnRoot && read.extra.exprRoot?.retained) addReasonExprs(ensureSlot(read.binding), expr);
|
|
4339
|
+
}
|
|
4340
|
+
function addAssignmentOwnerReason({ section: assignedSection }, section) {
|
|
4341
|
+
setReadsOwner(assignedSection, section);
|
|
4342
|
+
addOwnerReason(assignedSection, section, ALWAYS);
|
|
4343
|
+
}
|
|
4344
|
+
function addBindingName({ name }, names) {
|
|
4345
|
+
names.add(name);
|
|
4346
|
+
}
|
|
4347
|
+
function setCallReadsOwner(call, owner) {
|
|
4348
|
+
setReadsOwner(call.childScopeBinding.section, owner);
|
|
4349
|
+
}
|
|
4350
|
+
function addClosureSection(closure, section) {
|
|
4351
|
+
closure.closureSections = sectionUtil.add(closure.closureSections, section);
|
|
4352
|
+
addOwnerReason(section, closure.section, closure.sources);
|
|
4353
|
+
}
|
|
4354
|
+
function setReadHolder(read, holder) {
|
|
4355
|
+
read.holder = holder;
|
|
4356
|
+
}
|
|
4312
4357
|
function resolveBindings() {
|
|
4313
4358
|
const bindingNamesBySection = /* @__PURE__ */ new Map();
|
|
4314
4359
|
for (const binding of getBindings()) {
|
|
@@ -4319,14 +4364,11 @@ function resolveBindings() {
|
|
|
4319
4364
|
}
|
|
4320
4365
|
if (binding.type !== 0) {
|
|
4321
4366
|
resolveBindingSources(binding);
|
|
4322
|
-
forEach(binding.assignments,
|
|
4323
|
-
setReadsOwner(assignedSection, section);
|
|
4324
|
-
addOwnerReason(assignedSection, section, ALWAYS);
|
|
4325
|
-
});
|
|
4367
|
+
forEach(binding.assignments, addAssignmentOwnerReason, section);
|
|
4326
4368
|
let bindingNames = bindingNamesBySection.get(section);
|
|
4327
4369
|
if (!bindingNames) {
|
|
4328
4370
|
bindingNamesBySection.set(section, bindingNames = /* @__PURE__ */ new Set());
|
|
4329
|
-
forEach(section.bindings,
|
|
4371
|
+
forEach(section.bindings, addBindingName, bindingNames);
|
|
4330
4372
|
}
|
|
4331
4373
|
if (bindingNames.has(binding.name)) binding.name = generateUid(name);
|
|
4332
4374
|
}
|
|
@@ -4339,21 +4381,16 @@ function resolveBindings() {
|
|
|
4339
4381
|
if (section.parent !== highestHoistSection) section.parent.isHoistThrough = true;
|
|
4340
4382
|
}
|
|
4341
4383
|
}
|
|
4342
|
-
const canonicalBinding =
|
|
4384
|
+
const canonicalBinding = binding.canonical;
|
|
4343
4385
|
if (canonicalBinding === binding) section.bindings = bindingUtil.add(section.bindings, binding);
|
|
4344
4386
|
bindingNamesBySection.get(section)?.add(canonicalBinding.name);
|
|
4345
4387
|
if (binding.localOf) section.localClosures = bindingUtil.add(section.localClosures, binding);
|
|
4346
4388
|
}
|
|
4347
4389
|
}
|
|
4348
4390
|
function addSectionReasons(section) {
|
|
4349
|
-
if (section.readsOwner) forEach(section.renderedBy,
|
|
4350
|
-
setReadsOwner(call.childScopeBinding.section, section.parent);
|
|
4351
|
-
});
|
|
4391
|
+
if (section.readsOwner) forEach(section.renderedBy, setCallReadsOwner, section.parent);
|
|
4352
4392
|
if (section.isHoistThrough) addReason(ensureSectionSlot(section, 6), ALWAYS);
|
|
4353
|
-
forEach(section.referencedClosures,
|
|
4354
|
-
closure.closureSections = sectionUtil.add(closure.closureSections, section);
|
|
4355
|
-
addOwnerReason(section, closure.section, closure.sources);
|
|
4356
|
-
});
|
|
4393
|
+
forEach(section.referencedClosures, addClosureSection, section);
|
|
4357
4394
|
if (isOptionalBranch(section)) {
|
|
4358
4395
|
const closureSources = getSourcesForReferencedBindings(getDirectClosures(section));
|
|
4359
4396
|
const branchSlot = ensureSectionSlot(section, 9);
|
|
@@ -4438,14 +4475,15 @@ function getWalkedBinding(op) {
|
|
|
4438
4475
|
return typeof op === "object" && (op.kind === "node" || op.kind === "child") ? op.binding : void 0;
|
|
4439
4476
|
}
|
|
4440
4477
|
function getLastOwnSourceReturn(bindings, section) {
|
|
4478
|
+
if (!section.hasReturnedVar) return;
|
|
4441
4479
|
let last;
|
|
4442
4480
|
const seen = /* @__PURE__ */ new Set();
|
|
4443
4481
|
const track = (binding) => {
|
|
4444
4482
|
if (binding.section === section && !seen.has(binding)) {
|
|
4445
4483
|
seen.add(binding);
|
|
4446
|
-
const { returnedBy } =
|
|
4484
|
+
const { returnedBy } = binding;
|
|
4447
4485
|
if (returnedBy && (!last || last.id < returnedBy.scope.id)) last = returnedBy.scope;
|
|
4448
|
-
|
|
4486
|
+
forEach(getBindingsDerivedFrom(binding), track);
|
|
4449
4487
|
forEach(binding.sources?.state, track);
|
|
4450
4488
|
forEach(binding.sources?.param, track);
|
|
4451
4489
|
}
|
|
@@ -4479,17 +4517,8 @@ function resolveBindingSources(binding) {
|
|
|
4479
4517
|
if (resolvedSources.has(binding)) return;
|
|
4480
4518
|
resolvedSources.add(binding);
|
|
4481
4519
|
switch (binding.type) {
|
|
4482
|
-
case 1: {
|
|
4483
|
-
const aliasRoot = getAliasRoot(binding);
|
|
4484
|
-
if (aliasRoot !== binding) {
|
|
4485
|
-
resolveBindingSources(aliasRoot);
|
|
4486
|
-
binding.sources = aliasRoot.sources;
|
|
4487
|
-
} else if (binding.assignments) binding.sources = createSources(binding, void 0);
|
|
4488
|
-
else resolveDerivedSources(binding);
|
|
4489
|
-
return;
|
|
4490
|
-
}
|
|
4491
4520
|
case 2:
|
|
4492
|
-
binding.sources = createSources(void 0,
|
|
4521
|
+
binding.sources = createSources(void 0, binding.canonical);
|
|
4493
4522
|
return;
|
|
4494
4523
|
case 6:
|
|
4495
4524
|
binding.sources = globalSources;
|
|
@@ -4497,12 +4526,10 @@ function resolveBindingSources(binding) {
|
|
|
4497
4526
|
}
|
|
4498
4527
|
const aliasRoot = getAliasRoot(binding);
|
|
4499
4528
|
if (aliasRoot !== binding) {
|
|
4500
|
-
|
|
4501
|
-
resolvedSources.add(aliasRoot);
|
|
4502
|
-
resolveDerivedSources(aliasRoot);
|
|
4503
|
-
}
|
|
4529
|
+
resolveBindingSources(aliasRoot);
|
|
4504
4530
|
binding.sources = aliasRoot.sources;
|
|
4505
|
-
} else
|
|
4531
|
+
} else if (binding.type === 1 && binding.assignments) binding.sources = createSources(binding, void 0);
|
|
4532
|
+
else resolveDerivedSources(binding);
|
|
4506
4533
|
}
|
|
4507
4534
|
function resolveDerivedSources(binding) {
|
|
4508
4535
|
const exprs = binding.derivedFrom;
|
|
@@ -4555,22 +4582,33 @@ function isPrunedBinding(binding) {
|
|
|
4555
4582
|
function pruneBinding(binding) {
|
|
4556
4583
|
if (binding.pruned !== void 0) return binding.pruned;
|
|
4557
4584
|
binding.pruned = false;
|
|
4558
|
-
for (const read of binding.reads.keys()) pruneDerived(read);
|
|
4585
|
+
if (binding.reads) for (const read of binding.reads.keys()) pruneDerived(read);
|
|
4559
4586
|
forEach(binding.assignments, pruneAssignmentDerived);
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4587
|
+
if (binding.reads) {
|
|
4588
|
+
const assignedObject = getAssignedObject(binding);
|
|
4589
|
+
for (const [expr, reads] of binding.reads) {
|
|
4590
|
+
const ancestor = assignedObject ? getNearestReadBy(assignedObject, expr) || assignedObject : binding.aliasOf && !isRest(binding) && getNearestReadBy(binding.aliasOf, expr);
|
|
4591
|
+
if (ancestor) {
|
|
4592
|
+
forEach(reads, setReadHolder, ancestor);
|
|
4593
|
+
const ancestorReads = ancestor.reads ??= /* @__PURE__ */ new Map();
|
|
4594
|
+
ancestorReads.set(expr, concat(ancestorReads.get(expr), reads));
|
|
4595
|
+
binding.reads.delete(expr);
|
|
4596
|
+
}
|
|
4566
4597
|
}
|
|
4598
|
+
if (!binding.reads.size) binding.reads = void 0;
|
|
4567
4599
|
}
|
|
4568
4600
|
let shouldPrune = true;
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4601
|
+
if (binding.aliases) {
|
|
4602
|
+
for (const alias of binding.aliases) if (pruneBinding(alias)) binding.aliases.delete(alias);
|
|
4603
|
+
else shouldPrune = false;
|
|
4604
|
+
if (!binding.aliases.size) binding.aliases = void 0;
|
|
4605
|
+
}
|
|
4606
|
+
if (binding.propertyAliases) {
|
|
4607
|
+
for (const [key, alias] of binding.propertyAliases) if (pruneBinding(alias)) binding.propertyAliases.delete(key);
|
|
4608
|
+
else if (alias.type !== 5 || binding.type === 5) shouldPrune = false;
|
|
4609
|
+
if (!binding.propertyAliases.size) binding.propertyAliases = void 0;
|
|
4610
|
+
}
|
|
4611
|
+
shouldPrune &&= !binding.reads && !(binding.reserveSize && hasEmittedAssignment(binding));
|
|
4574
4612
|
binding.pruned = shouldPrune;
|
|
4575
4613
|
if (shouldPrune && !hasEmittedAssignment(binding)) {
|
|
4576
4614
|
if (binding.derivedFrom) forEach(binding.derivedFrom, dropUnreadValue);
|
|
@@ -4586,14 +4624,14 @@ function pruneAssignmentDerived({ exprRoot }) {
|
|
|
4586
4624
|
function pruneDerived(expr) {
|
|
4587
4625
|
if (isDroppableValue(expr)) forEach(expr.derives, pruneBinding);
|
|
4588
4626
|
}
|
|
4589
|
-
function resolveReferencedBindingsInFunction(
|
|
4627
|
+
function resolveReferencedBindingsInFunction(refs, reads) {
|
|
4590
4628
|
let referencedBindings;
|
|
4591
4629
|
let constantBindings;
|
|
4592
4630
|
const closest = /* @__PURE__ */ new Set();
|
|
4593
|
-
forEach(reads, ({ getter, binding }) => {
|
|
4631
|
+
forEach(reads, ({ getter, binding, holder }) => {
|
|
4594
4632
|
if (getter) {} else if (binding.type === 5) {
|
|
4595
4633
|
if (bindingUtil.has(refs, binding)) constantBindings = bindingUtil.add(constantBindings, binding);
|
|
4596
|
-
} else if (binding.type !== 0 && binding.type !== 6) closest.add(
|
|
4634
|
+
} else if (binding.type !== 0 && binding.type !== 6) closest.add(holder);
|
|
4597
4635
|
});
|
|
4598
4636
|
if (closest.size) referencedBindings = bindingUtil.filter(refs, (ref) => closest.has(ref));
|
|
4599
4637
|
return {
|
|
@@ -4603,19 +4641,20 @@ function resolveReferencedBindingsInFunction(expr, refs, reads) {
|
|
|
4603
4641
|
}
|
|
4604
4642
|
function getNearestReadBy(binding, expr) {
|
|
4605
4643
|
let cur = binding;
|
|
4606
|
-
while (!cur.reads
|
|
4644
|
+
while (!cur.reads?.has(expr)) {
|
|
4607
4645
|
if (!cur.aliasOf || isRest(cur)) return;
|
|
4608
4646
|
cur = cur.aliasOf;
|
|
4609
4647
|
}
|
|
4610
4648
|
return cur;
|
|
4611
4649
|
}
|
|
4612
4650
|
function markLazyRead(binding) {
|
|
4613
|
-
|
|
4651
|
+
binding.canonical.hasLazyReads = true;
|
|
4614
4652
|
}
|
|
4615
4653
|
function addBindingGetter(binding, { invoked, hoisted }) {
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
if (hoisted
|
|
4654
|
+
const getters = binding.getters ??= /* @__PURE__ */ new Map();
|
|
4655
|
+
if (!invoked || !getters.has(hoisted)) {
|
|
4656
|
+
if (hoisted === binding.section) getters.delete(false);
|
|
4657
|
+
if (hoisted || !getters.has(binding.section)) getters.set(hoisted, !invoked);
|
|
4619
4658
|
}
|
|
4620
4659
|
}
|
|
4621
4660
|
function isLazyRead(read, binding, isChangeHandlerRead) {
|
|
@@ -4636,7 +4675,7 @@ function resolveReferencedBindings(expr, reads, intersectionsBySection) {
|
|
|
4636
4675
|
const { extra, getter } = read;
|
|
4637
4676
|
if (getter) {
|
|
4638
4677
|
extra.section = expr.section;
|
|
4639
|
-
extra.read =
|
|
4678
|
+
extra.read = createResolvedRead(binding, void 0, false, getter);
|
|
4640
4679
|
addBindingGetter(binding, getter);
|
|
4641
4680
|
if (getter.hoisted) {
|
|
4642
4681
|
binding.hoists = sectionUtil.add(binding.hoists, getter.hoisted);
|
|
@@ -4644,14 +4683,14 @@ function resolveReferencedBindings(expr, reads, intersectionsBySection) {
|
|
|
4644
4683
|
}
|
|
4645
4684
|
} else {
|
|
4646
4685
|
const isChangeHandlerRead = extra.assignmentTo === binding;
|
|
4647
|
-
if (isChangeHandlerRead) binding =
|
|
4686
|
+
if (isChangeHandlerRead) binding = read.holder;
|
|
4648
4687
|
else if (binding.type !== 6) {
|
|
4649
4688
|
extra.section = expr.section;
|
|
4650
|
-
({binding} = extra.read = resolveConstantReference(binding) ?? resolveExpressionReference(
|
|
4689
|
+
({binding} = extra.read = resolveConstantReference(binding) ?? resolveExpressionReference(read));
|
|
4651
4690
|
}
|
|
4652
4691
|
if (binding.type === 6) globalBindings = bindingUtil.add(globalBindings, binding);
|
|
4653
4692
|
else if (binding.type !== 0) {
|
|
4654
|
-
const closure = binding.section !== expr.section &&
|
|
4693
|
+
const closure = binding.section !== expr.section && binding.canonical;
|
|
4655
4694
|
if (isLazyRead(read, binding, isChangeHandlerRead)) lazyBindings = bindingUtil.add(lazyBindings, binding);
|
|
4656
4695
|
else if (binding.type === 5) {
|
|
4657
4696
|
constantBindings = bindingUtil.add(constantBindings, binding);
|
|
@@ -4702,18 +4741,18 @@ function getConstantRoot(binding) {
|
|
|
4702
4741
|
}
|
|
4703
4742
|
return root;
|
|
4704
4743
|
}
|
|
4705
|
-
function resolveExpressionReference(
|
|
4706
|
-
const holder = getNearestReadBy(binding, expr);
|
|
4744
|
+
function resolveExpressionReference({ binding, holder, inOwnBody }) {
|
|
4707
4745
|
return holder === binding ? createResolvedRead(binding, void 0, inOwnBody) : createResolvedRead(holder, getPropertyPath(binding, holder));
|
|
4708
4746
|
}
|
|
4709
4747
|
// src/translator/util/get-declared-binding-expression.ts
|
|
4710
4748
|
function getDeclaredBindingExpression(binding, inPlace = false) {
|
|
4711
|
-
const canonicalBinding =
|
|
4749
|
+
const canonicalBinding = binding.canonical;
|
|
4712
4750
|
if (canonicalBinding.localOf) return getDeclaredBindingExpression(canonicalBinding.localOf, inPlace);
|
|
4713
|
-
const { aliasOf: aliased, property
|
|
4751
|
+
const { aliasOf: aliased, property } = canonicalBinding;
|
|
4714
4752
|
if (binding.declared) return _marko_compiler.types.identifier(binding.name);
|
|
4715
4753
|
if (canonicalBinding.declared || isRest(canonicalBinding)) return _marko_compiler.types.identifier(canonicalBinding.name);
|
|
4716
|
-
|
|
4754
|
+
const declaredAlias = getDeclaredAlias(canonicalBinding);
|
|
4755
|
+
if (declaredAlias && !isRest(declaredAlias)) return _marko_compiler.types.identifier(declaredAlias.name);
|
|
4717
4756
|
if (!aliased) return _marko_compiler.types.identifier(canonicalBinding.name);
|
|
4718
4757
|
if (property !== void 0) {
|
|
4719
4758
|
const alias = getDeclaredAlias(aliased);
|
|
@@ -4762,7 +4801,7 @@ function getDOMReadBase(read, section, signal) {
|
|
|
4762
4801
|
if (read.localFn) return isRegisteredFnExtra(read.localFn) ? toMemberExpression(localsIdentifier, getLocalsScopeAccessor(binding)) : _marko_compiler.types.identifier(binding.name);
|
|
4763
4802
|
const inlined = getSignals(section).get(binding)?.inline?.value;
|
|
4764
4803
|
if (inlined) return _marko_compiler.types.cloneNode(inlined, true);
|
|
4765
|
-
if (signal?.referencedBindings === binding && !signal.storesValue) return
|
|
4804
|
+
if (signal?.referencedBindings === binding && !signal.storesValue) return _marko_compiler.types.identifier(binding.canonical.name);
|
|
4766
4805
|
if (getter?.hoisted) return binding.aliasOf ? callRuntime("_hoist_read_error") : _marko_compiler.types.callExpression(getBindingGetterIdentifier(binding, getter.hoisted), [getScopeExpression(section, getter.hoisted)]);
|
|
4767
4806
|
if (properties === void 0 && binding.type === 0) return getter && _marko_compiler.types.callExpression(getBindingGetterIdentifier(binding, binding.section), [getScopeExpression(section, binding.section)]);
|
|
4768
4807
|
if (!isOptimize() && read.inOwnBody && isChildReturnVar(binding)) return callRuntime("_assert_init", section ? getScopeExpression(section, binding.section) : scopeIdentifier, getScopeAccessorLiteral(binding));
|
|
@@ -4773,7 +4812,7 @@ function isChildReturnVar(binding) {
|
|
|
4773
4812
|
}
|
|
4774
4813
|
function getHTMLReadBase(node, { binding, getter }) {
|
|
4775
4814
|
if (getter?.hoisted) return binding.aliasOf ? callRuntime("_hoist_read_error") : getBindingGetterIdentifier(binding, getter.hoisted);
|
|
4776
|
-
if (binding.type === 0) return binding.getters
|
|
4815
|
+
if (binding.type === 0) return binding.getters?.has(binding.section) ? getBindingGetterIdentifier(binding, binding.section) : void 0;
|
|
4777
4816
|
let root = node;
|
|
4778
4817
|
while (root.type === "MemberExpression" || root.type === "OptionalMemberExpression") root = root.object;
|
|
4779
4818
|
const rootBinding = root.extra?.binding;
|
|
@@ -4854,7 +4893,7 @@ function translateVar(tag, initialValue, kind = "const", statements) {
|
|
|
4854
4893
|
if (!binding?.aliasOf) return;
|
|
4855
4894
|
if (binding.assignments && binding.property !== void 0) {
|
|
4856
4895
|
const changeName = binding.property + "Change";
|
|
4857
|
-
const changeBinding = binding.aliasOf.propertyAliases
|
|
4896
|
+
const changeBinding = binding.aliasOf.propertyAliases?.get(changeName);
|
|
4858
4897
|
if (changeBinding && changeName !== changeBinding.name) {
|
|
4859
4898
|
const pattern = getDestructurePattern(id);
|
|
4860
4899
|
if (pattern) pattern.unshiftContainer("properties", _marko_compiler.types.objectProperty(toPropertyName(changeName), _marko_compiler.types.identifier(changeBinding.name)));
|
|
@@ -4903,7 +4942,7 @@ function translateAliasInSection(tag, id, alias, kind) {
|
|
|
4903
4942
|
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))]));
|
|
4904
4943
|
}
|
|
4905
4944
|
function translateRest(tag, id, rest, kind) {
|
|
4906
|
-
const source =
|
|
4945
|
+
const source = rest.aliasOf;
|
|
4907
4946
|
const from = getDeclaredAlias(source) || source;
|
|
4908
4947
|
let target = tag;
|
|
4909
4948
|
let inPlace = true;
|
|
@@ -5119,7 +5158,7 @@ function getSignal(section, referencedBindings, name) {
|
|
|
5119
5158
|
if (referencedBindings && !Array.isArray(referencedBindings)) {
|
|
5120
5159
|
if (referencedBindings.type === 5) return getSignal(section, void 0);
|
|
5121
5160
|
if (referencedBindings.section !== section) {
|
|
5122
|
-
const canonicalReference =
|
|
5161
|
+
const canonicalReference = referencedBindings.canonical;
|
|
5123
5162
|
if (canonicalReference !== referencedBindings) return getSignal(section, canonicalReference);
|
|
5124
5163
|
}
|
|
5125
5164
|
}
|
|
@@ -5156,7 +5195,7 @@ function getSignal(section, referencedBindings, name) {
|
|
|
5156
5195
|
const sourceSignal = getSignal(section, meta.source);
|
|
5157
5196
|
forEach(referencedBindings, (member) => {
|
|
5158
5197
|
const memberSignal = getSignal(section, member);
|
|
5159
|
-
const inline = !member.propertyAliases
|
|
5198
|
+
const inline = !member.propertyAliases && member.reads?.size === 1 && !getWriteReason(member) && sourceSignal.values.find((v) => v.signal === memberSignal);
|
|
5160
5199
|
if (inline) memberSignal.inline = inline;
|
|
5161
5200
|
else memberSignal.storesValue = memberSignal.forceStore = true;
|
|
5162
5201
|
});
|
|
@@ -5167,14 +5206,14 @@ function getSignal(section, referencedBindings, name) {
|
|
|
5167
5206
|
const render = buildSignalFn(signal);
|
|
5168
5207
|
const closureSignalBuilder = getClosureSignalBuilder(section);
|
|
5169
5208
|
if (closureSignalBuilder && isDirectClosure(section, closure)) return closureSignalBuilder(closure, render);
|
|
5170
|
-
return callRuntime("_closure_get", getClosureAccessorLiteral(closure), render, isInParentSection(closure, section) ? void 0 : _marko_compiler.types.arrowFunctionExpression([scopeIdentifier], getScopeExpression(section, closure.section)),
|
|
5209
|
+
return callRuntime("_closure_get", getClosureAccessorLiteral(closure), render, isInParentSection(closure, section) ? void 0 : _marko_compiler.types.arrowFunctionExpression([scopeIdentifier], getScopeExpression(section, closure.section)), getClosureSubscribeId(section, closure));
|
|
5171
5210
|
};
|
|
5172
5211
|
}
|
|
5173
5212
|
return signal;
|
|
5174
5213
|
}
|
|
5175
|
-
function
|
|
5214
|
+
function getClosureSubscribeId(section, closure) {
|
|
5176
5215
|
const { sources } = closure;
|
|
5177
|
-
|
|
5216
|
+
if (sources && isDynamicClosure(section, closure) && (!sources.state || some(sources.state, hasResumableWriter))) return _marko_compiler.types.stringLiteral(getResumeRegistryId(section, closure, "subscribe"));
|
|
5178
5217
|
}
|
|
5179
5218
|
function initValue(binding, isLet = false) {
|
|
5180
5219
|
const section = binding.section;
|
|
@@ -5183,35 +5222,40 @@ function initValue(binding, isLet = false) {
|
|
|
5183
5222
|
signal.build = () => {
|
|
5184
5223
|
if (isPureMemberForwarder(binding)) return;
|
|
5185
5224
|
const fn = buildSignalFn(signal);
|
|
5186
|
-
if (!signal.forceStore && (isDirectAlias(binding) || !signal.storesValue && !
|
|
5225
|
+
if (!signal.forceStore && (isDirectAlias(binding) || !signal.storesValue && !aliasStoresValue(binding) || !signalHasWork(signal))) return fn;
|
|
5187
5226
|
return callRuntime(isLet ? signal.extraArgs ? "_let_change" : "_let" : "_const", getScopeAccessorLiteral(binding, true, isLet), fn);
|
|
5188
5227
|
};
|
|
5189
|
-
binding.aliases
|
|
5190
|
-
binding.propertyAliases
|
|
5228
|
+
binding.aliases?.forEach(initAliasValue);
|
|
5229
|
+
binding.propertyAliases?.forEach(initAliasValue);
|
|
5191
5230
|
return signal;
|
|
5192
5231
|
}
|
|
5193
5232
|
function initAliasValue(alias) {
|
|
5194
5233
|
if (alias.type !== 5) initValue(alias);
|
|
5195
5234
|
}
|
|
5196
|
-
function aliasStoresValue(
|
|
5197
|
-
|
|
5235
|
+
function aliasStoresValue(binding) {
|
|
5236
|
+
if (binding.aliases) {
|
|
5237
|
+
for (const alias of binding.aliases) if (isDirectAlias(alias) && getSignal(alias.section, alias).storesValue) return true;
|
|
5238
|
+
}
|
|
5239
|
+
return false;
|
|
5198
5240
|
}
|
|
5199
5241
|
function signalHasWork(signal) {
|
|
5200
|
-
if (signal.extraArgs || signal.forceStore || signal.render.length || signal.effect.length || signal.
|
|
5242
|
+
if (signal.extraArgs || signal.forceStore || signal.render.length || signal.effect.length || signal.values.length || signal.intersections) return true;
|
|
5201
5243
|
const binding = signal.referencedBindings;
|
|
5202
5244
|
if (binding) {
|
|
5203
|
-
if (!Array.isArray(binding) && (binding.closureSections || binding.type === 0 || binding.section === signal.section && (binding.hoists || binding.aliases
|
|
5245
|
+
if (!Array.isArray(binding) && (binding.closureSections || binding.type === 0 || binding.section === signal.section && (binding.hoists || binding.aliases || hasNonConstantPropertyAlias(binding)))) return true;
|
|
5204
5246
|
} else if (signal.section.referencedClosures) return true;
|
|
5205
5247
|
return false;
|
|
5206
5248
|
}
|
|
5207
5249
|
function isPureMemberForwarder(binding) {
|
|
5208
|
-
if (binding.property === void 0 || binding.reads
|
|
5250
|
+
if (binding.property === void 0 || binding.reads || binding.exposed || binding.aliases || binding.assignments || getSignal(binding.section, binding).storesValue) return false;
|
|
5209
5251
|
return hasNonConstantPropertyAlias(binding);
|
|
5210
5252
|
}
|
|
5211
|
-
function pushMemberForwards(signal, value,
|
|
5212
|
-
if (
|
|
5213
|
-
|
|
5214
|
-
|
|
5253
|
+
function pushMemberForwards(signal, value, binding) {
|
|
5254
|
+
for (const [key, alias] of binding.propertyAliases) if (alias.type !== 5) {
|
|
5255
|
+
const member = toMemberExpression(_marko_compiler.types.cloneNode(value, true), key, binding.nullable);
|
|
5256
|
+
if (isPureMemberForwarder(alias)) pushMemberForwards(signal, member, alias);
|
|
5257
|
+
else pushForward(signal, getSignal(alias.section, alias), member);
|
|
5258
|
+
}
|
|
5215
5259
|
}
|
|
5216
5260
|
function pushForward(signal, target, value) {
|
|
5217
5261
|
if (pushSignalCall(signal, target, value)) signal.forwards = push(signal.forwards, target);
|
|
@@ -5233,7 +5277,7 @@ function pushSignalCall(signal, target, value) {
|
|
|
5233
5277
|
}
|
|
5234
5278
|
function isInlinedValue(signal) {
|
|
5235
5279
|
const binding = signal.referencedBindings;
|
|
5236
|
-
if (!binding || Array.isArray(binding) || binding.reads
|
|
5280
|
+
if (!binding || Array.isArray(binding) || binding.reads?.size !== 1 || signal.storesValue || signal.referenced || binding.exposed || binding.assignments || binding.aliases || binding.propertyAliases || binding.property === void 0 && (binding.type !== 4 || binding.aliasOf || !every(binding.derivedFrom || void 0, isPureExpr))) return false;
|
|
5237
5281
|
const [read] = binding.reads.values();
|
|
5238
5282
|
if (Array.isArray(read) || read.fnRoot) return false;
|
|
5239
5283
|
const from = getBindingsDerivedFrom(binding);
|
|
@@ -5251,7 +5295,7 @@ function buildSignalFn(signal) {
|
|
|
5251
5295
|
const isValue = isBinding && binding.section === section;
|
|
5252
5296
|
const assertsHoists = isValue && binding.hoists && !isOptimize();
|
|
5253
5297
|
if (isValue) {
|
|
5254
|
-
for (const alias of binding.aliases) {
|
|
5298
|
+
if (binding.aliases) for (const alias of binding.aliases) {
|
|
5255
5299
|
const aliasSignal = getSignal(alias.section, alias);
|
|
5256
5300
|
if (signalHasWork(aliasSignal)) {
|
|
5257
5301
|
let value = createScopeReadExpression(binding);
|
|
@@ -5262,7 +5306,7 @@ function buildSignalFn(signal) {
|
|
|
5262
5306
|
pushForward(signal, aliasSignal, value);
|
|
5263
5307
|
}
|
|
5264
5308
|
}
|
|
5265
|
-
|
|
5309
|
+
if (binding.propertyAliases) pushMemberForwards(signal, createScopeReadExpression(binding), binding);
|
|
5266
5310
|
if (assertsHoists) signal.render.push(_marko_compiler.types.expressionStatement(callRuntime("_assert_hoist", createScopeReadExpression(binding))));
|
|
5267
5311
|
}
|
|
5268
5312
|
for (const value of signal.values) {
|
|
@@ -5270,9 +5314,7 @@ function buildSignalFn(signal) {
|
|
|
5270
5314
|
if (signalHasWork(value.signal)) pushSignalCall(signal, value.signal, value.value);
|
|
5271
5315
|
else signal.render.push(_marko_compiler.types.expressionStatement(withLeadingComment(value.value, getDebugNames(value.signal.referencedBindings))));
|
|
5272
5316
|
}
|
|
5273
|
-
forEach(signal.intersections,
|
|
5274
|
-
pushScopeCall(signal.render, intersection.identifier);
|
|
5275
|
-
});
|
|
5317
|
+
forEach(signal.intersections, pushIntersectionCall, signal);
|
|
5276
5318
|
if (isBinding && binding.sources) {
|
|
5277
5319
|
let dynamicClosureArgs;
|
|
5278
5320
|
let dynamicClosureSignalIdentifier;
|
|
@@ -5294,10 +5336,13 @@ function buildSignalFn(signal) {
|
|
|
5294
5336
|
if (isValue && !signal.storesValue) {
|
|
5295
5337
|
const call = getOnlyCall(signal.render);
|
|
5296
5338
|
if (call && call.callee.type === "Identifier" && call.arguments.length === 2 && call.arguments[0] === scopeIdentifier && isOwnValueRead(call.arguments[1], binding)) return call.callee;
|
|
5297
|
-
return _marko_compiler.types.arrowFunctionExpression([scopeIdentifier,
|
|
5339
|
+
return _marko_compiler.types.arrowFunctionExpression([scopeIdentifier, _marko_compiler.types.identifier(binding.canonical.name)], toOnlyExpressionOrBlock(signal.render));
|
|
5298
5340
|
}
|
|
5299
5341
|
return toScopeFn(signal.render);
|
|
5300
5342
|
}
|
|
5343
|
+
function pushIntersectionCall(intersection, signal) {
|
|
5344
|
+
pushScopeCall(signal.render, intersection.identifier);
|
|
5345
|
+
}
|
|
5301
5346
|
function toScopeFn(render) {
|
|
5302
5347
|
const call = getOnlyCall(render);
|
|
5303
5348
|
if (call && call.arguments.length === 1 && call.arguments[0] === scopeIdentifier) {
|
|
@@ -5330,24 +5375,21 @@ function getTranslatedExtraArgs(signal) {
|
|
|
5330
5375
|
}
|
|
5331
5376
|
return emptyExtraArgs;
|
|
5332
5377
|
}
|
|
5333
|
-
function getSignalValueIdentifier(signal) {
|
|
5334
|
-
const canonicalBinding = getCanonicalBinding(signal.referencedBindings);
|
|
5335
|
-
return _marko_compiler.types.identifier(canonicalBinding.name);
|
|
5336
|
-
}
|
|
5337
5378
|
function isOwnValueRead(node, binding) {
|
|
5338
5379
|
const extra = node.extra;
|
|
5339
5380
|
const read = extra?.read;
|
|
5340
5381
|
return !!read && !extra.assignment && read.binding === binding && read.properties === void 0 && !read.getter?.invoked;
|
|
5341
5382
|
}
|
|
5342
5383
|
function subscribe(references, intersection) {
|
|
5343
|
-
if (references) forEach(references,
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5384
|
+
if (references) forEach(references, subscribeToBinding, intersection);
|
|
5385
|
+
}
|
|
5386
|
+
function subscribeToBinding(binding, intersection) {
|
|
5387
|
+
if (binding.type !== 5) {
|
|
5388
|
+
const source = binding.canonical;
|
|
5389
|
+
const providerSignal = getSignal(intersection.section, source);
|
|
5390
|
+
providerSignal.storesValue = true;
|
|
5391
|
+
providerSignal.intersections = push(providerSignal.intersections, intersection);
|
|
5392
|
+
}
|
|
5351
5393
|
}
|
|
5352
5394
|
function trimEmptyArgs(args) {
|
|
5353
5395
|
const len = args.length;
|
|
@@ -5413,7 +5455,7 @@ function getResumeRegistryId(section, referencedBindings, type) {
|
|
|
5413
5455
|
function writeSignals(section) {
|
|
5414
5456
|
const seen = /* @__PURE__ */ new Set();
|
|
5415
5457
|
const written = /* @__PURE__ */ new Set();
|
|
5416
|
-
|
|
5458
|
+
forEach(section.bindings, writeBindingGetters, section);
|
|
5417
5459
|
for (const signal of getSignals(section).values()) writeSignal(signal);
|
|
5418
5460
|
function writeSignal(signal) {
|
|
5419
5461
|
if (seen.has(signal)) return;
|
|
@@ -5435,7 +5477,7 @@ function writeSignals(section) {
|
|
|
5435
5477
|
if (signal.build) {
|
|
5436
5478
|
let value = signal.build();
|
|
5437
5479
|
const buildsEagerForward = _marko_compiler.types.isIdentifier(value) || _marko_compiler.types.isCallExpression(value) && _marko_compiler.types.isIdentifier(value.arguments.at(-1));
|
|
5438
|
-
if (!value || !signal.
|
|
5480
|
+
if (!value || !signal.referenced && _marko_compiler.types.isFunction(value) && _marko_compiler.types.isBlockStatement(value.body) && !value.body.body.length) return;
|
|
5439
5481
|
if (_marko_compiler.types.isCallExpression(value)) trimEmptyArgs(value.arguments);
|
|
5440
5482
|
if (signal.register) value = callRuntime("_var_resume", _marko_compiler.types.stringLiteral(getResumeRegistryId(section, signal.referencedBindings, "var")), value);
|
|
5441
5483
|
if (buildsEagerForward) forEach(signal.forwards, writeSignal);
|
|
@@ -5452,15 +5494,14 @@ function writeSignals(section) {
|
|
|
5452
5494
|
}
|
|
5453
5495
|
return written;
|
|
5454
5496
|
}
|
|
5455
|
-
function
|
|
5456
|
-
|
|
5457
|
-
|
|
5458
|
-
|
|
5459
|
-
|
|
5460
|
-
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
});
|
|
5497
|
+
function writeBindingGetters(binding, section) {
|
|
5498
|
+
if (!binding.getters) return;
|
|
5499
|
+
for (const [hoistSection, hasReference] of binding.getters) {
|
|
5500
|
+
const getterIdentifier = getBindingGetterIdentifier(binding, hoistSection);
|
|
5501
|
+
const accessors = [getScopeAccessorLiteral(binding, true)];
|
|
5502
|
+
if (hoistSection) forEachAncestorSection(binding.section, hoistSection, pushInstancesAccessor, accessors);
|
|
5503
|
+
(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))]));
|
|
5504
|
+
}
|
|
5464
5505
|
}
|
|
5465
5506
|
function pushInstancesAccessor(section, accessors) {
|
|
5466
5507
|
const instancesAccessor = getSectionScopesAccessorLiteral(section);
|
|
@@ -5474,22 +5515,23 @@ function pushInstancesAccessor(section, accessors) {
|
|
|
5474
5515
|
function writeRegisteredFns() {
|
|
5475
5516
|
const registeredFns = getRegisteredFns();
|
|
5476
5517
|
const statements = [];
|
|
5477
|
-
for (const
|
|
5518
|
+
for (const { node, extra } of registeredFns) {
|
|
5519
|
+
const { name, referencesScope } = extra;
|
|
5478
5520
|
let fn;
|
|
5479
|
-
if (
|
|
5521
|
+
if (referencesScope || extra.referencedLocalBindingsInFunction) {
|
|
5480
5522
|
let params;
|
|
5481
5523
|
let prologue;
|
|
5482
|
-
if (
|
|
5524
|
+
if (extra.referencedLocalBindingsInFunction) {
|
|
5483
5525
|
params = [localsIdentifier];
|
|
5484
|
-
if (
|
|
5526
|
+
if (referencesScope) prologue = [_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(scopeIdentifier, _marko_compiler.types.memberExpression(localsIdentifier, _marko_compiler.types.identifier(getAccessorProp().Owner)))])];
|
|
5485
5527
|
} else params = [scopeIdentifier];
|
|
5486
|
-
const body = toReturnedFunction(
|
|
5487
|
-
fn = _marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(
|
|
5488
|
-
} else if (
|
|
5489
|
-
else fn = _marko_compiler.types.functionDeclaration(_marko_compiler.types.identifier(
|
|
5528
|
+
const body = toReturnedFunction(node, prologue);
|
|
5529
|
+
fn = _marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(name), _marko_compiler.types.arrowFunctionExpression(params, body.length === 1 && body[0].type === "ReturnStatement" ? body[0].argument : _marko_compiler.types.blockStatement(body)))]);
|
|
5530
|
+
} else if (node.type === "FunctionDeclaration" && node.id?.name === name) fn = node;
|
|
5531
|
+
else fn = _marko_compiler.types.functionDeclaration(_marko_compiler.types.identifier(name), node.params, node.body.type === "BlockStatement" ? node.body : _marko_compiler.types.blockStatement([_marko_compiler.types.returnStatement(node.body)]), node.generator, node.async);
|
|
5490
5532
|
statements.push(fn);
|
|
5491
5533
|
}
|
|
5492
|
-
for (const
|
|
5534
|
+
for (const { extra } of registeredFns) statements.push(_marko_compiler.types.expressionStatement(registerRuntimeValue(extra.registryId, _marko_compiler.types.identifier(extra.name))));
|
|
5493
5535
|
(0, _marko_compiler_babel_utils.getProgram)().node.body.push(...statements);
|
|
5494
5536
|
}
|
|
5495
5537
|
function toReturnedFunction(rawFn, prologue) {
|
|
@@ -5502,7 +5544,7 @@ function toReturnedFunction(rawFn, prologue) {
|
|
|
5502
5544
|
}
|
|
5503
5545
|
function addHTMLEffectCall(section, expr) {
|
|
5504
5546
|
const signal = getSignal(section, getReferencedBindings(expr));
|
|
5505
|
-
signal.hasHTMLEffect =
|
|
5547
|
+
signal.hasHTMLEffect = true;
|
|
5506
5548
|
}
|
|
5507
5549
|
function writeHTMLResumeStatements(path) {
|
|
5508
5550
|
const bodyPath = flushInto(path);
|
|
@@ -5512,31 +5554,33 @@ function writeHTMLResumeStatements(path) {
|
|
|
5512
5554
|
const allSignals = Array.from(getSignals(section).values());
|
|
5513
5555
|
const scopeIdIdentifier = getScopeIdIdentifier(section);
|
|
5514
5556
|
const nodeReasons = getNodeReasons(section);
|
|
5515
|
-
const
|
|
5557
|
+
const markerAlwaysWritten = some(nodeReasons, isAlwaysWritten, section);
|
|
5558
|
+
let markerGuard;
|
|
5559
|
+
const getSectionMarkerGuard = () => markerAlwaysWritten ? void 0 : markerGuard ||= getWriteGuardForAny(section, nodeReasons, true);
|
|
5516
5560
|
const sectionReason = section.reason;
|
|
5517
5561
|
let linkedWithScope = some(section.bindings, isClientAssignedLet);
|
|
5518
5562
|
let linkReasons;
|
|
5519
5563
|
forEach(section.referencedClosures, (closure) => {
|
|
5520
5564
|
if (closure.sources) {
|
|
5521
5565
|
if (isDynamicClosure(section, closure)) {
|
|
5566
|
+
const closureScopes = findSlot(closure, 2);
|
|
5522
5567
|
const closureSignal = getSignal(closure.section, closure);
|
|
5523
5568
|
let identifier = htmlDynamicClosureInstancesIdentifier.get(closureSignal);
|
|
5524
5569
|
if (!identifier) {
|
|
5525
5570
|
htmlDynamicClosureInstancesIdentifier.set(closureSignal, identifier = generateUidIdentifier(closureSignal.identifier.name + "__closures"));
|
|
5526
5571
|
getHTMLSectionStatements(closure.section).push(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(identifier, _marko_compiler.types.newExpression(_marko_compiler.types.identifier("Set"), []))]));
|
|
5527
|
-
writeSlot(
|
|
5572
|
+
writeSlot(closureScopes, identifier);
|
|
5528
5573
|
}
|
|
5529
5574
|
const closureIndex = getDynamicClosureIndex(closure, section);
|
|
5530
5575
|
if (closureIndex) writeSlot(findSlot(closure, 3, section), _marko_compiler.types.numericLiteral(closureIndex));
|
|
5531
|
-
const closureScopesReason =
|
|
5576
|
+
const closureScopesReason = closureScopes?.reason;
|
|
5532
5577
|
const subscribeArg = isGuardedReason(closureScopesReason) && !isSameReason(closureScopesReason, sectionReason) ? getExprIfWritten(closure.section, closureScopesReason, identifier) : identifier;
|
|
5533
5578
|
if (subscribeArg) {
|
|
5534
|
-
const changeable = isChangeableDynamicClosure(section, closure);
|
|
5535
5579
|
if (subscribeArg === identifier) linkedWithScope = true;
|
|
5536
5580
|
else linkReasons = sourcesUtil.add(linkReasons, closureScopesReason);
|
|
5537
5581
|
addWriteScopeBuilder(section, (expr) => {
|
|
5538
|
-
const resumeId =
|
|
5539
|
-
return callRuntime("_subscribe", subscribeArg, expr, resumeId, resumeId &&
|
|
5582
|
+
const resumeId = getClosureSubscribeId(section, closure);
|
|
5583
|
+
return callRuntime("_subscribe", subscribeArg, expr, resumeId, resumeId && getSectionMarkerGuard());
|
|
5540
5584
|
});
|
|
5541
5585
|
}
|
|
5542
5586
|
}
|
|
@@ -5544,7 +5588,7 @@ function writeHTMLResumeStatements(path) {
|
|
|
5544
5588
|
});
|
|
5545
5589
|
for (let i = allSignals.length; i--;) if (allSignals[i].hasHTMLEffect) {
|
|
5546
5590
|
const signalRefs = allSignals[i].referencedBindings;
|
|
5547
|
-
body.push(_marko_compiler.types.expressionStatement(callRuntime("_script", scopeIdIdentifier, _marko_compiler.types.stringLiteral(getResumeRegistryId(section, signalRefs)),
|
|
5591
|
+
body.push(_marko_compiler.types.expressionStatement(callRuntime("_script", scopeIdIdentifier, _marko_compiler.types.stringLiteral(getResumeRegistryId(section, signalRefs)), getSectionMarkerGuard())));
|
|
5548
5592
|
}
|
|
5549
5593
|
const debug = !isOptimize();
|
|
5550
5594
|
const writeScopeBuilder = getSectionWriteScopeBuilder(section);
|
|
@@ -5595,23 +5639,30 @@ function writeHTMLResumeStatements(path) {
|
|
|
5595
5639
|
const write = getExprIfWritten(section, sectionReason, writeScopeBuilder ? writeScopeBuilder(callRuntime("_scope", ...writeScopeArgs)) : callRuntime("_scope", ...writeScopeArgs));
|
|
5596
5640
|
if (write) body.push(_marko_compiler.types.expressionStatement(write));
|
|
5597
5641
|
}
|
|
5598
|
-
if (
|
|
5642
|
+
if (!markerAlwaysWritten && !isBranchAlwaysMarked(section)) {
|
|
5599
5643
|
let link;
|
|
5600
5644
|
if (section.hasAbortSignal) link = callRuntime("_resume_branch", scopeIdIdentifier);
|
|
5601
5645
|
else if (sectionReason && !sourcesUtil.has(nodeReasons, sectionReason)) {
|
|
5602
5646
|
const guard = linkedWithScope ? void 0 : getWriteGuardForAny(section, sourcesUtil.difference(linkReasons, nodeReasons), true);
|
|
5603
5647
|
if (guard?.type !== "NumericLiteral") link = getExprIfWritten(section, sectionReason, andGuard(guard, callRuntime("_resume_branch", scopeIdIdentifier)));
|
|
5604
5648
|
}
|
|
5605
|
-
if (link)
|
|
5649
|
+
if (link) {
|
|
5650
|
+
const guard = getSectionMarkerGuard();
|
|
5651
|
+
body.push(_marko_compiler.types.expressionStatement(guard.type === "NumericLiteral" ? link : _marko_compiler.types.logicalExpression("||", guard, link)));
|
|
5652
|
+
}
|
|
5606
5653
|
}
|
|
5607
5654
|
const additionalStatements = getHTMLSectionStatements(section);
|
|
5608
5655
|
if (body.length || additionalStatements.length) body.unshift(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(scopeIdIdentifier, callRuntime("_scope_id"))]), ...additionalStatements);
|
|
5609
|
-
if (debug) forEach(section.bindings,
|
|
5610
|
-
if (binding.hoists && binding.type !== 0) body.push(_marko_compiler.types.expressionStatement(callRuntime("_assert_hoist", _marko_compiler.types.identifier(binding.name))));
|
|
5611
|
-
});
|
|
5656
|
+
if (debug) forEach(section.bindings, pushAssertHoist, body);
|
|
5612
5657
|
const returnIdentifier = getSectionReturnValueIdentifier(section);
|
|
5613
5658
|
if (returnIdentifier !== void 0) body.push(_marko_compiler.types.returnStatement(returnIdentifier));
|
|
5614
5659
|
}
|
|
5660
|
+
function isAlwaysWritten(reason, section) {
|
|
5661
|
+
return getWriteBit(section, reason) === 1;
|
|
5662
|
+
}
|
|
5663
|
+
function pushAssertHoist(binding, body) {
|
|
5664
|
+
if (binding.hoists && binding.type !== 0) body.push(_marko_compiler.types.expressionStatement(callRuntime("_assert_hoist", _marko_compiler.types.identifier(binding.name))));
|
|
5665
|
+
}
|
|
5615
5666
|
function getSetup(section) {
|
|
5616
5667
|
return getSignals(section).get(void 0);
|
|
5617
5668
|
}
|
|
@@ -5746,24 +5797,21 @@ function registerFnExpression(node) {
|
|
|
5746
5797
|
const referencesScope = extra.referencesScope;
|
|
5747
5798
|
const referencedLocals = extra.referencedLocalBindingsInFunction;
|
|
5748
5799
|
getRegisteredFns().push({
|
|
5749
|
-
id,
|
|
5750
5800
|
node,
|
|
5751
|
-
|
|
5752
|
-
section: extra.section,
|
|
5753
|
-
referencesScope,
|
|
5754
|
-
referencedLocals
|
|
5801
|
+
extra
|
|
5755
5802
|
});
|
|
5756
5803
|
if (referencedLocals) {
|
|
5757
5804
|
const properties = [];
|
|
5758
5805
|
if (referencesScope) properties.push(_marko_compiler.types.objectProperty(_marko_compiler.types.identifier(getAccessorProp().Owner), scopeIdentifier));
|
|
5759
|
-
forEach(referencedLocals,
|
|
5760
|
-
properties.push(toObjectProperty(getLocalsScopeAccessor(binding), getDeclaredBindingExpression(binding)));
|
|
5761
|
-
});
|
|
5806
|
+
forEach(referencedLocals, pushLocalProperty, properties);
|
|
5762
5807
|
return _marko_compiler.types.callExpression(_marko_compiler.types.identifier(id), [_marko_compiler.types.objectExpression(properties)]);
|
|
5763
5808
|
} else if (referencesScope) return _marko_compiler.types.callExpression(_marko_compiler.types.identifier(id), [scopeIdentifier]);
|
|
5764
5809
|
else return _marko_compiler.types.identifier(id);
|
|
5765
5810
|
}
|
|
5766
5811
|
}
|
|
5812
|
+
function pushLocalProperty(binding, properties) {
|
|
5813
|
+
properties.push(toObjectProperty(getLocalsScopeAccessor(binding), getDeclaredBindingExpression(binding)));
|
|
5814
|
+
}
|
|
5767
5815
|
function appendBindingKey(name, binding, section) {
|
|
5768
5816
|
return `${name}_${binding.name}#${binding.section === section ? "" : binding.section.id + ":"}${binding.id}`;
|
|
5769
5817
|
}
|
|
@@ -5800,13 +5848,10 @@ function translateAttrs(tag, paramsTree = true, statements = [], contentKey = "c
|
|
|
5800
5848
|
for (let i = 0; i < attrTags.length; i++) {
|
|
5801
5849
|
const child = attrTags[i];
|
|
5802
5850
|
if (child.isMarkoTag()) {
|
|
5803
|
-
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
|
-
|
|
5807
|
-
const translatedAttrTag = translateAttrs(child, getParamsTreeAt(paramsTree, attrTagMeta.name), statements, contentKey);
|
|
5808
|
-
addAttrTag(contentProperties, attrTagMeta, _marko_compiler.types.objectExpression(translatedAttrTag.properties));
|
|
5809
|
-
}
|
|
5851
|
+
const attrTagMeta = (0, _marko_compiler_babel_utils.isAttributeTag)(child) && attrTagLookup[getTagName(child)];
|
|
5852
|
+
if (attrTagMeta && !attrTagMeta.dynamic) {
|
|
5853
|
+
const translatedAttrTag = translateAttrs(child, getParamsTreeAt(paramsTree, attrTagMeta.name), statements, contentKey);
|
|
5854
|
+
addAttrTag(contentProperties, attrTagMeta, _marko_compiler.types.objectExpression(translatedAttrTag.properties));
|
|
5810
5855
|
} else i = addDynamicAttrTagStatements(attrTags, i, attrTagLookup, statements, paramsTree, contentKey);
|
|
5811
5856
|
}
|
|
5812
5857
|
}
|
|
@@ -5827,7 +5872,7 @@ function translateAttrs(tag, paramsTree = true, statements = [], contentKey = "c
|
|
|
5827
5872
|
const { value } = attr;
|
|
5828
5873
|
if (_marko_compiler.types.isMarkoSpreadAttribute(attr) && attr.extra?.knownSpread) {
|
|
5829
5874
|
const { knownSpread } = attr.extra;
|
|
5830
|
-
if (!
|
|
5875
|
+
if (!knownSpread.canonical.pruned) attrProperties.push(_marko_compiler.types.spreadElement(getDeclaredBindingExpression(knownSpread, true)));
|
|
5831
5876
|
} else if (!value.extra?.dropped) {
|
|
5832
5877
|
if (_marko_compiler.types.isMarkoSpreadAttribute(attr)) attrProperties.push(_marko_compiler.types.spreadElement(value));
|
|
5833
5878
|
else if (!seen.has(attr.name) && getParamsTreeAt(paramsTree, attr.name)) {
|
|
@@ -5982,6 +6027,7 @@ function knownTagAnalyze(tag, childSection, childParamsTree) {
|
|
|
5982
6027
|
if (varBinding) {
|
|
5983
6028
|
addSetupWork(section);
|
|
5984
6029
|
const { childScopeBinding } = tagExtra;
|
|
6030
|
+
section.hasReturnedVar = true;
|
|
5985
6031
|
varBinding.returnedBy = {
|
|
5986
6032
|
scope: childScopeBinding,
|
|
5987
6033
|
section: childSection,
|
|
@@ -6014,11 +6060,12 @@ function assertTerminates(tag, childSection) {
|
|
|
6014
6060
|
const callers = /* @__PURE__ */ new Set([getSection(tag)]);
|
|
6015
6061
|
for (const caller of callers) {
|
|
6016
6062
|
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>\`.`);
|
|
6017
|
-
forEach(caller.renderedBy,
|
|
6018
|
-
callers.add(call.childScopeBinding.section);
|
|
6019
|
-
});
|
|
6063
|
+
forEach(caller.renderedBy, addCaller, callers);
|
|
6020
6064
|
}
|
|
6021
6065
|
}
|
|
6066
|
+
function addCaller(call, callers) {
|
|
6067
|
+
callers.add(call.childScopeBinding.section);
|
|
6068
|
+
}
|
|
6022
6069
|
function exposeChildParamsTree(childSection) {
|
|
6023
6070
|
return childSection.params && exposeParamsTree(childSection.params, true);
|
|
6024
6071
|
}
|
|
@@ -6130,11 +6177,7 @@ function addKnownTagReasons(section) {
|
|
|
6130
6177
|
const knownExprs = tagExtra[kKnownExprs];
|
|
6131
6178
|
const { childSection } = tagExtra;
|
|
6132
6179
|
if (knownExprs && childSection.paramReasonGroups) {
|
|
6133
|
-
for (const group of childSection.paramReasonGroups) if (!findSlot(childScopeBinding, 5, section, group))
|
|
6134
|
-
const slot = ensureSlot(childScopeBinding, 5, section, group);
|
|
6135
|
-
slot.reasonExprs = mapParamReasonToExpr(knownExprs, group);
|
|
6136
|
-
addReason(slot, getSourcesForExprs(slot.reasonExprs));
|
|
6137
|
-
}
|
|
6180
|
+
for (const group of childSection.paramReasonGroups) if (!findSlot(childScopeBinding, 5, section, group)) addReason(ensureSlot(childScopeBinding, 5, section, group), getSourcesForExprs(mapParamReasonToExpr(knownExprs, group)));
|
|
6138
6181
|
}
|
|
6139
6182
|
}
|
|
6140
6183
|
}
|
|
@@ -6631,10 +6674,7 @@ function getSourcesForExpr(expr) {
|
|
|
6631
6674
|
return isReferencedExtra(root) ? getSourcesForReferencedBindings(getReferencedBindings(root)) : void 0;
|
|
6632
6675
|
}
|
|
6633
6676
|
function getSourcesForExprs(exprs) {
|
|
6634
|
-
|
|
6635
|
-
if (exprs === true) return ALWAYS;
|
|
6636
|
-
return reduce(exprs, mergeExprSources);
|
|
6637
|
-
}
|
|
6677
|
+
return reduce(exprs, mergeExprSources);
|
|
6638
6678
|
}
|
|
6639
6679
|
function getSourcesForReferencedBindings(bindings) {
|
|
6640
6680
|
return reduce(bindings, mergeBindingSources);
|
|
@@ -6693,12 +6733,6 @@ function getKnownExprsAt(exprs, binding) {
|
|
|
6693
6733
|
function applyReasonExprs(section) {
|
|
6694
6734
|
for (const slot of section.slots) addReason(slot, getSourcesForExprs(slot.reasonExprs));
|
|
6695
6735
|
}
|
|
6696
|
-
function mergeSlotReasons(section) {
|
|
6697
|
-
section.reason = section.slots.reduce(mergeSlotReason, section.reason);
|
|
6698
|
-
}
|
|
6699
|
-
function mergeSlotReason(sectionReason, slot) {
|
|
6700
|
-
return mergeSources(sectionReason, slot.reason);
|
|
6701
|
-
}
|
|
6702
6736
|
function getNodeReasons(section) {
|
|
6703
6737
|
return section.structure?.reduce(addNodeReason, void 0);
|
|
6704
6738
|
}
|
|
@@ -6740,12 +6774,13 @@ function createBinding(name, type, refSection, aliased, property, excludePropert
|
|
|
6740
6774
|
sources: void 0,
|
|
6741
6775
|
intersection: void 0,
|
|
6742
6776
|
derivedFrom: void 0,
|
|
6743
|
-
reads:
|
|
6744
|
-
aliases:
|
|
6777
|
+
reads: void 0,
|
|
6778
|
+
aliases: void 0,
|
|
6745
6779
|
hoists: void 0,
|
|
6746
|
-
getters:
|
|
6747
|
-
propertyAliases:
|
|
6780
|
+
getters: void 0,
|
|
6781
|
+
propertyAliases: void 0,
|
|
6748
6782
|
aliasOf: aliased,
|
|
6783
|
+
canonical: void 0,
|
|
6749
6784
|
iterates: void 0,
|
|
6750
6785
|
declaredAlias: void 0,
|
|
6751
6786
|
localOf: void 0,
|
|
@@ -6761,16 +6796,17 @@ function createBinding(name, type, refSection, aliased, property, excludePropert
|
|
|
6761
6796
|
hasLazyReads: false
|
|
6762
6797
|
};
|
|
6763
6798
|
if (property) {
|
|
6764
|
-
const propBinding = aliased.propertyAliases
|
|
6799
|
+
const propBinding = aliased.propertyAliases?.get(property);
|
|
6765
6800
|
if (propBinding) {
|
|
6766
6801
|
binding.property = void 0;
|
|
6767
6802
|
binding.aliasOf = propBinding;
|
|
6768
|
-
propBinding.aliases.add(binding);
|
|
6769
|
-
} else aliased.propertyAliases.set(property, binding);
|
|
6803
|
+
(propBinding.aliases ??= /* @__PURE__ */ new Set()).add(binding);
|
|
6804
|
+
} else (aliased.propertyAliases ??= /* @__PURE__ */ new Map()).set(property, binding);
|
|
6770
6805
|
} else if (aliased) {
|
|
6771
|
-
aliased.aliases.add(binding);
|
|
6806
|
+
(aliased.aliases ??= /* @__PURE__ */ new Set()).add(binding);
|
|
6772
6807
|
if (declared) aliased.declaredAlias ??= binding;
|
|
6773
6808
|
}
|
|
6809
|
+
binding.canonical = isDirectAlias(binding) ? binding.aliasOf : binding;
|
|
6774
6810
|
setNextBindingId(id + 1);
|
|
6775
6811
|
getBindings().add(binding);
|
|
6776
6812
|
return binding;
|
|
@@ -6779,8 +6815,8 @@ function reserveId(binding, offset) {
|
|
|
6779
6815
|
binding.reserveSize = Math.max(binding.reserveSize, offset);
|
|
6780
6816
|
}
|
|
6781
6817
|
function ensurePropertyAlias(binding, property) {
|
|
6782
|
-
const canonical =
|
|
6783
|
-
return canonical.propertyAliases
|
|
6818
|
+
const { canonical } = binding;
|
|
6819
|
+
return canonical.propertyAliases?.get(property) || createBinding(canonical.name + toIdentifierAccess(property), canonical.type, canonical.section, canonical, property);
|
|
6784
6820
|
}
|
|
6785
6821
|
function addAssignedProperty(binding, property) {
|
|
6786
6822
|
if (binding.assignedProperties !== true) binding.assignedProperties = property === void 0 || propertiesUtil.add(binding.assignedProperties, property);
|
|
@@ -6788,8 +6824,7 @@ function addAssignedProperty(binding, property) {
|
|
|
6788
6824
|
function getAssignedObject(binding) {
|
|
6789
6825
|
let object;
|
|
6790
6826
|
for (let alias = binding; alias.aliasOf && !isRest(alias); alias = alias.aliasOf) if (alias.property !== void 0) {
|
|
6791
|
-
|
|
6792
|
-
if (parent.assignedProperties === true || propertiesUtil.has(parent.assignedProperties, alias.property)) object = alias.aliasOf;
|
|
6827
|
+
if (alias.aliasOf.assignedProperties === true || propertiesUtil.has(alias.aliasOf.assignedProperties, alias.property)) object = alias.aliasOf;
|
|
6793
6828
|
}
|
|
6794
6829
|
return object;
|
|
6795
6830
|
}
|
|
@@ -6797,16 +6832,16 @@ function getPropertyAlias(binding, properties) {
|
|
|
6797
6832
|
return reduceWhile(properties, getExistingPropertyAlias, binding);
|
|
6798
6833
|
}
|
|
6799
6834
|
function getExistingPropertyAlias(binding, property) {
|
|
6800
|
-
return
|
|
6835
|
+
return binding.canonical.propertyAliases?.get(property);
|
|
6801
6836
|
}
|
|
6802
6837
|
function getDeepestPropertyAlias(binding, properties) {
|
|
6803
6838
|
let alias = binding;
|
|
6804
6839
|
if (Array.isArray(properties)) for (const property of properties) {
|
|
6805
|
-
const next = alias.propertyAliases
|
|
6840
|
+
const next = alias.propertyAliases?.get(property);
|
|
6806
6841
|
if (!next) break;
|
|
6807
6842
|
alias = next;
|
|
6808
6843
|
}
|
|
6809
|
-
else if (properties !== void 0) alias = alias.propertyAliases
|
|
6844
|
+
else if (properties !== void 0) alias = alias.propertyAliases?.get(properties) ?? alias;
|
|
6810
6845
|
return alias;
|
|
6811
6846
|
}
|
|
6812
6847
|
function compareReferences(a, b) {
|
|
@@ -6837,14 +6872,11 @@ const bindingUtil = new Sorted(function compareBindings(a, b) {
|
|
|
6837
6872
|
const propertiesUtil = new Sorted(function compareProperties(a, b) {
|
|
6838
6873
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
6839
6874
|
});
|
|
6840
|
-
function
|
|
6841
|
-
|
|
6842
|
-
if (
|
|
6843
|
-
|
|
6844
|
-
}
|
|
6845
|
-
function someAlias(binding, test, arg, directOnly) {
|
|
6846
|
-
if (test(binding, arg)) return true;
|
|
6847
|
-
for (const alias of binding.aliases) if ((!directOnly || isDirectAlias(alias)) && someAlias(alias, test, arg, directOnly)) return true;
|
|
6875
|
+
function someAlias(binding, test) {
|
|
6876
|
+
if (test(binding)) return true;
|
|
6877
|
+
if (binding.aliases) {
|
|
6878
|
+
for (const alias of binding.aliases) if (someAlias(alias, test)) return true;
|
|
6879
|
+
}
|
|
6848
6880
|
return false;
|
|
6849
6881
|
}
|
|
6850
6882
|
function someUpToAliasRoot(binding, test, arg) {
|
|
@@ -6855,13 +6887,13 @@ function getNearestDeclared(binding) {
|
|
|
6855
6887
|
for (let cur = binding; cur; cur = cur.aliasOf) if (cur.declared) return cur;
|
|
6856
6888
|
}
|
|
6857
6889
|
function getDeclaredAlias(binding) {
|
|
6858
|
-
return !getNearestDeclared(binding) && binding.declaredAlias;
|
|
6890
|
+
return binding.declaredAlias && !getNearestDeclared(binding) && binding.declaredAlias;
|
|
6859
6891
|
}
|
|
6860
6892
|
function isDirectAlias(binding) {
|
|
6861
6893
|
return binding.aliasOf !== void 0 && binding.property === void 0 && !isRest(binding);
|
|
6862
6894
|
}
|
|
6863
6895
|
function isRest(binding) {
|
|
6864
|
-
return binding.excludeProperties !== void 0 || binding.restOffset !== void 0;
|
|
6896
|
+
return binding.aliasOf !== void 0 && (binding.excludeProperties !== void 0 || binding.restOffset !== void 0);
|
|
6865
6897
|
}
|
|
6866
6898
|
function getDebugAccess(binding, toParam, formatProperty) {
|
|
6867
6899
|
let root = binding;
|
|
@@ -6896,11 +6928,13 @@ function toIdentifierAccess(property) {
|
|
|
6896
6928
|
return `_${property.replace(/[^a-z0-9_$]/gi, "_")}`;
|
|
6897
6929
|
}
|
|
6898
6930
|
function isInvokeOnlyBinding(binding) {
|
|
6899
|
-
return !someAlias(binding, isReadBeyondInvoking
|
|
6931
|
+
return !someAlias(binding, isReadBeyondInvoking);
|
|
6900
6932
|
}
|
|
6901
6933
|
function isReadBeyondInvoking(binding) {
|
|
6902
|
-
if (binding.assignments || binding.hoists || binding.getters
|
|
6903
|
-
|
|
6934
|
+
if (binding.assignments || binding.hoists || binding.getters || binding.propertyAliases || isRest(binding)) return true;
|
|
6935
|
+
if (binding.reads) {
|
|
6936
|
+
for (const reads of binding.reads.values()) if (some(reads, isReadOutsideInvokeOnly)) return true;
|
|
6937
|
+
}
|
|
6904
6938
|
return false;
|
|
6905
6939
|
}
|
|
6906
6940
|
function isReadOutsideInvokeOnly(read) {
|
|
@@ -6910,7 +6944,9 @@ function isOwnBinding(binding) {
|
|
|
6910
6944
|
return binding.section.program === (0, _marko_compiler_babel_utils.getProgram)().node.extra.section;
|
|
6911
6945
|
}
|
|
6912
6946
|
function hasNonConstantPropertyAlias(binding) {
|
|
6913
|
-
|
|
6947
|
+
if (binding.propertyAliases) {
|
|
6948
|
+
for (const alias of binding.propertyAliases.values()) if (alias.type !== 5) return true;
|
|
6949
|
+
}
|
|
6914
6950
|
return false;
|
|
6915
6951
|
}
|
|
6916
6952
|
function getPropertyPath(binding, ancestor) {
|
|
@@ -7137,7 +7173,11 @@ function getForAttrs(type) {
|
|
|
7137
7173
|
/** Throws for a param that a loop of `type` never supplies. */
|
|
7138
7174
|
function assertForParams(tag, type) {
|
|
7139
7175
|
const extraParam = tag.node.body.params[type === "of" || type === "in" ? 2 : 1];
|
|
7140
|
-
if (extraParam && extraParam.type !== "RestElement") throw tag.hub.buildError(extraParam, `The ${coreTagLink(tag)} only provides \`|${type
|
|
7176
|
+
if (extraParam && extraParam.type !== "RestElement") throw tag.hub.buildError(extraParam, `The ${coreTagLink(tag)} only provides \`|${getForParamNames(type)}|\` with \`${type}=\`, so this parameter is never supplied.`);
|
|
7177
|
+
}
|
|
7178
|
+
/** The params a loop of `type` supplies, as its docs name them. */
|
|
7179
|
+
function getForParamNames(type) {
|
|
7180
|
+
return type === "of" ? "item, index" : type === "in" ? "key, value" : "num";
|
|
7141
7181
|
}
|
|
7142
7182
|
function coreTagLink(tag) {
|
|
7143
7183
|
const tagName = getTagName(tag);
|
|
@@ -7321,6 +7361,12 @@ function text(path, binding, marker) {
|
|
|
7321
7361
|
function marker(path, binding) {
|
|
7322
7362
|
addNode(path, binding, true);
|
|
7323
7363
|
}
|
|
7364
|
+
function markerNode(tag, section) {
|
|
7365
|
+
const binding = createBinding("#text", 0, section);
|
|
7366
|
+
marker(tag, binding);
|
|
7367
|
+
enterShallow(tag);
|
|
7368
|
+
return binding;
|
|
7369
|
+
}
|
|
7324
7370
|
function controlFlowNode(tag, section) {
|
|
7325
7371
|
const extra = tag.node.extra ??= {};
|
|
7326
7372
|
const parentTagName = getOnlyChildParentTagName(tag);
|
|
@@ -7328,10 +7374,7 @@ function controlFlowNode(tag, section) {
|
|
|
7328
7374
|
const parentTag = getParentTag(tag).node;
|
|
7329
7375
|
return extra.nodeBinding = (parentTag.extra ??= {}).nodeBinding ??= createBinding("#" + parentTagName.toLowerCase(), 0, section);
|
|
7330
7376
|
}
|
|
7331
|
-
|
|
7332
|
-
marker(tag, binding);
|
|
7333
|
-
enterShallow(tag);
|
|
7334
|
-
return binding;
|
|
7377
|
+
return extra.nodeBinding = markerNode(tag, section);
|
|
7335
7378
|
}
|
|
7336
7379
|
function addNode(path, binding, marker) {
|
|
7337
7380
|
const { structure } = getSection(path);
|
|
@@ -7622,15 +7665,14 @@ const IfTag = {
|
|
|
7622
7665
|
},
|
|
7623
7666
|
exit(tag) {
|
|
7624
7667
|
if (tag.node.body.attributeTags) return;
|
|
7668
|
+
const branches = getBranches(tag);
|
|
7669
|
+
const [ifTag] = branches[0];
|
|
7625
7670
|
const bodySection = getSectionForBody(tag.get("body"));
|
|
7626
7671
|
if (bodySection) {
|
|
7627
|
-
const [ifTag] = getBranches(tag)[0];
|
|
7628
7672
|
resumeOwnerByMarkerWhenUnconditional(bodySection, ifTag.node.extra.nodeBinding);
|
|
7629
7673
|
writeHTMLResumeStatements(tag);
|
|
7630
7674
|
}
|
|
7631
7675
|
if (isLastBranch(tag)) {
|
|
7632
|
-
const branches = getBranches(tag);
|
|
7633
|
-
const [ifTag] = branches[0];
|
|
7634
7676
|
let branchReasons;
|
|
7635
7677
|
let statement;
|
|
7636
7678
|
for (let i = branches.length; i--;) {
|
|
@@ -8072,7 +8114,7 @@ var await_default = {
|
|
|
8072
8114
|
if (node.body.params.length && (node.body.params.length > 1 || node.body.params[0].type === "RestElement")) throw tag.get("name").buildCodeFrameError(`The ${coreTagLink(tag)} only supports a single parameter.`);
|
|
8073
8115
|
const section = ensureSection(tag);
|
|
8074
8116
|
const tagExtra = tag.node.extra ??= {};
|
|
8075
|
-
|
|
8117
|
+
tagExtra.nodeBinding = markerNode(tag, section);
|
|
8076
8118
|
const bodySection = ensureBodySection(tagBody);
|
|
8077
8119
|
const valueExtra = valueAttr.value.extra ??= {};
|
|
8078
8120
|
const paramsBinding = trackParamsReferences(tagBody, 4);
|
|
@@ -8086,8 +8128,6 @@ var await_default = {
|
|
|
8086
8128
|
tag: tagExtra
|
|
8087
8129
|
});
|
|
8088
8130
|
addSetupWork(section);
|
|
8089
|
-
marker(tag, nodeBinding);
|
|
8090
|
-
enterShallow(tag);
|
|
8091
8131
|
},
|
|
8092
8132
|
translate: translateByTarget({
|
|
8093
8133
|
html: {
|
|
@@ -8234,6 +8274,7 @@ var debug_default = {
|
|
|
8234
8274
|
types: runtime_info_default.name + "/tags/debug.d.marko"
|
|
8235
8275
|
};
|
|
8236
8276
|
// src/translator/core/define.ts
|
|
8277
|
+
const kOnlyDirectReferences = Symbol("<define> only direct references");
|
|
8237
8278
|
var define_default = {
|
|
8238
8279
|
analyze(tag) {
|
|
8239
8280
|
(0, _marko_compiler_babel_utils.assertNoArgs)(tag);
|
|
@@ -8271,8 +8312,9 @@ var define_default = {
|
|
|
8271
8312
|
}
|
|
8272
8313
|
}
|
|
8273
8314
|
if (allDirectReferences) {
|
|
8274
|
-
const inputAlias = allHaveInput && paramsBinding?.propertyAliases
|
|
8315
|
+
const inputAlias = allHaveInput && paramsBinding?.propertyAliases?.get("0");
|
|
8275
8316
|
if (inputAlias) inputAlias.nullable = false;
|
|
8317
|
+
tag.node.extra[kOnlyDirectReferences] = true;
|
|
8276
8318
|
dropNodes(getAllTagReferenceNodes(tag.node));
|
|
8277
8319
|
return;
|
|
8278
8320
|
}
|
|
@@ -8297,25 +8339,18 @@ var define_default = {
|
|
|
8297
8339
|
translateVar(tag, propsToExpression(translatedAttrs.properties), "const", translatedAttrs.statements);
|
|
8298
8340
|
replaceWithStatements(tag, translatedAttrs.statements);
|
|
8299
8341
|
} else {
|
|
8300
|
-
|
|
8301
|
-
|
|
8302
|
-
|
|
8303
|
-
|
|
8304
|
-
|
|
8305
|
-
|
|
8306
|
-
|
|
8307
|
-
|
|
8308
|
-
|
|
8309
|
-
|
|
8310
|
-
|
|
8311
|
-
|
|
8312
|
-
if (bodySection.hasSetupWork) return hasWork ? buildSignalFn(signal) : _marko_compiler.types.arrowFunctionExpression([getUnusedParamIdentifier()], _marko_compiler.types.numericLiteral(0));
|
|
8313
|
-
};
|
|
8314
|
-
}
|
|
8315
|
-
if (bodySection && allDirectReferences) {
|
|
8316
|
-
replaceWithStatements(tag);
|
|
8317
|
-
return;
|
|
8318
|
-
}
|
|
8342
|
+
const bodySection = getSectionForBody(tag.get("body"));
|
|
8343
|
+
if (bodySection?.renderedBy) {
|
|
8344
|
+
const signal = getSignal(bodySection, void 0);
|
|
8345
|
+
signal.build = () => {
|
|
8346
|
+
const hasWork = signalHasWork(signal);
|
|
8347
|
+
if (hasWork && !bodySection.hasSetupWork) throw new Error("Marko internal error: analysis marked a `<define>` body's setup as empty but translation produced statements for it. Please open an issue with a reproduction.");
|
|
8348
|
+
if (bodySection.hasSetupWork) return hasWork ? buildSignalFn(signal) : _marko_compiler.types.arrowFunctionExpression([getUnusedParamIdentifier()], _marko_compiler.types.numericLiteral(0));
|
|
8349
|
+
};
|
|
8350
|
+
}
|
|
8351
|
+
if (node.extra[kOnlyDirectReferences]) {
|
|
8352
|
+
replaceWithStatements(tag);
|
|
8353
|
+
return;
|
|
8319
8354
|
}
|
|
8320
8355
|
const section = getSection(tag);
|
|
8321
8356
|
if (translatedAttrs.statements.length) addStatement("render", section, node.extra, translatedAttrs.statements);
|
|
@@ -8380,7 +8415,7 @@ var for_default = {
|
|
|
8380
8415
|
const allowAttrs = getForAttrs(forType);
|
|
8381
8416
|
if (!isAttrTag) allowAttrs.push("by");
|
|
8382
8417
|
const keyAttr = tag.node.attributes.find(isKeyAttr);
|
|
8383
|
-
if (keyAttr) throw tag.hub.buildError(keyAttr, `The ${coreTagLink(tag)} keys items with the \`by=\` attribute, not \`key=\`. ${forType === "of" ? "
|
|
8418
|
+
if (keyAttr) throw tag.hub.buildError(keyAttr, `The ${coreTagLink(tag)} keys items with the \`by=\` attribute, not \`key=\`. Use ${forType === "of" ? "`by=\"propName\"` or " : ""}\`by=(${getForParamNames(forType)}) => key\`.`);
|
|
8384
8419
|
(0, _marko_compiler_babel_utils.assertAllowedAttributes)(tag, allowAttrs);
|
|
8385
8420
|
assertForParams(tag, forType);
|
|
8386
8421
|
if (isAttrTag) {
|
|
@@ -8390,7 +8425,7 @@ var for_default = {
|
|
|
8390
8425
|
const forAttrs = getKnownAttrValues(tag.node);
|
|
8391
8426
|
const byAttr = forAttrs.by;
|
|
8392
8427
|
if (byAttr) (byAttr.extra ??= {}).consumed = true;
|
|
8393
|
-
if (forType !== "of" && byAttr?.type === "StringLiteral") throw tag.hub.buildError(byAttr, `The ${coreTagLink(tag)} only supports a string \`by\` key with \`of\`; use a \`by=(${forType
|
|
8428
|
+
if (forType !== "of" && byAttr?.type === "StringLiteral") throw tag.hub.buildError(byAttr, `The ${coreTagLink(tag)} only supports a string \`by\` key with \`of\`; use a \`by=(${getForParamNames(forType)}) => ...\` function for \`<for ${forType}>\`.`);
|
|
8394
8429
|
const bodySection = ensureBodySection(tagBody);
|
|
8395
8430
|
if (!bodySection) {
|
|
8396
8431
|
dropNodes(getAllTagReferenceNodes(tag.node));
|
|
@@ -8479,10 +8514,10 @@ var for_default = {
|
|
|
8479
8514
|
};
|
|
8480
8515
|
function getLoopKeyBinding(byAttr, paramsBinding, forType) {
|
|
8481
8516
|
if (byAttr) {
|
|
8482
|
-
const item = paramsBinding.propertyAliases
|
|
8517
|
+
const item = paramsBinding.propertyAliases?.get("0");
|
|
8483
8518
|
return item && getKeyAlias(byAttr, item);
|
|
8484
8519
|
}
|
|
8485
|
-
return paramsBinding.propertyAliases
|
|
8520
|
+
return paramsBinding.propertyAliases?.get(forType === "of" ? "1" : "0");
|
|
8486
8521
|
}
|
|
8487
8522
|
function getKeyAlias(byAttr, item) {
|
|
8488
8523
|
if (byAttr.type === "StringLiteral") return getPropertyAlias(item, byAttr.value);
|
|
@@ -8659,11 +8694,11 @@ var id_default = {
|
|
|
8659
8694
|
replaceWithStatements(tag);
|
|
8660
8695
|
return;
|
|
8661
8696
|
}
|
|
8662
|
-
const id = isOutputHTML() ? callRuntime("_id") : callRuntime("_id", scopeIdentifier);
|
|
8663
8697
|
if (isOutputHTML()) {
|
|
8698
|
+
const id = callRuntime("_id");
|
|
8664
8699
|
translateVar(tag, valueAttr ? _marko_compiler.types.logicalExpression("||", valueAttr.value, id) : id);
|
|
8665
|
-
replaceWithStatements(tag);
|
|
8666
8700
|
} else {
|
|
8701
|
+
const id = callRuntime("_id", scopeIdentifier);
|
|
8667
8702
|
const section = getSection(tag);
|
|
8668
8703
|
const binding = node.var.extra.binding;
|
|
8669
8704
|
const signal = initValue(binding);
|
|
@@ -8671,8 +8706,8 @@ var id_default = {
|
|
|
8671
8706
|
const { value } = valueAttr;
|
|
8672
8707
|
addValue(section, value.extra, signal, _marko_compiler.types.logicalExpression("||", value, evaluate(value).confident ? id : callRuntime("_id", scopeIdentifier, _marko_compiler.types.stringLiteral(getPrefixedScopeAccessor(binding, getAccessorPrefix().IdFallback)))));
|
|
8673
8708
|
} else addValue(section, void 0, signal, id);
|
|
8674
|
-
replaceWithStatements(tag);
|
|
8675
8709
|
}
|
|
8710
|
+
replaceWithStatements(tag);
|
|
8676
8711
|
} },
|
|
8677
8712
|
parseOptions: { openTagOnly: true },
|
|
8678
8713
|
types: runtime_info_default.name + "/tags/id.d.marko"
|
|
@@ -8704,18 +8739,16 @@ var let_default = {
|
|
|
8704
8739
|
const binding = trackVarReferences(tag, 1);
|
|
8705
8740
|
const tagExtra = mergeReferences(tagSection, tag.node, [valueAttr?.value, valueChangeAttr?.value]);
|
|
8706
8741
|
setDerivedFrom(binding, tagExtra);
|
|
8742
|
+
tagExtra.pure = !valueAttr || evaluate(valueAttr.value).pure;
|
|
8707
8743
|
if (valueChangeAttr) {
|
|
8708
8744
|
const changeSlot = ensureSlot(binding, 1);
|
|
8709
8745
|
reserveId(binding, 1);
|
|
8710
8746
|
tagExtra.retained = true;
|
|
8711
|
-
tagExtra.pure
|
|
8747
|
+
tagExtra.pure &&= evaluate(valueChangeAttr.value).pure;
|
|
8712
8748
|
onFinalizeReferences(() => {
|
|
8713
8749
|
if (binding.assignments) addReason(changeSlot, ALWAYS);
|
|
8714
8750
|
});
|
|
8715
|
-
} else
|
|
8716
|
-
tagExtra.initialValue = true;
|
|
8717
|
-
tagExtra.pure = !valueAttr || evaluate(valueAttr.value).pure;
|
|
8718
|
-
}
|
|
8751
|
+
} else tagExtra.initialValue = true;
|
|
8719
8752
|
},
|
|
8720
8753
|
translate: { exit(tag) {
|
|
8721
8754
|
const { node } = tag;
|
|
@@ -8727,7 +8760,7 @@ var let_default = {
|
|
|
8727
8760
|
const { value, valueChange } = getKnownAttrValues(node);
|
|
8728
8761
|
const section = getSection(tag);
|
|
8729
8762
|
const binding = tagVar.extra.binding;
|
|
8730
|
-
const unused = binding.pruned && !
|
|
8763
|
+
const unused = binding.pruned && !binding.assignments;
|
|
8731
8764
|
if (isOutputDOM()) {
|
|
8732
8765
|
const tagExtra = tag.node.extra;
|
|
8733
8766
|
if (unused) {
|
|
@@ -8982,11 +9015,7 @@ var show_default = {
|
|
|
8982
9015
|
const tagSection = ensureSection(tag);
|
|
8983
9016
|
const content = tagExtra[kBodyContent] = getContentInfo(tag.get("body"));
|
|
8984
9017
|
if (getOnlyChildParentTagName(tag)) controlFlowNode(tag, tagSection);
|
|
8985
|
-
else if (!isSingleNodeContent(content))
|
|
8986
|
-
tagExtra[kStartBinding] = createBinding("#text", 0, tagSection);
|
|
8987
|
-
marker(tag, tagExtra[kStartBinding]);
|
|
8988
|
-
enterShallow(tag);
|
|
8989
|
-
}
|
|
9018
|
+
else if (!isSingleNodeContent(content)) tagExtra[kStartBinding] = markerNode(tag, tagSection);
|
|
8990
9019
|
if (tagExtra[kStaticDisplay] === void 0) mergeReferences(tagSection, tag.node, [display]);
|
|
8991
9020
|
else addSetupWork(tagSection);
|
|
8992
9021
|
},
|
|
@@ -9385,14 +9414,12 @@ var try_default = {
|
|
|
9385
9414
|
if (!attrTags) throw tag.get("name").buildCodeFrameError(`The ${coreTagLink(tag)} 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.`);
|
|
9386
9415
|
const section = ensureSection(tag);
|
|
9387
9416
|
const tagExtra = mergeTagReferences(section, tag.node);
|
|
9388
|
-
|
|
9417
|
+
tagExtra.nodeBinding = markerNode(tag, section);
|
|
9389
9418
|
tagExtra.textBefore = mayMergeWithText(tag, true);
|
|
9390
9419
|
initBranchSection(ensureBodySection(tag.get("body")), tagExtra, {
|
|
9391
9420
|
kind: "try",
|
|
9392
9421
|
tag: tagExtra
|
|
9393
9422
|
});
|
|
9394
|
-
marker(tag, nodeBinding);
|
|
9395
|
-
enterShallow(tag);
|
|
9396
9423
|
},
|
|
9397
9424
|
translate: translateByTarget({
|
|
9398
9425
|
html: {
|
|
@@ -9784,12 +9811,8 @@ const builder = {
|
|
|
9784
9811
|
body.push(exportInit ? _marko_compiler.types.exportDefaultDeclaration(_marko_compiler.types.arrowFunctionExpression([getUnusedParamIdentifier()], initExpression)) : _marko_compiler.types.expressionStatement(initExpression));
|
|
9785
9812
|
return body;
|
|
9786
9813
|
},
|
|
9787
|
-
visit(file, entryFile, visitChild = (
|
|
9788
|
-
|
|
9789
|
-
if (markReached(entryFile[kState].visited, resolved, reach)) {
|
|
9790
|
-
const childFile = (0, _marko_compiler_babel_utils.loadFileForImport)(entryFile, resolved);
|
|
9791
|
-
if (childFile) builder.visit(childFile, entryFile);
|
|
9792
|
-
}
|
|
9814
|
+
visit(file, entryFile, visitChild = (childFile, reach = 0) => {
|
|
9815
|
+
if (markReached(entryFile, entryFile[kState].visited, childFile, reach)) builder.visit(childFile, entryFile);
|
|
9793
9816
|
}) {
|
|
9794
9817
|
const state = entryFile[kState] ||= {
|
|
9795
9818
|
init: false,
|
|
@@ -9803,7 +9826,7 @@ const builder = {
|
|
|
9803
9826
|
visited: createVisited(entryFile)
|
|
9804
9827
|
};
|
|
9805
9828
|
const programExtra = file.path.node.extra;
|
|
9806
|
-
const {
|
|
9829
|
+
const { assetImports } = file.metadata.marko;
|
|
9807
9830
|
const { loadImports } = programExtra;
|
|
9808
9831
|
const init = !!programExtra.isInteractive;
|
|
9809
9832
|
const hasClientStatement = !!programExtra.hasClientStatement;
|
|
@@ -9817,13 +9840,14 @@ const builder = {
|
|
|
9817
9840
|
for (const request of assetImports) assets.add(resolveRelativeToEntry(entryFile, file, request));
|
|
9818
9841
|
}
|
|
9819
9842
|
if (isRoot) state.bundledDepth++;
|
|
9820
|
-
|
|
9821
|
-
|
|
9843
|
+
const analyzedFiles = file.___analyzedFiles;
|
|
9844
|
+
for (const [filename, childFile] of analyzedFiles) {
|
|
9845
|
+
const lazy = loadImports?.has(filename);
|
|
9822
9846
|
if (lazy) {
|
|
9823
9847
|
state.bundledDepth++;
|
|
9824
9848
|
state.lazyDepth++;
|
|
9825
9849
|
}
|
|
9826
|
-
visitChild(
|
|
9850
|
+
visitChild(childFile, state.lazyDepth ? 2 : state.bundledDepth ? 1 : 0);
|
|
9827
9851
|
if (lazy) {
|
|
9828
9852
|
state.bundledDepth--;
|
|
9829
9853
|
state.lazyDepth--;
|
|
@@ -9836,15 +9860,17 @@ function assertVisited(entryFile, state) {
|
|
|
9836
9860
|
if (!state) throw entryFile.path.buildCodeFrameError("Unable to build resume code, no files were visited before finalizing the build");
|
|
9837
9861
|
}
|
|
9838
9862
|
function createVisited(entryFile) {
|
|
9839
|
-
return /* @__PURE__ */ new Map([[
|
|
9863
|
+
return /* @__PURE__ */ new Map([[entryFile.opts.filename, 0]]);
|
|
9840
9864
|
}
|
|
9841
9865
|
function resolveRelativeToEntry(entryFile, file, req) {
|
|
9842
9866
|
return file === entryFile ? (0, _marko_compiler_babel_utils.resolveRelativePath)(file, req) : (0, _marko_compiler_babel_utils.resolveRelativePath)(entryFile, req[0] === "." ? path.default.join(file.opts.filename, "..", req) : req);
|
|
9843
9867
|
}
|
|
9844
|
-
function markReached(visited,
|
|
9845
|
-
const
|
|
9868
|
+
function markReached(entryFile, visited, file, reach) {
|
|
9869
|
+
const filename = file.opts.filename;
|
|
9870
|
+
const seen = visited.get(filename);
|
|
9846
9871
|
if (seen !== void 0 && seen <= reach) return false;
|
|
9847
|
-
visited.set(
|
|
9872
|
+
visited.set(filename, reach);
|
|
9873
|
+
(entryFile.metadata.marko.analyzedTags ||= /* @__PURE__ */ new Set()).add(filename);
|
|
9848
9874
|
return true;
|
|
9849
9875
|
}
|
|
9850
9876
|
// src/translator/util/get-style-file.ts
|
|
@@ -9931,8 +9957,9 @@ var dynamic_tag_default = {
|
|
|
9931
9957
|
if (!isEventHandler(attr.name)) (attr.value.extra ??= {}).retained = true;
|
|
9932
9958
|
}
|
|
9933
9959
|
if (isInteractive) (0, _marko_compiler_babel_utils.getProgram)().node.extra.isInteractive = true;
|
|
9934
|
-
const nodeBinding = tagExtra.nodeBinding =
|
|
9960
|
+
const nodeBinding = tagExtra.nodeBinding = markerNode(tag, tagSection);
|
|
9935
9961
|
if (hasVar) {
|
|
9962
|
+
tagSection.hasReturnedVar = true;
|
|
9936
9963
|
trackVarReferences(tag, 4).returnedBy = { scope: nodeBinding };
|
|
9937
9964
|
reserveId(nodeBinding, 1);
|
|
9938
9965
|
}
|
|
@@ -9945,8 +9972,6 @@ var dynamic_tag_default = {
|
|
|
9945
9972
|
if (usesVar) addAlwaysReason(nodeBinding);
|
|
9946
9973
|
addReasonExprs(ensureSlot(nodeBinding), tagExtra);
|
|
9947
9974
|
if (!hasVar && !node.arguments && !node.attributes.length && !node.body.body.length && !tagExtra.attrTagLookup) tagExtra.nameOnly = true;
|
|
9948
|
-
marker(tag, nodeBinding);
|
|
9949
|
-
enterShallow(tag);
|
|
9950
9975
|
if (bodySection && tagExtra.featureType === "class" && !(0, _marko_compiler_babel_utils.getTagTemplate)(tag)) bodySection.structure = null;
|
|
9951
9976
|
} },
|
|
9952
9977
|
translate: {
|
|
@@ -10015,28 +10040,25 @@ var dynamic_tag_default = {
|
|
|
10015
10040
|
const { properties, statements } = translateAttrs(tag, void 0, void 0, isClassAPI ? "renderBody" : "content");
|
|
10016
10041
|
const args = [];
|
|
10017
10042
|
const contentProp = getTranslatedBodyContentProperty(properties);
|
|
10018
|
-
let hasTagArgs = false;
|
|
10019
10043
|
if (node.arguments) {
|
|
10020
|
-
hasTagArgs = true;
|
|
10021
10044
|
args.push(...node.arguments);
|
|
10022
10045
|
if (properties.length) args.push(propsToExpression(properties));
|
|
10023
10046
|
} else if (contentProp) {
|
|
10024
10047
|
properties.splice(properties.indexOf(contentProp), 1);
|
|
10025
10048
|
args.push(propsToExpression(properties), contentProp.value);
|
|
10026
10049
|
} else args.push(propsToExpression(properties));
|
|
10050
|
+
const argsOrInput = node.arguments ? _marko_compiler.types.arrayExpression(args) : args[0];
|
|
10027
10051
|
if (isOutputHTML()) {
|
|
10028
10052
|
writeHTMLResumeStatements(tag);
|
|
10029
10053
|
const markerGuard = getMarkerGuard(nodeBinding);
|
|
10030
10054
|
const debugTagVar = !isOptimize() && node.var && _marko_compiler.types.numericLiteral(1);
|
|
10031
10055
|
const varId = node.var && isTagVarResumed(tag) && getResumeRegistryId(tagSection, node.var.extra?.binding, "var");
|
|
10032
|
-
const input = args[0];
|
|
10033
10056
|
const scopeIdArg = getScopeIdIdentifier(tagSection);
|
|
10034
10057
|
const accessorArg = getScopeAccessorLiteral(nodeBinding);
|
|
10035
|
-
const inputArg = hasTagArgs ? _marko_compiler.types.arrayExpression(args) : input;
|
|
10036
10058
|
const contentArg = contentProp ? contentProp.value : absentArg(0);
|
|
10037
|
-
const inputIsArgs =
|
|
10059
|
+
const inputIsArgs = node.arguments ? _marko_compiler.types.numericLiteral(1) : absentArg(0);
|
|
10038
10060
|
const markerArg = markerGuard || absentArg(1);
|
|
10039
|
-
const dynamicTagExpr = callRuntime("_dynamic_tag", scopeIdArg, accessorArg, tagExpression,
|
|
10061
|
+
const dynamicTagExpr = callRuntime("_dynamic_tag", scopeIdArg, accessorArg, tagExpression, argsOrInput, contentArg, inputIsArgs, markerArg, debugTagVar);
|
|
10040
10062
|
if (varId) {
|
|
10041
10063
|
const dynamicScopeIdentifier = generateUidIdentifier(tag.get("name").toString() + "_scope");
|
|
10042
10064
|
const mutatesTagVar = isTagVarAssigned(tag);
|
|
@@ -10047,9 +10069,8 @@ var dynamic_tag_default = {
|
|
|
10047
10069
|
else statements.push(_marko_compiler.types.expressionStatement(dynamicTagExpr));
|
|
10048
10070
|
replaceWithStatements(tag, statements);
|
|
10049
10071
|
} else {
|
|
10050
|
-
const section = getSection(tag);
|
|
10051
10072
|
const bodySection = getSectionForBody(tag.get("body"));
|
|
10052
|
-
const signal = getSignal(
|
|
10073
|
+
const signal = getSignal(tagSection, nodeBinding, "dynamicTag");
|
|
10053
10074
|
let tagVarSignal;
|
|
10054
10075
|
if (tag.node.var && isTagVarResumed(tag)) {
|
|
10055
10076
|
const varBinding = tag.node.var.extra.binding;
|
|
@@ -10059,21 +10080,18 @@ var dynamic_tag_default = {
|
|
|
10059
10080
|
tagVarSignal.buildAssignment = (valueSection, value) => buildVarChange(_marko_compiler.types.memberExpression(getScopeExpression(tagVarSignal.section, valueSection), _marko_compiler.types.stringLiteral(getPrefixedScopeAccessor(nodeBinding, getAccessorPrefix().BranchScopes)), true), value, varBinding);
|
|
10060
10081
|
}
|
|
10061
10082
|
signal.build = () => {
|
|
10062
|
-
return callRuntime("_dynamic_tag", getScopeAccessorLiteral(nodeBinding, true), bodySection && getSectionRendererIdentifier(bodySection), tagVarSignal ? _marko_compiler.types.arrowFunctionExpression([getUnusedParamIdentifier()], tagVarSignal.identifier) : void 0,
|
|
10083
|
+
return callRuntime("_dynamic_tag", getScopeAccessorLiteral(nodeBinding, true), bodySection && getSectionRendererIdentifier(bodySection), tagVarSignal ? _marko_compiler.types.arrowFunctionExpression([getUnusedParamIdentifier()], tagVarSignal.identifier) : void 0, node.arguments && _marko_compiler.types.numericLiteral(1));
|
|
10063
10084
|
};
|
|
10064
10085
|
const directBinding = getReferencedBindings(tagExtra);
|
|
10065
10086
|
const directName = directBinding && !Array.isArray(directBinding) && (0, _marko_compiler_babel_utils.getProgram)().node.extra.exportNames.directContent.get(directBinding);
|
|
10066
10087
|
if (directName) (0, _marko_compiler_babel_utils.getProgram)().node.body.push(_marko_compiler.types.exportNamedDeclaration(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(directName), callRuntime("_dynamic_tag_content", getScopeAccessorLiteral(nodeBinding, true)))])));
|
|
10067
|
-
if (args.length)
|
|
10068
|
-
const argsOrInput = hasTagArgs ? _marko_compiler.types.arrayExpression(args) : args[0];
|
|
10069
|
-
if (!_marko_compiler.types.isObjectExpression(argsOrInput) || argsOrInput.properties.length) signal.extraArgs = [_marko_compiler.types.arrowFunctionExpression([getUnusedParamIdentifier()], statements.length ? _marko_compiler.types.blockStatement(statements.concat(_marko_compiler.types.returnStatement(argsOrInput))) : argsOrInput)];
|
|
10070
|
-
}
|
|
10088
|
+
if (args.length && (!_marko_compiler.types.isObjectExpression(argsOrInput) || argsOrInput.properties.length)) signal.extraArgs = [_marko_compiler.types.arrowFunctionExpression([getUnusedParamIdentifier()], statements.length ? _marko_compiler.types.blockStatement(statements.concat(_marko_compiler.types.returnStatement(argsOrInput))) : argsOrInput)];
|
|
10071
10089
|
enableDynamicTagVar(tag);
|
|
10072
10090
|
if (!isClassAPI) {
|
|
10073
10091
|
if (mayHaveNativeAttr(tag, isEventOrChangeHandler)) importRuntimeFeature("dynamic-tag-script");
|
|
10074
10092
|
if (mayHaveNativeAttr(tag, isControllableAttr)) importRuntimeFeature("controllable");
|
|
10075
10093
|
}
|
|
10076
|
-
addValue(
|
|
10094
|
+
addValue(tagSection, tagExtra, signal, tagExpression);
|
|
10077
10095
|
replaceWithStatements(tag);
|
|
10078
10096
|
}
|
|
10079
10097
|
}
|
|
@@ -10129,9 +10147,7 @@ var dom_default = { translate: {
|
|
|
10129
10147
|
forEachSectionReverse((childSection) => {
|
|
10130
10148
|
if (childSection !== section) {
|
|
10131
10149
|
const tagParamsSignal = childSection.params && initValue(childSection.params);
|
|
10132
|
-
forEach(childSection.localClosures,
|
|
10133
|
-
initValue(closure).build = void 0;
|
|
10134
|
-
});
|
|
10150
|
+
forEach(childSection.localClosures, skipClosureBuild);
|
|
10135
10151
|
const tagParamsIdentifier = tagParamsSignal && signalHasWork(tagParamsSignal) ? tagParamsSignal.identifier : void 0;
|
|
10136
10152
|
const meta = getSectionMeta(childSection);
|
|
10137
10153
|
const { writes } = meta;
|
|
@@ -10199,12 +10215,16 @@ function markReturn(section, setup, params) {
|
|
|
10199
10215
|
function emptySetup() {
|
|
10200
10216
|
return _marko_compiler.types.arrowFunctionExpression([getUnusedParamIdentifier()], _marko_compiler.types.blockStatement([]));
|
|
10201
10217
|
}
|
|
10218
|
+
function skipClosureBuild(closure) {
|
|
10219
|
+
initValue(closure).build = void 0;
|
|
10220
|
+
}
|
|
10202
10221
|
// src/translator/visitors/program/html.ts
|
|
10203
10222
|
var html_default = { translate: {
|
|
10204
10223
|
enter() {
|
|
10205
10224
|
const sectionDynamicSubscribers = /* @__PURE__ */ new Set();
|
|
10206
10225
|
forEachSection((section) => {
|
|
10207
10226
|
forEach(section.bindings, (binding) => {
|
|
10227
|
+
if (!binding.getters) return;
|
|
10208
10228
|
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))))]));
|
|
10209
10229
|
});
|
|
10210
10230
|
forEach(section.hoisted, (binding) => {
|
|
@@ -10285,9 +10305,7 @@ function buildResumeCall(node) {
|
|
|
10285
10305
|
const referencedLocals = extra.referencedLocalBindingsInFunction;
|
|
10286
10306
|
if (referencedLocals) {
|
|
10287
10307
|
const localProperties = [];
|
|
10288
|
-
forEach(referencedLocals,
|
|
10289
|
-
localProperties.push(toObjectProperty(getLocalsScopeAccessor(binding), getDeclaredBindingExpression(binding)));
|
|
10290
|
-
});
|
|
10308
|
+
forEach(referencedLocals, pushLocalProperty, localProperties);
|
|
10291
10309
|
return callRuntime("_resume_locals", simplifyFunction(node), _marko_compiler.types.stringLiteral(extra.registryId), _marko_compiler.types.objectExpression(localProperties), extra.referencesScope && getScopeIdIdentifier(extra.section));
|
|
10292
10310
|
}
|
|
10293
10311
|
return callRuntime("_resume", simplifyFunction(node), _marko_compiler.types.stringLiteral(extra.registryId), extra.referencesScope && getScopeIdIdentifier(extra.section));
|
|
@@ -10342,14 +10360,14 @@ var program_default = {
|
|
|
10342
10360
|
{
|
|
10343
10361
|
const markoOpts = getMarkoOpts();
|
|
10344
10362
|
const { output, entry, runtimeId } = markoOpts;
|
|
10363
|
+
const entryFile = (0, _marko_compiler_babel_utils.getFile)();
|
|
10364
|
+
const { filename } = entryFile.opts;
|
|
10345
10365
|
const isLoadEntry = entry === "load";
|
|
10346
10366
|
const isDOMPageEntry = output === "dom" && entry === "page" || output === "hydrate";
|
|
10347
10367
|
const isServerEntry = output === "html" && entry === "page";
|
|
10348
10368
|
if (entry && !markoOpts.linkAssets) throw program.buildCodeFrameError("The \"entry\" option requires the `linkAssets` compiler option to be configured.");
|
|
10349
10369
|
if (runtimeId && !/^[_a-z][_a-z0-9]*$/i.test(runtimeId)) throw program.buildCodeFrameError(`Invalid runtimeId: "${runtimeId}". The runtimeId must start with a letter or underscore and only contain letters, numbers, and underscores.`);
|
|
10350
10370
|
if (isLoadEntry) {
|
|
10351
|
-
const entryFile = (0, _marko_compiler_babel_utils.getFile)();
|
|
10352
|
-
const { filename } = entryFile.opts;
|
|
10353
10371
|
const readyId = getReadyId(entryFile);
|
|
10354
10372
|
const report = !markoOpts.optimize;
|
|
10355
10373
|
program.node.body = [_marko_compiler.types.importDeclaration([_marko_compiler.types.importSpecifier(_marko_compiler.types.identifier("ready"), _marko_compiler.types.identifier("ready")), ...report ? [_marko_compiler.types.importSpecifier(_marko_compiler.types.identifier("readyFailed"), _marko_compiler.types.identifier("readyFailed"))] : []], _marko_compiler.types.stringLiteral(getRuntimePath("dom"))), _marko_compiler.types.expressionStatement(dynamicImport((0, _marko_compiler_babel_utils.resolveRelativePath)(entryFile, filename), _marko_compiler.types.arrowFunctionExpression([getUnusedParamIdentifier()], _marko_compiler.types.callExpression(_marko_compiler.types.identifier("ready"), [_marko_compiler.types.stringLiteral(readyId)])), report && _marko_compiler.types.arrowFunctionExpression([getUnusedParamIdentifier()], _marko_compiler.types.callExpression(_marko_compiler.types.identifier("readyFailed"), [_marko_compiler.types.stringLiteral(readyId)]))))];
|
|
@@ -10357,15 +10375,12 @@ var program_default = {
|
|
|
10357
10375
|
return;
|
|
10358
10376
|
}
|
|
10359
10377
|
if (isDOMPageEntry) {
|
|
10360
|
-
const entryFile = (0, _marko_compiler_babel_utils.getFile)();
|
|
10361
10378
|
builder.visit(entryFile, entryFile);
|
|
10362
10379
|
program.node.body = builder.build(entryFile);
|
|
10363
10380
|
program.skip();
|
|
10364
10381
|
return;
|
|
10365
10382
|
}
|
|
10366
10383
|
if (isServerEntry) {
|
|
10367
|
-
const entryFile = (0, _marko_compiler_babel_utils.getFile)();
|
|
10368
|
-
const { filename } = entryFile.opts;
|
|
10369
10384
|
const relativeImport = (0, _marko_compiler_babel_utils.resolveRelativePath)(entryFile, filename);
|
|
10370
10385
|
const templateId = (0, _marko_compiler_babel_utils.getTemplateId)(markoOpts, filename);
|
|
10371
10386
|
const pageAssetArgs = [
|
|
@@ -10576,9 +10591,8 @@ function translateDOM(tag) {
|
|
|
10576
10591
|
const childExports = childFile.ast.program.extra.exportNames;
|
|
10577
10592
|
const { childSection } = tagExtra;
|
|
10578
10593
|
const loadConfig = tagExtra.tagNameLoad;
|
|
10579
|
-
const isLoad = !!loadConfig;
|
|
10580
10594
|
const tagName = getTagNameHint(node);
|
|
10581
|
-
if (
|
|
10595
|
+
if (loadConfig) {
|
|
10582
10596
|
const childFileName = childFile.opts.filename;
|
|
10583
10597
|
const { triggers, signals, setups } = getLoadIdentifiers();
|
|
10584
10598
|
let triggerIdent = triggers.get(loadConfig);
|
|
@@ -10663,7 +10677,6 @@ function isTemplateImport(tag) {
|
|
|
10663
10677
|
// src/translator/visitors/tag/native-tag.ts
|
|
10664
10678
|
const kNodeOp = Symbol("native tag structure node");
|
|
10665
10679
|
const kNativeAttrs = Symbol("native tag attrs");
|
|
10666
|
-
const htmlContentAttrTags = /* @__PURE__ */ new WeakSet();
|
|
10667
10680
|
const htmlSelectArgs = /* @__PURE__ */ new WeakMap();
|
|
10668
10681
|
var native_tag_default = {
|
|
10669
10682
|
analyze: {
|
|
@@ -10697,7 +10710,6 @@ var native_tag_default = {
|
|
|
10697
10710
|
valueExtra.isEffect = true;
|
|
10698
10711
|
valueExtra.retained = true;
|
|
10699
10712
|
hasEventHandlers = true;
|
|
10700
|
-
hasDynamicAttributes = true;
|
|
10701
10713
|
if (!spread) {
|
|
10702
10714
|
spread = [];
|
|
10703
10715
|
controllable = getRelatedControllable(tagName, attributes, indexByName);
|
|
@@ -10753,7 +10765,10 @@ var native_tag_default = {
|
|
|
10753
10765
|
if (controllable && controllable.stateIsAttr && controllable.attrs[1] === void 0 && evaluate(attributes[controllable.attrs.find(isDefined)].value).confident) controllable = void 0;
|
|
10754
10766
|
own = addOwnControllableAttrs(own, controllableAttrNames, indexByName, controllable);
|
|
10755
10767
|
}
|
|
10756
|
-
if (controllable?.attrs[1] !== void 0)
|
|
10768
|
+
if (controllable?.attrs[1] !== void 0) {
|
|
10769
|
+
hasEventHandlers = true;
|
|
10770
|
+
addSetupWork(tagSection);
|
|
10771
|
+
}
|
|
10757
10772
|
assertExclusiveAttrs(indexByName, (msg) => {
|
|
10758
10773
|
throw tag.get("name").buildCodeFrameError(msg);
|
|
10759
10774
|
}, isDefined);
|
|
@@ -10797,7 +10812,6 @@ var native_tag_default = {
|
|
|
10797
10812
|
addSetupExpr(tagSection, textPlaceholders[0]);
|
|
10798
10813
|
}
|
|
10799
10814
|
if (injectsNonce && !spread) addSetupWork(tagSection);
|
|
10800
|
-
if (controllable?.attrs[1] !== void 0) addSetupWork(tagSection);
|
|
10801
10815
|
if (hasEventHandlers || usesVar) addAlwaysReason(nodeBinding);
|
|
10802
10816
|
trackDomVarReferences(tag, nodeBinding);
|
|
10803
10817
|
addReasonExprs(ensureSlot(nodeBinding), push(exprExtras, tagExtra));
|
|
@@ -10835,7 +10849,8 @@ var native_tag_default = {
|
|
|
10835
10849
|
content,
|
|
10836
10850
|
controllable,
|
|
10837
10851
|
spread,
|
|
10838
|
-
injectsNonce
|
|
10852
|
+
injectsNonce,
|
|
10853
|
+
spreadContent: !!spread && content === void 0 && !node$1.body.body.length && !isTextOnly && !(0, _marko_compiler_babel_utils.getTagDef)(tag)?.parseOptions?.openTagOnly
|
|
10839
10854
|
};
|
|
10840
10855
|
},
|
|
10841
10856
|
exit(tag) {
|
|
@@ -10887,31 +10902,28 @@ var native_tag_default = {
|
|
|
10887
10902
|
if (tagName === "select" && (controllable || spreadExpression)) flushBefore(tag);
|
|
10888
10903
|
write`<${tagName}`;
|
|
10889
10904
|
if (injectsNonce && !spread) write`${callRuntime("_attr_nonce")}`;
|
|
10905
|
+
let writeAtStartOfBody;
|
|
10890
10906
|
if (controllable) {
|
|
10891
|
-
|
|
10907
|
+
const args = controllable.attrs.map((index, i) => attrAt(attributes, index)?.value || i === 1 && absentArg(0));
|
|
10908
|
+
if (tagName === "select") htmlSelectArgs.set(tag.node, {
|
|
10909
|
+
helper: "_attr_select_value",
|
|
10910
|
+
args
|
|
10911
|
+
});
|
|
10912
|
+
else if (tagName !== "textarea") write`${callRuntime(getControllableHelper(tagName, controllable.state), getScopeIdIdentifier(tagSection), nodeAccessor, ...args)}`;
|
|
10913
|
+
else if (controllable.attrs[1] === void 0) writeAtStartOfBody = callRuntime("_textarea_value", ...args);
|
|
10914
|
+
else writeAtStartOfBody = callRuntime("_attr_textarea_value", getScopeIdIdentifier(tagSection), nodeAccessor, ...args);
|
|
10892
10915
|
if (controllable.attrs[1] !== void 0) addHTMLEffectCall(tagSection, void 0);
|
|
10893
10916
|
}
|
|
10894
|
-
let writeAtStartOfBody;
|
|
10895
10917
|
if (tagName === "html" && getMarkoOpts().linkAssets && !tag.node.body.body.some((child) => child.type === "MarkoTag" && child.name.type === "StringLiteral" && child.name.value === "head")) writeAtStartOfBody = callRuntime("_flush_head");
|
|
10896
|
-
if (
|
|
10897
|
-
if (
|
|
10898
|
-
helper: "_attr_select_value",
|
|
10899
|
-
args: [attrAt(attributes, controllable.attrs[0])?.value || _marko_compiler.types.buildUndefinedNode(), attrAt(attributes, controllable.attrs[1])?.value || absentArg(0)]
|
|
10900
|
-
});
|
|
10901
|
-
else if (spreadExpression) {
|
|
10918
|
+
if (spreadExpression && !controllable) {
|
|
10919
|
+
if (tagName === "select") {
|
|
10902
10920
|
const spreadIdentifier = declareConstBefore(tag, "select_input", spreadExpression);
|
|
10903
10921
|
htmlSelectArgs.set(tag.node, {
|
|
10904
10922
|
helper: "_attrs_select_value",
|
|
10905
10923
|
args: [spreadIdentifier]
|
|
10906
10924
|
});
|
|
10907
10925
|
spreadExpression = spreadIdentifier;
|
|
10908
|
-
}
|
|
10909
|
-
} else if (tagName === "textarea") {
|
|
10910
|
-
if (controllable) {
|
|
10911
|
-
const value = attrAt(attributes, controllable.attrs[0]);
|
|
10912
|
-
const valueChange = attrAt(attributes, controllable.attrs[1]);
|
|
10913
|
-
writeAtStartOfBody = valueChange ? callRuntime("_attr_textarea_value", getScopeIdIdentifier(tagSection), nodeAccessor, value?.value, valueChange.value) : callRuntime("_textarea_value", value.value);
|
|
10914
|
-
} else if (spreadExpression) {
|
|
10926
|
+
} else if (tagName === "textarea") {
|
|
10915
10927
|
const spreadIdentifier = declareConstBefore(tag, "textarea_input", spreadExpression);
|
|
10916
10928
|
writeAtStartOfBody = callRuntime("_attrs_textarea_value", getScopeIdIdentifier(tagSection), nodeAccessor, spreadIdentifier);
|
|
10917
10929
|
spreadExpression = spreadIdentifier;
|
|
@@ -10929,28 +10941,27 @@ var native_tag_default = {
|
|
|
10929
10941
|
if (handlers) for (const index of handlers) addHTMLEffectCall(tagSection, attributes[index].value.extra);
|
|
10930
10942
|
const isOpenOnly = !!(tagDef && tagDef.parseOptions?.openTagOnly);
|
|
10931
10943
|
const isTextOnly = getTagFacts(tag).textBody;
|
|
10932
|
-
const spreadContent =
|
|
10944
|
+
const { spreadContent } = nativeAttrs;
|
|
10945
|
+
let spreadCall;
|
|
10933
10946
|
if (spreadExpression) {
|
|
10934
10947
|
addHTMLEffectCall(tagSection, tagExtra);
|
|
10935
|
-
|
|
10936
|
-
|
|
10937
|
-
|
|
10938
|
-
|
|
10948
|
+
const scopeIdArg = getScopeIdIdentifier(tagSection);
|
|
10949
|
+
const tagNameArg = _marko_compiler.types.stringLiteral(tagName);
|
|
10950
|
+
const markerGuard = spreadContent && getMarkerGuard(nodeBinding);
|
|
10951
|
+
spreadCall = skipExpression ? callRuntime(spreadContent ? "_attrs_partial_content" : "_attrs_partial", spreadExpression, skipExpression, nodeAccessor, scopeIdArg, tagNameArg, markerGuard) : callRuntime(spreadContent ? "_attrs_content" : "_attrs", spreadExpression, nodeAccessor, scopeIdArg, tagNameArg, markerGuard);
|
|
10952
|
+
if (!spreadContent) write`${spreadCall}`;
|
|
10939
10953
|
}
|
|
10940
10954
|
if (isOpenOnly || isTextOnly) write`>`;
|
|
10941
10955
|
else if (contentAttr) {
|
|
10942
10956
|
write`>`;
|
|
10943
|
-
htmlContentAttrTags.add(tag.node);
|
|
10944
10957
|
tag.node.body.body = [_marko_compiler.types.expressionStatement(callRuntime("_attr_content", nodeAccessor, getScopeIdIdentifier(tagSection), contentAttr.value, getMarkerGuard(nodeBinding)))];
|
|
10945
|
-
} else if (spreadContent)
|
|
10946
|
-
|
|
10947
|
-
htmlContentAttrTags.add(tag.node);
|
|
10948
|
-
tag.node.body.body = [skipExpression ? _marko_compiler.types.expressionStatement(callRuntime("_attrs_partial_content", spreadExpression, skipExpression, nodeAccessor, getScopeIdIdentifier(tagSection), _marko_compiler.types.stringLiteral(tagName), markerGuard)) : _marko_compiler.types.expressionStatement(callRuntime("_attrs_content", spreadExpression, nodeAccessor, getScopeIdIdentifier(tagSection), _marko_compiler.types.stringLiteral(tagName), markerGuard))];
|
|
10949
|
-
} else write`>`;
|
|
10958
|
+
} else if (spreadContent) tag.node.body.body = [_marko_compiler.types.expressionStatement(spreadCall)];
|
|
10959
|
+
else write`>`;
|
|
10950
10960
|
if (writeAtStartOfBody) write`${writeAtStartOfBody}`;
|
|
10951
10961
|
},
|
|
10952
10962
|
exit(tag) {
|
|
10953
|
-
const
|
|
10963
|
+
const tagExtra = tag.node.extra;
|
|
10964
|
+
const nodeBinding = tagExtra.nodeBinding;
|
|
10954
10965
|
const isOpenOnly = (0, _marko_compiler_babel_utils.getTagDef)(tag)?.parseOptions?.openTagOnly;
|
|
10955
10966
|
const isTextOnly = getTagFacts(tag).textBody;
|
|
10956
10967
|
const selectArgs = htmlSelectArgs.get(tag.node);
|
|
@@ -10959,7 +10970,8 @@ var native_tag_default = {
|
|
|
10959
10970
|
const skipEndTag = isEndTagWrittenByBranch(nodeBinding);
|
|
10960
10971
|
const markerReason = !skipEndTag && nodeBinding && getWriteReason(nodeBinding);
|
|
10961
10972
|
const write = writeTo$1(tag, tagName === "html" || !markerReason && tagName === "body");
|
|
10962
|
-
|
|
10973
|
+
const { content, spreadContent } = tagExtra[kNativeAttrs];
|
|
10974
|
+
if (content !== void 0 || spreadContent) flushBefore(tag);
|
|
10963
10975
|
let statements = [];
|
|
10964
10976
|
if (selectArgs) {
|
|
10965
10977
|
if (!skipEndTag) write`</${tagName}>`;
|
|
@@ -11008,44 +11020,39 @@ var native_tag_default = {
|
|
|
11008
11020
|
}
|
|
11009
11021
|
if (own) for (const index of own) {
|
|
11010
11022
|
const { name, value } = attributes[index];
|
|
11011
|
-
|
|
11012
|
-
|
|
11013
|
-
|
|
11014
|
-
|
|
11015
|
-
|
|
11016
|
-
|
|
11017
|
-
|
|
11018
|
-
|
|
11019
|
-
|
|
11020
|
-
|
|
11021
|
-
|
|
11022
|
-
|
|
11023
|
-
|
|
11024
|
-
|
|
11025
|
-
|
|
11026
|
-
|
|
11027
|
-
|
|
11028
|
-
|
|
11029
|
-
|
|
11030
|
-
|
|
11031
|
-
}
|
|
11032
|
-
for (const call of calls) addStatement("render", tagSection, value.extra, call, true);
|
|
11033
|
-
}
|
|
11034
|
-
break;
|
|
11035
|
-
default: if (confident) break;
|
|
11036
|
-
else addStatement("render", tagSection, value.extra, callRuntime("_attr", createScopeReadExpression(nodeBinding), _marko_compiler.types.stringLiteral(name), value), true);
|
|
11023
|
+
if (evaluate(value).confident) continue;
|
|
11024
|
+
if (name !== "class" && name !== "style") {
|
|
11025
|
+
addStatement("render", tagSection, value.extra, callRuntime("_attr", createScopeReadExpression(nodeBinding), _marko_compiler.types.stringLiteral(name), value), true);
|
|
11026
|
+
continue;
|
|
11027
|
+
}
|
|
11028
|
+
const calls = [];
|
|
11029
|
+
const meta = getDelimitedAttrMeta(tag, name, value);
|
|
11030
|
+
const items = getDelimitedAttrItems(name, meta);
|
|
11031
|
+
const assert = buildClassTogglesAssert(meta);
|
|
11032
|
+
if (assert) calls.push(assert);
|
|
11033
|
+
if (!items) calls.push(callRuntime(`_attr_${name}`, createScopeReadExpression(nodeBinding), value));
|
|
11034
|
+
else {
|
|
11035
|
+
const single = [];
|
|
11036
|
+
for (const { key, value } of items) if (isLiteralPart(key) && !/\s/.test(key)) single.push({
|
|
11037
|
+
key,
|
|
11038
|
+
value
|
|
11039
|
+
});
|
|
11040
|
+
else calls.push(callRuntime("_attr_class_names", createScopeReadExpression(nodeBinding), toClassPartExpression(key), value));
|
|
11041
|
+
if (single.length === 1) calls.push(callRuntime(`_attr_${name}_item`, createScopeReadExpression(nodeBinding), _marko_compiler.types.stringLiteral(single[0].key), single[0].value));
|
|
11042
|
+
else if (single.length) calls.push(callRuntime(`_attr_${name}_items`, createScopeReadExpression(nodeBinding), _marko_compiler.types.objectExpression(single.map(({ key, value }) => _marko_compiler.types.objectProperty(toPropertyName(key), value)))));
|
|
11037
11043
|
}
|
|
11044
|
+
for (const call of calls) addStatement("render", tagSection, value.extra, call, true);
|
|
11038
11045
|
}
|
|
11039
11046
|
if (handlers) for (const index of handlers) {
|
|
11040
11047
|
const { name, value } = attributes[index];
|
|
11041
11048
|
addStatement("effect", tagSection, value.extra, callRuntime("_on", createScopeReadExpression(nodeBinding), _marko_compiler.types.stringLiteral(getEventType(name)), value));
|
|
11042
11049
|
}
|
|
11043
11050
|
if (spreadExpression) {
|
|
11044
|
-
const spreadContent = spreadRendersContent(tag, contentAttr, getTagFacts(tag).textBody);
|
|
11045
11051
|
const element = controllableElements.get(tagName);
|
|
11046
11052
|
const spreadHelper = !controllable && element?.spreadHelper;
|
|
11047
|
-
|
|
11048
|
-
|
|
11053
|
+
const helperArg = spreadHelper && importRuntime(spreadHelper);
|
|
11054
|
+
const { spreadContent } = nativeAttrs;
|
|
11055
|
+
addStatement("render", tagSection, tagExtra, skipExpression ? callRuntime(spreadContent ? "_attrs_partial_content" : "_attrs_partial", scopeIdentifier, nodeAccessor, spreadExpression, skipExpression, helperArg) : callRuntime(spreadContent ? "_attrs_content" : "_attrs", scopeIdentifier, nodeAccessor, spreadExpression, helperArg));
|
|
11049
11056
|
if (element) importRuntimeFeature(element.feature);
|
|
11050
11057
|
addStatement("effect", tagSection, tagExtra, callRuntime("_attrs_script", scopeIdentifier, nodeAccessor));
|
|
11051
11058
|
}
|
|
@@ -11137,9 +11144,6 @@ function getInputValueMode(typeAttr) {
|
|
|
11137
11144
|
function getDOMControllableDefaultHelper(helper, { valueMode }) {
|
|
11138
11145
|
return helper === "_attr_input_value" && valueMode ? `_attr_input_value_${valueMode}_default` : `${helper}_default`;
|
|
11139
11146
|
}
|
|
11140
|
-
function spreadRendersContent(tag, staticContentAttr, isTextOnly) {
|
|
11141
|
-
return !(staticContentAttr || tag.node.body.body.length || isTextOnly || (0, _marko_compiler_babel_utils.getTagDef)(tag)?.parseOptions?.openTagOnly);
|
|
11142
|
-
}
|
|
11143
11147
|
function buildSpreadExpression(attributes, spread, injectsNonce) {
|
|
11144
11148
|
const props = [];
|
|
11145
11149
|
if (injectsNonce) props.push(_marko_compiler.types.objectProperty(_marko_compiler.types.identifier("nonce"), _marko_compiler.types.memberExpression(isOutputHTML() ? callRuntime("$global") : toMemberExpression(scopeIdentifier, getAccessorProp().Global), _marko_compiler.types.identifier("cspNonce"))));
|
|
@@ -11212,8 +11216,9 @@ function warnCamelCaseStyleKeys(tag, attr) {
|
|
|
11212
11216
|
}
|
|
11213
11217
|
}
|
|
11214
11218
|
function assertNativeHandlerAttr(tag, attr) {
|
|
11215
|
-
|
|
11216
|
-
if (
|
|
11219
|
+
const kind = isEventHandler(attr.name) ? "event handler" : "change handler";
|
|
11220
|
+
if (_marko_compiler.types.isObjectExpression(attr.value)) throw tag.hub.buildError(attr.value, `The \`${attr.name}\` ${kind} on a [native tag](https://markojs.com/docs/reference/native-tag) must be a function. Attribute values in Marko are plain JavaScript expressions, not JSX; remove the wrapping \`{ }\` (e.g. \`${attr.name}=myHandler\` or \`${attr.name}() { ... }\`).`, Error);
|
|
11221
|
+
if ((0, _marko_compiler_babel_utils.computeNode)(attr.value)?.value) throw tag.hub.buildError(attr.value, `The \`${attr.name}\` ${kind} on a [native tag](https://markojs.com/docs/reference/native-tag) must be a function or a falsey value (\`null\`, \`undefined\`, \`false\`, \`0\`, …).`, Error);
|
|
11217
11222
|
}
|
|
11218
11223
|
function getCanonicalTagName(tag) {
|
|
11219
11224
|
const tagName = getTagName(tag);
|
|
@@ -11491,6 +11496,12 @@ function addToggle(meta, key, value, alternate) {
|
|
|
11491
11496
|
});
|
|
11492
11497
|
}
|
|
11493
11498
|
// src/translator/visitors/tag/index.ts
|
|
11499
|
+
const tagVisitors = {
|
|
11500
|
+
[0]: native_tag_default,
|
|
11501
|
+
[1]: custom_tag_default,
|
|
11502
|
+
[2]: dynamic_tag_default,
|
|
11503
|
+
[3]: attribute_tag_default
|
|
11504
|
+
};
|
|
11494
11505
|
const kAnalyzeFailed = Symbol("analyze failed");
|
|
11495
11506
|
var tag_default = {
|
|
11496
11507
|
analyze: {
|
|
@@ -11499,23 +11510,8 @@ var tag_default = {
|
|
|
11499
11510
|
const tagDef = (0, _marko_compiler_babel_utils.getTagDef)(tag);
|
|
11500
11511
|
const type = analyzeTagNameType(tag);
|
|
11501
11512
|
const hook = tagDef?.analyzer?.hook;
|
|
11502
|
-
if (hook)
|
|
11503
|
-
|
|
11504
|
-
return;
|
|
11505
|
-
}
|
|
11506
|
-
if (type === 0) {
|
|
11507
|
-
native_tag_default.analyze.enter(tag);
|
|
11508
|
-
return;
|
|
11509
|
-
}
|
|
11510
|
-
switch (type) {
|
|
11511
|
-
case 1:
|
|
11512
|
-
custom_tag_default.analyze.enter(tag);
|
|
11513
|
-
break;
|
|
11514
|
-
case 3:
|
|
11515
|
-
attribute_tag_default.analyze.enter(tag);
|
|
11516
|
-
break;
|
|
11517
|
-
case 2: dynamic_tag_default.analyze.enter(tag);
|
|
11518
|
-
}
|
|
11513
|
+
if (hook) enterHook(hook, tag);
|
|
11514
|
+
else tagVisitors[type].analyze.enter(tag);
|
|
11519
11515
|
} catch (err) {
|
|
11520
11516
|
(tag.node.extra ??= {})[kAnalyzeFailed] = true;
|
|
11521
11517
|
reportAnalyzeError(tag, err);
|
|
@@ -11550,18 +11546,7 @@ var tag_default = {
|
|
|
11550
11546
|
for (const attr of tag.get("attributes")) if (attr.isMarkoAttribute()) {
|
|
11551
11547
|
if (attr.node.arguments) throw attr.buildCodeFrameError(`Unsupported arguments on the \`${attr.node.name}\` attribute.`);
|
|
11552
11548
|
}
|
|
11553
|
-
|
|
11554
|
-
case 0:
|
|
11555
|
-
native_tag_default.translate.enter(tag);
|
|
11556
|
-
break;
|
|
11557
|
-
case 1:
|
|
11558
|
-
custom_tag_default.translate.enter(tag);
|
|
11559
|
-
break;
|
|
11560
|
-
case 2:
|
|
11561
|
-
dynamic_tag_default.translate.enter(tag);
|
|
11562
|
-
break;
|
|
11563
|
-
case 3: attribute_tag_default.translate.enter(tag);
|
|
11564
|
-
}
|
|
11549
|
+
tagVisitors[analyzeTagNameType(tag)].translate.enter(tag);
|
|
11565
11550
|
},
|
|
11566
11551
|
exit(tag) {
|
|
11567
11552
|
writeBodyStatements(tag.node.body);
|
|
@@ -11570,18 +11555,7 @@ var tag_default = {
|
|
|
11570
11555
|
exitHook(translator.hook, tag);
|
|
11571
11556
|
return;
|
|
11572
11557
|
}
|
|
11573
|
-
|
|
11574
|
-
case 0:
|
|
11575
|
-
native_tag_default.translate.exit(tag);
|
|
11576
|
-
break;
|
|
11577
|
-
case 1:
|
|
11578
|
-
custom_tag_default.translate.exit(tag);
|
|
11579
|
-
break;
|
|
11580
|
-
case 2:
|
|
11581
|
-
dynamic_tag_default.translate.exit(tag);
|
|
11582
|
-
break;
|
|
11583
|
-
case 3: attribute_tag_default.translate.exit(tag);
|
|
11584
|
-
}
|
|
11558
|
+
tagVisitors[analyzeTagNameType(tag)].translate.exit(tag);
|
|
11585
11559
|
}
|
|
11586
11560
|
}
|
|
11587
11561
|
};
|
|
@@ -11712,11 +11686,9 @@ function getFeatureTypeFromCoreTagName(tagName) {
|
|
|
11712
11686
|
case "macro":
|
|
11713
11687
|
case "module-code":
|
|
11714
11688
|
case "while": return Class;
|
|
11715
|
-
case "attrs":
|
|
11716
11689
|
case "const":
|
|
11717
11690
|
case "debug":
|
|
11718
11691
|
case "define":
|
|
11719
|
-
case "effect":
|
|
11720
11692
|
case "id":
|
|
11721
11693
|
case "let":
|
|
11722
11694
|
case "lifecycle":
|
|
@@ -11817,10 +11789,8 @@ function createInteropTranslator(translate5) {
|
|
|
11817
11789
|
const { output, entry } = entryFile.markoOpts;
|
|
11818
11790
|
if (!(output === "dom" && entry === "page" || output === "hydrate")) return enterProgram?.call(this, program, state);
|
|
11819
11791
|
const visitedFiles = createVisited(entryFile);
|
|
11820
|
-
entryBuilder.visit(entryFile, entryFile, function visitChild(
|
|
11821
|
-
if (
|
|
11822
|
-
const file = (0, _marko_compiler_babel_utils.loadFileForImport)(entryFile, resolved);
|
|
11823
|
-
if (file) entryBuilder.visit(file, entryFile, (id, childReach = 0) => visitChild(resolveRelativeToEntry(entryFile, file, id), childReach > reach ? childReach : reach));
|
|
11792
|
+
entryBuilder.visit(entryFile, entryFile, function visitChild(file, reach = 0) {
|
|
11793
|
+
if (markReached(entryFile, visitedFiles, file, reach)) entryBuilder.visit(file, entryFile, (childFile, childReach = 0) => visitChild(childFile, childReach > reach ? childReach : reach));
|
|
11824
11794
|
});
|
|
11825
11795
|
program.node.body = entryBuilder.build(entryFile);
|
|
11826
11796
|
program.skip();
|
|
@@ -11883,12 +11853,8 @@ function mergeObjects(a, b, cb) {
|
|
|
11883
11853
|
const value = cb(key, aValue, bValue);
|
|
11884
11854
|
if (value !== void 0) merged[key] = value;
|
|
11885
11855
|
};
|
|
11886
|
-
|
|
11887
|
-
|
|
11888
|
-
for (const key in a) assign(key, a[key], b[key]);
|
|
11889
|
-
for (const key in b) if (!(key in a)) assign(key, void 0, b[key]);
|
|
11890
|
-
} else for (const key in a) assign(key, a[key], void 0);
|
|
11891
|
-
} else if (b) for (const key in b) assign(key, void 0, b[key]);
|
|
11856
|
+
for (const key in a) assign(key, a[key], b?.[key]);
|
|
11857
|
+
for (const key in b) if (!a || !(key in a)) assign(key, void 0, b[key]);
|
|
11892
11858
|
return merged;
|
|
11893
11859
|
}
|
|
11894
11860
|
function normalizeTagDef(tagDef) {
|