marko 6.4.15 → 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-sfzdCRAg.js → dom-BiJ_UKJV.js} +12 -12
- package/dist/debug/{dom-BORByF2b.mjs → dom-D3A8gh_D.mjs} +5 -5
- package/dist/debug/dom.js +3 -2
- package/dist/debug/dom.mjs +2 -2
- package/dist/debug/html/compat.feat.js +1 -1
- package/dist/debug/html/compat.feat.mjs +1 -1
- package/dist/debug/{html-C17tAtch.mjs → html-Bfl3MJP9.mjs} +29 -22
- package/dist/debug/{html-7qRi22mK.js → html-shBfuhlc.js} +29 -22
- 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/renderer.d.ts +1 -1
- package/dist/{dom-DRiewpRL.js → dom-B3piR0q1.js} +7 -7
- package/dist/{dom-DKn1bCPC.mjs → dom-CPk_8CMB.mjs} +5 -5
- package/dist/dom.d.ts +1 -1
- package/dist/dom.js +3 -3
- package/dist/dom.mjs +2 -2
- package/dist/html/assets.d.ts +1 -1
- package/dist/html/compat.feat.js +1 -1
- package/dist/html/compat.feat.mjs +1 -1
- package/dist/html/control-flow.d.ts +9 -9
- package/dist/html/for.d.ts +3 -3
- package/dist/html/serializer.d.ts +2 -0
- package/dist/html/writer.d.ts +2 -2
- package/dist/{html-6w1jd6wm.mjs → html-BD-y50wS.mjs} +27 -24
- package/dist/{html-BaAyg2TB.js → html-aFBpTKdf.js} +27 -24
- 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 +808 -751
- package/dist/translator/interop/build-aggregate-error.d.ts +1 -1
- 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 +2 -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 +5 -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 +8 -6
- package/dist/translator/util/structure.d.ts +1 -0
- package/dist/translator/util/write-guard.d.ts +2 -0
- package/dist/translator/util/writer.d.ts +1 -2
- 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;
|
|
@@ -591,6 +575,9 @@ function joinRepeatable(compare, a, b) {
|
|
|
591
575
|
const compareResult = compare(a, b);
|
|
592
576
|
return compareResult === 0 ? a : compareResult < 0 ? [a, b] : [b, a];
|
|
593
577
|
}
|
|
578
|
+
function at(data, index) {
|
|
579
|
+
return Array.isArray(data) ? data[index] : index ? void 0 : data;
|
|
580
|
+
}
|
|
594
581
|
function first(data) {
|
|
595
582
|
return Array.isArray(data) ? data[0] : data;
|
|
596
583
|
}
|
|
@@ -981,60 +968,99 @@ const SectionRef = "sectionRef";
|
|
|
981
968
|
const ExportRef = "exportRef";
|
|
982
969
|
// src/translator/util/cyclic-memo.ts
|
|
983
970
|
let computations = 0;
|
|
971
|
+
const running = [];
|
|
984
972
|
let provisionalAt = Infinity;
|
|
973
|
+
let provisionalTo = -1;
|
|
985
974
|
function createCyclicMemo(compute, cycleAnswer) {
|
|
986
975
|
const cache = /* @__PURE__ */ new WeakMap();
|
|
987
976
|
const computing = /* @__PURE__ */ new Map();
|
|
977
|
+
const provisional = /* @__PURE__ */ new WeakMap();
|
|
988
978
|
return (key) => {
|
|
989
979
|
if (cache.has(key)) return cache.get(key);
|
|
990
980
|
const at = computing.get(key);
|
|
991
981
|
if (at !== void 0) {
|
|
992
|
-
|
|
982
|
+
takeCycleAnswers(at, at);
|
|
993
983
|
return cycleAnswer;
|
|
994
984
|
}
|
|
995
|
-
const
|
|
996
|
-
|
|
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);
|
|
997
992
|
const outerProvisionalAt = provisionalAt;
|
|
993
|
+
const outerProvisionalTo = provisionalTo;
|
|
998
994
|
provisionalAt = Infinity;
|
|
995
|
+
provisionalTo = -1;
|
|
999
996
|
try {
|
|
1000
997
|
const result = compute(key);
|
|
1001
|
-
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
|
+
});
|
|
1002
1005
|
return result;
|
|
1003
1006
|
} finally {
|
|
1004
1007
|
computing.delete(key);
|
|
1005
|
-
|
|
1008
|
+
running.pop();
|
|
1009
|
+
if (provisionalAt >= depth) {
|
|
1010
|
+
provisionalAt = outerProvisionalAt;
|
|
1011
|
+
provisionalTo = outerProvisionalTo;
|
|
1012
|
+
} else takeCycleAnswers(outerProvisionalAt, outerProvisionalTo);
|
|
1006
1013
|
}
|
|
1007
1014
|
};
|
|
1008
1015
|
}
|
|
1016
|
+
function takeCycleAnswers(at, to) {
|
|
1017
|
+
if (at < provisionalAt) provisionalAt = at;
|
|
1018
|
+
if (to > provisionalTo) provisionalTo = to;
|
|
1019
|
+
}
|
|
1009
1020
|
function createAnalysisMemo(compute, cycleAnswer) {
|
|
1010
1021
|
const create = () => createCyclicMemo(compute, cycleAnswer);
|
|
1011
1022
|
const [getMemo, setMemo] = createAnalysisState(create);
|
|
1012
|
-
return [(key) =>
|
|
1013
|
-
|
|
1014
|
-
|
|
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));
|
|
1015
1031
|
function createPassMemo(compute, cycleAnswer) {
|
|
1016
|
-
const
|
|
1017
|
-
|
|
1018
|
-
|
|
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
|
+
};
|
|
1019
1039
|
}
|
|
1020
1040
|
function resetPassMemos() {
|
|
1021
|
-
|
|
1041
|
+
const memos = getPassMemos();
|
|
1042
|
+
for (let i = 0; i < memos.length; i++) memos[i] = void 0;
|
|
1022
1043
|
}
|
|
1023
|
-
function
|
|
1044
|
+
function createPathKeys() {
|
|
1024
1045
|
const keys = /* @__PURE__ */ new WeakMap();
|
|
1025
|
-
const memo = createPassMemo(([key, path]) => compute(key, path), cycleAnswer);
|
|
1026
1046
|
return (key, path) => {
|
|
1027
1047
|
let pathKeys = keys.get(key);
|
|
1028
|
-
if (!pathKeys) keys.set(key, pathKeys =
|
|
1029
|
-
|
|
1030
|
-
return memo(reduce(path, ensurePropKeys, pathKeys).value ??= [key, path]);
|
|
1048
|
+
if (!pathKeys) keys.set(key, pathKeys = createPathKeysRecord());
|
|
1049
|
+
return path === true ? pathKeys.all ??= [key, path] : reduce(path, ensurePropKeys, pathKeys).value ??= [key, path];
|
|
1031
1050
|
};
|
|
1032
1051
|
}
|
|
1033
1052
|
function ensurePropKeys(pathKeys, property) {
|
|
1034
1053
|
let next = pathKeys.properties?.get(property);
|
|
1035
|
-
if (!next) (pathKeys.properties ??= /* @__PURE__ */ new Map()).set(property, next =
|
|
1054
|
+
if (!next) (pathKeys.properties ??= /* @__PURE__ */ new Map()).set(property, next = createPathKeysRecord());
|
|
1036
1055
|
return next;
|
|
1037
1056
|
}
|
|
1057
|
+
function createPathKeysRecord() {
|
|
1058
|
+
return {
|
|
1059
|
+
value: void 0,
|
|
1060
|
+
all: void 0,
|
|
1061
|
+
properties: void 0
|
|
1062
|
+
};
|
|
1063
|
+
}
|
|
1038
1064
|
// src/translator/util/for-each-identifier.ts
|
|
1039
1065
|
function forEachIdentifier(node, cb) {
|
|
1040
1066
|
switch (node.type) {
|
|
@@ -1175,7 +1201,7 @@ const globalSources = {
|
|
|
1175
1201
|
always: void 0
|
|
1176
1202
|
};
|
|
1177
1203
|
function sharesSources(a, b) {
|
|
1178
|
-
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));
|
|
1179
1205
|
}
|
|
1180
1206
|
function createSources(state, param, global, always) {
|
|
1181
1207
|
/* v8 ignore next 6 -- every caller passes at least one source */
|
|
@@ -1219,10 +1245,10 @@ function mergeSources(a, b) {
|
|
|
1219
1245
|
function unionParamSources(a, b) {
|
|
1220
1246
|
const merged = bindingUtil.union(a, b);
|
|
1221
1247
|
if (merged === a || merged === b) return merged;
|
|
1222
|
-
return bindingUtil.union(
|
|
1248
|
+
return bindingUtil.union(bindingUtil.filter(a, isUncoveredAlias, b), bindingUtil.filter(b, isUncoveredAlias, a));
|
|
1223
1249
|
}
|
|
1224
|
-
function
|
|
1225
|
-
return
|
|
1250
|
+
function isUncoveredAlias(binding, params) {
|
|
1251
|
+
return !isCoveredParam(binding.aliasOf, params);
|
|
1226
1252
|
}
|
|
1227
1253
|
function isInParams(binding, params) {
|
|
1228
1254
|
return bindingUtil.has(params, binding);
|
|
@@ -1230,7 +1256,7 @@ function isInParams(binding, params) {
|
|
|
1230
1256
|
function isSupersetSources(a, b) {
|
|
1231
1257
|
if (!b.sources) return true;
|
|
1232
1258
|
if (!a.sources) return false;
|
|
1233
|
-
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);
|
|
1234
1260
|
}
|
|
1235
1261
|
function isCoveredParam(binding, params) {
|
|
1236
1262
|
return someUpToAliasRoot(binding, isInParams, params);
|
|
@@ -1286,7 +1312,7 @@ function trackVarReferences(tag, type, aliased) {
|
|
|
1286
1312
|
const tagVar = tag.node.var;
|
|
1287
1313
|
if (tagVar) {
|
|
1288
1314
|
const section = ensureSection(tag);
|
|
1289
|
-
let target = aliased
|
|
1315
|
+
let target = aliased?.canonical;
|
|
1290
1316
|
if (target) {
|
|
1291
1317
|
const { excludeProperties, restOffset } = target;
|
|
1292
1318
|
if (isRest(target)) target = target.aliasOf;
|
|
@@ -1394,7 +1420,7 @@ function trackAssignment(assignment, binding) {
|
|
|
1394
1420
|
const fnParent = getFnParent(assignment);
|
|
1395
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.`);
|
|
1396
1422
|
if (binding.type === 3) throw assignment.buildCodeFrameError(`\`${binding.name}\` is a tag parameter and cannot be assigned to.`);
|
|
1397
|
-
const assigned =
|
|
1423
|
+
const assigned = binding.canonical;
|
|
1398
1424
|
const fnRoot = getFnRoot(fnParent);
|
|
1399
1425
|
const fnExtra = fnRoot && (fnRoot.node.extra ??= {});
|
|
1400
1426
|
const section = ensureSection(assignment);
|
|
@@ -1414,7 +1440,7 @@ function trackAssignment(assignment, binding) {
|
|
|
1414
1440
|
if (assigned.aliasOf && assigned.property !== void 0) {
|
|
1415
1441
|
if (assigned.aliasOf === assigned.section.params) throw assignment.buildCodeFrameError(`\`${binding.name}\` is a tag parameter and cannot be assigned to.`);
|
|
1416
1442
|
const changePropName = assigned.property + "Change";
|
|
1417
|
-
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);
|
|
1418
1444
|
idExtra.assignmentTo = changeBinding;
|
|
1419
1445
|
addReadToExpression(id, changeBinding, void 0);
|
|
1420
1446
|
}
|
|
@@ -1483,7 +1509,7 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, aliased, p
|
|
|
1483
1509
|
}
|
|
1484
1510
|
}
|
|
1485
1511
|
function ensurePatternBinding(lVal, type, section, aliased, property, excludeProperties) {
|
|
1486
|
-
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));
|
|
1487
1513
|
if (patternBinding.section === section) patternBinding.nullable = false;
|
|
1488
1514
|
return patternBinding;
|
|
1489
1515
|
}
|
|
@@ -1508,13 +1534,13 @@ function trackReference(referencePath, binding) {
|
|
|
1508
1534
|
if (parent.object !== root.node) break;
|
|
1509
1535
|
let prop = getMemberExpressionPropString(parent);
|
|
1510
1536
|
if (isAssignedMember(root.parentPath)) {
|
|
1511
|
-
const object =
|
|
1537
|
+
const object = reference.canonical;
|
|
1512
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>\`.`);
|
|
1513
1539
|
addAssignedProperty(object, prop);
|
|
1514
1540
|
break;
|
|
1515
1541
|
}
|
|
1516
1542
|
if (prop === void 0) break;
|
|
1517
|
-
if (
|
|
1543
|
+
if (isRest(reference)) {
|
|
1518
1544
|
if (reference.restOffset !== void 0) {
|
|
1519
1545
|
if (isIndexProperty(prop)) {
|
|
1520
1546
|
prop = `${+prop + reference.restOffset}`;
|
|
@@ -1557,9 +1583,7 @@ function mergeReferenceGroup(section, nodes) {
|
|
|
1557
1583
|
function mergeInto(section, extra, nodes) {
|
|
1558
1584
|
const targetExtra = extra;
|
|
1559
1585
|
const readsByExpression = getReadsByExpression();
|
|
1560
|
-
const fnReadsByExpression = getFunctionReadsByExpression();
|
|
1561
1586
|
let reads = readsByExpression.get(targetExtra);
|
|
1562
|
-
let exprFnReads = fnReadsByExpression.get(targetExtra);
|
|
1563
1587
|
let { isEffect, retained } = targetExtra;
|
|
1564
1588
|
for (const node of nodes) {
|
|
1565
1589
|
if (!node) continue;
|
|
@@ -1568,7 +1592,6 @@ function mergeInto(section, extra, nodes) {
|
|
|
1568
1592
|
retained ||= extra.retained;
|
|
1569
1593
|
if (isReferencedExtra(extra)) {
|
|
1570
1594
|
const additionalReads = readsByExpression.get(extra);
|
|
1571
|
-
const additionalExprFnReads = fnReadsByExpression.get(extra);
|
|
1572
1595
|
isEffect ||= extra.isEffect;
|
|
1573
1596
|
if (additionalReads) {
|
|
1574
1597
|
forEach(additionalReads, (read) => {
|
|
@@ -1579,10 +1602,6 @@ function mergeInto(section, extra, nodes) {
|
|
|
1579
1602
|
reads = concat(reads, additionalReads);
|
|
1580
1603
|
readsByExpression.delete(extra);
|
|
1581
1604
|
}
|
|
1582
|
-
if (additionalExprFnReads) {
|
|
1583
|
-
if (exprFnReads) for (const [key, value] of additionalExprFnReads) exprFnReads.set(key, value);
|
|
1584
|
-
else fnReadsByExpression.set(targetExtra, exprFnReads = new Map(additionalExprFnReads));
|
|
1585
|
-
}
|
|
1586
1605
|
} else if (extra.dropped)
|
|
1587
1606
|
/* v8 ignore next -- a dropped reference is never merged into another */
|
|
1588
1607
|
throw new Error("Cannot merge a dropped reference.");
|
|
@@ -1619,7 +1638,6 @@ function setDerivedFrom(binding, expr, exprs) {
|
|
|
1619
1638
|
}
|
|
1620
1639
|
const [getAssignments] = createAnalysisState(() => []);
|
|
1621
1640
|
const [getReadsByExpression] = createAnalysisState(() => /* @__PURE__ */ new Map());
|
|
1622
|
-
const [getFunctionReadsByExpression] = createAnalysisState(() => /* @__PURE__ */ new Map());
|
|
1623
1641
|
const [getReferenceFinalizers] = createAnalysisState(() => []);
|
|
1624
1642
|
function onFinalizeReferences(finalize) {
|
|
1625
1643
|
getReferenceFinalizers().push(finalize);
|
|
@@ -1629,6 +1647,7 @@ function addRead(exprExtra, extra, exprRoot, binding, section, getter) {
|
|
|
1629
1647
|
const readsByExpression = getReadsByExpression();
|
|
1630
1648
|
const read = {
|
|
1631
1649
|
binding,
|
|
1650
|
+
holder: binding,
|
|
1632
1651
|
extra,
|
|
1633
1652
|
getter,
|
|
1634
1653
|
inOwnBody: false,
|
|
@@ -1637,7 +1656,8 @@ function addRead(exprExtra, extra, exprRoot, binding, section, getter) {
|
|
|
1637
1656
|
fnRoot: void 0
|
|
1638
1657
|
};
|
|
1639
1658
|
if (section.dropped) return read;
|
|
1640
|
-
binding.reads
|
|
1659
|
+
const bindingReads = binding.reads ??= /* @__PURE__ */ new Map();
|
|
1660
|
+
bindingReads.set(exprExtra, push(bindingReads.get(exprExtra), read));
|
|
1641
1661
|
exprExtra.section = section;
|
|
1642
1662
|
readsByExpression.set(exprExtra, push(readsByExpression.get(exprExtra), read));
|
|
1643
1663
|
return read;
|
|
@@ -1666,12 +1686,12 @@ function untrackExpr(exprExtra) {
|
|
|
1666
1686
|
const reads = readsByExpr.get(exprExtra);
|
|
1667
1687
|
if (reads) {
|
|
1668
1688
|
readsByExpr.delete(exprExtra);
|
|
1669
|
-
|
|
1670
|
-
forEach(reads, (read) => {
|
|
1671
|
-
for (let cur = read.binding; cur; cur = cur.aliasOf) cur.reads.delete(exprExtra);
|
|
1672
|
-
});
|
|
1689
|
+
forEach(reads, untrackRead, exprExtra);
|
|
1673
1690
|
}
|
|
1674
1691
|
}
|
|
1692
|
+
function untrackRead({ holder }, exprExtra) {
|
|
1693
|
+
if (holder.reads?.delete(exprExtra) && !holder.reads.size) holder.reads = void 0;
|
|
1694
|
+
}
|
|
1675
1695
|
function dropContent(body) {
|
|
1676
1696
|
const bodyExtra = body.extra ??= {};
|
|
1677
1697
|
bodyExtra.dropped = true;
|
|
@@ -1714,14 +1734,10 @@ function addReadToExpression(root, binding, getter) {
|
|
|
1714
1734
|
if (!getter && root.parent.type === "MarkoSpreadAttribute") extra.spreadFrom = binding;
|
|
1715
1735
|
if (fnRoot) {
|
|
1716
1736
|
read.deferred = fnRoot.node.type !== "ObjectMethod" || fnRoot.node.kind === "method";
|
|
1717
|
-
const fnReadsByExpr = getFunctionReadsByExpression();
|
|
1718
|
-
let exprFnReads = fnReadsByExpr.get(exprExtra);
|
|
1719
|
-
if (!exprFnReads) fnReadsByExpr.set(exprExtra, exprFnReads = /* @__PURE__ */ new Map());
|
|
1720
1737
|
const fnExtra = fnRoot.node.extra ??= {};
|
|
1721
1738
|
fnExtra.section = section;
|
|
1722
1739
|
fnExtra.exprRoot = rootExtra;
|
|
1723
1740
|
read.fnRoot = fnExtra;
|
|
1724
|
-
exprFnReads.set(fnExtra, push(exprFnReads.get(fnExtra), read));
|
|
1725
1741
|
}
|
|
1726
1742
|
}
|
|
1727
1743
|
function getAllTagReferenceNodes(tag, referenceNodes = [], collectAttrTag) {
|
|
@@ -1739,19 +1755,11 @@ function getChildTagReferenceNodes(tag, referenceNodes, collectAttrTag) {
|
|
|
1739
1755
|
}
|
|
1740
1756
|
return referenceNodes;
|
|
1741
1757
|
}
|
|
1742
|
-
function createResolvedRead(binding, properties, inOwnBody = false) {
|
|
1758
|
+
function createResolvedRead(binding, properties, inOwnBody = false, getter) {
|
|
1743
1759
|
return {
|
|
1744
1760
|
binding,
|
|
1745
1761
|
properties,
|
|
1746
1762
|
inOwnBody,
|
|
1747
|
-
getter: void 0
|
|
1748
|
-
};
|
|
1749
|
-
}
|
|
1750
|
-
function createResolvedGetterRead(binding, properties, getter) {
|
|
1751
|
-
return {
|
|
1752
|
-
binding,
|
|
1753
|
-
properties,
|
|
1754
|
-
inOwnBody: false,
|
|
1755
1763
|
getter
|
|
1756
1764
|
};
|
|
1757
1765
|
}
|
|
@@ -1815,18 +1823,16 @@ function addNumericPropertiesUntil(properties, len) {
|
|
|
1815
1823
|
}
|
|
1816
1824
|
// src/translator/util/for-selector.ts
|
|
1817
1825
|
function isForSelectorClosure(bodySection, closure) {
|
|
1818
|
-
return !!bodySection.selector?.has(
|
|
1819
|
-
}
|
|
1820
|
-
function isForSelectorValue(binding) {
|
|
1821
|
-
return some(binding.closureSections, (section) => !!section.selector?.has(binding));
|
|
1826
|
+
return !!bodySection.selector?.has(closure.canonical);
|
|
1822
1827
|
}
|
|
1823
1828
|
function detectForSelector(bodySection, keyBinding) {
|
|
1829
|
+
if (!keyBinding.reads) return;
|
|
1824
1830
|
const parentSection = bodySection.parent;
|
|
1825
1831
|
let closures;
|
|
1826
1832
|
for (const expr of keyBinding.reads.keys()) {
|
|
1827
1833
|
if (expr.section !== bodySection) continue;
|
|
1828
1834
|
forEach(getReferencedBindings(expr), (closure) => {
|
|
1829
|
-
const canonical =
|
|
1835
|
+
const canonical = closure.canonical;
|
|
1830
1836
|
if (!closures?.has(canonical) && bindingUtil.has(bodySection.referencedClosures, canonical) && !parentSection.selector?.has(canonical) && onlyComparesKey(closure, canonical, bodySection, keyBinding)) {
|
|
1831
1837
|
(closures ||= /* @__PURE__ */ new Set()).add(canonical);
|
|
1832
1838
|
if (canonical.section !== parentSection) parentSection.referencedClosures = bindingUtil.add(parentSection.referencedClosures, canonical);
|
|
@@ -1837,47 +1843,50 @@ function detectForSelector(bodySection, keyBinding) {
|
|
|
1837
1843
|
}
|
|
1838
1844
|
function onlyComparesKey(closure, canonical, bodySection, keyBinding) {
|
|
1839
1845
|
let found = false;
|
|
1840
|
-
for (let chain = closure; chain; chain = chain.aliasOf)
|
|
1841
|
-
if (
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
if (resolved
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
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
|
+
}
|
|
1853
1862
|
}
|
|
1854
1863
|
return found;
|
|
1855
1864
|
}
|
|
1856
1865
|
function resolvesTo(read, canonical) {
|
|
1857
1866
|
const binding = getPropertyAlias(read.binding, read.properties);
|
|
1858
|
-
return !!binding &&
|
|
1867
|
+
return !!binding && binding.canonical === canonical;
|
|
1859
1868
|
}
|
|
1860
1869
|
function resolvesThrough(read, canonical) {
|
|
1861
1870
|
let binding = read.binding;
|
|
1862
1871
|
let through = false;
|
|
1863
1872
|
forEach(read.properties, (prop) => {
|
|
1864
1873
|
if (binding) {
|
|
1865
|
-
through ||=
|
|
1866
|
-
binding = binding.propertyAliases
|
|
1874
|
+
through ||= binding.canonical === canonical;
|
|
1875
|
+
binding = binding.propertyAliases?.get(prop);
|
|
1867
1876
|
}
|
|
1868
1877
|
});
|
|
1869
1878
|
return through;
|
|
1870
1879
|
}
|
|
1871
1880
|
function readsKey(read, keyBinding) {
|
|
1872
|
-
return !!read && !read.getter && resolvesTo(read,
|
|
1881
|
+
return !!read && !read.getter && resolvesTo(read, keyBinding);
|
|
1873
1882
|
}
|
|
1874
1883
|
// src/translator/util/slots.ts
|
|
1875
1884
|
function ensureSlot(binding, kind = 0, section, group) {
|
|
1876
|
-
const owner =
|
|
1885
|
+
const owner = binding.canonical;
|
|
1877
1886
|
return ensureIn(section || owner.section, owner, kind, group);
|
|
1878
1887
|
}
|
|
1879
1888
|
function findSlot(binding, kind = 0, section, group) {
|
|
1880
|
-
const owner =
|
|
1889
|
+
const owner = binding.canonical;
|
|
1881
1890
|
return findIn((section || owner.section).slots, owner.uid, kind, group);
|
|
1882
1891
|
}
|
|
1883
1892
|
function ensureSectionSlot(owner, kind, section = owner) {
|
|
@@ -1951,6 +1960,7 @@ const pureDOMFunctions = /* @__PURE__ */ new Set([
|
|
|
1951
1960
|
"_try",
|
|
1952
1961
|
"_dynamic_tag",
|
|
1953
1962
|
"_dynamic_tag_content",
|
|
1963
|
+
"_content",
|
|
1954
1964
|
"_content_closures",
|
|
1955
1965
|
"_template",
|
|
1956
1966
|
"_return_setup",
|
|
@@ -1979,17 +1989,9 @@ const pureDOMFunctions = /* @__PURE__ */ new Set([
|
|
|
1979
1989
|
"_load_media_trigger",
|
|
1980
1990
|
"_load_race_trigger"
|
|
1981
1991
|
]);
|
|
1982
|
-
const [getRuntimeImports] = createOutputState(() => /* @__PURE__ */ new Map());
|
|
1983
1992
|
function importRuntime(name) {
|
|
1984
1993
|
assertTranslate("importRuntime", name);
|
|
1985
|
-
|
|
1986
|
-
const imports = getRuntimeImports();
|
|
1987
|
-
let localName = imports.get(name);
|
|
1988
|
-
if (!localName) {
|
|
1989
|
-
localName = (0, _marko_compiler_babel_utils.importNamed)((0, _marko_compiler_babel_utils.getFile)(), getRuntimePath(output), name).name;
|
|
1990
|
-
imports.set(name, localName);
|
|
1991
|
-
}
|
|
1992
|
-
return _marko_compiler.types.identifier(localName);
|
|
1994
|
+
return (0, _marko_compiler_babel_utils.importNamed)((0, _marko_compiler_babel_utils.getFile)(), getRuntimePath(getMarkoOpts().output), name);
|
|
1993
1995
|
}
|
|
1994
1996
|
function registerRuntimeValue(id, value) {
|
|
1995
1997
|
return _marko_compiler.types.assignmentExpression("=", toMemberExpression(importRuntime("_resumed"), id), value);
|
|
@@ -2032,9 +2034,16 @@ function importRuntimeFeature(feature) {
|
|
|
2032
2034
|
function getRuntimeFeatureImport(feature) {
|
|
2033
2035
|
return _marko_compiler.types.importDeclaration([], _marko_compiler.types.stringLiteral(`${getRuntimePath("dom")}/${feature}.feat`));
|
|
2034
2036
|
}
|
|
2037
|
+
const runtimePaths = {
|
|
2038
|
+
dom: `${runtime_info_default.name}/dom`,
|
|
2039
|
+
html: `${runtime_info_default.name}/html`
|
|
2040
|
+
};
|
|
2041
|
+
const debugRuntimePaths = {
|
|
2042
|
+
dom: `${runtime_info_default.name}/debug/dom`,
|
|
2043
|
+
html: `${runtime_info_default.name}/debug/html`
|
|
2044
|
+
};
|
|
2035
2045
|
function getRuntimePath(output) {
|
|
2036
|
-
|
|
2037
|
-
return `${runtime_info_default.name}/${optimize ? "" : "debug/"}${output === "html" ? "html" : "dom"}`;
|
|
2046
|
+
return (getMarkoOpts().optimize ? runtimePaths : debugRuntimePaths)[output === "html" ? "html" : "dom"];
|
|
2038
2047
|
}
|
|
2039
2048
|
function assertTranslate(helper, name) {
|
|
2040
2049
|
if (!isTranslate()) throw new Error(`\`${helper}(${JSON.stringify(name)})\` may only be called during the translate stage.`);
|
|
@@ -2114,6 +2123,12 @@ function getScopeReasonStatement(section) {
|
|
|
2114
2123
|
function getWriteReason(binding) {
|
|
2115
2124
|
return findSlot(binding)?.reason;
|
|
2116
2125
|
}
|
|
2126
|
+
function getMarkerGuard(nodeBinding) {
|
|
2127
|
+
return getWriteGuard(nodeBinding.section, getWriteReason(nodeBinding), true);
|
|
2128
|
+
}
|
|
2129
|
+
function isMarkerWritten(nodeBinding) {
|
|
2130
|
+
return getWriteBit(nodeBinding.section, getWriteReason(nodeBinding)) !== 0;
|
|
2131
|
+
}
|
|
2117
2132
|
function getBranchWriteReason(section) {
|
|
2118
2133
|
return findSectionSlot(section, 9)?.reason;
|
|
2119
2134
|
}
|
|
@@ -2201,10 +2216,10 @@ function getOrShareSectionGuard(section, params, check) {
|
|
|
2201
2216
|
return _marko_compiler.types.parenthesizedExpression(_marko_compiler.types.identifier(shared));
|
|
2202
2217
|
}
|
|
2203
2218
|
function isDynamicWriteGuard(section, reason) {
|
|
2204
|
-
return isGuardedReason(reason) && !
|
|
2219
|
+
return isGuardedReason(reason) && !some(reason.param, isOutsideSection, section);
|
|
2205
2220
|
}
|
|
2206
|
-
function
|
|
2207
|
-
return
|
|
2221
|
+
function isOutsideSection(param, section) {
|
|
2222
|
+
return !isSameOrAncestorSection(param.section, section);
|
|
2208
2223
|
}
|
|
2209
2224
|
function getStaticGroupBit(body, group) {
|
|
2210
2225
|
const index = findParamReasonGroupIndex(body, group);
|
|
@@ -2219,7 +2234,9 @@ function getCallsBit(body, group) {
|
|
|
2219
2234
|
let bit;
|
|
2220
2235
|
for (const call of Array.isArray(renderedBy) ? renderedBy : [renderedBy]) {
|
|
2221
2236
|
const callSection = call.childScopeBinding.section;
|
|
2222
|
-
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);
|
|
2223
2240
|
if (callBit === void 0 || bit !== void 0 && bit !== callBit) return;
|
|
2224
2241
|
bit = callBit;
|
|
2225
2242
|
}
|
|
@@ -2229,7 +2246,7 @@ function isOnlyCalled(body) {
|
|
|
2229
2246
|
return !!body.renderedBy && !!body.derives && !some(body.derives.binding, isUsed);
|
|
2230
2247
|
}
|
|
2231
2248
|
function isUsed(binding) {
|
|
2232
|
-
return !!binding.reads
|
|
2249
|
+
return !!(binding.reads || binding.aliases || binding.propertyAliases);
|
|
2233
2250
|
}
|
|
2234
2251
|
function createGuardShares() {
|
|
2235
2252
|
return {
|
|
@@ -2490,15 +2507,21 @@ function solveReasons(intersectionsBySection) {
|
|
|
2490
2507
|
forEachSection((section) => addIntersectionReasons(section, intersectionsBySection.get(section)));
|
|
2491
2508
|
forEachSection(addClosureReasons);
|
|
2492
2509
|
forEachSection(addCallOwnerReasons);
|
|
2493
|
-
addRegisteredFnReasons(
|
|
2510
|
+
addRegisteredFnReasons();
|
|
2511
|
+
} while (reasonsVersion !== getReasonsVersion());
|
|
2512
|
+
do {
|
|
2513
|
+
reasonsVersion = getReasonsVersion();
|
|
2494
2514
|
forEachSectionReverse(solveSectionReasons);
|
|
2495
2515
|
} while (reasonsVersion !== getReasonsVersion());
|
|
2496
|
-
getFunctionReadsByExpression().clear();
|
|
2497
2516
|
}
|
|
2498
2517
|
function solveSectionReasons(section) {
|
|
2499
2518
|
addKnownTagReasons(section);
|
|
2500
|
-
|
|
2501
|
-
|
|
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);
|
|
2502
2525
|
}
|
|
2503
2526
|
function addIntersectionReasons(section, intersections) {
|
|
2504
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++) {
|
|
@@ -2516,14 +2539,17 @@ function hasReadIntermediate(member, partner, seen) {
|
|
|
2516
2539
|
return some(getBindingsDerivedFrom(member), (from) => {
|
|
2517
2540
|
if (seen.has(from) || !sharesSources(from, partner)) return false;
|
|
2518
2541
|
seen.add(from);
|
|
2519
|
-
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;
|
|
2520
2543
|
return !!findSlot(from)?.reason || hasReadIntermediate(from, partner, seen);
|
|
2521
2544
|
});
|
|
2522
2545
|
}
|
|
2523
2546
|
function withoutOwnSources(closure, sources) {
|
|
2524
2547
|
const own = closure.sources;
|
|
2525
2548
|
if (!sources || !own || hasReadIntermediate(closure, closure, /* @__PURE__ */ new Set())) return sources;
|
|
2526
|
-
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);
|
|
2527
2553
|
}
|
|
2528
2554
|
function getBranchExprReason(section) {
|
|
2529
2555
|
const { derives, branchExpr } = section;
|
|
@@ -2544,30 +2570,32 @@ function getBranchExprReasonUntil(section, ancestor) {
|
|
|
2544
2570
|
return reason;
|
|
2545
2571
|
}
|
|
2546
2572
|
function addClosureReasons(section) {
|
|
2547
|
-
forEach(section.referencedConstants,
|
|
2548
|
-
forEach(section.referencedClosures,
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
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
|
+
}
|
|
2555
2582
|
}
|
|
2556
|
-
function addClosureReason(
|
|
2583
|
+
function addClosureReason(binding, section) {
|
|
2557
2584
|
const sourceSection = binding.section;
|
|
2558
2585
|
const branchesReason = getBranchExprReasonUntil(section, sourceSection);
|
|
2559
2586
|
addReason(ensureSlot(binding), branchesReason?.always ? branchesReason : withoutOwnSources(binding, branchesReason));
|
|
2560
2587
|
if (isDynamicClosure(section, binding)) addOwnerReason(section, sourceSection, branchesReason);
|
|
2561
2588
|
}
|
|
2562
2589
|
function addCallOwnerReasons(body) {
|
|
2563
|
-
if (body.readsOwner) forEach(body.renderedBy,
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
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));
|
|
2567
2595
|
}
|
|
2568
|
-
function addRegisteredFnReasons(
|
|
2596
|
+
function addRegisteredFnReasons() {
|
|
2569
2597
|
addFunctionReasons();
|
|
2570
|
-
for (const
|
|
2598
|
+
for (const fn of getReferencesByFn().keys()) {
|
|
2571
2599
|
const reason = fn.reason;
|
|
2572
2600
|
if (reason) {
|
|
2573
2601
|
const addReadReason = (binding) => {
|
|
@@ -2581,7 +2609,6 @@ function addRegisteredFnReasons(fnReadsByExpression) {
|
|
|
2581
2609
|
}
|
|
2582
2610
|
const LANDS_RETAINED = 1;
|
|
2583
2611
|
const LANDS_RETAINED_INPUT = 2;
|
|
2584
|
-
const LANDS_UNSEEN = 4;
|
|
2585
2612
|
const UNREAD = {
|
|
2586
2613
|
reason: void 0,
|
|
2587
2614
|
lands: 0
|
|
@@ -2590,58 +2617,62 @@ const ALWAYS_READ = {
|
|
|
2590
2617
|
reason: ALWAYS,
|
|
2591
2618
|
lands: 0
|
|
2592
2619
|
};
|
|
2593
|
-
const UNSEEN_READ = {
|
|
2594
|
-
reason: void 0,
|
|
2595
|
-
lands: LANDS_UNSEEN
|
|
2596
|
-
};
|
|
2597
|
-
const RETAINED_TAG_NAME_READ = {
|
|
2598
|
-
reason: void 0,
|
|
2599
|
-
lands: LANDS_RETAINED
|
|
2600
|
-
};
|
|
2601
|
-
const RETAINED_INPUT_READ = {
|
|
2602
|
-
reason: void 0,
|
|
2603
|
-
lands: 3
|
|
2604
|
-
};
|
|
2605
2620
|
const exprReaders = createPassMemo(computeExprReaders, UNREAD);
|
|
2606
|
-
const bindingReaders =
|
|
2607
|
-
|
|
2608
|
-
|
|
2621
|
+
const bindingReaders = createPassMemo(computeBindingReaders, UNREAD);
|
|
2622
|
+
const getWalkKey = createPathKeys();
|
|
2623
|
+
function getReasonForBinding(binding, properties, exprs) {
|
|
2624
|
+
return readersOf(binding, properties, exprs).reason;
|
|
2609
2625
|
}
|
|
2610
2626
|
function getReasonForExpr(extra) {
|
|
2611
2627
|
return extra.isEffect ? ALWAYS : exprReaders(extra).reason;
|
|
2612
2628
|
}
|
|
2613
2629
|
function bindingLandsRetained(binding, properties) {
|
|
2614
|
-
return !!(bindingReaders(binding, properties).lands & LANDS_RETAINED_INPUT);
|
|
2630
|
+
return !!(bindingReaders(getWalkKey(binding, properties)).lands & LANDS_RETAINED_INPUT);
|
|
2615
2631
|
}
|
|
2616
2632
|
function getContentSites({ binding, properties }) {
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2633
|
+
return reduce(binding, (sites, part) => joinSites(sites, getSitesAt(getWalkKey(part, properties))), NO_SITES);
|
|
2634
|
+
}
|
|
2635
|
+
const NO_SITES = { unseen: false };
|
|
2636
|
+
const UNSEEN_SITES = { unseen: true };
|
|
2637
|
+
const [getSitesAt] = createAnalysisMemo(([binding, properties]) => {
|
|
2638
|
+
let sites;
|
|
2639
|
+
let deepSites;
|
|
2640
|
+
const unseen = someReachedRead(binding, properties, (read, reader, pastCall) => {
|
|
2641
|
+
if (read.isEffect) return false;
|
|
2642
|
+
if (!isNamedBy(read, reader)) return !read.derives;
|
|
2643
|
+
if (pastCall) deepSites = push(deepSites, read);
|
|
2644
|
+
else sites = push(sites, read);
|
|
2645
|
+
return false;
|
|
2646
|
+
});
|
|
2647
|
+
return unseen ? UNSEEN_SITES : {
|
|
2648
|
+
unseen,
|
|
2620
2649
|
sites,
|
|
2621
2650
|
deepSites
|
|
2622
2651
|
};
|
|
2652
|
+
}, NO_SITES);
|
|
2653
|
+
function joinSites(a, b) {
|
|
2654
|
+
return a === NO_SITES ? b : a.unseen || b.unseen ? UNSEEN_SITES : {
|
|
2655
|
+
unseen: false,
|
|
2656
|
+
sites: concat(a.sites, b.sites),
|
|
2657
|
+
deepSites: concat(a.deepSites, b.deepSites)
|
|
2658
|
+
};
|
|
2623
2659
|
}
|
|
2624
2660
|
function landsRetained(extra) {
|
|
2625
2661
|
return !!extra.retained || !extra.isEffect && !!(exprReaders(extra).lands & LANDS_RETAINED);
|
|
2626
2662
|
}
|
|
2627
2663
|
function computeExprReaders(extra) {
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
const exprs = extra.callSiteExprs;
|
|
2641
|
-
return exprs && (linked.reason || linked.sites) ? {
|
|
2642
|
-
reason: linked.reason && mapParamReason(binding.section.program, linked.reason, exprs, true),
|
|
2643
|
-
lands: linked.lands,
|
|
2644
|
-
deepSites: mergeSites(linked.deepSites, linked.sites)
|
|
2664
|
+
const folding = {
|
|
2665
|
+
readers: isReturned(extra) ? ALWAYS_READ : UNREAD,
|
|
2666
|
+
head: void 0
|
|
2667
|
+
};
|
|
2668
|
+
forEachDerivedStep(extra, void 0, void 0, READERS_STEP, folding);
|
|
2669
|
+
return folding.readers;
|
|
2670
|
+
}
|
|
2671
|
+
function readersOf(binding, path, exprs) {
|
|
2672
|
+
const linked = bindingReaders(getWalkKey(binding, path));
|
|
2673
|
+
return exprs && linked.reason ? {
|
|
2674
|
+
reason: mapParamReason(binding.section.program, linked.reason, exprs, true),
|
|
2675
|
+
lands: linked.lands
|
|
2645
2676
|
} : linked;
|
|
2646
2677
|
}
|
|
2647
2678
|
function getDerivedPath(extra, binding, part, properties) {
|
|
@@ -2656,78 +2687,125 @@ function getDerivedPath(extra, binding, part, properties) {
|
|
|
2656
2687
|
}
|
|
2657
2688
|
function isReferenceTo(extra, binding) {
|
|
2658
2689
|
const { read } = extra;
|
|
2659
|
-
return !!read && read.properties === void 0 &&
|
|
2690
|
+
return !!read && read.properties === void 0 && read.binding.canonical === binding.canonical;
|
|
2660
2691
|
}
|
|
2661
2692
|
function isPartOf(binding, value) {
|
|
2662
2693
|
return !!value && binding.aliasOf === value && !isDirectAlias(binding);
|
|
2663
2694
|
}
|
|
2664
|
-
function computeBindingReaders(binding, properties) {
|
|
2695
|
+
function computeBindingReaders([binding, properties]) {
|
|
2696
|
+
if (isLeftOut(binding, properties)) return UNREAD;
|
|
2665
2697
|
const head = properties === true || properties === void 0 ? void 0 : first(properties);
|
|
2666
2698
|
const reason = findSlot(binding)?.reason;
|
|
2667
|
-
|
|
2668
|
-
reason
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
continue;
|
|
2677
|
-
}
|
|
2678
|
-
readers = mergeReaders(readers, landingReaders(expr, binding));
|
|
2679
|
-
readers = mergeReaders(readers, renderingReaders(expr, binding));
|
|
2680
|
-
readers = mergeReaders(readers, readersOfDerives(expr, binding, properties));
|
|
2681
|
-
}
|
|
2682
|
-
for (const alias of binding.aliases) readers = mergeReaders(readers, bindingReaders(alias, properties));
|
|
2683
|
-
if (properties === void 0) return readers;
|
|
2684
|
-
if (properties === true) {
|
|
2685
|
-
for (const propBinding of binding.propertyAliases.values()) readers = mergeReaders(readers, bindingReaders(propBinding, true));
|
|
2686
|
-
return readers;
|
|
2687
|
-
}
|
|
2688
|
-
const property = first(properties);
|
|
2689
|
-
if (propertiesUtil.has(binding.excludeProperties, property)) return UNREAD;
|
|
2690
|
-
readers = mergePropertyReaders(readers, binding, property, properties);
|
|
2691
|
-
for (const alias of binding.aliases) readers = mergePropertyReaders(readers, alias, property, properties);
|
|
2692
|
-
return readers;
|
|
2699
|
+
const folding = {
|
|
2700
|
+
readers: reason ? {
|
|
2701
|
+
reason,
|
|
2702
|
+
lands: 0
|
|
2703
|
+
} : UNREAD,
|
|
2704
|
+
head
|
|
2705
|
+
};
|
|
2706
|
+
forEachStep(binding, properties, READERS_STEP, folding);
|
|
2707
|
+
return folding.readers;
|
|
2693
2708
|
}
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2709
|
+
const READERS_STEP = {
|
|
2710
|
+
land(folding, read, binding) {
|
|
2711
|
+
folding.readers = landIn(folding.readers, read, binding, folding.head);
|
|
2712
|
+
},
|
|
2713
|
+
reach(folding, binding, path, exprs) {
|
|
2714
|
+
folding.readers = mergeReaders(folding.readers, readersOf(binding, path, exprs));
|
|
2715
|
+
}
|
|
2716
|
+
};
|
|
2717
|
+
function landIn(readers, read, binding, head) {
|
|
2718
|
+
if (read.isEffect) return head === "content" && read.rendersContent && bindingUtil.has(read.spreadFrom, binding) ? readers : mergeReaders(readers, ALWAYS_READ);
|
|
2719
|
+
return withLands(isReturned(read) ? mergeReaders(readers, ALWAYS_READ) : readers, getLandingBits(read, binding));
|
|
2697
2720
|
}
|
|
2698
2721
|
function mergeReaders(a, b) {
|
|
2699
2722
|
if (a === UNREAD) return b;
|
|
2700
2723
|
if (b === UNREAD) return a;
|
|
2701
2724
|
const reason = mergeSources(a.reason, b.reason);
|
|
2702
2725
|
const lands = a.lands | b.lands;
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
if (reason === a.reason && lands === a.lands && sites === a.sites && deepSites === a.deepSites) return a;
|
|
2706
|
-
if (reason === b.reason && lands === b.lands && sites === b.sites && deepSites === b.deepSites) return b;
|
|
2726
|
+
if (reason === a.reason && lands === a.lands) return a;
|
|
2727
|
+
if (reason === b.reason && lands === b.lands) return b;
|
|
2707
2728
|
return {
|
|
2708
2729
|
reason,
|
|
2709
|
-
lands
|
|
2710
|
-
|
|
2711
|
-
|
|
2730
|
+
lands
|
|
2731
|
+
};
|
|
2732
|
+
}
|
|
2733
|
+
function withLands(readers, lands) {
|
|
2734
|
+
return (readers.lands | lands) === readers.lands ? readers : {
|
|
2735
|
+
reason: readers.reason,
|
|
2736
|
+
lands: readers.lands | lands
|
|
2712
2737
|
};
|
|
2713
2738
|
}
|
|
2714
|
-
function
|
|
2715
|
-
return
|
|
2739
|
+
function getLandingBits(read, binding) {
|
|
2740
|
+
return read.retained ? isNamedBy(read, binding) ? LANDS_RETAINED : 3 : 0;
|
|
2716
2741
|
}
|
|
2717
|
-
function
|
|
2718
|
-
return
|
|
2742
|
+
function isNamedBy(read, binding) {
|
|
2743
|
+
return every(binding.reads?.get(read), isTagNameRead);
|
|
2719
2744
|
}
|
|
2720
2745
|
function isTagNameRead({ extra }) {
|
|
2721
2746
|
return !!extra.exprRoot?.tagName;
|
|
2722
2747
|
}
|
|
2723
|
-
function
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2748
|
+
function isLeftOut(binding, properties) {
|
|
2749
|
+
return properties !== void 0 && properties !== true && propertiesUtil.has(binding.excludeProperties, first(properties));
|
|
2750
|
+
}
|
|
2751
|
+
function forEachStep(binding, properties, step, state) {
|
|
2752
|
+
const aliased = binding.aliasOf;
|
|
2753
|
+
if (properties !== true && aliased) step.reach(state, aliased, concat(binding.property, properties), void 0);
|
|
2754
|
+
if (binding.reads) for (const read of binding.reads.keys()) {
|
|
2755
|
+
step.land(state, read, binding);
|
|
2756
|
+
if (!read.isEffect) forEachDerivedStep(read, binding, properties, step, state);
|
|
2757
|
+
}
|
|
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) {
|
|
2762
|
+
const property = first(properties);
|
|
2763
|
+
let part = binding.propertyAliases?.get(property);
|
|
2764
|
+
if (part) step.reach(state, part, rest(properties), void 0);
|
|
2765
|
+
if (binding.aliases) for (const alias of binding.aliases) {
|
|
2766
|
+
part = alias.propertyAliases?.get(property);
|
|
2767
|
+
if (part) step.reach(state, part, rest(properties), void 0);
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
function forEachDerivedStep(read, part, properties, step, state) {
|
|
2772
|
+
const { derives } = read;
|
|
2773
|
+
if (!isReturned(read)) for (let i = 0; i < size(derives); i++) {
|
|
2774
|
+
const binding = at(derives, i);
|
|
2775
|
+
if (!isPartOf(binding, part)) step.reach(state, binding, getDerivedPath(read, binding, part, properties), binding.exposed ? read.callSiteExprs : void 0);
|
|
2776
|
+
}
|
|
2777
|
+
}
|
|
2778
|
+
function isReturned(extra) {
|
|
2779
|
+
return extra === (0, _marko_compiler_babel_utils.getProgram)().node.extra.section.returnValueExpr;
|
|
2780
|
+
}
|
|
2781
|
+
function someReachedRead(binding, properties, test) {
|
|
2782
|
+
const walk = {
|
|
2783
|
+
test,
|
|
2784
|
+
found: false,
|
|
2785
|
+
pastCall: false,
|
|
2786
|
+
walked: /* @__PURE__ */ new Set(),
|
|
2787
|
+
walkedPastCall: /* @__PURE__ */ new Set()
|
|
2729
2788
|
};
|
|
2730
|
-
|
|
2789
|
+
walkFrom(walk, binding, properties);
|
|
2790
|
+
return walk.found;
|
|
2791
|
+
}
|
|
2792
|
+
const WALK_STEP = {
|
|
2793
|
+
land(walk, read, binding) {
|
|
2794
|
+
walk.found ||= walk.test(read, binding, walk.pastCall);
|
|
2795
|
+
},
|
|
2796
|
+
reach(walk, binding, path, exprs) {
|
|
2797
|
+
const { pastCall } = walk;
|
|
2798
|
+
walk.pastCall ||= !!exprs;
|
|
2799
|
+
walkFrom(walk, binding, path);
|
|
2800
|
+
walk.pastCall = pastCall;
|
|
2801
|
+
}
|
|
2802
|
+
};
|
|
2803
|
+
function walkFrom(walk, binding, properties) {
|
|
2804
|
+
const seen = walk.pastCall ? walk.walkedPastCall : walk.walked;
|
|
2805
|
+
const key = getWalkKey(binding, properties);
|
|
2806
|
+
if (walk.found || seen.has(key) || isLeftOut(binding, properties)) return;
|
|
2807
|
+
seen.add(key);
|
|
2808
|
+
forEachStep(binding, properties, WALK_STEP, walk);
|
|
2731
2809
|
}
|
|
2732
2810
|
// src/common/helpers.ts
|
|
2733
2811
|
const invalidNativeAttrNameReg = /^[^a-z_]|[^a-z0-9._:-]/i;
|
|
@@ -3572,6 +3650,7 @@ function ensureBodySection(path) {
|
|
|
3572
3650
|
abortSignalExprs: 0,
|
|
3573
3651
|
readsOwner: false,
|
|
3574
3652
|
hasSetupWork: false,
|
|
3653
|
+
hasReturnedVar: false,
|
|
3575
3654
|
branch: void 0,
|
|
3576
3655
|
structure: parentSection && !parentSection.structure ? null : []
|
|
3577
3656
|
};
|
|
@@ -3610,7 +3689,7 @@ function forEachSection(fn) {
|
|
|
3610
3689
|
}
|
|
3611
3690
|
function getDynamicTagContentClosures(section) {
|
|
3612
3691
|
const { derives } = section;
|
|
3613
|
-
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);
|
|
3614
3693
|
}
|
|
3615
3694
|
function mayBeUnwritten(closure) {
|
|
3616
3695
|
const reason = getWriteReason(closure);
|
|
@@ -3683,17 +3762,21 @@ function getNodeContentType(path, edge) {
|
|
|
3683
3762
|
function isKnownChild(section) {
|
|
3684
3763
|
return !section.parent || !!section.renderedBy;
|
|
3685
3764
|
}
|
|
3686
|
-
const [getSectionTextBefore] = createAnalysisMemo(
|
|
3687
|
-
function
|
|
3765
|
+
const [getSectionTextBefore] = createAnalysisMemo(computeSectionTextBefore, false);
|
|
3766
|
+
function computeSectionTextBefore(section) {
|
|
3688
3767
|
const { branch, derives } = section;
|
|
3689
|
-
if (branch)
|
|
3690
|
-
const { tag } = branch;
|
|
3691
|
-
const tagSection = tag.nodeBinding.section;
|
|
3692
|
-
return !isStartMarked(branch, section, content) && (branch.kind === "for" && mayEndWithText(section) || (tag.textBefore ?? (content ? getTextBeforeIn(tagSection, content) : getSectionTextBefore(tagSection))));
|
|
3693
|
-
}
|
|
3768
|
+
if (branch) return getBranchTextBefore(branch, section, void 0);
|
|
3694
3769
|
if (!section.parent) return void 0;
|
|
3695
3770
|
return !derives || !!section.renderedBy || mayContentFollowText(section);
|
|
3696
3771
|
}
|
|
3772
|
+
function getTextBeforeIn(section, content) {
|
|
3773
|
+
const { branch } = section;
|
|
3774
|
+
return content && branch ? getBranchTextBefore(branch, section, content) : getSectionTextBefore(section);
|
|
3775
|
+
}
|
|
3776
|
+
function getBranchTextBefore(branch, section, content) {
|
|
3777
|
+
const { tag } = branch;
|
|
3778
|
+
return !isStartMarked(branch, section, content) && (isLoopBody(section) && mayEndWithText(section) || (tag.textBefore ?? getTextBeforeIn(tag.nodeBinding.section, content)));
|
|
3779
|
+
}
|
|
3697
3780
|
function mayContentFollowText(section) {
|
|
3698
3781
|
const { tag } = section.derives;
|
|
3699
3782
|
const { unseen, sites, deepSites } = getContentSites(section.derives);
|
|
@@ -3709,9 +3792,9 @@ function getSiteTextBefore(site, content) {
|
|
|
3709
3792
|
function isStartMarked(branch, section, content) {
|
|
3710
3793
|
const { nodeBinding } = branch.tag;
|
|
3711
3794
|
const tagSection = nodeBinding.section;
|
|
3712
|
-
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));
|
|
3713
3796
|
}
|
|
3714
|
-
function isAlwaysWritten(section, reason, content) {
|
|
3797
|
+
function isAlwaysWritten$1(section, reason, content) {
|
|
3715
3798
|
return content ? isWrittenForCall(section, reason, content.derives.tag, content.parent) : getWriteBit(section, reason) === 1;
|
|
3716
3799
|
}
|
|
3717
3800
|
function mayEndWithText(section) {
|
|
@@ -3758,16 +3841,22 @@ function getRendererReason(section) {
|
|
|
3758
3841
|
if (isOptionalBranch(section)) return false;
|
|
3759
3842
|
if (section.branchExpr?.tagNameType === 0) return false;
|
|
3760
3843
|
const { derives } = section;
|
|
3761
|
-
if (derives)
|
|
3762
|
-
const
|
|
3763
|
-
return
|
|
3764
|
-
|
|
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
|
+
}
|
|
3765
3851
|
return ALWAYS;
|
|
3766
3852
|
}
|
|
3767
3853
|
function isOptionalBranch(section) {
|
|
3768
3854
|
const kind = section.branch?.kind;
|
|
3769
3855
|
return kind === "if" || kind === "for";
|
|
3770
3856
|
}
|
|
3857
|
+
function isLoopBody(section) {
|
|
3858
|
+
return section.branch?.kind === "for";
|
|
3859
|
+
}
|
|
3771
3860
|
function isInParentSection(binding, section) {
|
|
3772
3861
|
return section.parent?.id === binding.section.id;
|
|
3773
3862
|
}
|
|
@@ -3790,7 +3879,7 @@ function getForClosureIndex(closure, closureSection) {
|
|
|
3790
3879
|
let index = 0;
|
|
3791
3880
|
find(closure.closureSections, (section) => {
|
|
3792
3881
|
if (section === closureSection) return true;
|
|
3793
|
-
if (section
|
|
3882
|
+
if (isLoopBody(section) && section.parent === closure.section && !isForSelectorClosure(section, closure)) index++;
|
|
3794
3883
|
return false;
|
|
3795
3884
|
});
|
|
3796
3885
|
return index;
|
|
@@ -3811,10 +3900,6 @@ function getCommonSection(section, other) {
|
|
|
3811
3900
|
else b = b.parent;
|
|
3812
3901
|
return a;
|
|
3813
3902
|
}
|
|
3814
|
-
function ensureSectionReasonGroups(section) {
|
|
3815
|
-
ensureReasonGroups(section, section.reason);
|
|
3816
|
-
for (const slot of section.slots) ensureReasonGroups(slot.section, slot.reason);
|
|
3817
|
-
}
|
|
3818
3903
|
function ensureReasonGroups(section, reason) {
|
|
3819
3904
|
const ownReason = mapBodyParams(section, reason);
|
|
3820
3905
|
if (isGuardedReason(ownReason)) forEachParamGroup(ownReason.param, ensureParamReasonGroup);
|
|
@@ -3886,22 +3971,24 @@ function exposeParamsTree(binding, bodyAnalyzed) {
|
|
|
3886
3971
|
properties: void 0,
|
|
3887
3972
|
rest: void 0
|
|
3888
3973
|
};
|
|
3889
|
-
if (!binding.reads
|
|
3974
|
+
if (!binding.reads) {
|
|
3890
3975
|
let restAlias;
|
|
3891
3976
|
let aliasCount = 0;
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3977
|
+
if (binding.aliases) {
|
|
3978
|
+
for (const alias of binding.aliases) if (!bodyAnalyzed || isPossiblyRead(alias)) {
|
|
3979
|
+
restAlias = alias;
|
|
3980
|
+
if (++aliasCount > 1) break;
|
|
3981
|
+
}
|
|
3895
3982
|
}
|
|
3896
3983
|
if (!restAlias) {
|
|
3897
3984
|
tree.properties = Object.create(null);
|
|
3898
|
-
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);
|
|
3899
3986
|
} else if (aliasCount === 1) {
|
|
3900
3987
|
if (hasSupersetExcludeProperties(binding, restAlias.excludeProperties)) {
|
|
3901
3988
|
tree.rest = exposeParamsTree(restAlias, bodyAnalyzed);
|
|
3902
3989
|
tree.properties = Object.create(null);
|
|
3903
3990
|
forEach(restAlias.excludeProperties, (property) => {
|
|
3904
|
-
const propAlias = binding.propertyAliases
|
|
3991
|
+
const propAlias = binding.propertyAliases?.get(property);
|
|
3905
3992
|
if (propAlias) tree.properties[property] = exposeParamsTree(propAlias, bodyAnalyzed);
|
|
3906
3993
|
});
|
|
3907
3994
|
}
|
|
@@ -3913,19 +4000,25 @@ function exposeParamsTree(binding, bodyAnalyzed) {
|
|
|
3913
4000
|
return tree;
|
|
3914
4001
|
}
|
|
3915
4002
|
function isDirectContentBinding(binding) {
|
|
3916
|
-
if (binding.reads
|
|
4003
|
+
if (binding.reads?.size !== 1) return false;
|
|
3917
4004
|
const [[expr, read]] = binding.reads;
|
|
3918
4005
|
return expr.nameOnly && expr.section === binding.section && !Array.isArray(read) && !!read.extra.tagName;
|
|
3919
4006
|
}
|
|
3920
4007
|
function isPossiblyRead(alias) {
|
|
3921
|
-
if (alias.reads
|
|
3922
|
-
|
|
3923
|
-
|
|
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
|
+
}
|
|
3924
4015
|
return false;
|
|
3925
4016
|
}
|
|
3926
4017
|
function hasSupersetExcludeProperties(binding, excludeProperties) {
|
|
3927
4018
|
if (excludeProperties === void 0) return false;
|
|
3928
|
-
|
|
4019
|
+
if (binding.propertyAliases) {
|
|
4020
|
+
for (const prop of binding.propertyAliases.keys()) if (!propertiesUtil.has(excludeProperties, prop)) return false;
|
|
4021
|
+
}
|
|
3929
4022
|
return true;
|
|
3930
4023
|
}
|
|
3931
4024
|
function getSettledParamsTree(paramsTree) {
|
|
@@ -4035,14 +4128,14 @@ function getScopeOffsetAccessor(nodeBinding) {
|
|
|
4035
4128
|
return isOptimize() ? decodeAccessor(id) : `#scopeOffset/${id}`;
|
|
4036
4129
|
}
|
|
4037
4130
|
function getReservedId(binding, offset) {
|
|
4038
|
-
return
|
|
4131
|
+
return binding.canonical.id + offset;
|
|
4039
4132
|
}
|
|
4040
4133
|
function getScopeAccessorLiteral(binding, encoded, includeId) {
|
|
4041
|
-
const canonicalBinding =
|
|
4134
|
+
const canonicalBinding = binding.canonical;
|
|
4042
4135
|
return encoded && isOptimize() && canonicalBinding.type !== 5 ? _marko_compiler.types.numericLiteral(canonicalBinding.id) : _marko_compiler.types.stringLiteral(getScopeAccessor(binding, encoded, includeId));
|
|
4043
4136
|
}
|
|
4044
4137
|
function getScopeAccessor(binding, encoded, includeId) {
|
|
4045
|
-
const canonicalBinding =
|
|
4138
|
+
const canonicalBinding = binding.canonical;
|
|
4046
4139
|
if (canonicalBinding.type === 5) return canonicalBinding.scopeAccessor ?? canonicalBinding.name;
|
|
4047
4140
|
else if (isOptimize()) return encoded ? canonicalBinding.id + "" : decodeAccessor(canonicalBinding.id);
|
|
4048
4141
|
const name = reservedDebugAccessors.has(canonicalBinding.name) ? `${canonicalBinding.name}/${canonicalBinding.id}` : canonicalBinding.name;
|
|
@@ -4054,7 +4147,7 @@ function getLocalsScopeAccessor(binding) {
|
|
|
4054
4147
|
return getScopeAccessor(binding, false, true);
|
|
4055
4148
|
}
|
|
4056
4149
|
function getPrefixedScopeAccessor(binding, prefix) {
|
|
4057
|
-
const canonicalBinding =
|
|
4150
|
+
const canonicalBinding = binding.canonical;
|
|
4058
4151
|
if (isOptimize()) switch (prefix) {
|
|
4059
4152
|
case getAccessorPrefix().TagVariableChange: return decodeAccessor(getReservedId(canonicalBinding, 1));
|
|
4060
4153
|
case getAccessorPrefix().ClosureScopes: return decodeAccessor(getClosureAccessorId(canonicalBinding));
|
|
@@ -4070,7 +4163,7 @@ function getDebugClosureAccessor(binding) {
|
|
|
4070
4163
|
return `${getScopeAccessor(binding)}/${getClosureAccessorId(binding)}`;
|
|
4071
4164
|
}
|
|
4072
4165
|
function getClosureAccessorId(binding) {
|
|
4073
|
-
const id =
|
|
4166
|
+
const id = binding.canonical.closureId;
|
|
4074
4167
|
/* v8 ignore next 5 -- analyze reserves an id for every closure binding */
|
|
4075
4168
|
if (id === void 0) throw new Error(`No closure accessor id was reserved for "${binding.name}".`);
|
|
4076
4169
|
return id;
|
|
@@ -4108,16 +4201,18 @@ function getSectionRendererIdentifier(section) {
|
|
|
4108
4201
|
return isSectionRendererElided(section) ? void 0 : _marko_compiler.types.identifier(section.name);
|
|
4109
4202
|
}
|
|
4110
4203
|
function isSectionRendererElided(section) {
|
|
4111
|
-
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);
|
|
4112
4205
|
}
|
|
4113
4206
|
function isPropertyPathRead(binding, properties) {
|
|
4114
4207
|
if (binding.pruned) return false;
|
|
4115
4208
|
else if (binding.pruned === void 0) throw new Error("Binding must be pruned before checking properties");
|
|
4116
|
-
if (binding.reads
|
|
4209
|
+
if (binding.reads || !properties) return true;
|
|
4117
4210
|
const property = first(properties);
|
|
4118
|
-
const propBinding = binding.propertyAliases
|
|
4211
|
+
const propBinding = binding.propertyAliases?.get(property);
|
|
4119
4212
|
if (propBinding && isPropertyPathRead(propBinding, rest(properties))) return true;
|
|
4120
|
-
|
|
4213
|
+
if (binding.aliases) {
|
|
4214
|
+
for (const alias of binding.aliases) if (isPropertyPathRead(alias, properties)) return true;
|
|
4215
|
+
}
|
|
4121
4216
|
return false;
|
|
4122
4217
|
}
|
|
4123
4218
|
// src/translator/util/setup-work.ts
|
|
@@ -4195,11 +4290,12 @@ function excludeAssignedChangeHandlers() {
|
|
|
4195
4290
|
const excluded = /* @__PURE__ */ new Set();
|
|
4196
4291
|
for (const { assignment: binding } of getAssignments()) if (binding.assignments && binding.aliasOf && binding.property !== void 0 && !excluded.has(binding)) {
|
|
4197
4292
|
excluded.add(binding);
|
|
4198
|
-
|
|
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
|
+
}
|
|
4199
4296
|
}
|
|
4200
4297
|
}
|
|
4201
4298
|
function resolveReads(intersectionsBySection) {
|
|
4202
|
-
const fnReadsByExpression = getFunctionReadsByExpression();
|
|
4203
4299
|
for (const [expr, reads] of getReadsByExpression()) if (isReferencedExtra(expr)) {
|
|
4204
4300
|
const exprBindings = resolveReferencedBindings(expr, reads, intersectionsBySection);
|
|
4205
4301
|
setResolvedReads(expr, exprBindings.referencedBindings, exprBindings.lazyBindings);
|
|
@@ -4222,18 +4318,42 @@ function resolveReads(intersectionsBySection) {
|
|
|
4222
4318
|
forEach(exprBindings.constantBindings, addAlwaysReason);
|
|
4223
4319
|
}
|
|
4224
4320
|
forEach(exprBindings.lazyBindings, addAlwaysReason);
|
|
4225
|
-
} else forEach(reads,
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
}
|
|
4321
|
+
} else forEach(reads, addRetainedReadReason, expr);
|
|
4322
|
+
if (exprBindings.allBindings) resolveFunctionReads(expr, exprBindings, exprBindings.allBindings, reads);
|
|
4323
|
+
}
|
|
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);
|
|
4235
4330
|
}
|
|
4236
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
|
+
}
|
|
4237
4357
|
function resolveBindings() {
|
|
4238
4358
|
const bindingNamesBySection = /* @__PURE__ */ new Map();
|
|
4239
4359
|
for (const binding of getBindings()) {
|
|
@@ -4244,14 +4364,11 @@ function resolveBindings() {
|
|
|
4244
4364
|
}
|
|
4245
4365
|
if (binding.type !== 0) {
|
|
4246
4366
|
resolveBindingSources(binding);
|
|
4247
|
-
forEach(binding.assignments,
|
|
4248
|
-
setReadsOwner(assignedSection, section);
|
|
4249
|
-
addOwnerReason(assignedSection, section, ALWAYS);
|
|
4250
|
-
});
|
|
4367
|
+
forEach(binding.assignments, addAssignmentOwnerReason, section);
|
|
4251
4368
|
let bindingNames = bindingNamesBySection.get(section);
|
|
4252
4369
|
if (!bindingNames) {
|
|
4253
4370
|
bindingNamesBySection.set(section, bindingNames = /* @__PURE__ */ new Set());
|
|
4254
|
-
forEach(section.bindings,
|
|
4371
|
+
forEach(section.bindings, addBindingName, bindingNames);
|
|
4255
4372
|
}
|
|
4256
4373
|
if (bindingNames.has(binding.name)) binding.name = generateUid(name);
|
|
4257
4374
|
}
|
|
@@ -4264,21 +4381,16 @@ function resolveBindings() {
|
|
|
4264
4381
|
if (section.parent !== highestHoistSection) section.parent.isHoistThrough = true;
|
|
4265
4382
|
}
|
|
4266
4383
|
}
|
|
4267
|
-
const canonicalBinding =
|
|
4384
|
+
const canonicalBinding = binding.canonical;
|
|
4268
4385
|
if (canonicalBinding === binding) section.bindings = bindingUtil.add(section.bindings, binding);
|
|
4269
4386
|
bindingNamesBySection.get(section)?.add(canonicalBinding.name);
|
|
4270
4387
|
if (binding.localOf) section.localClosures = bindingUtil.add(section.localClosures, binding);
|
|
4271
4388
|
}
|
|
4272
4389
|
}
|
|
4273
4390
|
function addSectionReasons(section) {
|
|
4274
|
-
if (section.readsOwner) forEach(section.renderedBy,
|
|
4275
|
-
setReadsOwner(call.childScopeBinding.section, section.parent);
|
|
4276
|
-
});
|
|
4391
|
+
if (section.readsOwner) forEach(section.renderedBy, setCallReadsOwner, section.parent);
|
|
4277
4392
|
if (section.isHoistThrough) addReason(ensureSectionSlot(section, 6), ALWAYS);
|
|
4278
|
-
forEach(section.referencedClosures,
|
|
4279
|
-
closure.closureSections = sectionUtil.add(closure.closureSections, section);
|
|
4280
|
-
addOwnerReason(section, closure.section, closure.sources);
|
|
4281
|
-
});
|
|
4393
|
+
forEach(section.referencedClosures, addClosureSection, section);
|
|
4282
4394
|
if (isOptionalBranch(section)) {
|
|
4283
4395
|
const closureSources = getSourcesForReferencedBindings(getDirectClosures(section));
|
|
4284
4396
|
const branchSlot = ensureSectionSlot(section, 9);
|
|
@@ -4363,14 +4475,15 @@ function getWalkedBinding(op) {
|
|
|
4363
4475
|
return typeof op === "object" && (op.kind === "node" || op.kind === "child") ? op.binding : void 0;
|
|
4364
4476
|
}
|
|
4365
4477
|
function getLastOwnSourceReturn(bindings, section) {
|
|
4478
|
+
if (!section.hasReturnedVar) return;
|
|
4366
4479
|
let last;
|
|
4367
4480
|
const seen = /* @__PURE__ */ new Set();
|
|
4368
4481
|
const track = (binding) => {
|
|
4369
4482
|
if (binding.section === section && !seen.has(binding)) {
|
|
4370
4483
|
seen.add(binding);
|
|
4371
|
-
const { returnedBy } =
|
|
4484
|
+
const { returnedBy } = binding;
|
|
4372
4485
|
if (returnedBy && (!last || last.id < returnedBy.scope.id)) last = returnedBy.scope;
|
|
4373
|
-
|
|
4486
|
+
forEach(getBindingsDerivedFrom(binding), track);
|
|
4374
4487
|
forEach(binding.sources?.state, track);
|
|
4375
4488
|
forEach(binding.sources?.param, track);
|
|
4376
4489
|
}
|
|
@@ -4404,17 +4517,8 @@ function resolveBindingSources(binding) {
|
|
|
4404
4517
|
if (resolvedSources.has(binding)) return;
|
|
4405
4518
|
resolvedSources.add(binding);
|
|
4406
4519
|
switch (binding.type) {
|
|
4407
|
-
case 1: {
|
|
4408
|
-
const aliasRoot = getAliasRoot(binding);
|
|
4409
|
-
if (aliasRoot !== binding) {
|
|
4410
|
-
resolveBindingSources(aliasRoot);
|
|
4411
|
-
binding.sources = aliasRoot.sources;
|
|
4412
|
-
} else if (binding.assignments) binding.sources = createSources(binding, void 0);
|
|
4413
|
-
else resolveDerivedSources(binding);
|
|
4414
|
-
return;
|
|
4415
|
-
}
|
|
4416
4520
|
case 2:
|
|
4417
|
-
binding.sources = createSources(void 0,
|
|
4521
|
+
binding.sources = createSources(void 0, binding.canonical);
|
|
4418
4522
|
return;
|
|
4419
4523
|
case 6:
|
|
4420
4524
|
binding.sources = globalSources;
|
|
@@ -4422,12 +4526,10 @@ function resolveBindingSources(binding) {
|
|
|
4422
4526
|
}
|
|
4423
4527
|
const aliasRoot = getAliasRoot(binding);
|
|
4424
4528
|
if (aliasRoot !== binding) {
|
|
4425
|
-
|
|
4426
|
-
resolvedSources.add(aliasRoot);
|
|
4427
|
-
resolveDerivedSources(aliasRoot);
|
|
4428
|
-
}
|
|
4529
|
+
resolveBindingSources(aliasRoot);
|
|
4429
4530
|
binding.sources = aliasRoot.sources;
|
|
4430
|
-
} else
|
|
4531
|
+
} else if (binding.type === 1 && binding.assignments) binding.sources = createSources(binding, void 0);
|
|
4532
|
+
else resolveDerivedSources(binding);
|
|
4431
4533
|
}
|
|
4432
4534
|
function resolveDerivedSources(binding) {
|
|
4433
4535
|
const exprs = binding.derivedFrom;
|
|
@@ -4480,22 +4582,33 @@ function isPrunedBinding(binding) {
|
|
|
4480
4582
|
function pruneBinding(binding) {
|
|
4481
4583
|
if (binding.pruned !== void 0) return binding.pruned;
|
|
4482
4584
|
binding.pruned = false;
|
|
4483
|
-
for (const read of binding.reads.keys()) pruneDerived(read);
|
|
4585
|
+
if (binding.reads) for (const read of binding.reads.keys()) pruneDerived(read);
|
|
4484
4586
|
forEach(binding.assignments, pruneAssignmentDerived);
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
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
|
+
}
|
|
4491
4597
|
}
|
|
4598
|
+
if (!binding.reads.size) binding.reads = void 0;
|
|
4492
4599
|
}
|
|
4493
4600
|
let shouldPrune = true;
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
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));
|
|
4499
4612
|
binding.pruned = shouldPrune;
|
|
4500
4613
|
if (shouldPrune && !hasEmittedAssignment(binding)) {
|
|
4501
4614
|
if (binding.derivedFrom) forEach(binding.derivedFrom, dropUnreadValue);
|
|
@@ -4511,14 +4624,14 @@ function pruneAssignmentDerived({ exprRoot }) {
|
|
|
4511
4624
|
function pruneDerived(expr) {
|
|
4512
4625
|
if (isDroppableValue(expr)) forEach(expr.derives, pruneBinding);
|
|
4513
4626
|
}
|
|
4514
|
-
function resolveReferencedBindingsInFunction(
|
|
4627
|
+
function resolveReferencedBindingsInFunction(refs, reads) {
|
|
4515
4628
|
let referencedBindings;
|
|
4516
4629
|
let constantBindings;
|
|
4517
4630
|
const closest = /* @__PURE__ */ new Set();
|
|
4518
|
-
forEach(reads, ({ getter, binding }) => {
|
|
4631
|
+
forEach(reads, ({ getter, binding, holder }) => {
|
|
4519
4632
|
if (getter) {} else if (binding.type === 5) {
|
|
4520
4633
|
if (bindingUtil.has(refs, binding)) constantBindings = bindingUtil.add(constantBindings, binding);
|
|
4521
|
-
} else if (binding.type !== 0 && binding.type !== 6) closest.add(
|
|
4634
|
+
} else if (binding.type !== 0 && binding.type !== 6) closest.add(holder);
|
|
4522
4635
|
});
|
|
4523
4636
|
if (closest.size) referencedBindings = bindingUtil.filter(refs, (ref) => closest.has(ref));
|
|
4524
4637
|
return {
|
|
@@ -4528,19 +4641,20 @@ function resolveReferencedBindingsInFunction(expr, refs, reads) {
|
|
|
4528
4641
|
}
|
|
4529
4642
|
function getNearestReadBy(binding, expr) {
|
|
4530
4643
|
let cur = binding;
|
|
4531
|
-
while (!cur.reads
|
|
4644
|
+
while (!cur.reads?.has(expr)) {
|
|
4532
4645
|
if (!cur.aliasOf || isRest(cur)) return;
|
|
4533
4646
|
cur = cur.aliasOf;
|
|
4534
4647
|
}
|
|
4535
4648
|
return cur;
|
|
4536
4649
|
}
|
|
4537
4650
|
function markLazyRead(binding) {
|
|
4538
|
-
|
|
4651
|
+
binding.canonical.hasLazyReads = true;
|
|
4539
4652
|
}
|
|
4540
4653
|
function addBindingGetter(binding, { invoked, hoisted }) {
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
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);
|
|
4544
4658
|
}
|
|
4545
4659
|
}
|
|
4546
4660
|
function isLazyRead(read, binding, isChangeHandlerRead) {
|
|
@@ -4561,7 +4675,7 @@ function resolveReferencedBindings(expr, reads, intersectionsBySection) {
|
|
|
4561
4675
|
const { extra, getter } = read;
|
|
4562
4676
|
if (getter) {
|
|
4563
4677
|
extra.section = expr.section;
|
|
4564
|
-
extra.read =
|
|
4678
|
+
extra.read = createResolvedRead(binding, void 0, false, getter);
|
|
4565
4679
|
addBindingGetter(binding, getter);
|
|
4566
4680
|
if (getter.hoisted) {
|
|
4567
4681
|
binding.hoists = sectionUtil.add(binding.hoists, getter.hoisted);
|
|
@@ -4569,14 +4683,14 @@ function resolveReferencedBindings(expr, reads, intersectionsBySection) {
|
|
|
4569
4683
|
}
|
|
4570
4684
|
} else {
|
|
4571
4685
|
const isChangeHandlerRead = extra.assignmentTo === binding;
|
|
4572
|
-
if (isChangeHandlerRead) binding =
|
|
4686
|
+
if (isChangeHandlerRead) binding = read.holder;
|
|
4573
4687
|
else if (binding.type !== 6) {
|
|
4574
4688
|
extra.section = expr.section;
|
|
4575
|
-
({binding} = extra.read = resolveConstantReference(binding) ?? resolveExpressionReference(
|
|
4689
|
+
({binding} = extra.read = resolveConstantReference(binding) ?? resolveExpressionReference(read));
|
|
4576
4690
|
}
|
|
4577
4691
|
if (binding.type === 6) globalBindings = bindingUtil.add(globalBindings, binding);
|
|
4578
4692
|
else if (binding.type !== 0) {
|
|
4579
|
-
const closure = binding.section !== expr.section &&
|
|
4693
|
+
const closure = binding.section !== expr.section && binding.canonical;
|
|
4580
4694
|
if (isLazyRead(read, binding, isChangeHandlerRead)) lazyBindings = bindingUtil.add(lazyBindings, binding);
|
|
4581
4695
|
else if (binding.type === 5) {
|
|
4582
4696
|
constantBindings = bindingUtil.add(constantBindings, binding);
|
|
@@ -4627,18 +4741,18 @@ function getConstantRoot(binding) {
|
|
|
4627
4741
|
}
|
|
4628
4742
|
return root;
|
|
4629
4743
|
}
|
|
4630
|
-
function resolveExpressionReference(
|
|
4631
|
-
const holder = getNearestReadBy(binding, expr);
|
|
4744
|
+
function resolveExpressionReference({ binding, holder, inOwnBody }) {
|
|
4632
4745
|
return holder === binding ? createResolvedRead(binding, void 0, inOwnBody) : createResolvedRead(holder, getPropertyPath(binding, holder));
|
|
4633
4746
|
}
|
|
4634
4747
|
// src/translator/util/get-declared-binding-expression.ts
|
|
4635
4748
|
function getDeclaredBindingExpression(binding, inPlace = false) {
|
|
4636
|
-
const canonicalBinding =
|
|
4749
|
+
const canonicalBinding = binding.canonical;
|
|
4637
4750
|
if (canonicalBinding.localOf) return getDeclaredBindingExpression(canonicalBinding.localOf, inPlace);
|
|
4638
|
-
const { aliasOf: aliased, property
|
|
4751
|
+
const { aliasOf: aliased, property } = canonicalBinding;
|
|
4639
4752
|
if (binding.declared) return _marko_compiler.types.identifier(binding.name);
|
|
4640
4753
|
if (canonicalBinding.declared || isRest(canonicalBinding)) return _marko_compiler.types.identifier(canonicalBinding.name);
|
|
4641
|
-
|
|
4754
|
+
const declaredAlias = getDeclaredAlias(canonicalBinding);
|
|
4755
|
+
if (declaredAlias && !isRest(declaredAlias)) return _marko_compiler.types.identifier(declaredAlias.name);
|
|
4642
4756
|
if (!aliased) return _marko_compiler.types.identifier(canonicalBinding.name);
|
|
4643
4757
|
if (property !== void 0) {
|
|
4644
4758
|
const alias = getDeclaredAlias(aliased);
|
|
@@ -4687,7 +4801,7 @@ function getDOMReadBase(read, section, signal) {
|
|
|
4687
4801
|
if (read.localFn) return isRegisteredFnExtra(read.localFn) ? toMemberExpression(localsIdentifier, getLocalsScopeAccessor(binding)) : _marko_compiler.types.identifier(binding.name);
|
|
4688
4802
|
const inlined = getSignals(section).get(binding)?.inline?.value;
|
|
4689
4803
|
if (inlined) return _marko_compiler.types.cloneNode(inlined, true);
|
|
4690
|
-
if (signal?.referencedBindings === binding && !signal.storesValue) return
|
|
4804
|
+
if (signal?.referencedBindings === binding && !signal.storesValue) return _marko_compiler.types.identifier(binding.canonical.name);
|
|
4691
4805
|
if (getter?.hoisted) return binding.aliasOf ? callRuntime("_hoist_read_error") : _marko_compiler.types.callExpression(getBindingGetterIdentifier(binding, getter.hoisted), [getScopeExpression(section, getter.hoisted)]);
|
|
4692
4806
|
if (properties === void 0 && binding.type === 0) return getter && _marko_compiler.types.callExpression(getBindingGetterIdentifier(binding, binding.section), [getScopeExpression(section, binding.section)]);
|
|
4693
4807
|
if (!isOptimize() && read.inOwnBody && isChildReturnVar(binding)) return callRuntime("_assert_init", section ? getScopeExpression(section, binding.section) : scopeIdentifier, getScopeAccessorLiteral(binding));
|
|
@@ -4698,7 +4812,7 @@ function isChildReturnVar(binding) {
|
|
|
4698
4812
|
}
|
|
4699
4813
|
function getHTMLReadBase(node, { binding, getter }) {
|
|
4700
4814
|
if (getter?.hoisted) return binding.aliasOf ? callRuntime("_hoist_read_error") : getBindingGetterIdentifier(binding, getter.hoisted);
|
|
4701
|
-
if (binding.type === 0) return binding.getters
|
|
4815
|
+
if (binding.type === 0) return binding.getters?.has(binding.section) ? getBindingGetterIdentifier(binding, binding.section) : void 0;
|
|
4702
4816
|
let root = node;
|
|
4703
4817
|
while (root.type === "MemberExpression" || root.type === "OptionalMemberExpression") root = root.object;
|
|
4704
4818
|
const rootBinding = root.extra?.binding;
|
|
@@ -4779,7 +4893,7 @@ function translateVar(tag, initialValue, kind = "const", statements) {
|
|
|
4779
4893
|
if (!binding?.aliasOf) return;
|
|
4780
4894
|
if (binding.assignments && binding.property !== void 0) {
|
|
4781
4895
|
const changeName = binding.property + "Change";
|
|
4782
|
-
const changeBinding = binding.aliasOf.propertyAliases
|
|
4896
|
+
const changeBinding = binding.aliasOf.propertyAliases?.get(changeName);
|
|
4783
4897
|
if (changeBinding && changeName !== changeBinding.name) {
|
|
4784
4898
|
const pattern = getDestructurePattern(id);
|
|
4785
4899
|
if (pattern) pattern.unshiftContainer("properties", _marko_compiler.types.objectProperty(toPropertyName(changeName), _marko_compiler.types.identifier(changeBinding.name)));
|
|
@@ -4828,7 +4942,7 @@ function translateAliasInSection(tag, id, alias, kind) {
|
|
|
4828
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))]));
|
|
4829
4943
|
}
|
|
4830
4944
|
function translateRest(tag, id, rest, kind) {
|
|
4831
|
-
const source =
|
|
4945
|
+
const source = rest.aliasOf;
|
|
4832
4946
|
const from = getDeclaredAlias(source) || source;
|
|
4833
4947
|
let target = tag;
|
|
4834
4948
|
let inPlace = true;
|
|
@@ -4959,14 +5073,9 @@ function flushInto(path) {
|
|
|
4959
5073
|
if (expr) target.node.body.push(expr);
|
|
4960
5074
|
return target;
|
|
4961
5075
|
}
|
|
4962
|
-
function markNode(path, nodeBinding,
|
|
5076
|
+
function markNode(path, nodeBinding, deferred) {
|
|
4963
5077
|
if (nodeBinding.type !== 0) throw path.buildCodeFrameError("POTENTIAL MARKO BUG: Tried to mark a node that was not determined to need a mark during analyze.");
|
|
4964
|
-
if (isOutputHTML()) {
|
|
4965
|
-
if (reason) {
|
|
4966
|
-
const section = getSection(path);
|
|
4967
|
-
writeTo$1(path, deferred)`${callRuntime("_el_mark", getScopeIdIdentifier(section), getScopeAccessorLiteral(nodeBinding), getWriteGuard(section, reason, true))}`;
|
|
4968
|
-
}
|
|
4969
|
-
}
|
|
5078
|
+
if (isOutputHTML() && isMarkerWritten(nodeBinding)) writeTo$1(path, deferred)`${callRuntime("_el_mark", getScopeIdIdentifier(nodeBinding.section), getScopeAccessorLiteral(nodeBinding), getMarkerGuard(nodeBinding))}`;
|
|
4970
5079
|
}
|
|
4971
5080
|
function unwrapWrite(write) {
|
|
4972
5081
|
return typeof write === "function" ? write() || "" : write;
|
|
@@ -5049,7 +5158,7 @@ function getSignal(section, referencedBindings, name) {
|
|
|
5049
5158
|
if (referencedBindings && !Array.isArray(referencedBindings)) {
|
|
5050
5159
|
if (referencedBindings.type === 5) return getSignal(section, void 0);
|
|
5051
5160
|
if (referencedBindings.section !== section) {
|
|
5052
|
-
const canonicalReference =
|
|
5161
|
+
const canonicalReference = referencedBindings.canonical;
|
|
5053
5162
|
if (canonicalReference !== referencedBindings) return getSignal(section, canonicalReference);
|
|
5054
5163
|
}
|
|
5055
5164
|
}
|
|
@@ -5086,7 +5195,7 @@ function getSignal(section, referencedBindings, name) {
|
|
|
5086
5195
|
const sourceSignal = getSignal(section, meta.source);
|
|
5087
5196
|
forEach(referencedBindings, (member) => {
|
|
5088
5197
|
const memberSignal = getSignal(section, member);
|
|
5089
|
-
const inline = !member.propertyAliases
|
|
5198
|
+
const inline = !member.propertyAliases && member.reads?.size === 1 && !getWriteReason(member) && sourceSignal.values.find((v) => v.signal === memberSignal);
|
|
5090
5199
|
if (inline) memberSignal.inline = inline;
|
|
5091
5200
|
else memberSignal.storesValue = memberSignal.forceStore = true;
|
|
5092
5201
|
});
|
|
@@ -5097,14 +5206,14 @@ function getSignal(section, referencedBindings, name) {
|
|
|
5097
5206
|
const render = buildSignalFn(signal);
|
|
5098
5207
|
const closureSignalBuilder = getClosureSignalBuilder(section);
|
|
5099
5208
|
if (closureSignalBuilder && isDirectClosure(section, closure)) return closureSignalBuilder(closure, render);
|
|
5100
|
-
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));
|
|
5101
5210
|
};
|
|
5102
5211
|
}
|
|
5103
5212
|
return signal;
|
|
5104
5213
|
}
|
|
5105
|
-
function
|
|
5214
|
+
function getClosureSubscribeId(section, closure) {
|
|
5106
5215
|
const { sources } = closure;
|
|
5107
|
-
|
|
5216
|
+
if (sources && isDynamicClosure(section, closure) && (!sources.state || some(sources.state, hasResumableWriter))) return _marko_compiler.types.stringLiteral(getResumeRegistryId(section, closure, "subscribe"));
|
|
5108
5217
|
}
|
|
5109
5218
|
function initValue(binding, isLet = false) {
|
|
5110
5219
|
const section = binding.section;
|
|
@@ -5113,35 +5222,40 @@ function initValue(binding, isLet = false) {
|
|
|
5113
5222
|
signal.build = () => {
|
|
5114
5223
|
if (isPureMemberForwarder(binding)) return;
|
|
5115
5224
|
const fn = buildSignalFn(signal);
|
|
5116
|
-
if (!signal.forceStore && (isDirectAlias(binding) || !signal.storesValue && !
|
|
5225
|
+
if (!signal.forceStore && (isDirectAlias(binding) || !signal.storesValue && !aliasStoresValue(binding) || !signalHasWork(signal))) return fn;
|
|
5117
5226
|
return callRuntime(isLet ? signal.extraArgs ? "_let_change" : "_let" : "_const", getScopeAccessorLiteral(binding, true, isLet), fn);
|
|
5118
5227
|
};
|
|
5119
|
-
binding.aliases
|
|
5120
|
-
binding.propertyAliases
|
|
5228
|
+
binding.aliases?.forEach(initAliasValue);
|
|
5229
|
+
binding.propertyAliases?.forEach(initAliasValue);
|
|
5121
5230
|
return signal;
|
|
5122
5231
|
}
|
|
5123
5232
|
function initAliasValue(alias) {
|
|
5124
5233
|
if (alias.type !== 5) initValue(alias);
|
|
5125
5234
|
}
|
|
5126
|
-
function aliasStoresValue(
|
|
5127
|
-
|
|
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;
|
|
5128
5240
|
}
|
|
5129
5241
|
function signalHasWork(signal) {
|
|
5130
|
-
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;
|
|
5131
5243
|
const binding = signal.referencedBindings;
|
|
5132
5244
|
if (binding) {
|
|
5133
|
-
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;
|
|
5134
5246
|
} else if (signal.section.referencedClosures) return true;
|
|
5135
5247
|
return false;
|
|
5136
5248
|
}
|
|
5137
5249
|
function isPureMemberForwarder(binding) {
|
|
5138
|
-
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;
|
|
5139
5251
|
return hasNonConstantPropertyAlias(binding);
|
|
5140
5252
|
}
|
|
5141
|
-
function pushMemberForwards(signal, value,
|
|
5142
|
-
if (
|
|
5143
|
-
|
|
5144
|
-
|
|
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
|
+
}
|
|
5145
5259
|
}
|
|
5146
5260
|
function pushForward(signal, target, value) {
|
|
5147
5261
|
if (pushSignalCall(signal, target, value)) signal.forwards = push(signal.forwards, target);
|
|
@@ -5163,7 +5277,7 @@ function pushSignalCall(signal, target, value) {
|
|
|
5163
5277
|
}
|
|
5164
5278
|
function isInlinedValue(signal) {
|
|
5165
5279
|
const binding = signal.referencedBindings;
|
|
5166
|
-
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;
|
|
5167
5281
|
const [read] = binding.reads.values();
|
|
5168
5282
|
if (Array.isArray(read) || read.fnRoot) return false;
|
|
5169
5283
|
const from = getBindingsDerivedFrom(binding);
|
|
@@ -5181,7 +5295,7 @@ function buildSignalFn(signal) {
|
|
|
5181
5295
|
const isValue = isBinding && binding.section === section;
|
|
5182
5296
|
const assertsHoists = isValue && binding.hoists && !isOptimize();
|
|
5183
5297
|
if (isValue) {
|
|
5184
|
-
for (const alias of binding.aliases) {
|
|
5298
|
+
if (binding.aliases) for (const alias of binding.aliases) {
|
|
5185
5299
|
const aliasSignal = getSignal(alias.section, alias);
|
|
5186
5300
|
if (signalHasWork(aliasSignal)) {
|
|
5187
5301
|
let value = createScopeReadExpression(binding);
|
|
@@ -5192,7 +5306,7 @@ function buildSignalFn(signal) {
|
|
|
5192
5306
|
pushForward(signal, aliasSignal, value);
|
|
5193
5307
|
}
|
|
5194
5308
|
}
|
|
5195
|
-
|
|
5309
|
+
if (binding.propertyAliases) pushMemberForwards(signal, createScopeReadExpression(binding), binding);
|
|
5196
5310
|
if (assertsHoists) signal.render.push(_marko_compiler.types.expressionStatement(callRuntime("_assert_hoist", createScopeReadExpression(binding))));
|
|
5197
5311
|
}
|
|
5198
5312
|
for (const value of signal.values) {
|
|
@@ -5200,9 +5314,7 @@ function buildSignalFn(signal) {
|
|
|
5200
5314
|
if (signalHasWork(value.signal)) pushSignalCall(signal, value.signal, value.value);
|
|
5201
5315
|
else signal.render.push(_marko_compiler.types.expressionStatement(withLeadingComment(value.value, getDebugNames(value.signal.referencedBindings))));
|
|
5202
5316
|
}
|
|
5203
|
-
forEach(signal.intersections,
|
|
5204
|
-
pushScopeCall(signal.render, intersection.identifier);
|
|
5205
|
-
});
|
|
5317
|
+
forEach(signal.intersections, pushIntersectionCall, signal);
|
|
5206
5318
|
if (isBinding && binding.sources) {
|
|
5207
5319
|
let dynamicClosureArgs;
|
|
5208
5320
|
let dynamicClosureSignalIdentifier;
|
|
@@ -5224,10 +5336,13 @@ function buildSignalFn(signal) {
|
|
|
5224
5336
|
if (isValue && !signal.storesValue) {
|
|
5225
5337
|
const call = getOnlyCall(signal.render);
|
|
5226
5338
|
if (call && call.callee.type === "Identifier" && call.arguments.length === 2 && call.arguments[0] === scopeIdentifier && isOwnValueRead(call.arguments[1], binding)) return call.callee;
|
|
5227
|
-
return _marko_compiler.types.arrowFunctionExpression([scopeIdentifier,
|
|
5339
|
+
return _marko_compiler.types.arrowFunctionExpression([scopeIdentifier, _marko_compiler.types.identifier(binding.canonical.name)], toOnlyExpressionOrBlock(signal.render));
|
|
5228
5340
|
}
|
|
5229
5341
|
return toScopeFn(signal.render);
|
|
5230
5342
|
}
|
|
5343
|
+
function pushIntersectionCall(intersection, signal) {
|
|
5344
|
+
pushScopeCall(signal.render, intersection.identifier);
|
|
5345
|
+
}
|
|
5231
5346
|
function toScopeFn(render) {
|
|
5232
5347
|
const call = getOnlyCall(render);
|
|
5233
5348
|
if (call && call.arguments.length === 1 && call.arguments[0] === scopeIdentifier) {
|
|
@@ -5260,24 +5375,21 @@ function getTranslatedExtraArgs(signal) {
|
|
|
5260
5375
|
}
|
|
5261
5376
|
return emptyExtraArgs;
|
|
5262
5377
|
}
|
|
5263
|
-
function getSignalValueIdentifier(signal) {
|
|
5264
|
-
const canonicalBinding = getCanonicalBinding(signal.referencedBindings);
|
|
5265
|
-
return _marko_compiler.types.identifier(canonicalBinding.name);
|
|
5266
|
-
}
|
|
5267
5378
|
function isOwnValueRead(node, binding) {
|
|
5268
5379
|
const extra = node.extra;
|
|
5269
5380
|
const read = extra?.read;
|
|
5270
5381
|
return !!read && !extra.assignment && read.binding === binding && read.properties === void 0 && !read.getter?.invoked;
|
|
5271
5382
|
}
|
|
5272
5383
|
function subscribe(references, intersection) {
|
|
5273
|
-
if (references) forEach(references,
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
|
|
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
|
+
}
|
|
5281
5393
|
}
|
|
5282
5394
|
function trimEmptyArgs(args) {
|
|
5283
5395
|
const len = args.length;
|
|
@@ -5343,7 +5455,7 @@ function getResumeRegistryId(section, referencedBindings, type) {
|
|
|
5343
5455
|
function writeSignals(section) {
|
|
5344
5456
|
const seen = /* @__PURE__ */ new Set();
|
|
5345
5457
|
const written = /* @__PURE__ */ new Set();
|
|
5346
|
-
|
|
5458
|
+
forEach(section.bindings, writeBindingGetters, section);
|
|
5347
5459
|
for (const signal of getSignals(section).values()) writeSignal(signal);
|
|
5348
5460
|
function writeSignal(signal) {
|
|
5349
5461
|
if (seen.has(signal)) return;
|
|
@@ -5365,7 +5477,7 @@ function writeSignals(section) {
|
|
|
5365
5477
|
if (signal.build) {
|
|
5366
5478
|
let value = signal.build();
|
|
5367
5479
|
const buildsEagerForward = _marko_compiler.types.isIdentifier(value) || _marko_compiler.types.isCallExpression(value) && _marko_compiler.types.isIdentifier(value.arguments.at(-1));
|
|
5368
|
-
if (!value || !signal.
|
|
5480
|
+
if (!value || !signal.referenced && _marko_compiler.types.isFunction(value) && _marko_compiler.types.isBlockStatement(value.body) && !value.body.body.length) return;
|
|
5369
5481
|
if (_marko_compiler.types.isCallExpression(value)) trimEmptyArgs(value.arguments);
|
|
5370
5482
|
if (signal.register) value = callRuntime("_var_resume", _marko_compiler.types.stringLiteral(getResumeRegistryId(section, signal.referencedBindings, "var")), value);
|
|
5371
5483
|
if (buildsEagerForward) forEach(signal.forwards, writeSignal);
|
|
@@ -5382,15 +5494,14 @@ function writeSignals(section) {
|
|
|
5382
5494
|
}
|
|
5383
5495
|
return written;
|
|
5384
5496
|
}
|
|
5385
|
-
function
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
});
|
|
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
|
+
}
|
|
5394
5505
|
}
|
|
5395
5506
|
function pushInstancesAccessor(section, accessors) {
|
|
5396
5507
|
const instancesAccessor = getSectionScopesAccessorLiteral(section);
|
|
@@ -5404,22 +5515,23 @@ function pushInstancesAccessor(section, accessors) {
|
|
|
5404
5515
|
function writeRegisteredFns() {
|
|
5405
5516
|
const registeredFns = getRegisteredFns();
|
|
5406
5517
|
const statements = [];
|
|
5407
|
-
for (const
|
|
5518
|
+
for (const { node, extra } of registeredFns) {
|
|
5519
|
+
const { name, referencesScope } = extra;
|
|
5408
5520
|
let fn;
|
|
5409
|
-
if (
|
|
5521
|
+
if (referencesScope || extra.referencedLocalBindingsInFunction) {
|
|
5410
5522
|
let params;
|
|
5411
5523
|
let prologue;
|
|
5412
|
-
if (
|
|
5524
|
+
if (extra.referencedLocalBindingsInFunction) {
|
|
5413
5525
|
params = [localsIdentifier];
|
|
5414
|
-
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)))])];
|
|
5415
5527
|
} else params = [scopeIdentifier];
|
|
5416
|
-
const body = toReturnedFunction(
|
|
5417
|
-
fn = _marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(
|
|
5418
|
-
} else if (
|
|
5419
|
-
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);
|
|
5420
5532
|
statements.push(fn);
|
|
5421
5533
|
}
|
|
5422
|
-
for (const
|
|
5534
|
+
for (const { extra } of registeredFns) statements.push(_marko_compiler.types.expressionStatement(registerRuntimeValue(extra.registryId, _marko_compiler.types.identifier(extra.name))));
|
|
5423
5535
|
(0, _marko_compiler_babel_utils.getProgram)().node.body.push(...statements);
|
|
5424
5536
|
}
|
|
5425
5537
|
function toReturnedFunction(rawFn, prologue) {
|
|
@@ -5432,7 +5544,7 @@ function toReturnedFunction(rawFn, prologue) {
|
|
|
5432
5544
|
}
|
|
5433
5545
|
function addHTMLEffectCall(section, expr) {
|
|
5434
5546
|
const signal = getSignal(section, getReferencedBindings(expr));
|
|
5435
|
-
signal.hasHTMLEffect =
|
|
5547
|
+
signal.hasHTMLEffect = true;
|
|
5436
5548
|
}
|
|
5437
5549
|
function writeHTMLResumeStatements(path) {
|
|
5438
5550
|
const bodyPath = flushInto(path);
|
|
@@ -5442,31 +5554,33 @@ function writeHTMLResumeStatements(path) {
|
|
|
5442
5554
|
const allSignals = Array.from(getSignals(section).values());
|
|
5443
5555
|
const scopeIdIdentifier = getScopeIdIdentifier(section);
|
|
5444
5556
|
const nodeReasons = getNodeReasons(section);
|
|
5445
|
-
const
|
|
5557
|
+
const markerAlwaysWritten = some(nodeReasons, isAlwaysWritten, section);
|
|
5558
|
+
let markerGuard;
|
|
5559
|
+
const getSectionMarkerGuard = () => markerAlwaysWritten ? void 0 : markerGuard ||= getWriteGuardForAny(section, nodeReasons, true);
|
|
5446
5560
|
const sectionReason = section.reason;
|
|
5447
5561
|
let linkedWithScope = some(section.bindings, isClientAssignedLet);
|
|
5448
5562
|
let linkReasons;
|
|
5449
5563
|
forEach(section.referencedClosures, (closure) => {
|
|
5450
5564
|
if (closure.sources) {
|
|
5451
5565
|
if (isDynamicClosure(section, closure)) {
|
|
5566
|
+
const closureScopes = findSlot(closure, 2);
|
|
5452
5567
|
const closureSignal = getSignal(closure.section, closure);
|
|
5453
5568
|
let identifier = htmlDynamicClosureInstancesIdentifier.get(closureSignal);
|
|
5454
5569
|
if (!identifier) {
|
|
5455
5570
|
htmlDynamicClosureInstancesIdentifier.set(closureSignal, identifier = generateUidIdentifier(closureSignal.identifier.name + "__closures"));
|
|
5456
5571
|
getHTMLSectionStatements(closure.section).push(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(identifier, _marko_compiler.types.newExpression(_marko_compiler.types.identifier("Set"), []))]));
|
|
5457
|
-
writeSlot(
|
|
5572
|
+
writeSlot(closureScopes, identifier);
|
|
5458
5573
|
}
|
|
5459
5574
|
const closureIndex = getDynamicClosureIndex(closure, section);
|
|
5460
5575
|
if (closureIndex) writeSlot(findSlot(closure, 3, section), _marko_compiler.types.numericLiteral(closureIndex));
|
|
5461
|
-
const closureScopesReason =
|
|
5576
|
+
const closureScopesReason = closureScopes?.reason;
|
|
5462
5577
|
const subscribeArg = isGuardedReason(closureScopesReason) && !isSameReason(closureScopesReason, sectionReason) ? getExprIfWritten(closure.section, closureScopesReason, identifier) : identifier;
|
|
5463
5578
|
if (subscribeArg) {
|
|
5464
|
-
const changeable = isChangeableDynamicClosure(section, closure);
|
|
5465
5579
|
if (subscribeArg === identifier) linkedWithScope = true;
|
|
5466
5580
|
else linkReasons = sourcesUtil.add(linkReasons, closureScopesReason);
|
|
5467
5581
|
addWriteScopeBuilder(section, (expr) => {
|
|
5468
|
-
const resumeId =
|
|
5469
|
-
return callRuntime("_subscribe", subscribeArg, expr, resumeId, resumeId &&
|
|
5582
|
+
const resumeId = getClosureSubscribeId(section, closure);
|
|
5583
|
+
return callRuntime("_subscribe", subscribeArg, expr, resumeId, resumeId && getSectionMarkerGuard());
|
|
5470
5584
|
});
|
|
5471
5585
|
}
|
|
5472
5586
|
}
|
|
@@ -5474,7 +5588,7 @@ function writeHTMLResumeStatements(path) {
|
|
|
5474
5588
|
});
|
|
5475
5589
|
for (let i = allSignals.length; i--;) if (allSignals[i].hasHTMLEffect) {
|
|
5476
5590
|
const signalRefs = allSignals[i].referencedBindings;
|
|
5477
|
-
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())));
|
|
5478
5592
|
}
|
|
5479
5593
|
const debug = !isOptimize();
|
|
5480
5594
|
const writeScopeBuilder = getSectionWriteScopeBuilder(section);
|
|
@@ -5525,23 +5639,30 @@ function writeHTMLResumeStatements(path) {
|
|
|
5525
5639
|
const write = getExprIfWritten(section, sectionReason, writeScopeBuilder ? writeScopeBuilder(callRuntime("_scope", ...writeScopeArgs)) : callRuntime("_scope", ...writeScopeArgs));
|
|
5526
5640
|
if (write) body.push(_marko_compiler.types.expressionStatement(write));
|
|
5527
5641
|
}
|
|
5528
|
-
if (
|
|
5642
|
+
if (!markerAlwaysWritten && !isBranchAlwaysMarked(section)) {
|
|
5529
5643
|
let link;
|
|
5530
5644
|
if (section.hasAbortSignal) link = callRuntime("_resume_branch", scopeIdIdentifier);
|
|
5531
5645
|
else if (sectionReason && !sourcesUtil.has(nodeReasons, sectionReason)) {
|
|
5532
5646
|
const guard = linkedWithScope ? void 0 : getWriteGuardForAny(section, sourcesUtil.difference(linkReasons, nodeReasons), true);
|
|
5533
5647
|
if (guard?.type !== "NumericLiteral") link = getExprIfWritten(section, sectionReason, andGuard(guard, callRuntime("_resume_branch", scopeIdIdentifier)));
|
|
5534
5648
|
}
|
|
5535
|
-
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
|
+
}
|
|
5536
5653
|
}
|
|
5537
5654
|
const additionalStatements = getHTMLSectionStatements(section);
|
|
5538
5655
|
if (body.length || additionalStatements.length) body.unshift(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(scopeIdIdentifier, callRuntime("_scope_id"))]), ...additionalStatements);
|
|
5539
|
-
if (debug) forEach(section.bindings,
|
|
5540
|
-
if (binding.hoists && binding.type !== 0) body.push(_marko_compiler.types.expressionStatement(callRuntime("_assert_hoist", _marko_compiler.types.identifier(binding.name))));
|
|
5541
|
-
});
|
|
5656
|
+
if (debug) forEach(section.bindings, pushAssertHoist, body);
|
|
5542
5657
|
const returnIdentifier = getSectionReturnValueIdentifier(section);
|
|
5543
5658
|
if (returnIdentifier !== void 0) body.push(_marko_compiler.types.returnStatement(returnIdentifier));
|
|
5544
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
|
+
}
|
|
5545
5666
|
function getSetup(section) {
|
|
5546
5667
|
return getSignals(section).get(void 0);
|
|
5547
5668
|
}
|
|
@@ -5676,24 +5797,21 @@ function registerFnExpression(node) {
|
|
|
5676
5797
|
const referencesScope = extra.referencesScope;
|
|
5677
5798
|
const referencedLocals = extra.referencedLocalBindingsInFunction;
|
|
5678
5799
|
getRegisteredFns().push({
|
|
5679
|
-
id,
|
|
5680
5800
|
node,
|
|
5681
|
-
|
|
5682
|
-
section: extra.section,
|
|
5683
|
-
referencesScope,
|
|
5684
|
-
referencedLocals
|
|
5801
|
+
extra
|
|
5685
5802
|
});
|
|
5686
5803
|
if (referencedLocals) {
|
|
5687
5804
|
const properties = [];
|
|
5688
5805
|
if (referencesScope) properties.push(_marko_compiler.types.objectProperty(_marko_compiler.types.identifier(getAccessorProp().Owner), scopeIdentifier));
|
|
5689
|
-
forEach(referencedLocals,
|
|
5690
|
-
properties.push(toObjectProperty(getLocalsScopeAccessor(binding), getDeclaredBindingExpression(binding)));
|
|
5691
|
-
});
|
|
5806
|
+
forEach(referencedLocals, pushLocalProperty, properties);
|
|
5692
5807
|
return _marko_compiler.types.callExpression(_marko_compiler.types.identifier(id), [_marko_compiler.types.objectExpression(properties)]);
|
|
5693
5808
|
} else if (referencesScope) return _marko_compiler.types.callExpression(_marko_compiler.types.identifier(id), [scopeIdentifier]);
|
|
5694
5809
|
else return _marko_compiler.types.identifier(id);
|
|
5695
5810
|
}
|
|
5696
5811
|
}
|
|
5812
|
+
function pushLocalProperty(binding, properties) {
|
|
5813
|
+
properties.push(toObjectProperty(getLocalsScopeAccessor(binding), getDeclaredBindingExpression(binding)));
|
|
5814
|
+
}
|
|
5697
5815
|
function appendBindingKey(name, binding, section) {
|
|
5698
5816
|
return `${name}_${binding.name}#${binding.section === section ? "" : binding.section.id + ":"}${binding.id}`;
|
|
5699
5817
|
}
|
|
@@ -5730,13 +5848,10 @@ function translateAttrs(tag, paramsTree = true, statements = [], contentKey = "c
|
|
|
5730
5848
|
for (let i = 0; i < attrTags.length; i++) {
|
|
5731
5849
|
const child = attrTags[i];
|
|
5732
5850
|
if (child.isMarkoTag()) {
|
|
5733
|
-
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
|
|
5737
|
-
const translatedAttrTag = translateAttrs(child, getParamsTreeAt(paramsTree, attrTagMeta.name), statements, contentKey);
|
|
5738
|
-
addAttrTag(contentProperties, attrTagMeta, _marko_compiler.types.objectExpression(translatedAttrTag.properties));
|
|
5739
|
-
}
|
|
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));
|
|
5740
5855
|
} else i = addDynamicAttrTagStatements(attrTags, i, attrTagLookup, statements, paramsTree, contentKey);
|
|
5741
5856
|
}
|
|
5742
5857
|
}
|
|
@@ -5757,7 +5872,7 @@ function translateAttrs(tag, paramsTree = true, statements = [], contentKey = "c
|
|
|
5757
5872
|
const { value } = attr;
|
|
5758
5873
|
if (_marko_compiler.types.isMarkoSpreadAttribute(attr) && attr.extra?.knownSpread) {
|
|
5759
5874
|
const { knownSpread } = attr.extra;
|
|
5760
|
-
if (!
|
|
5875
|
+
if (!knownSpread.canonical.pruned) attrProperties.push(_marko_compiler.types.spreadElement(getDeclaredBindingExpression(knownSpread, true)));
|
|
5761
5876
|
} else if (!value.extra?.dropped) {
|
|
5762
5877
|
if (_marko_compiler.types.isMarkoSpreadAttribute(attr)) attrProperties.push(_marko_compiler.types.spreadElement(value));
|
|
5763
5878
|
else if (!seen.has(attr.name) && getParamsTreeAt(paramsTree, attr.name)) {
|
|
@@ -5912,6 +6027,7 @@ function knownTagAnalyze(tag, childSection, childParamsTree) {
|
|
|
5912
6027
|
if (varBinding) {
|
|
5913
6028
|
addSetupWork(section);
|
|
5914
6029
|
const { childScopeBinding } = tagExtra;
|
|
6030
|
+
section.hasReturnedVar = true;
|
|
5915
6031
|
varBinding.returnedBy = {
|
|
5916
6032
|
scope: childScopeBinding,
|
|
5917
6033
|
section: childSection,
|
|
@@ -5944,11 +6060,12 @@ function assertTerminates(tag, childSection) {
|
|
|
5944
6060
|
const callers = /* @__PURE__ */ new Set([getSection(tag)]);
|
|
5945
6061
|
for (const caller of callers) {
|
|
5946
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>\`.`);
|
|
5947
|
-
forEach(caller.renderedBy,
|
|
5948
|
-
callers.add(call.childScopeBinding.section);
|
|
5949
|
-
});
|
|
6063
|
+
forEach(caller.renderedBy, addCaller, callers);
|
|
5950
6064
|
}
|
|
5951
6065
|
}
|
|
6066
|
+
function addCaller(call, callers) {
|
|
6067
|
+
callers.add(call.childScopeBinding.section);
|
|
6068
|
+
}
|
|
5952
6069
|
function exposeChildParamsTree(childSection) {
|
|
5953
6070
|
return childSection.params && exposeParamsTree(childSection.params, true);
|
|
5954
6071
|
}
|
|
@@ -6060,11 +6177,7 @@ function addKnownTagReasons(section) {
|
|
|
6060
6177
|
const knownExprs = tagExtra[kKnownExprs];
|
|
6061
6178
|
const { childSection } = tagExtra;
|
|
6062
6179
|
if (knownExprs && childSection.paramReasonGroups) {
|
|
6063
|
-
for (const group of childSection.paramReasonGroups) if (!findSlot(childScopeBinding, 5, section, group))
|
|
6064
|
-
const slot = ensureSlot(childScopeBinding, 5, section, group);
|
|
6065
|
-
slot.reasonExprs = mapParamReasonToExpr(knownExprs, group);
|
|
6066
|
-
addReason(slot, getSourcesForExprs(slot.reasonExprs));
|
|
6067
|
-
}
|
|
6180
|
+
for (const group of childSection.paramReasonGroups) if (!findSlot(childScopeBinding, 5, section, group)) addReason(ensureSlot(childScopeBinding, 5, section, group), getSourcesForExprs(mapParamReasonToExpr(knownExprs, group)));
|
|
6068
6181
|
}
|
|
6069
6182
|
}
|
|
6070
6183
|
}
|
|
@@ -6561,10 +6674,7 @@ function getSourcesForExpr(expr) {
|
|
|
6561
6674
|
return isReferencedExtra(root) ? getSourcesForReferencedBindings(getReferencedBindings(root)) : void 0;
|
|
6562
6675
|
}
|
|
6563
6676
|
function getSourcesForExprs(exprs) {
|
|
6564
|
-
|
|
6565
|
-
if (exprs === true) return ALWAYS;
|
|
6566
|
-
return reduce(exprs, mergeExprSources);
|
|
6567
|
-
}
|
|
6677
|
+
return reduce(exprs, mergeExprSources);
|
|
6568
6678
|
}
|
|
6569
6679
|
function getSourcesForReferencedBindings(bindings) {
|
|
6570
6680
|
return reduce(bindings, mergeBindingSources);
|
|
@@ -6623,17 +6733,11 @@ function getKnownExprsAt(exprs, binding) {
|
|
|
6623
6733
|
function applyReasonExprs(section) {
|
|
6624
6734
|
for (const slot of section.slots) addReason(slot, getSourcesForExprs(slot.reasonExprs));
|
|
6625
6735
|
}
|
|
6626
|
-
function mergeSlotReasons(section) {
|
|
6627
|
-
section.reason = section.slots.reduce(mergeSlotReason, section.reason);
|
|
6628
|
-
}
|
|
6629
|
-
function mergeSlotReason(sectionReason, slot) {
|
|
6630
|
-
return mergeSources(sectionReason, slot.reason);
|
|
6631
|
-
}
|
|
6632
6736
|
function getNodeReasons(section) {
|
|
6633
6737
|
return section.structure?.reduce(addNodeReason, void 0);
|
|
6634
6738
|
}
|
|
6635
6739
|
function addNodeReason(reasons, op) {
|
|
6636
|
-
const reason = typeof op === "object" && op.kind === "node" && op.binding &&
|
|
6740
|
+
const reason = typeof op === "object" && op.kind === "node" && op.binding && getWriteReason(op.binding);
|
|
6637
6741
|
return reason ? sourcesUtil.add(reasons, reason) : reasons;
|
|
6638
6742
|
}
|
|
6639
6743
|
let reasonsVersion = 0;
|
|
@@ -6670,12 +6774,13 @@ function createBinding(name, type, refSection, aliased, property, excludePropert
|
|
|
6670
6774
|
sources: void 0,
|
|
6671
6775
|
intersection: void 0,
|
|
6672
6776
|
derivedFrom: void 0,
|
|
6673
|
-
reads:
|
|
6674
|
-
aliases:
|
|
6777
|
+
reads: void 0,
|
|
6778
|
+
aliases: void 0,
|
|
6675
6779
|
hoists: void 0,
|
|
6676
|
-
getters:
|
|
6677
|
-
propertyAliases:
|
|
6780
|
+
getters: void 0,
|
|
6781
|
+
propertyAliases: void 0,
|
|
6678
6782
|
aliasOf: aliased,
|
|
6783
|
+
canonical: void 0,
|
|
6679
6784
|
iterates: void 0,
|
|
6680
6785
|
declaredAlias: void 0,
|
|
6681
6786
|
localOf: void 0,
|
|
@@ -6691,16 +6796,17 @@ function createBinding(name, type, refSection, aliased, property, excludePropert
|
|
|
6691
6796
|
hasLazyReads: false
|
|
6692
6797
|
};
|
|
6693
6798
|
if (property) {
|
|
6694
|
-
const propBinding = aliased.propertyAliases
|
|
6799
|
+
const propBinding = aliased.propertyAliases?.get(property);
|
|
6695
6800
|
if (propBinding) {
|
|
6696
6801
|
binding.property = void 0;
|
|
6697
6802
|
binding.aliasOf = propBinding;
|
|
6698
|
-
propBinding.aliases.add(binding);
|
|
6699
|
-
} else aliased.propertyAliases.set(property, binding);
|
|
6803
|
+
(propBinding.aliases ??= /* @__PURE__ */ new Set()).add(binding);
|
|
6804
|
+
} else (aliased.propertyAliases ??= /* @__PURE__ */ new Map()).set(property, binding);
|
|
6700
6805
|
} else if (aliased) {
|
|
6701
|
-
aliased.aliases.add(binding);
|
|
6806
|
+
(aliased.aliases ??= /* @__PURE__ */ new Set()).add(binding);
|
|
6702
6807
|
if (declared) aliased.declaredAlias ??= binding;
|
|
6703
6808
|
}
|
|
6809
|
+
binding.canonical = isDirectAlias(binding) ? binding.aliasOf : binding;
|
|
6704
6810
|
setNextBindingId(id + 1);
|
|
6705
6811
|
getBindings().add(binding);
|
|
6706
6812
|
return binding;
|
|
@@ -6709,8 +6815,8 @@ function reserveId(binding, offset) {
|
|
|
6709
6815
|
binding.reserveSize = Math.max(binding.reserveSize, offset);
|
|
6710
6816
|
}
|
|
6711
6817
|
function ensurePropertyAlias(binding, property) {
|
|
6712
|
-
const canonical =
|
|
6713
|
-
return canonical.propertyAliases
|
|
6818
|
+
const { canonical } = binding;
|
|
6819
|
+
return canonical.propertyAliases?.get(property) || createBinding(canonical.name + toIdentifierAccess(property), canonical.type, canonical.section, canonical, property);
|
|
6714
6820
|
}
|
|
6715
6821
|
function addAssignedProperty(binding, property) {
|
|
6716
6822
|
if (binding.assignedProperties !== true) binding.assignedProperties = property === void 0 || propertiesUtil.add(binding.assignedProperties, property);
|
|
@@ -6718,8 +6824,7 @@ function addAssignedProperty(binding, property) {
|
|
|
6718
6824
|
function getAssignedObject(binding) {
|
|
6719
6825
|
let object;
|
|
6720
6826
|
for (let alias = binding; alias.aliasOf && !isRest(alias); alias = alias.aliasOf) if (alias.property !== void 0) {
|
|
6721
|
-
|
|
6722
|
-
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;
|
|
6723
6828
|
}
|
|
6724
6829
|
return object;
|
|
6725
6830
|
}
|
|
@@ -6727,16 +6832,16 @@ function getPropertyAlias(binding, properties) {
|
|
|
6727
6832
|
return reduceWhile(properties, getExistingPropertyAlias, binding);
|
|
6728
6833
|
}
|
|
6729
6834
|
function getExistingPropertyAlias(binding, property) {
|
|
6730
|
-
return
|
|
6835
|
+
return binding.canonical.propertyAliases?.get(property);
|
|
6731
6836
|
}
|
|
6732
6837
|
function getDeepestPropertyAlias(binding, properties) {
|
|
6733
6838
|
let alias = binding;
|
|
6734
6839
|
if (Array.isArray(properties)) for (const property of properties) {
|
|
6735
|
-
const next = alias.propertyAliases
|
|
6840
|
+
const next = alias.propertyAliases?.get(property);
|
|
6736
6841
|
if (!next) break;
|
|
6737
6842
|
alias = next;
|
|
6738
6843
|
}
|
|
6739
|
-
else if (properties !== void 0) alias = alias.propertyAliases
|
|
6844
|
+
else if (properties !== void 0) alias = alias.propertyAliases?.get(properties) ?? alias;
|
|
6740
6845
|
return alias;
|
|
6741
6846
|
}
|
|
6742
6847
|
function compareReferences(a, b) {
|
|
@@ -6767,14 +6872,11 @@ const bindingUtil = new Sorted(function compareBindings(a, b) {
|
|
|
6767
6872
|
const propertiesUtil = new Sorted(function compareProperties(a, b) {
|
|
6768
6873
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
6769
6874
|
});
|
|
6770
|
-
function
|
|
6771
|
-
|
|
6772
|
-
if (
|
|
6773
|
-
|
|
6774
|
-
}
|
|
6775
|
-
function someAlias(binding, test, arg, directOnly) {
|
|
6776
|
-
if (test(binding, arg)) return true;
|
|
6777
|
-
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
|
+
}
|
|
6778
6880
|
return false;
|
|
6779
6881
|
}
|
|
6780
6882
|
function someUpToAliasRoot(binding, test, arg) {
|
|
@@ -6785,13 +6887,13 @@ function getNearestDeclared(binding) {
|
|
|
6785
6887
|
for (let cur = binding; cur; cur = cur.aliasOf) if (cur.declared) return cur;
|
|
6786
6888
|
}
|
|
6787
6889
|
function getDeclaredAlias(binding) {
|
|
6788
|
-
return !getNearestDeclared(binding) && binding.declaredAlias;
|
|
6890
|
+
return binding.declaredAlias && !getNearestDeclared(binding) && binding.declaredAlias;
|
|
6789
6891
|
}
|
|
6790
6892
|
function isDirectAlias(binding) {
|
|
6791
6893
|
return binding.aliasOf !== void 0 && binding.property === void 0 && !isRest(binding);
|
|
6792
6894
|
}
|
|
6793
6895
|
function isRest(binding) {
|
|
6794
|
-
return binding.excludeProperties !== void 0 || binding.restOffset !== void 0;
|
|
6896
|
+
return binding.aliasOf !== void 0 && (binding.excludeProperties !== void 0 || binding.restOffset !== void 0);
|
|
6795
6897
|
}
|
|
6796
6898
|
function getDebugAccess(binding, toParam, formatProperty) {
|
|
6797
6899
|
let root = binding;
|
|
@@ -6826,11 +6928,13 @@ function toIdentifierAccess(property) {
|
|
|
6826
6928
|
return `_${property.replace(/[^a-z0-9_$]/gi, "_")}`;
|
|
6827
6929
|
}
|
|
6828
6930
|
function isInvokeOnlyBinding(binding) {
|
|
6829
|
-
return !someAlias(binding, isReadBeyondInvoking
|
|
6931
|
+
return !someAlias(binding, isReadBeyondInvoking);
|
|
6830
6932
|
}
|
|
6831
6933
|
function isReadBeyondInvoking(binding) {
|
|
6832
|
-
if (binding.assignments || binding.hoists || binding.getters
|
|
6833
|
-
|
|
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
|
+
}
|
|
6834
6938
|
return false;
|
|
6835
6939
|
}
|
|
6836
6940
|
function isReadOutsideInvokeOnly(read) {
|
|
@@ -6840,7 +6944,9 @@ function isOwnBinding(binding) {
|
|
|
6840
6944
|
return binding.section.program === (0, _marko_compiler_babel_utils.getProgram)().node.extra.section;
|
|
6841
6945
|
}
|
|
6842
6946
|
function hasNonConstantPropertyAlias(binding) {
|
|
6843
|
-
|
|
6947
|
+
if (binding.propertyAliases) {
|
|
6948
|
+
for (const alias of binding.propertyAliases.values()) if (alias.type !== 5) return true;
|
|
6949
|
+
}
|
|
6844
6950
|
return false;
|
|
6845
6951
|
}
|
|
6846
6952
|
function getPropertyPath(binding, ancestor) {
|
|
@@ -7067,7 +7173,11 @@ function getForAttrs(type) {
|
|
|
7067
7173
|
/** Throws for a param that a loop of `type` never supplies. */
|
|
7068
7174
|
function assertForParams(tag, type) {
|
|
7069
7175
|
const extraParam = tag.node.body.params[type === "of" || type === "in" ? 2 : 1];
|
|
7070
|
-
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";
|
|
7071
7181
|
}
|
|
7072
7182
|
function coreTagLink(tag) {
|
|
7073
7183
|
const tagName = getTagName(tag);
|
|
@@ -7251,6 +7361,12 @@ function text(path, binding, marker) {
|
|
|
7251
7361
|
function marker(path, binding) {
|
|
7252
7362
|
addNode(path, binding, true);
|
|
7253
7363
|
}
|
|
7364
|
+
function markerNode(tag, section) {
|
|
7365
|
+
const binding = createBinding("#text", 0, section);
|
|
7366
|
+
marker(tag, binding);
|
|
7367
|
+
enterShallow(tag);
|
|
7368
|
+
return binding;
|
|
7369
|
+
}
|
|
7254
7370
|
function controlFlowNode(tag, section) {
|
|
7255
7371
|
const extra = tag.node.extra ??= {};
|
|
7256
7372
|
const parentTagName = getOnlyChildParentTagName(tag);
|
|
@@ -7258,10 +7374,7 @@ function controlFlowNode(tag, section) {
|
|
|
7258
7374
|
const parentTag = getParentTag(tag).node;
|
|
7259
7375
|
return extra.nodeBinding = (parentTag.extra ??= {}).nodeBinding ??= createBinding("#" + parentTagName.toLowerCase(), 0, section);
|
|
7260
7376
|
}
|
|
7261
|
-
|
|
7262
|
-
marker(tag, binding);
|
|
7263
|
-
enterShallow(tag);
|
|
7264
|
-
return binding;
|
|
7377
|
+
return extra.nodeBinding = markerNode(tag, section);
|
|
7265
7378
|
}
|
|
7266
7379
|
function addNode(path, binding, marker) {
|
|
7267
7380
|
const { structure } = getSection(path);
|
|
@@ -7552,15 +7665,14 @@ const IfTag = {
|
|
|
7552
7665
|
},
|
|
7553
7666
|
exit(tag) {
|
|
7554
7667
|
if (tag.node.body.attributeTags) return;
|
|
7668
|
+
const branches = getBranches(tag);
|
|
7669
|
+
const [ifTag] = branches[0];
|
|
7555
7670
|
const bodySection = getSectionForBody(tag.get("body"));
|
|
7556
7671
|
if (bodySection) {
|
|
7557
|
-
const [ifTag] = getBranches(tag)[0];
|
|
7558
7672
|
resumeOwnerByMarkerWhenUnconditional(bodySection, ifTag.node.extra.nodeBinding);
|
|
7559
7673
|
writeHTMLResumeStatements(tag);
|
|
7560
7674
|
}
|
|
7561
7675
|
if (isLastBranch(tag)) {
|
|
7562
|
-
const branches = getBranches(tag);
|
|
7563
|
-
const [ifTag] = branches[0];
|
|
7564
7676
|
let branchReasons;
|
|
7565
7677
|
let statement;
|
|
7566
7678
|
for (let i = branches.length; i--;) {
|
|
@@ -8002,7 +8114,7 @@ var await_default = {
|
|
|
8002
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.`);
|
|
8003
8115
|
const section = ensureSection(tag);
|
|
8004
8116
|
const tagExtra = tag.node.extra ??= {};
|
|
8005
|
-
|
|
8117
|
+
tagExtra.nodeBinding = markerNode(tag, section);
|
|
8006
8118
|
const bodySection = ensureBodySection(tagBody);
|
|
8007
8119
|
const valueExtra = valueAttr.value.extra ??= {};
|
|
8008
8120
|
const paramsBinding = trackParamsReferences(tagBody, 4);
|
|
@@ -8016,8 +8128,6 @@ var await_default = {
|
|
|
8016
8128
|
tag: tagExtra
|
|
8017
8129
|
});
|
|
8018
8130
|
addSetupWork(section);
|
|
8019
|
-
marker(tag, nodeBinding);
|
|
8020
|
-
enterShallow(tag);
|
|
8021
8131
|
},
|
|
8022
8132
|
translate: translateByTarget({
|
|
8023
8133
|
html: {
|
|
@@ -8164,6 +8274,7 @@ var debug_default = {
|
|
|
8164
8274
|
types: runtime_info_default.name + "/tags/debug.d.marko"
|
|
8165
8275
|
};
|
|
8166
8276
|
// src/translator/core/define.ts
|
|
8277
|
+
const kOnlyDirectReferences = Symbol("<define> only direct references");
|
|
8167
8278
|
var define_default = {
|
|
8168
8279
|
analyze(tag) {
|
|
8169
8280
|
(0, _marko_compiler_babel_utils.assertNoArgs)(tag);
|
|
@@ -8201,8 +8312,9 @@ var define_default = {
|
|
|
8201
8312
|
}
|
|
8202
8313
|
}
|
|
8203
8314
|
if (allDirectReferences) {
|
|
8204
|
-
const inputAlias = allHaveInput && paramsBinding?.propertyAliases
|
|
8315
|
+
const inputAlias = allHaveInput && paramsBinding?.propertyAliases?.get("0");
|
|
8205
8316
|
if (inputAlias) inputAlias.nullable = false;
|
|
8317
|
+
tag.node.extra[kOnlyDirectReferences] = true;
|
|
8206
8318
|
dropNodes(getAllTagReferenceNodes(tag.node));
|
|
8207
8319
|
return;
|
|
8208
8320
|
}
|
|
@@ -8227,25 +8339,18 @@ var define_default = {
|
|
|
8227
8339
|
translateVar(tag, propsToExpression(translatedAttrs.properties), "const", translatedAttrs.statements);
|
|
8228
8340
|
replaceWithStatements(tag, translatedAttrs.statements);
|
|
8229
8341
|
} else {
|
|
8230
|
-
|
|
8231
|
-
|
|
8232
|
-
|
|
8233
|
-
|
|
8234
|
-
|
|
8235
|
-
|
|
8236
|
-
|
|
8237
|
-
|
|
8238
|
-
|
|
8239
|
-
|
|
8240
|
-
|
|
8241
|
-
|
|
8242
|
-
if (bodySection.hasSetupWork) return hasWork ? buildSignalFn(signal) : _marko_compiler.types.arrowFunctionExpression([getUnusedParamIdentifier()], _marko_compiler.types.numericLiteral(0));
|
|
8243
|
-
};
|
|
8244
|
-
}
|
|
8245
|
-
if (bodySection && allDirectReferences) {
|
|
8246
|
-
replaceWithStatements(tag);
|
|
8247
|
-
return;
|
|
8248
|
-
}
|
|
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;
|
|
8249
8354
|
}
|
|
8250
8355
|
const section = getSection(tag);
|
|
8251
8356
|
if (translatedAttrs.statements.length) addStatement("render", section, node.extra, translatedAttrs.statements);
|
|
@@ -8310,7 +8415,7 @@ var for_default = {
|
|
|
8310
8415
|
const allowAttrs = getForAttrs(forType);
|
|
8311
8416
|
if (!isAttrTag) allowAttrs.push("by");
|
|
8312
8417
|
const keyAttr = tag.node.attributes.find(isKeyAttr);
|
|
8313
|
-
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\`.`);
|
|
8314
8419
|
(0, _marko_compiler_babel_utils.assertAllowedAttributes)(tag, allowAttrs);
|
|
8315
8420
|
assertForParams(tag, forType);
|
|
8316
8421
|
if (isAttrTag) {
|
|
@@ -8320,7 +8425,7 @@ var for_default = {
|
|
|
8320
8425
|
const forAttrs = getKnownAttrValues(tag.node);
|
|
8321
8426
|
const byAttr = forAttrs.by;
|
|
8322
8427
|
if (byAttr) (byAttr.extra ??= {}).consumed = true;
|
|
8323
|
-
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}>\`.`);
|
|
8324
8429
|
const bodySection = ensureBodySection(tagBody);
|
|
8325
8430
|
if (!bodySection) {
|
|
8326
8431
|
dropNodes(getAllTagReferenceNodes(tag.node));
|
|
@@ -8398,7 +8503,7 @@ var for_default = {
|
|
|
8398
8503
|
const forAttrs = getKnownAttrValues(node);
|
|
8399
8504
|
const signal = getSignal(tagSection, nodeBinding, "for");
|
|
8400
8505
|
signal.build = () => {
|
|
8401
|
-
return callRuntime(
|
|
8506
|
+
return callRuntime(isUnkeyed(forType, forAttrs) ? forTypeToUnkeyedBranchRuntime(forType) : forTypeToBranchRuntime(forType), getScopeAccessorLiteral(nodeBinding, true), ...trimEmptyArgs(getBranchRendererArgs(bodySection)));
|
|
8402
8507
|
};
|
|
8403
8508
|
addValue(tagSection, tagExtra, signal, _marko_compiler.types.arrayExpression(getLoopArgs(forType, forAttrs)));
|
|
8404
8509
|
replaceWithStatements(tag);
|
|
@@ -8409,10 +8514,10 @@ var for_default = {
|
|
|
8409
8514
|
};
|
|
8410
8515
|
function getLoopKeyBinding(byAttr, paramsBinding, forType) {
|
|
8411
8516
|
if (byAttr) {
|
|
8412
|
-
const item = paramsBinding.propertyAliases
|
|
8517
|
+
const item = paramsBinding.propertyAliases?.get("0");
|
|
8413
8518
|
return item && getKeyAlias(byAttr, item);
|
|
8414
8519
|
}
|
|
8415
|
-
return paramsBinding.propertyAliases
|
|
8520
|
+
return paramsBinding.propertyAliases?.get(forType === "of" ? "1" : "0");
|
|
8416
8521
|
}
|
|
8417
8522
|
function getKeyAlias(byAttr, item) {
|
|
8418
8523
|
if (byAttr.type === "StringLiteral") return getPropertyAlias(item, byAttr.value);
|
|
@@ -8436,7 +8541,7 @@ function getMemberChainAlias(node, rootName, item) {
|
|
|
8436
8541
|
}
|
|
8437
8542
|
}
|
|
8438
8543
|
}
|
|
8439
|
-
function
|
|
8544
|
+
function isUnkeyed(type, attrs) {
|
|
8440
8545
|
if (attrs.by) return false;
|
|
8441
8546
|
switch (type) {
|
|
8442
8547
|
case "of": return true;
|
|
@@ -8522,7 +8627,7 @@ var html_comment_default = {
|
|
|
8522
8627
|
const textLiteral = bodyToText(tag.node.body);
|
|
8523
8628
|
if (!_marko_compiler.types.isStringLiteral(textLiteral)) addStatement("render", tagSection, tagExtra, callRuntime("_text", createScopeReadExpression(nodeBinding), textLiteral));
|
|
8524
8629
|
}
|
|
8525
|
-
if (nodeBinding) markNode(tag, nodeBinding
|
|
8630
|
+
if (nodeBinding) markNode(tag, nodeBinding);
|
|
8526
8631
|
replaceWithStatements(tag);
|
|
8527
8632
|
} },
|
|
8528
8633
|
parseOptions: { text: true },
|
|
@@ -8589,17 +8694,20 @@ var id_default = {
|
|
|
8589
8694
|
replaceWithStatements(tag);
|
|
8590
8695
|
return;
|
|
8591
8696
|
}
|
|
8592
|
-
|
|
8593
|
-
|
|
8594
|
-
|
|
8697
|
+
if (isOutputHTML()) {
|
|
8698
|
+
const id = callRuntime("_id");
|
|
8699
|
+
translateVar(tag, valueAttr ? _marko_compiler.types.logicalExpression("||", valueAttr.value, id) : id);
|
|
8700
|
+
} else {
|
|
8701
|
+
const id = callRuntime("_id", scopeIdentifier);
|
|
8595
8702
|
const section = getSection(tag);
|
|
8596
|
-
const
|
|
8703
|
+
const binding = node.var.extra.binding;
|
|
8704
|
+
const signal = initValue(binding);
|
|
8597
8705
|
if (valueAttr) {
|
|
8598
8706
|
const { value } = valueAttr;
|
|
8599
|
-
addValue(section, value.extra, signal, _marko_compiler.types.logicalExpression("||", value, evaluate(value).confident ? id : callRuntime("_id", scopeIdentifier, _marko_compiler.types.stringLiteral(getPrefixedScopeAccessor(
|
|
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)))));
|
|
8600
8708
|
} else addValue(section, void 0, signal, id);
|
|
8601
|
-
replaceWithStatements(tag);
|
|
8602
8709
|
}
|
|
8710
|
+
replaceWithStatements(tag);
|
|
8603
8711
|
} },
|
|
8604
8712
|
parseOptions: { openTagOnly: true },
|
|
8605
8713
|
types: runtime_info_default.name + "/tags/id.d.marko"
|
|
@@ -8631,18 +8739,16 @@ var let_default = {
|
|
|
8631
8739
|
const binding = trackVarReferences(tag, 1);
|
|
8632
8740
|
const tagExtra = mergeReferences(tagSection, tag.node, [valueAttr?.value, valueChangeAttr?.value]);
|
|
8633
8741
|
setDerivedFrom(binding, tagExtra);
|
|
8742
|
+
tagExtra.pure = !valueAttr || evaluate(valueAttr.value).pure;
|
|
8634
8743
|
if (valueChangeAttr) {
|
|
8635
8744
|
const changeSlot = ensureSlot(binding, 1);
|
|
8636
8745
|
reserveId(binding, 1);
|
|
8637
8746
|
tagExtra.retained = true;
|
|
8638
|
-
tagExtra.pure
|
|
8747
|
+
tagExtra.pure &&= evaluate(valueChangeAttr.value).pure;
|
|
8639
8748
|
onFinalizeReferences(() => {
|
|
8640
8749
|
if (binding.assignments) addReason(changeSlot, ALWAYS);
|
|
8641
8750
|
});
|
|
8642
|
-
} else
|
|
8643
|
-
tagExtra.initialValue = true;
|
|
8644
|
-
tagExtra.pure = !valueAttr || evaluate(valueAttr.value).pure;
|
|
8645
|
-
}
|
|
8751
|
+
} else tagExtra.initialValue = true;
|
|
8646
8752
|
},
|
|
8647
8753
|
translate: { exit(tag) {
|
|
8648
8754
|
const { node } = tag;
|
|
@@ -8654,7 +8760,7 @@ var let_default = {
|
|
|
8654
8760
|
const { value, valueChange } = getKnownAttrValues(node);
|
|
8655
8761
|
const section = getSection(tag);
|
|
8656
8762
|
const binding = tagVar.extra.binding;
|
|
8657
|
-
const unused = binding.pruned && !
|
|
8763
|
+
const unused = binding.pruned && !binding.assignments;
|
|
8658
8764
|
if (isOutputDOM()) {
|
|
8659
8765
|
const tagExtra = tag.node.extra;
|
|
8660
8766
|
if (unused) {
|
|
@@ -8909,11 +9015,7 @@ var show_default = {
|
|
|
8909
9015
|
const tagSection = ensureSection(tag);
|
|
8910
9016
|
const content = tagExtra[kBodyContent] = getContentInfo(tag.get("body"));
|
|
8911
9017
|
if (getOnlyChildParentTagName(tag)) controlFlowNode(tag, tagSection);
|
|
8912
|
-
else if (!isSingleNodeContent(content))
|
|
8913
|
-
tagExtra[kStartBinding] = createBinding("#text", 0, tagSection);
|
|
8914
|
-
marker(tag, tagExtra[kStartBinding]);
|
|
8915
|
-
enterShallow(tag);
|
|
8916
|
-
}
|
|
9018
|
+
else if (!isSingleNodeContent(content)) tagExtra[kStartBinding] = markerNode(tag, tagSection);
|
|
8917
9019
|
if (tagExtra[kStaticDisplay] === void 0) mergeReferences(tagSection, tag.node, [display]);
|
|
8918
9020
|
else addSetupWork(tagSection);
|
|
8919
9021
|
},
|
|
@@ -9190,7 +9292,7 @@ function translateHTML$1(tag) {
|
|
|
9190
9292
|
const binding = node.extra?.nodeBinding;
|
|
9191
9293
|
if (binding) {
|
|
9192
9294
|
writeTo$1(tag)`${callRuntime("_style_html", buildStyleDecls(node))}`;
|
|
9193
|
-
markNode(tag, binding
|
|
9295
|
+
markNode(tag, binding);
|
|
9194
9296
|
}
|
|
9195
9297
|
emitStyleImport(tag);
|
|
9196
9298
|
replaceWithStatements(tag);
|
|
@@ -9312,14 +9414,12 @@ var try_default = {
|
|
|
9312
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.`);
|
|
9313
9415
|
const section = ensureSection(tag);
|
|
9314
9416
|
const tagExtra = mergeTagReferences(section, tag.node);
|
|
9315
|
-
|
|
9417
|
+
tagExtra.nodeBinding = markerNode(tag, section);
|
|
9316
9418
|
tagExtra.textBefore = mayMergeWithText(tag, true);
|
|
9317
9419
|
initBranchSection(ensureBodySection(tag.get("body")), tagExtra, {
|
|
9318
9420
|
kind: "try",
|
|
9319
9421
|
tag: tagExtra
|
|
9320
9422
|
});
|
|
9321
|
-
marker(tag, nodeBinding);
|
|
9322
|
-
enterShallow(tag);
|
|
9323
9423
|
},
|
|
9324
9424
|
translate: translateByTarget({
|
|
9325
9425
|
html: {
|
|
@@ -9639,10 +9739,9 @@ function translateExit(placeholder) {
|
|
|
9639
9739
|
if (isHTML) write`${node.escape ? _escape(computed) : _unescaped(computed)}`;
|
|
9640
9740
|
} else {
|
|
9641
9741
|
const section = getSection(placeholder);
|
|
9642
|
-
const markerReason = nodeBinding && getWriteReason(nodeBinding);
|
|
9643
9742
|
if (isHTML) {
|
|
9644
|
-
if (
|
|
9645
|
-
const guard =
|
|
9743
|
+
if (nodeBinding && isMarkerWritten(nodeBinding)) {
|
|
9744
|
+
const guard = getMarkerGuard(nodeBinding);
|
|
9646
9745
|
write`${callRuntime(node.escape ? "_text_mark" : "_html_mark", getScopeIdIdentifier(section), getScopeAccessorLiteral(nodeBinding), value, extra.textBefore ?? getSectionTextBefore(section) ?? true ? guard ? _marko_compiler.types.binaryExpression("*", guard, _marko_compiler.types.numericLiteral(2)) : _marko_compiler.types.numericLiteral(2) : guard)}`;
|
|
9647
9746
|
} else write`${method === "_escape" ? buildEscapedTextExpression(value) : callRuntime(method, value)}`;
|
|
9648
9747
|
} else addStatement("render", section, value.extra, method === "_text" ? callRuntime("_text", createScopeReadExpression(nodeBinding), value) : callRuntime("_html", scopeIdentifier, value, getScopeAccessorLiteral(nodeBinding)), true);
|
|
@@ -9712,12 +9811,8 @@ const builder = {
|
|
|
9712
9811
|
body.push(exportInit ? _marko_compiler.types.exportDefaultDeclaration(_marko_compiler.types.arrowFunctionExpression([getUnusedParamIdentifier()], initExpression)) : _marko_compiler.types.expressionStatement(initExpression));
|
|
9713
9812
|
return body;
|
|
9714
9813
|
},
|
|
9715
|
-
visit(file, entryFile, visitChild = (
|
|
9716
|
-
|
|
9717
|
-
if (markReached(entryFile[kState].visited, resolved, reach)) {
|
|
9718
|
-
const childFile = (0, _marko_compiler_babel_utils.loadFileForImport)(entryFile, resolved);
|
|
9719
|
-
if (childFile) builder.visit(childFile, entryFile);
|
|
9720
|
-
}
|
|
9814
|
+
visit(file, entryFile, visitChild = (childFile, reach = 0) => {
|
|
9815
|
+
if (markReached(entryFile, entryFile[kState].visited, childFile, reach)) builder.visit(childFile, entryFile);
|
|
9721
9816
|
}) {
|
|
9722
9817
|
const state = entryFile[kState] ||= {
|
|
9723
9818
|
init: false,
|
|
@@ -9731,7 +9826,7 @@ const builder = {
|
|
|
9731
9826
|
visited: createVisited(entryFile)
|
|
9732
9827
|
};
|
|
9733
9828
|
const programExtra = file.path.node.extra;
|
|
9734
|
-
const {
|
|
9829
|
+
const { assetImports } = file.metadata.marko;
|
|
9735
9830
|
const { loadImports } = programExtra;
|
|
9736
9831
|
const init = !!programExtra.isInteractive;
|
|
9737
9832
|
const hasClientStatement = !!programExtra.hasClientStatement;
|
|
@@ -9745,13 +9840,14 @@ const builder = {
|
|
|
9745
9840
|
for (const request of assetImports) assets.add(resolveRelativeToEntry(entryFile, file, request));
|
|
9746
9841
|
}
|
|
9747
9842
|
if (isRoot) state.bundledDepth++;
|
|
9748
|
-
|
|
9749
|
-
|
|
9843
|
+
const analyzedFiles = file.___analyzedFiles;
|
|
9844
|
+
for (const [filename, childFile] of analyzedFiles) {
|
|
9845
|
+
const lazy = loadImports?.has(filename);
|
|
9750
9846
|
if (lazy) {
|
|
9751
9847
|
state.bundledDepth++;
|
|
9752
9848
|
state.lazyDepth++;
|
|
9753
9849
|
}
|
|
9754
|
-
visitChild(
|
|
9850
|
+
visitChild(childFile, state.lazyDepth ? 2 : state.bundledDepth ? 1 : 0);
|
|
9755
9851
|
if (lazy) {
|
|
9756
9852
|
state.bundledDepth--;
|
|
9757
9853
|
state.lazyDepth--;
|
|
@@ -9764,15 +9860,17 @@ function assertVisited(entryFile, state) {
|
|
|
9764
9860
|
if (!state) throw entryFile.path.buildCodeFrameError("Unable to build resume code, no files were visited before finalizing the build");
|
|
9765
9861
|
}
|
|
9766
9862
|
function createVisited(entryFile) {
|
|
9767
|
-
return /* @__PURE__ */ new Map([[
|
|
9863
|
+
return /* @__PURE__ */ new Map([[entryFile.opts.filename, 0]]);
|
|
9768
9864
|
}
|
|
9769
9865
|
function resolveRelativeToEntry(entryFile, file, req) {
|
|
9770
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);
|
|
9771
9867
|
}
|
|
9772
|
-
function markReached(visited,
|
|
9773
|
-
const
|
|
9868
|
+
function markReached(entryFile, visited, file, reach) {
|
|
9869
|
+
const filename = file.opts.filename;
|
|
9870
|
+
const seen = visited.get(filename);
|
|
9774
9871
|
if (seen !== void 0 && seen <= reach) return false;
|
|
9775
|
-
visited.set(
|
|
9872
|
+
visited.set(filename, reach);
|
|
9873
|
+
(entryFile.metadata.marko.analyzedTags ||= /* @__PURE__ */ new Set()).add(filename);
|
|
9776
9874
|
return true;
|
|
9777
9875
|
}
|
|
9778
9876
|
// src/translator/util/get-style-file.ts
|
|
@@ -9859,8 +9957,9 @@ var dynamic_tag_default = {
|
|
|
9859
9957
|
if (!isEventHandler(attr.name)) (attr.value.extra ??= {}).retained = true;
|
|
9860
9958
|
}
|
|
9861
9959
|
if (isInteractive) (0, _marko_compiler_babel_utils.getProgram)().node.extra.isInteractive = true;
|
|
9862
|
-
const nodeBinding = tagExtra.nodeBinding =
|
|
9960
|
+
const nodeBinding = tagExtra.nodeBinding = markerNode(tag, tagSection);
|
|
9863
9961
|
if (hasVar) {
|
|
9962
|
+
tagSection.hasReturnedVar = true;
|
|
9864
9963
|
trackVarReferences(tag, 4).returnedBy = { scope: nodeBinding };
|
|
9865
9964
|
reserveId(nodeBinding, 1);
|
|
9866
9965
|
}
|
|
@@ -9873,8 +9972,6 @@ var dynamic_tag_default = {
|
|
|
9873
9972
|
if (usesVar) addAlwaysReason(nodeBinding);
|
|
9874
9973
|
addReasonExprs(ensureSlot(nodeBinding), tagExtra);
|
|
9875
9974
|
if (!hasVar && !node.arguments && !node.attributes.length && !node.body.body.length && !tagExtra.attrTagLookup) tagExtra.nameOnly = true;
|
|
9876
|
-
marker(tag, nodeBinding);
|
|
9877
|
-
enterShallow(tag);
|
|
9878
9975
|
if (bodySection && tagExtra.featureType === "class" && !(0, _marko_compiler_babel_utils.getTagTemplate)(tag)) bodySection.structure = null;
|
|
9879
9976
|
} },
|
|
9880
9977
|
translate: {
|
|
@@ -9943,33 +10040,37 @@ var dynamic_tag_default = {
|
|
|
9943
10040
|
const { properties, statements } = translateAttrs(tag, void 0, void 0, isClassAPI ? "renderBody" : "content");
|
|
9944
10041
|
const args = [];
|
|
9945
10042
|
const contentProp = getTranslatedBodyContentProperty(properties);
|
|
9946
|
-
let hasTagArgs = false;
|
|
9947
10043
|
if (node.arguments) {
|
|
9948
|
-
hasTagArgs = true;
|
|
9949
10044
|
args.push(...node.arguments);
|
|
9950
10045
|
if (properties.length) args.push(propsToExpression(properties));
|
|
9951
10046
|
} else if (contentProp) {
|
|
9952
10047
|
properties.splice(properties.indexOf(contentProp), 1);
|
|
9953
10048
|
args.push(propsToExpression(properties), contentProp.value);
|
|
9954
10049
|
} else args.push(propsToExpression(properties));
|
|
10050
|
+
const argsOrInput = node.arguments ? _marko_compiler.types.arrayExpression(args) : args[0];
|
|
9955
10051
|
if (isOutputHTML()) {
|
|
9956
10052
|
writeHTMLResumeStatements(tag);
|
|
9957
|
-
const markerGuard =
|
|
10053
|
+
const markerGuard = getMarkerGuard(nodeBinding);
|
|
9958
10054
|
const debugTagVar = !isOptimize() && node.var && _marko_compiler.types.numericLiteral(1);
|
|
9959
|
-
const
|
|
9960
|
-
|
|
10055
|
+
const varId = node.var && isTagVarResumed(tag) && getResumeRegistryId(tagSection, node.var.extra?.binding, "var");
|
|
10056
|
+
const scopeIdArg = getScopeIdIdentifier(tagSection);
|
|
10057
|
+
const accessorArg = getScopeAccessorLiteral(nodeBinding);
|
|
10058
|
+
const contentArg = contentProp ? contentProp.value : absentArg(0);
|
|
10059
|
+
const inputIsArgs = node.arguments ? _marko_compiler.types.numericLiteral(1) : absentArg(0);
|
|
10060
|
+
const markerArg = markerGuard || absentArg(1);
|
|
10061
|
+
const dynamicTagExpr = callRuntime("_dynamic_tag", scopeIdArg, accessorArg, tagExpression, argsOrInput, contentArg, inputIsArgs, markerArg, debugTagVar);
|
|
10062
|
+
if (varId) {
|
|
9961
10063
|
const dynamicScopeIdentifier = generateUidIdentifier(tag.get("name").toString() + "_scope");
|
|
9962
10064
|
const mutatesTagVar = isTagVarAssigned(tag);
|
|
9963
10065
|
statements.push(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(dynamicScopeIdentifier, callRuntime("_peek_scope_id"))]));
|
|
9964
10066
|
translateVar(tag, dynamicTagExpr, "let", statements);
|
|
9965
|
-
statements.push(_marko_compiler.types.expressionStatement(callRuntime("_var", getScopeIdIdentifier(tagSection), getScopeOffsetAccessorLiteral(nodeBinding), dynamicScopeIdentifier, _marko_compiler.types.stringLiteral(
|
|
10067
|
+
statements.push(_marko_compiler.types.expressionStatement(callRuntime("_var", getScopeIdIdentifier(tagSection), getScopeOffsetAccessorLiteral(nodeBinding), dynamicScopeIdentifier, _marko_compiler.types.stringLiteral(varId), mutatesTagVar ? getScopeAccessorLiteral(nodeBinding) : void 0)));
|
|
9966
10068
|
} else if (node.var) translateVar(tag, dynamicTagExpr, "let", statements);
|
|
9967
10069
|
else statements.push(_marko_compiler.types.expressionStatement(dynamicTagExpr));
|
|
9968
10070
|
replaceWithStatements(tag, statements);
|
|
9969
10071
|
} else {
|
|
9970
|
-
const section = getSection(tag);
|
|
9971
10072
|
const bodySection = getSectionForBody(tag.get("body"));
|
|
9972
|
-
const signal = getSignal(
|
|
10073
|
+
const signal = getSignal(tagSection, nodeBinding, "dynamicTag");
|
|
9973
10074
|
let tagVarSignal;
|
|
9974
10075
|
if (tag.node.var && isTagVarResumed(tag)) {
|
|
9975
10076
|
const varBinding = tag.node.var.extra.binding;
|
|
@@ -9979,21 +10080,18 @@ var dynamic_tag_default = {
|
|
|
9979
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);
|
|
9980
10081
|
}
|
|
9981
10082
|
signal.build = () => {
|
|
9982
|
-
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));
|
|
9983
10084
|
};
|
|
9984
10085
|
const directBinding = getReferencedBindings(tagExtra);
|
|
9985
10086
|
const directName = directBinding && !Array.isArray(directBinding) && (0, _marko_compiler_babel_utils.getProgram)().node.extra.exportNames.directContent.get(directBinding);
|
|
9986
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)))])));
|
|
9987
|
-
if (args.length)
|
|
9988
|
-
const argsOrInput = hasTagArgs ? _marko_compiler.types.arrayExpression(args) : args[0];
|
|
9989
|
-
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)];
|
|
9990
|
-
}
|
|
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)];
|
|
9991
10089
|
enableDynamicTagVar(tag);
|
|
9992
10090
|
if (!isClassAPI) {
|
|
9993
10091
|
if (mayHaveNativeAttr(tag, isEventOrChangeHandler)) importRuntimeFeature("dynamic-tag-script");
|
|
9994
10092
|
if (mayHaveNativeAttr(tag, isControllableAttr)) importRuntimeFeature("controllable");
|
|
9995
10093
|
}
|
|
9996
|
-
addValue(
|
|
10094
|
+
addValue(tagSection, tagExtra, signal, tagExpression);
|
|
9997
10095
|
replaceWithStatements(tag);
|
|
9998
10096
|
}
|
|
9999
10097
|
}
|
|
@@ -10049,9 +10147,7 @@ var dom_default = { translate: {
|
|
|
10049
10147
|
forEachSectionReverse((childSection) => {
|
|
10050
10148
|
if (childSection !== section) {
|
|
10051
10149
|
const tagParamsSignal = childSection.params && initValue(childSection.params);
|
|
10052
|
-
forEach(childSection.localClosures,
|
|
10053
|
-
initValue(closure).build = void 0;
|
|
10054
|
-
});
|
|
10150
|
+
forEach(childSection.localClosures, skipClosureBuild);
|
|
10055
10151
|
const tagParamsIdentifier = tagParamsSignal && signalHasWork(tagParamsSignal) ? tagParamsSignal.identifier : void 0;
|
|
10056
10152
|
const meta = getSectionMeta(childSection);
|
|
10057
10153
|
const { writes } = meta;
|
|
@@ -10082,16 +10178,16 @@ var dom_default = { translate: {
|
|
|
10082
10178
|
}
|
|
10083
10179
|
});
|
|
10084
10180
|
const registerWrapper = !!(registerReason && objProps.length);
|
|
10085
|
-
|
|
10181
|
+
const registerClosures = !!registerReason && !!getDynamicTagContentClosures(childSection);
|
|
10182
|
+
let renderer = callRuntime(registerReason && !registerWrapper && !registerClosures ? "_content_resume" : "_content", _marko_compiler.types.stringLiteral(registryId), ...trimEmptyArgs([
|
|
10086
10183
|
writes,
|
|
10087
10184
|
walks,
|
|
10088
10185
|
...markReturn(childSection, setupIdentifier, tagParamsIdentifier),
|
|
10089
10186
|
childSection.hoisted || childSection.isHoistThrough ? getSectionScopesAccessorLiteral(childSection) : void 0
|
|
10090
10187
|
]));
|
|
10091
|
-
if (!registerReason || registerWrapper) renderer = _marko_compiler.types.addComment(renderer, "leading", "@__PURE__");
|
|
10092
10188
|
if (objProps.length) renderer = callRuntime("_content_closures", renderer, _marko_compiler.types.objectExpression(objProps));
|
|
10093
10189
|
program.node.body.push(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(childSection.name), renderer)]));
|
|
10094
|
-
if (
|
|
10190
|
+
if (registerClosures) program.node.body.push(_marko_compiler.types.expressionStatement(callRuntime("_content_closures_resume", _marko_compiler.types.identifier(childSection.name), registerWrapper && _marko_compiler.types.numericLiteral(1))));
|
|
10095
10191
|
else if (registerWrapper) program.node.body.push(_marko_compiler.types.expressionStatement(registerRuntimeValue(registryId, _marko_compiler.types.identifier(childSection.name))));
|
|
10096
10192
|
}
|
|
10097
10193
|
}
|
|
@@ -10119,12 +10215,16 @@ function markReturn(section, setup, params) {
|
|
|
10119
10215
|
function emptySetup() {
|
|
10120
10216
|
return _marko_compiler.types.arrowFunctionExpression([getUnusedParamIdentifier()], _marko_compiler.types.blockStatement([]));
|
|
10121
10217
|
}
|
|
10218
|
+
function skipClosureBuild(closure) {
|
|
10219
|
+
initValue(closure).build = void 0;
|
|
10220
|
+
}
|
|
10122
10221
|
// src/translator/visitors/program/html.ts
|
|
10123
10222
|
var html_default = { translate: {
|
|
10124
10223
|
enter() {
|
|
10125
10224
|
const sectionDynamicSubscribers = /* @__PURE__ */ new Set();
|
|
10126
10225
|
forEachSection((section) => {
|
|
10127
10226
|
forEach(section.bindings, (binding) => {
|
|
10227
|
+
if (!binding.getters) return;
|
|
10128
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))))]));
|
|
10129
10229
|
});
|
|
10130
10230
|
forEach(section.hoisted, (binding) => {
|
|
@@ -10205,9 +10305,7 @@ function buildResumeCall(node) {
|
|
|
10205
10305
|
const referencedLocals = extra.referencedLocalBindingsInFunction;
|
|
10206
10306
|
if (referencedLocals) {
|
|
10207
10307
|
const localProperties = [];
|
|
10208
|
-
forEach(referencedLocals,
|
|
10209
|
-
localProperties.push(toObjectProperty(getLocalsScopeAccessor(binding), getDeclaredBindingExpression(binding)));
|
|
10210
|
-
});
|
|
10308
|
+
forEach(referencedLocals, pushLocalProperty, localProperties);
|
|
10211
10309
|
return callRuntime("_resume_locals", simplifyFunction(node), _marko_compiler.types.stringLiteral(extra.registryId), _marko_compiler.types.objectExpression(localProperties), extra.referencesScope && getScopeIdIdentifier(extra.section));
|
|
10212
10310
|
}
|
|
10213
10311
|
return callRuntime("_resume", simplifyFunction(node), _marko_compiler.types.stringLiteral(extra.registryId), extra.referencesScope && getScopeIdIdentifier(extra.section));
|
|
@@ -10262,14 +10360,14 @@ var program_default = {
|
|
|
10262
10360
|
{
|
|
10263
10361
|
const markoOpts = getMarkoOpts();
|
|
10264
10362
|
const { output, entry, runtimeId } = markoOpts;
|
|
10363
|
+
const entryFile = (0, _marko_compiler_babel_utils.getFile)();
|
|
10364
|
+
const { filename } = entryFile.opts;
|
|
10265
10365
|
const isLoadEntry = entry === "load";
|
|
10266
10366
|
const isDOMPageEntry = output === "dom" && entry === "page" || output === "hydrate";
|
|
10267
10367
|
const isServerEntry = output === "html" && entry === "page";
|
|
10268
10368
|
if (entry && !markoOpts.linkAssets) throw program.buildCodeFrameError("The \"entry\" option requires the `linkAssets` compiler option to be configured.");
|
|
10269
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.`);
|
|
10270
10370
|
if (isLoadEntry) {
|
|
10271
|
-
const entryFile = (0, _marko_compiler_babel_utils.getFile)();
|
|
10272
|
-
const { filename } = entryFile.opts;
|
|
10273
10371
|
const readyId = getReadyId(entryFile);
|
|
10274
10372
|
const report = !markoOpts.optimize;
|
|
10275
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)]))))];
|
|
@@ -10277,15 +10375,12 @@ var program_default = {
|
|
|
10277
10375
|
return;
|
|
10278
10376
|
}
|
|
10279
10377
|
if (isDOMPageEntry) {
|
|
10280
|
-
const entryFile = (0, _marko_compiler_babel_utils.getFile)();
|
|
10281
10378
|
builder.visit(entryFile, entryFile);
|
|
10282
10379
|
program.node.body = builder.build(entryFile);
|
|
10283
10380
|
program.skip();
|
|
10284
10381
|
return;
|
|
10285
10382
|
}
|
|
10286
10383
|
if (isServerEntry) {
|
|
10287
|
-
const entryFile = (0, _marko_compiler_babel_utils.getFile)();
|
|
10288
|
-
const { filename } = entryFile.opts;
|
|
10289
10384
|
const relativeImport = (0, _marko_compiler_babel_utils.resolveRelativePath)(entryFile, filename);
|
|
10290
10385
|
const templateId = (0, _marko_compiler_babel_utils.getTemplateId)(markoOpts, filename);
|
|
10291
10386
|
const pageAssetArgs = [
|
|
@@ -10496,9 +10591,8 @@ function translateDOM(tag) {
|
|
|
10496
10591
|
const childExports = childFile.ast.program.extra.exportNames;
|
|
10497
10592
|
const { childSection } = tagExtra;
|
|
10498
10593
|
const loadConfig = tagExtra.tagNameLoad;
|
|
10499
|
-
const isLoad = !!loadConfig;
|
|
10500
10594
|
const tagName = getTagNameHint(node);
|
|
10501
|
-
if (
|
|
10595
|
+
if (loadConfig) {
|
|
10502
10596
|
const childFileName = childFile.opts.filename;
|
|
10503
10597
|
const { triggers, signals, setups } = getLoadIdentifiers();
|
|
10504
10598
|
let triggerIdent = triggers.get(loadConfig);
|
|
@@ -10583,7 +10677,6 @@ function isTemplateImport(tag) {
|
|
|
10583
10677
|
// src/translator/visitors/tag/native-tag.ts
|
|
10584
10678
|
const kNodeOp = Symbol("native tag structure node");
|
|
10585
10679
|
const kNativeAttrs = Symbol("native tag attrs");
|
|
10586
|
-
const htmlContentAttrTags = /* @__PURE__ */ new WeakSet();
|
|
10587
10680
|
const htmlSelectArgs = /* @__PURE__ */ new WeakMap();
|
|
10588
10681
|
var native_tag_default = {
|
|
10589
10682
|
analyze: {
|
|
@@ -10617,7 +10710,6 @@ var native_tag_default = {
|
|
|
10617
10710
|
valueExtra.isEffect = true;
|
|
10618
10711
|
valueExtra.retained = true;
|
|
10619
10712
|
hasEventHandlers = true;
|
|
10620
|
-
hasDynamicAttributes = true;
|
|
10621
10713
|
if (!spread) {
|
|
10622
10714
|
spread = [];
|
|
10623
10715
|
controllable = getRelatedControllable(tagName, attributes, indexByName);
|
|
@@ -10673,7 +10765,10 @@ var native_tag_default = {
|
|
|
10673
10765
|
if (controllable && controllable.stateIsAttr && controllable.attrs[1] === void 0 && evaluate(attributes[controllable.attrs.find(isDefined)].value).confident) controllable = void 0;
|
|
10674
10766
|
own = addOwnControllableAttrs(own, controllableAttrNames, indexByName, controllable);
|
|
10675
10767
|
}
|
|
10676
|
-
if (controllable?.attrs[1] !== void 0)
|
|
10768
|
+
if (controllable?.attrs[1] !== void 0) {
|
|
10769
|
+
hasEventHandlers = true;
|
|
10770
|
+
addSetupWork(tagSection);
|
|
10771
|
+
}
|
|
10677
10772
|
assertExclusiveAttrs(indexByName, (msg) => {
|
|
10678
10773
|
throw tag.get("name").buildCodeFrameError(msg);
|
|
10679
10774
|
}, isDefined);
|
|
@@ -10717,7 +10812,6 @@ var native_tag_default = {
|
|
|
10717
10812
|
addSetupExpr(tagSection, textPlaceholders[0]);
|
|
10718
10813
|
}
|
|
10719
10814
|
if (injectsNonce && !spread) addSetupWork(tagSection);
|
|
10720
|
-
if (controllable?.attrs[1] !== void 0) addSetupWork(tagSection);
|
|
10721
10815
|
if (hasEventHandlers || usesVar) addAlwaysReason(nodeBinding);
|
|
10722
10816
|
trackDomVarReferences(tag, nodeBinding);
|
|
10723
10817
|
addReasonExprs(ensureSlot(nodeBinding), push(exprExtras, tagExtra));
|
|
@@ -10755,7 +10849,8 @@ var native_tag_default = {
|
|
|
10755
10849
|
content,
|
|
10756
10850
|
controllable,
|
|
10757
10851
|
spread,
|
|
10758
|
-
injectsNonce
|
|
10852
|
+
injectsNonce,
|
|
10853
|
+
spreadContent: !!spread && content === void 0 && !node$1.body.body.length && !isTextOnly && !(0, _marko_compiler_babel_utils.getTagDef)(tag)?.parseOptions?.openTagOnly
|
|
10759
10854
|
};
|
|
10760
10855
|
},
|
|
10761
10856
|
exit(tag) {
|
|
@@ -10807,31 +10902,28 @@ var native_tag_default = {
|
|
|
10807
10902
|
if (tagName === "select" && (controllable || spreadExpression)) flushBefore(tag);
|
|
10808
10903
|
write`<${tagName}`;
|
|
10809
10904
|
if (injectsNonce && !spread) write`${callRuntime("_attr_nonce")}`;
|
|
10905
|
+
let writeAtStartOfBody;
|
|
10810
10906
|
if (controllable) {
|
|
10811
|
-
|
|
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);
|
|
10812
10915
|
if (controllable.attrs[1] !== void 0) addHTMLEffectCall(tagSection, void 0);
|
|
10813
10916
|
}
|
|
10814
|
-
let writeAtStartOfBody;
|
|
10815
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");
|
|
10816
|
-
if (
|
|
10817
|
-
if (
|
|
10818
|
-
helper: "_attr_select_value",
|
|
10819
|
-
args: [attrAt(attributes, controllable.attrs[0])?.value || _marko_compiler.types.buildUndefinedNode(), attrAt(attributes, controllable.attrs[1])?.value || absentArg(0)]
|
|
10820
|
-
});
|
|
10821
|
-
else if (spreadExpression) {
|
|
10918
|
+
if (spreadExpression && !controllable) {
|
|
10919
|
+
if (tagName === "select") {
|
|
10822
10920
|
const spreadIdentifier = declareConstBefore(tag, "select_input", spreadExpression);
|
|
10823
10921
|
htmlSelectArgs.set(tag.node, {
|
|
10824
10922
|
helper: "_attrs_select_value",
|
|
10825
10923
|
args: [spreadIdentifier]
|
|
10826
10924
|
});
|
|
10827
10925
|
spreadExpression = spreadIdentifier;
|
|
10828
|
-
}
|
|
10829
|
-
} else if (tagName === "textarea") {
|
|
10830
|
-
if (controllable) {
|
|
10831
|
-
const value = attrAt(attributes, controllable.attrs[0]);
|
|
10832
|
-
const valueChange = attrAt(attributes, controllable.attrs[1]);
|
|
10833
|
-
writeAtStartOfBody = valueChange ? callRuntime("_attr_textarea_value", getScopeIdIdentifier(tagSection), nodeAccessor, value?.value, valueChange.value) : callRuntime("_textarea_value", value.value);
|
|
10834
|
-
} else if (spreadExpression) {
|
|
10926
|
+
} else if (tagName === "textarea") {
|
|
10835
10927
|
const spreadIdentifier = declareConstBefore(tag, "textarea_input", spreadExpression);
|
|
10836
10928
|
writeAtStartOfBody = callRuntime("_attrs_textarea_value", getScopeIdIdentifier(tagSection), nodeAccessor, spreadIdentifier);
|
|
10837
10929
|
spreadExpression = spreadIdentifier;
|
|
@@ -10849,28 +10941,27 @@ var native_tag_default = {
|
|
|
10849
10941
|
if (handlers) for (const index of handlers) addHTMLEffectCall(tagSection, attributes[index].value.extra);
|
|
10850
10942
|
const isOpenOnly = !!(tagDef && tagDef.parseOptions?.openTagOnly);
|
|
10851
10943
|
const isTextOnly = getTagFacts(tag).textBody;
|
|
10852
|
-
const spreadContent =
|
|
10944
|
+
const { spreadContent } = nativeAttrs;
|
|
10945
|
+
let spreadCall;
|
|
10853
10946
|
if (spreadExpression) {
|
|
10854
10947
|
addHTMLEffectCall(tagSection, tagExtra);
|
|
10855
|
-
|
|
10856
|
-
|
|
10857
|
-
|
|
10858
|
-
|
|
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}`;
|
|
10859
10953
|
}
|
|
10860
10954
|
if (isOpenOnly || isTextOnly) write`>`;
|
|
10861
10955
|
else if (contentAttr) {
|
|
10862
10956
|
write`>`;
|
|
10863
|
-
|
|
10864
|
-
|
|
10865
|
-
|
|
10866
|
-
const markerGuard = getWriteGuard(tagSection, nodeBinding && getWriteReason(nodeBinding), true);
|
|
10867
|
-
htmlContentAttrTags.add(tag.node);
|
|
10868
|
-
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))];
|
|
10869
|
-
} else write`>`;
|
|
10957
|
+
tag.node.body.body = [_marko_compiler.types.expressionStatement(callRuntime("_attr_content", nodeAccessor, getScopeIdIdentifier(tagSection), contentAttr.value, getMarkerGuard(nodeBinding)))];
|
|
10958
|
+
} else if (spreadContent) tag.node.body.body = [_marko_compiler.types.expressionStatement(spreadCall)];
|
|
10959
|
+
else write`>`;
|
|
10870
10960
|
if (writeAtStartOfBody) write`${writeAtStartOfBody}`;
|
|
10871
10961
|
},
|
|
10872
10962
|
exit(tag) {
|
|
10873
|
-
const
|
|
10963
|
+
const tagExtra = tag.node.extra;
|
|
10964
|
+
const nodeBinding = tagExtra.nodeBinding;
|
|
10874
10965
|
const isOpenOnly = (0, _marko_compiler_babel_utils.getTagDef)(tag)?.parseOptions?.openTagOnly;
|
|
10875
10966
|
const isTextOnly = getTagFacts(tag).textBody;
|
|
10876
10967
|
const selectArgs = htmlSelectArgs.get(tag.node);
|
|
@@ -10879,7 +10970,8 @@ var native_tag_default = {
|
|
|
10879
10970
|
const skipEndTag = isEndTagWrittenByBranch(nodeBinding);
|
|
10880
10971
|
const markerReason = !skipEndTag && nodeBinding && getWriteReason(nodeBinding);
|
|
10881
10972
|
const write = writeTo$1(tag, tagName === "html" || !markerReason && tagName === "body");
|
|
10882
|
-
|
|
10973
|
+
const { content, spreadContent } = tagExtra[kNativeAttrs];
|
|
10974
|
+
if (content !== void 0 || spreadContent) flushBefore(tag);
|
|
10883
10975
|
let statements = [];
|
|
10884
10976
|
if (selectArgs) {
|
|
10885
10977
|
if (!skipEndTag) write`</${tagName}>`;
|
|
@@ -10897,7 +10989,7 @@ var native_tag_default = {
|
|
|
10897
10989
|
if (tagName === "head" && getMarkoOpts().linkAssets) write`${callRuntime("_flush_head")}`;
|
|
10898
10990
|
write`</${tagName}>`;
|
|
10899
10991
|
}
|
|
10900
|
-
if (markerReason) markNode(tag, nodeBinding,
|
|
10992
|
+
if (markerReason) markNode(tag, nodeBinding, tagName === "html");
|
|
10901
10993
|
replaceWithStatements(tag, statements);
|
|
10902
10994
|
}
|
|
10903
10995
|
},
|
|
@@ -10928,44 +11020,39 @@ var native_tag_default = {
|
|
|
10928
11020
|
}
|
|
10929
11021
|
if (own) for (const index of own) {
|
|
10930
11022
|
const { name, value } = attributes[index];
|
|
10931
|
-
|
|
10932
|
-
|
|
10933
|
-
|
|
10934
|
-
|
|
10935
|
-
|
|
10936
|
-
|
|
10937
|
-
|
|
10938
|
-
|
|
10939
|
-
|
|
10940
|
-
|
|
10941
|
-
|
|
10942
|
-
|
|
10943
|
-
|
|
10944
|
-
|
|
10945
|
-
|
|
10946
|
-
|
|
10947
|
-
|
|
10948
|
-
|
|
10949
|
-
|
|
10950
|
-
|
|
10951
|
-
}
|
|
10952
|
-
for (const call of calls) addStatement("render", tagSection, value.extra, call, true);
|
|
10953
|
-
}
|
|
10954
|
-
break;
|
|
10955
|
-
default: if (confident) break;
|
|
10956
|
-
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)))));
|
|
10957
11043
|
}
|
|
11044
|
+
for (const call of calls) addStatement("render", tagSection, value.extra, call, true);
|
|
10958
11045
|
}
|
|
10959
11046
|
if (handlers) for (const index of handlers) {
|
|
10960
11047
|
const { name, value } = attributes[index];
|
|
10961
11048
|
addStatement("effect", tagSection, value.extra, callRuntime("_on", createScopeReadExpression(nodeBinding), _marko_compiler.types.stringLiteral(getEventType(name)), value));
|
|
10962
11049
|
}
|
|
10963
11050
|
if (spreadExpression) {
|
|
10964
|
-
const spreadContent = spreadRendersContent(tag, contentAttr, getTagFacts(tag).textBody);
|
|
10965
11051
|
const element = controllableElements.get(tagName);
|
|
10966
11052
|
const spreadHelper = !controllable && element?.spreadHelper;
|
|
10967
|
-
|
|
10968
|
-
|
|
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));
|
|
10969
11056
|
if (element) importRuntimeFeature(element.feature);
|
|
10970
11057
|
addStatement("effect", tagSection, tagExtra, callRuntime("_attrs_script", scopeIdentifier, nodeAccessor));
|
|
10971
11058
|
}
|
|
@@ -11057,9 +11144,6 @@ function getInputValueMode(typeAttr) {
|
|
|
11057
11144
|
function getDOMControllableDefaultHelper(helper, { valueMode }) {
|
|
11058
11145
|
return helper === "_attr_input_value" && valueMode ? `_attr_input_value_${valueMode}_default` : `${helper}_default`;
|
|
11059
11146
|
}
|
|
11060
|
-
function spreadRendersContent(tag, staticContentAttr, isTextOnly) {
|
|
11061
|
-
return !(staticContentAttr || tag.node.body.body.length || isTextOnly || (0, _marko_compiler_babel_utils.getTagDef)(tag)?.parseOptions?.openTagOnly);
|
|
11062
|
-
}
|
|
11063
11147
|
function buildSpreadExpression(attributes, spread, injectsNonce) {
|
|
11064
11148
|
const props = [];
|
|
11065
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"))));
|
|
@@ -11132,8 +11216,9 @@ function warnCamelCaseStyleKeys(tag, attr) {
|
|
|
11132
11216
|
}
|
|
11133
11217
|
}
|
|
11134
11218
|
function assertNativeHandlerAttr(tag, attr) {
|
|
11135
|
-
|
|
11136
|
-
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);
|
|
11137
11222
|
}
|
|
11138
11223
|
function getCanonicalTagName(tag) {
|
|
11139
11224
|
const tagName = getTagName(tag);
|
|
@@ -11411,6 +11496,12 @@ function addToggle(meta, key, value, alternate) {
|
|
|
11411
11496
|
});
|
|
11412
11497
|
}
|
|
11413
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
|
+
};
|
|
11414
11505
|
const kAnalyzeFailed = Symbol("analyze failed");
|
|
11415
11506
|
var tag_default = {
|
|
11416
11507
|
analyze: {
|
|
@@ -11419,23 +11510,8 @@ var tag_default = {
|
|
|
11419
11510
|
const tagDef = (0, _marko_compiler_babel_utils.getTagDef)(tag);
|
|
11420
11511
|
const type = analyzeTagNameType(tag);
|
|
11421
11512
|
const hook = tagDef?.analyzer?.hook;
|
|
11422
|
-
if (hook)
|
|
11423
|
-
|
|
11424
|
-
return;
|
|
11425
|
-
}
|
|
11426
|
-
if (type === 0) {
|
|
11427
|
-
native_tag_default.analyze.enter(tag);
|
|
11428
|
-
return;
|
|
11429
|
-
}
|
|
11430
|
-
switch (type) {
|
|
11431
|
-
case 1:
|
|
11432
|
-
custom_tag_default.analyze.enter(tag);
|
|
11433
|
-
break;
|
|
11434
|
-
case 3:
|
|
11435
|
-
attribute_tag_default.analyze.enter(tag);
|
|
11436
|
-
break;
|
|
11437
|
-
case 2: dynamic_tag_default.analyze.enter(tag);
|
|
11438
|
-
}
|
|
11513
|
+
if (hook) enterHook(hook, tag);
|
|
11514
|
+
else tagVisitors[type].analyze.enter(tag);
|
|
11439
11515
|
} catch (err) {
|
|
11440
11516
|
(tag.node.extra ??= {})[kAnalyzeFailed] = true;
|
|
11441
11517
|
reportAnalyzeError(tag, err);
|
|
@@ -11470,18 +11546,7 @@ var tag_default = {
|
|
|
11470
11546
|
for (const attr of tag.get("attributes")) if (attr.isMarkoAttribute()) {
|
|
11471
11547
|
if (attr.node.arguments) throw attr.buildCodeFrameError(`Unsupported arguments on the \`${attr.node.name}\` attribute.`);
|
|
11472
11548
|
}
|
|
11473
|
-
|
|
11474
|
-
case 0:
|
|
11475
|
-
native_tag_default.translate.enter(tag);
|
|
11476
|
-
break;
|
|
11477
|
-
case 1:
|
|
11478
|
-
custom_tag_default.translate.enter(tag);
|
|
11479
|
-
break;
|
|
11480
|
-
case 2:
|
|
11481
|
-
dynamic_tag_default.translate.enter(tag);
|
|
11482
|
-
break;
|
|
11483
|
-
case 3: attribute_tag_default.translate.enter(tag);
|
|
11484
|
-
}
|
|
11549
|
+
tagVisitors[analyzeTagNameType(tag)].translate.enter(tag);
|
|
11485
11550
|
},
|
|
11486
11551
|
exit(tag) {
|
|
11487
11552
|
writeBodyStatements(tag.node.body);
|
|
@@ -11490,18 +11555,7 @@ var tag_default = {
|
|
|
11490
11555
|
exitHook(translator.hook, tag);
|
|
11491
11556
|
return;
|
|
11492
11557
|
}
|
|
11493
|
-
|
|
11494
|
-
case 0:
|
|
11495
|
-
native_tag_default.translate.exit(tag);
|
|
11496
|
-
break;
|
|
11497
|
-
case 1:
|
|
11498
|
-
custom_tag_default.translate.exit(tag);
|
|
11499
|
-
break;
|
|
11500
|
-
case 2:
|
|
11501
|
-
dynamic_tag_default.translate.exit(tag);
|
|
11502
|
-
break;
|
|
11503
|
-
case 3: attribute_tag_default.translate.exit(tag);
|
|
11504
|
-
}
|
|
11558
|
+
tagVisitors[analyzeTagNameType(tag)].translate.exit(tag);
|
|
11505
11559
|
}
|
|
11506
11560
|
}
|
|
11507
11561
|
};
|
|
@@ -11519,10 +11573,10 @@ var text_default = {
|
|
|
11519
11573
|
} }
|
|
11520
11574
|
};
|
|
11521
11575
|
// src/translator/interop/build-aggregate-error.ts
|
|
11522
|
-
function buildAggregateError(file, rootMsg, ...
|
|
11576
|
+
function buildAggregateError(file, rootMsg, ...features) {
|
|
11523
11577
|
const err = /* @__PURE__ */ new SyntaxError();
|
|
11524
11578
|
const fileName = path.default.relative(_marko_compiler_modules.cwd, file.opts.filename);
|
|
11525
|
-
const finalMsg = `${rootMsg}:\n\n${
|
|
11579
|
+
const finalMsg = `${rootMsg}:\n\n${features.map(([msg, node]) => `\x1b[90m${msg} at ${getFileNameWithLoc(fileName, node)}:\x1b[0m\n${getFrame(file, node)}`).join("\n\n")}`;
|
|
11526
11580
|
if (!("MARKO_DEBUG" in process.env)) err.stack = finalMsg;
|
|
11527
11581
|
Object.defineProperty(err, "message", {
|
|
11528
11582
|
get() {
|
|
@@ -11532,7 +11586,7 @@ function buildAggregateError(file, rootMsg, ...paths) {
|
|
|
11532
11586
|
});
|
|
11533
11587
|
return err;
|
|
11534
11588
|
}
|
|
11535
|
-
function getFrame(file, {
|
|
11589
|
+
function getFrame(file, { loc }) {
|
|
11536
11590
|
return loc ? (0, _marko_compiler_internal_babel.codeFrameColumns)(file.code, {
|
|
11537
11591
|
start: {
|
|
11538
11592
|
line: loc.start.line,
|
|
@@ -11544,7 +11598,7 @@ function getFrame(file, { node: { loc } }) {
|
|
|
11544
11598
|
} : void 0
|
|
11545
11599
|
}, { highlightCode: true }) : "";
|
|
11546
11600
|
}
|
|
11547
|
-
function getFileNameWithLoc(fileName, {
|
|
11601
|
+
function getFileNameWithLoc(fileName, { loc }) {
|
|
11548
11602
|
if (loc) return `${fileName}(${loc.start.line},${loc.start.column + 1})`;
|
|
11549
11603
|
return fileName;
|
|
11550
11604
|
}
|
|
@@ -11559,9 +11613,9 @@ function isTagsAPI(file = (0, _marko_compiler_babel_utils.getFile)()) {
|
|
|
11559
11613
|
if (!featureType) {
|
|
11560
11614
|
const lookup = (0, _marko_compiler_babel_utils.getTaglibLookup)(file);
|
|
11561
11615
|
const tagsDir = getTagsDir(lookup, file.opts.filename);
|
|
11562
|
-
const state = {};
|
|
11563
|
-
if (tagsDir && !lookup.manualTagsDirs?.has(tagsDir)) addFeature(state, Tags, "Template file within a tags directory", program);
|
|
11564
|
-
scanBody(state, program.
|
|
11616
|
+
const state = { file };
|
|
11617
|
+
if (tagsDir && !lookup.manualTagsDirs?.has(tagsDir)) addFeature(state, Tags, "Template file within a tags directory", program.node);
|
|
11618
|
+
scanBody(state, program.node.body, void 0);
|
|
11565
11619
|
featureType = file.metadata.marko.api = programExtra.featureType = state.feature?.type || (lookup.exclusiveTagDiscoveryDirs === "tags" ? "tags" : "class");
|
|
11566
11620
|
}
|
|
11567
11621
|
return featureType === Tags;
|
|
@@ -11571,45 +11625,56 @@ function getTagsDir(lookup, filename) {
|
|
|
11571
11625
|
for (const dir of lookup.discoveryDirs || []) if (filename.startsWith(dir) && (filename[dir.length] === "/" || filename[dir.length] === "\\") && (!nearest || dir.length > nearest.length)) nearest = dir;
|
|
11572
11626
|
return !!nearest && /[/\\]tags$/.test(nearest) && nearest;
|
|
11573
11627
|
}
|
|
11574
|
-
|
|
11628
|
+
/** Scans `body`, in the tag whose fully resolved name is `parentName`. */
|
|
11629
|
+
function scanBody(state, body, parentName) {
|
|
11575
11630
|
for (const child of body) switch (child.type) {
|
|
11576
11631
|
case "MarkoTag":
|
|
11577
|
-
scanTag(state, child);
|
|
11632
|
+
scanTag(state, child, parentName);
|
|
11578
11633
|
break;
|
|
11579
11634
|
case "MarkoComment":
|
|
11580
|
-
if (/^\s*use tags\s*$/.test(child.
|
|
11581
|
-
else if (/^\s*use class\s*$/.test(child.
|
|
11635
|
+
if (/^\s*use tags\s*$/.test(child.value)) addFeature(state, Tags, "<!-- use tags -->", child);
|
|
11636
|
+
else if (/^\s*use class\s*$/.test(child.value)) addFeature(state, Class, "<!-- use class -->", child);
|
|
11582
11637
|
break;
|
|
11583
11638
|
case "MarkoScriptlet":
|
|
11584
|
-
if (!child.
|
|
11639
|
+
if (!child.static) addFeature(state, Class, "Scriptlet", child);
|
|
11585
11640
|
break;
|
|
11586
|
-
case "MarkoClass": addFeature(state, Class, "Class block", child.
|
|
11641
|
+
case "MarkoClass": addFeature(state, Class, "Class block", child.body);
|
|
11587
11642
|
}
|
|
11588
11643
|
}
|
|
11589
|
-
function scanTag(state, tag) {
|
|
11590
|
-
if (tag.
|
|
11591
|
-
const
|
|
11644
|
+
function scanTag(state, tag, parentName) {
|
|
11645
|
+
if (tag.var) addFeature(state, Tags, "Tag variable", tag.var);
|
|
11646
|
+
const { name } = tag;
|
|
11647
|
+
const fullName = name.type !== "StringLiteral" ? "*" : name.value[0] === "@" ? (parentName ? parentName + ":" : "") + name.value.slice(1) : name.value;
|
|
11648
|
+
const tagDef = getNodeTagDef(state.file, tag, fullName);
|
|
11592
11649
|
if (tagDef) {
|
|
11593
11650
|
if (tagDef.name === "style") {
|
|
11594
|
-
if (/^style(?:(?:\.[^.\s\\/:*?"<>|({]+)+)?\s*\{/.test(tag.
|
|
11651
|
+
if (/^style(?:(?:\.[^.\s\\/:*?"<>|({]+)+)?\s*\{/.test(tag.rawValue || "")) addFeature(state, Class, `style block`, tag.name);
|
|
11595
11652
|
} else if (tagDef.taglibId === runtime_info_default.taglibId) {
|
|
11596
11653
|
const feature = getFeatureTypeFromCoreTagName(tagDef.name);
|
|
11597
|
-
if (feature) addFeature(state, feature, `<${tagDef.name}> tag`, tag.
|
|
11654
|
+
if (feature) addFeature(state, feature, `<${tagDef.name}> tag`, tag.name);
|
|
11598
11655
|
}
|
|
11599
11656
|
}
|
|
11600
11657
|
if (!tagDef?.parseOptions?.rawOpenTag) {
|
|
11601
|
-
for (const attr of tag.
|
|
11602
|
-
if (attr.
|
|
11603
|
-
addFeature(state, Class, "Attribute arguments", attr.
|
|
11658
|
+
for (const attr of tag.attributes) if (attr.type === "MarkoAttribute") {
|
|
11659
|
+
if (attr.arguments?.length) {
|
|
11660
|
+
addFeature(state, Class, "Attribute arguments", attr.arguments[0]);
|
|
11604
11661
|
break;
|
|
11605
|
-
} else if (attr.
|
|
11662
|
+
} else if (attr.bound) {
|
|
11606
11663
|
addFeature(state, Tags, "Bound attribute", attr);
|
|
11607
11664
|
break;
|
|
11608
11665
|
}
|
|
11609
11666
|
}
|
|
11610
11667
|
}
|
|
11611
|
-
|
|
11612
|
-
scanBody(state, tag.
|
|
11668
|
+
const childParentName = (0, _marko_compiler_babel_utils.isTransparentTag)({ node: tag }) ? parentName : fullName;
|
|
11669
|
+
scanBody(state, tag.body.body, childParentName);
|
|
11670
|
+
scanBody(state, tag.attributeTags, childParentName);
|
|
11671
|
+
}
|
|
11672
|
+
function getNodeTagDef(file, tag, fullName) {
|
|
11673
|
+
if (tag.tagDef === void 0) {
|
|
11674
|
+
const { name } = tag;
|
|
11675
|
+
tag.tagDef = name.type !== "StringLiteral" || (0, _marko_compiler_babel_utils.hasMacro)(file.path, name.value) ? null : (0, _marko_compiler_babel_utils.getTagDefForTagName)(file, fullName) || null;
|
|
11676
|
+
}
|
|
11677
|
+
return tag.tagDef;
|
|
11613
11678
|
}
|
|
11614
11679
|
function getFeatureTypeFromCoreTagName(tagName) {
|
|
11615
11680
|
switch (tagName) {
|
|
@@ -11621,11 +11686,9 @@ function getFeatureTypeFromCoreTagName(tagName) {
|
|
|
11621
11686
|
case "macro":
|
|
11622
11687
|
case "module-code":
|
|
11623
11688
|
case "while": return Class;
|
|
11624
|
-
case "attrs":
|
|
11625
11689
|
case "const":
|
|
11626
11690
|
case "debug":
|
|
11627
11691
|
case "define":
|
|
11628
|
-
case "effect":
|
|
11629
11692
|
case "id":
|
|
11630
11693
|
case "let":
|
|
11631
11694
|
case "lifecycle":
|
|
@@ -11636,12 +11699,12 @@ function getFeatureTypeFromCoreTagName(tagName) {
|
|
|
11636
11699
|
default: return;
|
|
11637
11700
|
}
|
|
11638
11701
|
}
|
|
11639
|
-
function addFeature(state, type, name,
|
|
11702
|
+
function addFeature(state, type, name, node) {
|
|
11640
11703
|
if (state.feature) {
|
|
11641
|
-
if (state.feature.type !== type) throw buildAggregateError(
|
|
11704
|
+
if (state.feature.type !== type) throw buildAggregateError(state.file, "Cannot mix Tags API and Class API features in the same file", [state.feature.name, state.feature.node], [name, node]);
|
|
11642
11705
|
} else state.feature = {
|
|
11643
11706
|
name,
|
|
11644
|
-
|
|
11707
|
+
node,
|
|
11645
11708
|
type
|
|
11646
11709
|
};
|
|
11647
11710
|
}
|
|
@@ -11726,10 +11789,8 @@ function createInteropTranslator(translate5) {
|
|
|
11726
11789
|
const { output, entry } = entryFile.markoOpts;
|
|
11727
11790
|
if (!(output === "dom" && entry === "page" || output === "hydrate")) return enterProgram?.call(this, program, state);
|
|
11728
11791
|
const visitedFiles = createVisited(entryFile);
|
|
11729
|
-
entryBuilder.visit(entryFile, entryFile, function visitChild(
|
|
11730
|
-
if (
|
|
11731
|
-
const file = (0, _marko_compiler_babel_utils.loadFileForImport)(entryFile, resolved);
|
|
11732
|
-
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));
|
|
11733
11794
|
});
|
|
11734
11795
|
program.node.body = entryBuilder.build(entryFile);
|
|
11735
11796
|
program.skip();
|
|
@@ -11792,12 +11853,8 @@ function mergeObjects(a, b, cb) {
|
|
|
11792
11853
|
const value = cb(key, aValue, bValue);
|
|
11793
11854
|
if (value !== void 0) merged[key] = value;
|
|
11794
11855
|
};
|
|
11795
|
-
|
|
11796
|
-
|
|
11797
|
-
for (const key in a) assign(key, a[key], b[key]);
|
|
11798
|
-
for (const key in b) if (!(key in a)) assign(key, void 0, b[key]);
|
|
11799
|
-
} else for (const key in a) assign(key, a[key], void 0);
|
|
11800
|
-
} 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]);
|
|
11801
11858
|
return merged;
|
|
11802
11859
|
}
|
|
11803
11860
|
function normalizeTagDef(tagDef) {
|