marko 6.3.55 → 6.4.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 +3 -2
- package/dist/common/accessor.d.ts +3 -0
- package/dist/common/accessor.debug.d.ts +3 -0
- package/dist/common/constants/accessor-prefix.d.ts +1 -0
- package/dist/common/constants/accessor-prefix.debug.d.ts +1 -0
- package/dist/common/constants/accessor-prop.d.ts +3 -0
- package/dist/common/constants/accessor-prop.debug.d.ts +3 -0
- package/dist/common/constants/closure-scopes-prop.d.ts +4 -0
- package/dist/common/constants/closure-scopes-prop.debug.d.ts +4 -0
- package/dist/common/types.d.ts +9 -3
- package/dist/debug/dom/catch.feat.js +12 -14
- package/dist/debug/dom/catch.feat.mjs +12 -14
- 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 +4 -0
- package/dist/debug/dom/lazy.feat.mjs +4 -0
- package/dist/debug/dom/placeholder.feat.js +1 -1
- package/dist/debug/dom/placeholder.feat.mjs +1 -1
- package/dist/debug/{dom-CI0Vojyk.js → dom-BRO5aArp.js} +248 -193
- package/dist/debug/{dom-tl43c2wO.mjs → dom-Btj2QJhk.mjs} +225 -176
- package/dist/debug/dom.js +15 -13
- package/dist/debug/dom.mjs +15 -13
- package/dist/debug/html.js +605 -523
- package/dist/debug/html.mjs +604 -524
- package/dist/dom/abort-signal.d.ts +2 -0
- package/dist/dom/catch.feat.js +6 -7
- package/dist/dom/catch.feat.mjs +5 -7
- package/dist/dom/control-flow.d.ts +3 -5
- package/dist/dom/controllable-input.feat.js +3 -2
- package/dist/dom/controllable-input.feat.mjs +1 -1
- package/dist/dom/controllable-open.feat.js +3 -2
- package/dist/dom/controllable-open.feat.mjs +1 -1
- package/dist/dom/controllable-select.feat.js +3 -2
- package/dist/dom/controllable-select.feat.mjs +1 -1
- package/dist/dom/controllable-textarea.feat.js +3 -2
- package/dist/dom/controllable-textarea.feat.mjs +1 -1
- package/dist/dom/controllable.feat.js +3 -2
- package/dist/dom/controllable.feat.mjs +1 -1
- package/dist/dom/dynamic-tag-script.feat.js +3 -2
- package/dist/dom/dynamic-tag-script.feat.mjs +1 -1
- package/dist/dom/dynamic-tag-var.feat.js +2 -1
- package/dist/dom/dynamic-tag-var.feat.mjs +1 -1
- package/dist/dom/lazy.feat.d.ts +1 -0
- package/dist/dom/lazy.feat.js +4 -0
- package/dist/dom/lazy.feat.mjs +4 -0
- package/dist/dom/load.d.ts +3 -3
- package/dist/dom/placeholder.feat.js +4 -3
- package/dist/dom/placeholder.feat.mjs +1 -1
- package/dist/dom/queue.d.ts +2 -4
- package/dist/dom/resume.d.ts +2 -2
- package/dist/dom/scope.d.ts +0 -1
- package/dist/dom/signals.d.ts +1 -1
- package/dist/{dom-4udEPZaj.mjs → dom-B-v8Gw6T.mjs} +122 -92
- package/dist/{dom-C1mr-TA7.js → dom-BSsI9OPC.js} +218 -187
- package/dist/dom.d.ts +1 -1
- package/dist/dom.js +59 -56
- package/dist/dom.mjs +35 -33
- package/dist/html/attrs.d.ts +2 -0
- package/dist/html/writer.d.ts +5 -11
- package/dist/html.d.ts +1 -1
- package/dist/html.js +367 -327
- package/dist/html.mjs +366 -327
- package/dist/translator/index.js +866 -748
- package/dist/translator/util/binding-has-prop.d.ts +2 -0
- package/dist/translator/util/entry-builder.d.ts +2 -0
- package/dist/translator/util/generate-uid.d.ts +5 -0
- package/dist/translator/util/optional.d.ts +1 -3
- package/dist/translator/util/references.d.ts +6 -2
- package/dist/translator/util/runtime.d.ts +3 -3
- package/dist/translator/util/sections.d.ts +8 -2
- package/dist/translator/util/serialize-reasons.d.ts +3 -1
- package/dist/translator/util/setup-work.d.ts +5 -0
- package/dist/translator/util/signals.d.ts +5 -7
- package/dist/translator/util/translate-attrs.d.ts +2 -1
- package/dist/translator/visitors/tag/native-tag.d.ts +1 -0
- package/package.json +3 -3
- package/tags-html.d.ts +4 -3
- package/dist/translator/util/setup-statements.d.ts +0 -5
package/dist/translator/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
26
26
|
}
|
|
27
27
|
return to;
|
|
28
28
|
};
|
|
29
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
29
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
30
30
|
value: mod,
|
|
31
31
|
enumerable: true
|
|
32
32
|
}) : target, mod));
|
|
@@ -86,7 +86,7 @@ function assertNoBodyContent(tag) {
|
|
|
86
86
|
//#endregion
|
|
87
87
|
//#region src/translator/core/attrs.ts
|
|
88
88
|
var attrs_default = {
|
|
89
|
-
migrate:
|
|
89
|
+
migrate: (tag) => {
|
|
90
90
|
(0, _marko_compiler_babel_utils.assertNoArgs)(tag);
|
|
91
91
|
(0, _marko_compiler_babel_utils.assertNoParams)(tag);
|
|
92
92
|
(0, _marko_compiler_babel_utils.assertNoAttributes)(tag);
|
|
@@ -103,7 +103,7 @@ var attrs_default = {
|
|
|
103
103
|
} else tag.remove();
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
|
-
}
|
|
106
|
+
},
|
|
107
107
|
attributes: {},
|
|
108
108
|
autocomplete: [{
|
|
109
109
|
displayText: "attrs/{ ... }",
|
|
@@ -128,7 +128,8 @@ var accessor_prefix_debug_exports = /* @__PURE__ */ __exportAll({
|
|
|
128
128
|
KeyedScopes: () => KeyedScopes$1,
|
|
129
129
|
Lifecycle: () => Lifecycle$1,
|
|
130
130
|
Promise: () => Promise$2,
|
|
131
|
-
TagVariableChange: () => TagVariableChange$3
|
|
131
|
+
TagVariableChange: () => TagVariableChange$3,
|
|
132
|
+
TryBranch: () => TryBranch$3
|
|
132
133
|
});
|
|
133
134
|
const BranchScopes$3 = "BranchScopes:";
|
|
134
135
|
const ClosureScopes$1 = "ClosureScopes:";
|
|
@@ -145,6 +146,7 @@ const KeyedScopes$1 = "KeyedScopes:";
|
|
|
145
146
|
const Lifecycle$1 = "Lifecycle:";
|
|
146
147
|
const Promise$2 = "Promise:";
|
|
147
148
|
const TagVariableChange$3 = "TagVariableChange:";
|
|
149
|
+
const TryBranch$3 = "TryBranch:";
|
|
148
150
|
//#endregion
|
|
149
151
|
//#region src/common/constants/accessor-prop.debug.ts
|
|
150
152
|
var accessor_prop_debug_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -166,16 +168,19 @@ var accessor_prop_debug_exports = /* @__PURE__ */ __exportAll({
|
|
|
166
168
|
LoopKey: () => LoopKey$1,
|
|
167
169
|
Owner: () => "_",
|
|
168
170
|
ParentBranch: () => ParentBranch$1,
|
|
171
|
+
PendingEffectScopes: () => PendingEffectScopes$1,
|
|
169
172
|
PendingEffects: () => PendingEffects$1,
|
|
170
173
|
PendingRenders: () => PendingRenders$1,
|
|
171
174
|
PendingScopes: () => PendingScopes$1,
|
|
172
175
|
PlaceholderBranch: () => PlaceholderBranch$1,
|
|
173
176
|
PlaceholderContent: () => PlaceholderContent$1,
|
|
174
177
|
Renderer: () => Renderer$1,
|
|
178
|
+
ReturnValue: () => ReturnValue$1,
|
|
175
179
|
StartNode: () => StartNode$1,
|
|
176
180
|
Subscriptions: () => Subscriptions$1,
|
|
177
181
|
TagVariable: () => TagVariable$1,
|
|
178
|
-
TagVariableChange: () => TagVariableChange$2
|
|
182
|
+
TagVariableChange: () => TagVariableChange$2,
|
|
183
|
+
TryBranch: () => TryBranch$2
|
|
179
184
|
});
|
|
180
185
|
const Global$1 = "$global";
|
|
181
186
|
const AbortControllers$1 = "#AbortControllers";
|
|
@@ -194,45 +199,52 @@ const LoopKey$1 = "#LoopKey";
|
|
|
194
199
|
const LoopIndex$1 = "#LoopIndex";
|
|
195
200
|
const ParentBranch$1 = "#ParentBranch";
|
|
196
201
|
const PendingEffects$1 = "#PendingEffects";
|
|
202
|
+
const PendingEffectScopes$1 = "#PendingEffectScopes";
|
|
197
203
|
const PendingRenders$1 = "#PendingRenders";
|
|
198
204
|
const PendingScopes$1 = "#PendingScopes";
|
|
199
205
|
const PlaceholderBranch$1 = "#PlaceholderBranch";
|
|
200
206
|
const PlaceholderContent$1 = "#PlaceholderContent";
|
|
201
207
|
const Renderer$1 = "#Renderer";
|
|
208
|
+
const ReturnValue$1 = "#ReturnValue";
|
|
202
209
|
const StartNode$1 = "#StartNode";
|
|
203
210
|
const Subscriptions$1 = "#Subscriptions";
|
|
204
211
|
const TagVariable$1 = "#TagVariable";
|
|
205
212
|
const TagVariableChange$2 = "#TagVariableChange";
|
|
213
|
+
const TryBranch$2 = "#TryBranch";
|
|
206
214
|
//#endregion
|
|
207
215
|
//#region src/translator/util/traverse.ts
|
|
208
216
|
const skip = Symbol("skip");
|
|
209
217
|
function traverseReplace(container, key, enter, state) {
|
|
210
218
|
const node = container[key];
|
|
211
|
-
if (node)
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
219
|
+
if (node) {
|
|
220
|
+
if (Array.isArray(node)) for (let i = node.length; i--;) traverseReplace(node, i, enter, state);
|
|
221
|
+
else {
|
|
222
|
+
const keys = _marko_compiler.types.VISITOR_KEYS[node.type];
|
|
223
|
+
for (let i = keys.length; i--;) traverseReplace(node, keys[i], enter, state);
|
|
224
|
+
const replacement = enter(node, state);
|
|
225
|
+
if (replacement) container[key] = replacement;
|
|
226
|
+
}
|
|
217
227
|
}
|
|
218
228
|
}
|
|
219
229
|
function traverseContains(node, check) {
|
|
220
230
|
return !!traverseFind(node, check);
|
|
221
231
|
}
|
|
222
232
|
function traverseFind(node, check) {
|
|
223
|
-
if (node)
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
switch (check(node)) {
|
|
229
|
-
case true: return node;
|
|
230
|
-
case skip: return;
|
|
231
|
-
}
|
|
232
|
-
for (const key of _marko_compiler.types.VISITOR_KEYS[node.type]) {
|
|
233
|
-
const found = traverseFind(node[key], check);
|
|
233
|
+
if (node) {
|
|
234
|
+
if (Array.isArray(node)) for (const item of node) {
|
|
235
|
+
const found = traverseFind(item, check);
|
|
234
236
|
if (found) return found;
|
|
235
237
|
}
|
|
238
|
+
else {
|
|
239
|
+
switch (check(node)) {
|
|
240
|
+
case true: return node;
|
|
241
|
+
case skip: return;
|
|
242
|
+
}
|
|
243
|
+
for (const key of _marko_compiler.types.VISITOR_KEYS[node.type]) {
|
|
244
|
+
const found = traverseFind(node[key], check);
|
|
245
|
+
if (found) return found;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
236
248
|
}
|
|
237
249
|
}
|
|
238
250
|
function traverseFindAwait(node) {
|
|
@@ -401,19 +413,21 @@ const toDelimitedString = function toDelimitedString(val, delimiter, stringify)
|
|
|
401
413
|
let str = "";
|
|
402
414
|
let sep = "";
|
|
403
415
|
let part;
|
|
404
|
-
if (val)
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
416
|
+
if (val) {
|
|
417
|
+
if (typeof val !== "object") str += val;
|
|
418
|
+
else if (Array.isArray(val)) for (const v of val) {
|
|
419
|
+
part = toDelimitedString(v, delimiter, stringify);
|
|
420
|
+
if (part) {
|
|
421
|
+
str += sep + part;
|
|
422
|
+
sep = delimiter;
|
|
423
|
+
}
|
|
410
424
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
425
|
+
else for (const name in val) {
|
|
426
|
+
part = stringify(name, val[name]);
|
|
427
|
+
if (part) {
|
|
428
|
+
str += sep + part;
|
|
429
|
+
sep = delimiter;
|
|
430
|
+
}
|
|
417
431
|
}
|
|
418
432
|
}
|
|
419
433
|
return str;
|
|
@@ -472,16 +486,8 @@ function generateUid(name = "") {
|
|
|
472
486
|
const file = (0, _marko_compiler_babel_utils.getFile)();
|
|
473
487
|
let counts = countsForFile.get(file);
|
|
474
488
|
if (!counts) {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
const cacheKey = `uid-counts:${filename}`;
|
|
478
|
-
counts = cache.get(cacheKey);
|
|
479
|
-
if (counts) {
|
|
480
|
-
if (isTranslate()) counts = new Map(counts);
|
|
481
|
-
} else {
|
|
482
|
-
counts = getInitialCounts(file);
|
|
483
|
-
if (!isTranslate()) cache.set(cacheKey, counts);
|
|
484
|
-
}
|
|
489
|
+
counts = (file.path.node.extra ??= {}).uidCounts ??= getInitialCounts(file);
|
|
490
|
+
if (isTranslate()) counts = new Map(counts);
|
|
485
491
|
countsForFile.set(file, counts);
|
|
486
492
|
}
|
|
487
493
|
name = name.replace(/^[^a-z$_]|[^a-z$_0-9]/gi, "") || "temp";
|
|
@@ -498,20 +504,7 @@ const sharedUIDsForFile = /* @__PURE__ */ new WeakMap();
|
|
|
498
504
|
function getSharedUid(name, section) {
|
|
499
505
|
const file = (0, _marko_compiler_babel_utils.getFile)();
|
|
500
506
|
let sharedUIDs = sharedUIDsForFile.get(file);
|
|
501
|
-
if (!sharedUIDs)
|
|
502
|
-
const { cache } = file.markoOpts;
|
|
503
|
-
const { filename } = file.opts;
|
|
504
|
-
let cacheKey = `uid-shared:${filename}`;
|
|
505
|
-
if (section) cacheKey += `:${section.id}`;
|
|
506
|
-
sharedUIDs = cache.get(cacheKey);
|
|
507
|
-
if (sharedUIDs) {
|
|
508
|
-
if (isTranslate()) sharedUIDs = new Map(sharedUIDs);
|
|
509
|
-
} else {
|
|
510
|
-
sharedUIDs = /* @__PURE__ */ new Map();
|
|
511
|
-
if (!isTranslate()) cache.set(cacheKey, sharedUIDs);
|
|
512
|
-
}
|
|
513
|
-
sharedUIDsForFile.set(file, sharedUIDs);
|
|
514
|
-
}
|
|
507
|
+
if (!sharedUIDs) sharedUIDsForFile.set(file, sharedUIDs = /* @__PURE__ */ new Map());
|
|
515
508
|
const nameKey = section ? `${section.id}:${name}` : name;
|
|
516
509
|
let uniqueName = sharedUIDs.get(nameKey);
|
|
517
510
|
if (!uniqueName) {
|
|
@@ -562,9 +555,7 @@ function getFnRoot(path) {
|
|
|
562
555
|
else switch (curPath.type) {
|
|
563
556
|
case "OptionalCallExpression":
|
|
564
557
|
case "CallExpression":
|
|
565
|
-
case "NewExpression":
|
|
566
|
-
fnPath = void 0;
|
|
567
|
-
break;
|
|
558
|
+
case "NewExpression": fnPath = void 0;
|
|
568
559
|
}
|
|
569
560
|
const parentPath = curPath.parentPath;
|
|
570
561
|
if (parentPath) curPath = parentPath;
|
|
@@ -626,9 +617,7 @@ function isFunctionOrVariableDeclaration(path) {
|
|
|
626
617
|
function getTagName(tag) {
|
|
627
618
|
switch (tag.node.name.type) {
|
|
628
619
|
case "StringLiteral": return tag.node.name.value;
|
|
629
|
-
case "TemplateLiteral":
|
|
630
|
-
if (tag.node.name.quasis.length === 1) return tag.node.name.quasis[0].value.cooked;
|
|
631
|
-
break;
|
|
620
|
+
case "TemplateLiteral": if (tag.node.name.quasis.length === 1) return tag.node.name.quasis[0].value.cooked;
|
|
632
621
|
}
|
|
633
622
|
}
|
|
634
623
|
function getStaticTagName(node) {
|
|
@@ -643,12 +632,10 @@ function isCoreTag(tag) {
|
|
|
643
632
|
const tagDef = (0, _marko_compiler_babel_utils.getTagDef)(tag);
|
|
644
633
|
if (tagDef) switch (tagDef.taglibId) {
|
|
645
634
|
case taglibId: return true;
|
|
646
|
-
case htmlTaglibId:
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
}
|
|
651
|
-
break;
|
|
635
|
+
case htmlTaglibId: switch (tagDef.name) {
|
|
636
|
+
case "script":
|
|
637
|
+
case "style": return true;
|
|
638
|
+
}
|
|
652
639
|
}
|
|
653
640
|
}
|
|
654
641
|
return false;
|
|
@@ -713,8 +700,10 @@ var Sorted = class {
|
|
|
713
700
|
union(a, b) {
|
|
714
701
|
if (a !== void 0) {
|
|
715
702
|
if (Array.isArray(a)) {
|
|
716
|
-
if (b !== void 0)
|
|
717
|
-
|
|
703
|
+
if (b !== void 0) {
|
|
704
|
+
if (Array.isArray(b)) return unionSortedRepeatable(this.compare, a, b);
|
|
705
|
+
else return addSorted(this.compare, a, b);
|
|
706
|
+
}
|
|
718
707
|
return a;
|
|
719
708
|
}
|
|
720
709
|
if (b !== void 0) {
|
|
@@ -746,11 +735,13 @@ var Sorted = class {
|
|
|
746
735
|
}
|
|
747
736
|
groupBy(data, cb) {
|
|
748
737
|
const group = /* @__PURE__ */ new Map();
|
|
749
|
-
if (data !== void 0)
|
|
750
|
-
|
|
751
|
-
|
|
738
|
+
if (data !== void 0) {
|
|
739
|
+
if (Array.isArray(data)) for (const item of data) {
|
|
740
|
+
const key = cb(item);
|
|
741
|
+
group.set(key, this.union(group.get(key), item));
|
|
742
|
+
}
|
|
743
|
+
else group.set(cb(data), data);
|
|
752
744
|
}
|
|
753
|
-
else group.set(cb(data), data);
|
|
754
745
|
return group;
|
|
755
746
|
}
|
|
756
747
|
intersects(a, b) {
|
|
@@ -808,9 +799,11 @@ function push(data, item) {
|
|
|
808
799
|
}
|
|
809
800
|
function concat(a, b) {
|
|
810
801
|
if (a !== void 0) {
|
|
811
|
-
if (b !== void 0)
|
|
812
|
-
|
|
813
|
-
|
|
802
|
+
if (b !== void 0) {
|
|
803
|
+
if (Array.isArray(a)) return a.concat(b);
|
|
804
|
+
else if (Array.isArray(b)) return [a, ...b];
|
|
805
|
+
else return [a, b];
|
|
806
|
+
}
|
|
814
807
|
return a;
|
|
815
808
|
}
|
|
816
809
|
return b;
|
|
@@ -848,10 +841,12 @@ function filter(data, cb) {
|
|
|
848
841
|
}
|
|
849
842
|
}
|
|
850
843
|
function forEach(data, cb) {
|
|
851
|
-
if (data !== void 0)
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
844
|
+
if (data !== void 0) {
|
|
845
|
+
if (Array.isArray(data)) {
|
|
846
|
+
let i = 0;
|
|
847
|
+
for (const item of data) cb(item, i++);
|
|
848
|
+
} else cb(data, 0);
|
|
849
|
+
}
|
|
855
850
|
}
|
|
856
851
|
function fromIter(data) {
|
|
857
852
|
let one;
|
|
@@ -861,13 +856,6 @@ function fromIter(data) {
|
|
|
861
856
|
else one = item;
|
|
862
857
|
return many || one;
|
|
863
858
|
}
|
|
864
|
-
function* toIter(data) {
|
|
865
|
-
if (data !== void 0) if (Array.isArray(data)) yield* data;
|
|
866
|
-
else yield data;
|
|
867
|
-
}
|
|
868
|
-
function includes(data, item) {
|
|
869
|
-
return data !== void 0 ? Array.isArray(data) ? data.includes(item) : data === item : false;
|
|
870
|
-
}
|
|
871
859
|
function find(data, cb) {
|
|
872
860
|
if (data !== void 0) {
|
|
873
861
|
if (Array.isArray(data)) return data.find(cb);
|
|
@@ -886,6 +874,9 @@ function reduce(data, cb, initial) {
|
|
|
886
874
|
function toArray(data, cb) {
|
|
887
875
|
return data !== void 0 ? Array.isArray(data) ? data.map(cb) : [cb(data, 0)] : [];
|
|
888
876
|
}
|
|
877
|
+
function toSet(data) {
|
|
878
|
+
return data !== void 0 ? Array.isArray(data) ? new Set(data) : (/* @__PURE__ */ new Set()).add(data) : /* @__PURE__ */ new Set();
|
|
879
|
+
}
|
|
889
880
|
function mapToString(data, sep, cb) {
|
|
890
881
|
if (data !== void 0) {
|
|
891
882
|
if (Array.isArray(data)) {
|
|
@@ -981,9 +972,6 @@ function joinRepeatable(compare, a, b) {
|
|
|
981
972
|
const compareResult = compare(a, b);
|
|
982
973
|
return compareResult === 0 ? a : compareResult < 0 ? [a, b] : [b, a];
|
|
983
974
|
}
|
|
984
|
-
function addUnique(data, item) {
|
|
985
|
-
return includes(data, item) ? data : push(data, item);
|
|
986
|
-
}
|
|
987
975
|
function at(data, index) {
|
|
988
976
|
return Array.isArray(data) ? data[index] : index ? void 0 : data;
|
|
989
977
|
}
|
|
@@ -995,8 +983,11 @@ function rest(data) {
|
|
|
995
983
|
}
|
|
996
984
|
//#endregion
|
|
997
985
|
//#region src/translator/util/binding-has-prop.ts
|
|
986
|
+
function getSectionRendererIdentifier(section) {
|
|
987
|
+
return isSectionRendererElided(section) ? void 0 : _marko_compiler.types.identifier(section.name);
|
|
988
|
+
}
|
|
998
989
|
function isSectionRendererElided(section) {
|
|
999
|
-
return !!section.downstream && !some(section.downstream.binding, (binding) => bindingHasProperty(binding, section.downstream.properties));
|
|
990
|
+
return section.pruned || !!section.downstream && !(section.downstream.tag.tagNameNullable && section.downstream.properties === "content") && !some(section.downstream.binding, (binding) => bindingHasProperty(binding, section.downstream.properties));
|
|
1000
991
|
}
|
|
1001
992
|
function bindingHasProperty(binding, properties) {
|
|
1002
993
|
if (binding.pruned) return false;
|
|
@@ -1035,7 +1026,8 @@ var accessor_prefix_exports = /* @__PURE__ */ __exportAll({
|
|
|
1035
1026
|
KeyedScopes: () => "O",
|
|
1036
1027
|
Lifecycle: () => "K",
|
|
1037
1028
|
Promise: () => "L",
|
|
1038
|
-
TagVariableChange: () => "M"
|
|
1029
|
+
TagVariableChange: () => "M",
|
|
1030
|
+
TryBranch: () => "Q"
|
|
1039
1031
|
});
|
|
1040
1032
|
//#endregion
|
|
1041
1033
|
//#region src/common/constants/accessor-prop.ts
|
|
@@ -1058,16 +1050,19 @@ var accessor_prop_exports = /* @__PURE__ */ __exportAll({
|
|
|
1058
1050
|
LoopKey: () => "M",
|
|
1059
1051
|
Owner: () => "_",
|
|
1060
1052
|
ParentBranch: () => "N",
|
|
1053
|
+
PendingEffectScopes: () => "JS",
|
|
1061
1054
|
PendingEffects: () => "J",
|
|
1062
1055
|
PendingRenders: () => "W",
|
|
1063
1056
|
PendingScopes: () => "Y",
|
|
1064
1057
|
PlaceholderBranch: () => "P",
|
|
1065
1058
|
PlaceholderContent: () => "Q",
|
|
1066
1059
|
Renderer: () => "R",
|
|
1060
|
+
ReturnValue: () => "RV",
|
|
1067
1061
|
StartNode: () => "S",
|
|
1068
1062
|
Subscriptions: () => "Z",
|
|
1069
1063
|
TagVariable: () => "T",
|
|
1070
|
-
TagVariableChange: () => "U"
|
|
1064
|
+
TagVariableChange: () => "U",
|
|
1065
|
+
TryBranch: () => "PT"
|
|
1071
1066
|
});
|
|
1072
1067
|
//#endregion
|
|
1073
1068
|
//#region src/translator/util/marko-config.ts
|
|
@@ -1120,14 +1115,16 @@ function addSerializeReason(section, reason, prop, prefix) {
|
|
|
1120
1115
|
}
|
|
1121
1116
|
}
|
|
1122
1117
|
function addSerializeExpr(section, expr, prop, prefix) {
|
|
1123
|
-
if (expr)
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1118
|
+
if (expr) {
|
|
1119
|
+
if (prop) {
|
|
1120
|
+
const key = getPropKey(section, prop, prefix);
|
|
1121
|
+
const curExprs = section.propSerializeExprs ??= /* @__PURE__ */ new Map();
|
|
1122
|
+
const curExpr = curExprs.get(key);
|
|
1123
|
+
curExprs.set(key, curExpr ? concat(curExpr, expr) : expr);
|
|
1124
|
+
} else {
|
|
1125
|
+
const curExpr = section.serializeExprs;
|
|
1126
|
+
section.serializeExprs = curExpr ? concat(curExpr, expr) : expr;
|
|
1127
|
+
}
|
|
1131
1128
|
}
|
|
1132
1129
|
}
|
|
1133
1130
|
function addOwnerSerializeReason(from, to, reason) {
|
|
@@ -1194,6 +1191,9 @@ function mergeRemappedSources(reason, params, mapped) {
|
|
|
1194
1191
|
function mergeSerializeReasons(a, b) {
|
|
1195
1192
|
return mergeSources(a, b);
|
|
1196
1193
|
}
|
|
1194
|
+
function isOwnResumeReason(reason) {
|
|
1195
|
+
return !!reason && !!(reason.state || reason.forced);
|
|
1196
|
+
}
|
|
1197
1197
|
function applySerializeExprs(section) {
|
|
1198
1198
|
const propExprs = section.propSerializeExprs;
|
|
1199
1199
|
if (propExprs) {
|
|
@@ -1262,6 +1262,10 @@ function setPropSerializeReason(section, key, reason) {
|
|
|
1262
1262
|
if (!isSameSources(section.serializeReasons.get(key), reason)) reasonsVersion++;
|
|
1263
1263
|
section.serializeReasons.set(key, reason);
|
|
1264
1264
|
}
|
|
1265
|
+
function setParamReasonGroups(section, groups) {
|
|
1266
|
+
reasonsVersion++;
|
|
1267
|
+
section.paramReasonGroups = groups;
|
|
1268
|
+
}
|
|
1265
1269
|
function isSameSources(a, b) {
|
|
1266
1270
|
return !!a && compareSources(a, b) === 0;
|
|
1267
1271
|
}
|
|
@@ -1327,33 +1331,6 @@ function joinWithAnd(a) {
|
|
|
1327
1331
|
}
|
|
1328
1332
|
}
|
|
1329
1333
|
//#endregion
|
|
1330
|
-
//#region src/html/content.ts
|
|
1331
|
-
function _unescaped(val) {
|
|
1332
|
-
return val ? val + "" : val === 0 ? "0" : "";
|
|
1333
|
-
}
|
|
1334
|
-
const unsafeXMLReg = /[<&\r]/g;
|
|
1335
|
-
const replaceUnsafeXML = (c) => c === "&" ? "&" : c === "<" ? "<" : " ";
|
|
1336
|
-
const escapeXMLStr = (str) => unsafeXMLReg.test(str) ? str.replace(unsafeXMLReg, replaceUnsafeXML) : str;
|
|
1337
|
-
function _escape(val) {
|
|
1338
|
-
return val ? escapeXMLStr(val + "") : val === 0 ? "0" : "";
|
|
1339
|
-
}
|
|
1340
|
-
const unsafeScriptReg = /<(\/?script|!--)/gi;
|
|
1341
|
-
const escapeScriptStr = (str) => unsafeScriptReg.test(str) ? str.replace(unsafeScriptReg, "\\x3C$1") : str;
|
|
1342
|
-
function _escape_script(val) {
|
|
1343
|
-
return val ? escapeScriptStr(val + "") : val === 0 ? "0" : "";
|
|
1344
|
-
}
|
|
1345
|
-
const unsafeStyleReg = /<(\/style)/gi;
|
|
1346
|
-
const escapeStyleStr = (str) => unsafeStyleReg.test(str) ? str.replace(unsafeStyleReg, "\\3C$1") : str;
|
|
1347
|
-
function _escape_style(val) {
|
|
1348
|
-
return val ? escapeStyleStr(val + "") : val === 0 ? "0" : "";
|
|
1349
|
-
}
|
|
1350
|
-
const unsafeCommentReg = />/g;
|
|
1351
|
-
const escapeCommentStr = (str) => unsafeCommentReg.test(str) ? str.replace(unsafeCommentReg, ">") : str;
|
|
1352
|
-
function _escape_comment(val) {
|
|
1353
|
-
return val ? escapeCommentStr(val + "") : val === 0 ? "0" : "";
|
|
1354
|
-
}
|
|
1355
|
-
globalThis.setImmediate || globalThis.setTimeout || globalThis.queueMicrotask;
|
|
1356
|
-
//#endregion
|
|
1357
1334
|
//#region src/html/attrs.ts
|
|
1358
1335
|
function _attr_class(value) {
|
|
1359
1336
|
return stringAttr("class", toDelimitedString(value, " ", stringifyClassObject));
|
|
@@ -1393,6 +1370,28 @@ function escapeDoubleQuotedAttrValue(value) {
|
|
|
1393
1370
|
function replaceUnsafeDoubleQuoteAttrChar(match) {
|
|
1394
1371
|
return match === "\"" ? """ : match === "\r" ? " " : "&";
|
|
1395
1372
|
}
|
|
1373
|
+
globalThis.setImmediate || globalThis.setTimeout || globalThis.queueMicrotask;
|
|
1374
|
+
//#endregion
|
|
1375
|
+
//#region src/html/content.ts
|
|
1376
|
+
function _unescaped(val) {
|
|
1377
|
+
return val ? val + "" : val === 0 ? "0" : "";
|
|
1378
|
+
}
|
|
1379
|
+
const unsafeXMLReg = /[<&\r]/g;
|
|
1380
|
+
const replaceUnsafeXML = (c) => c === "&" ? "&" : c === "<" ? "<" : " ";
|
|
1381
|
+
const escapeXMLStr = (str) => unsafeXMLReg.test(str) ? str.replace(unsafeXMLReg, replaceUnsafeXML) : str;
|
|
1382
|
+
function _escape(val) {
|
|
1383
|
+
return val ? escapeXMLStr(val + "") : val === 0 ? "0" : "";
|
|
1384
|
+
}
|
|
1385
|
+
const unsafeScriptReg = /<(\/?script|!--)/gi;
|
|
1386
|
+
const escapeScriptStr = (str) => unsafeScriptReg.test(str) ? str.replace(unsafeScriptReg, "\\x3C$1") : str;
|
|
1387
|
+
function _escape_script(val) {
|
|
1388
|
+
return val ? escapeScriptStr(val + "") : val === 0 ? "0" : "";
|
|
1389
|
+
}
|
|
1390
|
+
const unsafeStyleReg = /<(\/style)/gi;
|
|
1391
|
+
const escapeStyleStr = (str) => unsafeStyleReg.test(str) ? str.replace(unsafeStyleReg, "\\3C$1") : str;
|
|
1392
|
+
function _escape_style(val) {
|
|
1393
|
+
return val ? escapeStyleStr(val + "") : val === 0 ? "0" : "";
|
|
1394
|
+
}
|
|
1396
1395
|
//#endregion
|
|
1397
1396
|
//#region src/translator/util/to-property-name.ts
|
|
1398
1397
|
function getMemberExpressionPropString(expr) {
|
|
@@ -1493,6 +1492,7 @@ const domRuntimeFeatures = [
|
|
|
1493
1492
|
"controllable-textarea",
|
|
1494
1493
|
"dynamic-tag-script",
|
|
1495
1494
|
"dynamic-tag-var",
|
|
1495
|
+
"lazy",
|
|
1496
1496
|
"placeholder"
|
|
1497
1497
|
];
|
|
1498
1498
|
const importedFeatures = /* @__PURE__ */ new WeakMap();
|
|
@@ -1503,16 +1503,18 @@ function importRuntimeFeature(feature) {
|
|
|
1503
1503
|
if (!features) importedFeatures.set(program.node, features = /* @__PURE__ */ new Set());
|
|
1504
1504
|
if (!features.has(feature)) {
|
|
1505
1505
|
features.add(feature);
|
|
1506
|
-
const decl =
|
|
1506
|
+
const decl = getRuntimeFeatureImport(feature);
|
|
1507
1507
|
const lastImport = program.get("body").findLast((stmt) => stmt.isImportDeclaration());
|
|
1508
1508
|
if (lastImport) lastImport.insertAfter(decl);
|
|
1509
1509
|
else program.unshiftContainer("body", decl);
|
|
1510
1510
|
}
|
|
1511
1511
|
}
|
|
1512
|
+
function getRuntimeFeatureImport(feature) {
|
|
1513
|
+
return _marko_compiler.types.importDeclaration([], _marko_compiler.types.stringLiteral(`${getRuntimePath("dom")}/${feature}.feat`));
|
|
1514
|
+
}
|
|
1512
1515
|
function getHTMLRuntime() {
|
|
1513
1516
|
return {
|
|
1514
1517
|
_escape,
|
|
1515
|
-
_escape_comment,
|
|
1516
1518
|
_unescaped,
|
|
1517
1519
|
_attr,
|
|
1518
1520
|
_attr_class,
|
|
@@ -1849,7 +1851,6 @@ function startSection(path) {
|
|
|
1849
1851
|
referencedHoists: void 0,
|
|
1850
1852
|
bindings: void 0,
|
|
1851
1853
|
hoisted: void 0,
|
|
1852
|
-
hoistedTo: void 0,
|
|
1853
1854
|
isHoistThrough: void 0,
|
|
1854
1855
|
serializeReason: void 0,
|
|
1855
1856
|
serializeReasons: /* @__PURE__ */ new Map(),
|
|
@@ -1864,9 +1865,11 @@ function startSection(path) {
|
|
|
1864
1865
|
upstreamExpression: void 0,
|
|
1865
1866
|
callSections: void 0,
|
|
1866
1867
|
downstream: void 0,
|
|
1868
|
+
pruned: !!extra.pruned,
|
|
1867
1869
|
hasAbortSignal: false,
|
|
1868
1870
|
abortSignalExprs: 0,
|
|
1869
1871
|
readsOwner: false,
|
|
1872
|
+
hasSetupWork: false,
|
|
1870
1873
|
isBranch: false,
|
|
1871
1874
|
structure: parentSection && !parentSection.structure ? null : []
|
|
1872
1875
|
};
|
|
@@ -1885,6 +1888,9 @@ function getOrCreateSection(path) {
|
|
|
1885
1888
|
function getSectionForBody(body) {
|
|
1886
1889
|
return body.node.extra?.section;
|
|
1887
1890
|
}
|
|
1891
|
+
function removePrunedContent(tag) {
|
|
1892
|
+
if (tag.node.body.extra?.pruned) tag.node.body.body = [];
|
|
1893
|
+
}
|
|
1888
1894
|
function getSection(path) {
|
|
1889
1895
|
let section;
|
|
1890
1896
|
let currentPath = path;
|
|
@@ -1977,17 +1983,19 @@ function getNodeContentType(path, extraMember, contentInfo) {
|
|
|
1977
1983
|
}
|
|
1978
1984
|
else if ((0, _marko_compiler_babel_utils.isNativeTag)(tag)) return 3;
|
|
1979
1985
|
else if ((0, _marko_compiler_babel_utils.isAttributeTag)(tag)) return null;
|
|
1980
|
-
else
|
|
1981
|
-
const tagSection = (0, _marko_compiler_babel_utils.loadFileForTag)(tag)
|
|
1982
|
-
if (tagSection)
|
|
1983
|
-
if (
|
|
1984
|
-
if (
|
|
1985
|
-
|
|
1986
|
-
|
|
1986
|
+
else {
|
|
1987
|
+
const tagSection = tag.node.extra?.defineBodySection || analyzeTagNameType(tag) === 1 && !tag.node.extra.tagNameLoad && (0, _marko_compiler_babel_utils.loadFileForTag)(tag).ast.program.extra.section;
|
|
1988
|
+
if (tagSection) {
|
|
1989
|
+
if (tagSection.content) {
|
|
1990
|
+
if (contentInfo && !tagSection.content.singleChild) {
|
|
1991
|
+
if (extraMember === "endType") {
|
|
1992
|
+
contentInfo.startType = tagSection.content.startType;
|
|
1993
|
+
contentInfo.singleChild = false;
|
|
1994
|
+
}
|
|
1987
1995
|
}
|
|
1988
|
-
|
|
1989
|
-
return
|
|
1990
|
-
}
|
|
1996
|
+
return tagSection.content[extraMember];
|
|
1997
|
+
} else return null;
|
|
1998
|
+
}
|
|
1991
1999
|
}
|
|
1992
2000
|
}
|
|
1993
2001
|
}
|
|
@@ -2065,7 +2073,7 @@ function ensureParamReasonGroup(section, reason) {
|
|
|
2065
2073
|
id: Symbol(getDebugNames(reason)),
|
|
2066
2074
|
reason
|
|
2067
2075
|
};
|
|
2068
|
-
section
|
|
2076
|
+
setParamReasonGroups(section, paramReasonGroups ? addSorted(compareParamGroups, paramReasonGroups, group) : [group]);
|
|
2069
2077
|
}
|
|
2070
2078
|
function getParamReasonGroupIndex(section, reason) {
|
|
2071
2079
|
const index = section.paramReasonGroups && findIndexSorted(compareParamGroups, section.paramReasonGroups, { reason });
|
|
@@ -2362,7 +2370,10 @@ const builder = {
|
|
|
2362
2370
|
if (state.init || state.load) {
|
|
2363
2371
|
const isPage = entryFile.path.node.extra.page;
|
|
2364
2372
|
const initHelper = isPage ? "init" : "initEmbedded";
|
|
2365
|
-
if (state.init)
|
|
2373
|
+
if (state.init) {
|
|
2374
|
+
body.push(_marko_compiler.types.importDeclaration([_marko_compiler.types.importSpecifier(_marko_compiler.types.identifier(initHelper), _marko_compiler.types.identifier(initHelper))], _marko_compiler.types.stringLiteral(getRuntimePath("dom"))));
|
|
2375
|
+
if (state.lazy) body.push(getRuntimeFeatureImport("lazy"));
|
|
2376
|
+
}
|
|
2366
2377
|
for (const root of state.roots) body.push(_marko_compiler.types.importDeclaration([], _marko_compiler.types.stringLiteral(root)));
|
|
2367
2378
|
if (!state.init) {
|
|
2368
2379
|
if (exportInit) body.push(_marko_compiler.types.exportDefaultDeclaration(_marko_compiler.types.arrowFunctionExpression([], _marko_compiler.types.blockStatement([]))));
|
|
@@ -2390,6 +2401,7 @@ const builder = {
|
|
|
2390
2401
|
const state = entryFile[kState] ||= {
|
|
2391
2402
|
init: false,
|
|
2392
2403
|
load: false,
|
|
2404
|
+
lazy: false,
|
|
2393
2405
|
bundled: 0,
|
|
2394
2406
|
roots: [],
|
|
2395
2407
|
assets: /* @__PURE__ */ new Set(),
|
|
@@ -2404,6 +2416,7 @@ const builder = {
|
|
|
2404
2416
|
const isRoot = !state.bundled && (init || load || !!programExtra.hasResumes);
|
|
2405
2417
|
if (init) state.init = true;
|
|
2406
2418
|
if (load) state.load = true;
|
|
2419
|
+
if (loadImports) state.lazy = true;
|
|
2407
2420
|
if (isRoot) state.roots.push((0, _marko_compiler_babel_utils.resolveRelativePath)(entryFile, file.opts.filename));
|
|
2408
2421
|
if (assetImports) {
|
|
2409
2422
|
const assets = isRoot || state.bundled ? state.bundledAssets : state.assets;
|
|
@@ -2461,25 +2474,41 @@ function escapeRegExp(str) {
|
|
|
2461
2474
|
return str.replace(regexpCharsReg, "\\$&");
|
|
2462
2475
|
}
|
|
2463
2476
|
//#endregion
|
|
2464
|
-
//#region src/translator/util/setup-
|
|
2477
|
+
//#region src/translator/util/setup-work.ts
|
|
2465
2478
|
/**
|
|
2466
|
-
* Tracks during analyze whether
|
|
2467
|
-
* template
|
|
2479
|
+
* Tracks during analyze whether a section has work keyed by setup, so callers
|
|
2480
|
+
* of a template or `<define>` body can skip calling a noop setup.
|
|
2468
2481
|
*/
|
|
2469
|
-
const [getSetupInfo] = createSectionState("
|
|
2482
|
+
const [getSetupInfo] = createSectionState("setupWork", () => ({
|
|
2470
2483
|
forced: false,
|
|
2471
2484
|
exprs: /* @__PURE__ */ new Set()
|
|
2472
2485
|
}));
|
|
2473
|
-
function
|
|
2486
|
+
function addSetupWork(section) {
|
|
2474
2487
|
getSetupInfo(section).forced = true;
|
|
2475
2488
|
}
|
|
2476
2489
|
function addSetupExpr(section, node) {
|
|
2477
2490
|
if (node) getSetupInfo(section).exprs.add(node.extra ??= {});
|
|
2478
2491
|
else getSetupInfo(section).forced = true;
|
|
2479
2492
|
}
|
|
2480
|
-
function
|
|
2493
|
+
function finalizeSetupWork() {
|
|
2494
|
+
forEachSection((section) => {
|
|
2495
|
+
if (hasOwnSetupWork(section)) section.hasSetupWork = true;
|
|
2496
|
+
});
|
|
2497
|
+
forEachSection((section) => {
|
|
2498
|
+
if (section.hasSetupWork || section.readsOwner) setCallSectionsSetup(section);
|
|
2499
|
+
});
|
|
2500
|
+
}
|
|
2501
|
+
function setCallSectionsSetup(body) {
|
|
2502
|
+
forEach(body.callSections, (callSection) => {
|
|
2503
|
+
if (!callSection.hasSetupWork) {
|
|
2504
|
+
callSection.hasSetupWork = true;
|
|
2505
|
+
setCallSectionsSetup(callSection);
|
|
2506
|
+
}
|
|
2507
|
+
});
|
|
2508
|
+
}
|
|
2509
|
+
function hasOwnSetupWork(section) {
|
|
2481
2510
|
const info = getSetupInfo(section);
|
|
2482
|
-
if (info.forced) return true;
|
|
2511
|
+
if (info.forced || section.referencedClosures) return true;
|
|
2483
2512
|
for (let extra of info.exprs) {
|
|
2484
2513
|
while (extra.merged) extra = extra.merged;
|
|
2485
2514
|
if (!extra.pruned && !extra.referencedBindings) return true;
|
|
@@ -2619,22 +2648,24 @@ function normalizeStringExpression(parts, useIife) {
|
|
|
2619
2648
|
let curStr = "";
|
|
2620
2649
|
for (let i = 0; i < parts.length; i++) {
|
|
2621
2650
|
let content = parts[i];
|
|
2622
|
-
if (typeof content === "object")
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2651
|
+
if (typeof content === "object") {
|
|
2652
|
+
if (_marko_compiler.types.isStringLiteral(content)) content = content.value;
|
|
2653
|
+
else if (_marko_compiler.types.isTemplateLiteral(content)) {
|
|
2654
|
+
let nextIndex = i + 1;
|
|
2655
|
+
const exprLen = content.expressions.length;
|
|
2656
|
+
shiftItems(parts, nextIndex, content.quasis.length + exprLen);
|
|
2657
|
+
for (let j = 0; j < exprLen; j++) {
|
|
2658
|
+
parts[nextIndex++] = content.quasis[j].value.cooked ?? "";
|
|
2659
|
+
parts[nextIndex++] = content.expressions[j];
|
|
2660
|
+
}
|
|
2661
|
+
parts[nextIndex] = content.quasis[exprLen].value.cooked ?? "";
|
|
2662
|
+
continue;
|
|
2663
|
+
} else {
|
|
2664
|
+
exprs.push(content);
|
|
2665
|
+
strs.push(curStr);
|
|
2666
|
+
curStr = "";
|
|
2667
|
+
continue;
|
|
2668
|
+
}
|
|
2638
2669
|
}
|
|
2639
2670
|
curStr += content;
|
|
2640
2671
|
}
|
|
@@ -2731,47 +2762,33 @@ function getExprIfSerialized(section, reason, expr) {
|
|
|
2731
2762
|
return guard ? _marko_compiler.types.logicalExpression("&&", guard, expr) : expr;
|
|
2732
2763
|
}
|
|
2733
2764
|
function getOrHoist(reason, isGuard) {
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
const
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
const expr = buildGuardExpr(paramsSection, params, isGuard);
|
|
2762
|
-
orExpr = orExpr ? _marko_compiler.types.logicalExpression("||", orExpr, expr) : expr;
|
|
2763
|
-
}
|
|
2764
|
-
return orExpr;
|
|
2765
|
-
}
|
|
2766
|
-
function buildGuardExpr(paramsSection, params, isGuard) {
|
|
2767
|
-
const serializeIdentifier = scopeReasonIdentifier(paramsSection);
|
|
2768
|
-
return paramsSection.paramReasonGroups ? callRuntime(isGuard ? "_serialize_guard" : "_serialize_if", serializeIdentifier, withLeadingComment(_marko_compiler.types.numericLiteral(getParamReasonGroupIndex(paramsSection, params)), getDebugNames(params))) : serializeIdentifier;
|
|
2769
|
-
}
|
|
2770
|
-
function getOnlySection(params) {
|
|
2771
|
-
if (params === void 0) return void 0;
|
|
2772
|
-
if (!Array.isArray(params)) return params.section;
|
|
2773
|
-
const { section } = params[0];
|
|
2774
|
-
return section === params[params.length - 1].section ? section : void 0;
|
|
2765
|
+
let expr;
|
|
2766
|
+
for (const [section, params] of groupParamsBySection(reason.param)) {
|
|
2767
|
+
const part = getOrHoistSectionGuard(section, params, isGuard);
|
|
2768
|
+
expr = expr ? _marko_compiler.types.logicalExpression("||", expr, part) : part;
|
|
2769
|
+
}
|
|
2770
|
+
return expr;
|
|
2771
|
+
}
|
|
2772
|
+
function getOrHoistSectionGuard(section, params, isGuard) {
|
|
2773
|
+
if (!section.paramReasonGroups) return scopeReasonIdentifier(section);
|
|
2774
|
+
const state = getSectionReasonState(section);
|
|
2775
|
+
const tracking = isGuard ? state.guard : state.if;
|
|
2776
|
+
const index = getParamReasonGroupIndex(section, params);
|
|
2777
|
+
const name = tracking.names.get(index);
|
|
2778
|
+
if (name) return _marko_compiler.types.identifier(name);
|
|
2779
|
+
const guard = callRuntime(isGuard ? "_serialize_guard" : "_serialize_if", scopeReasonIdentifier(section), withLeadingComment(_marko_compiler.types.numericLiteral(index), getDebugNames(params)));
|
|
2780
|
+
const pending = tracking.pending.get(index);
|
|
2781
|
+
if (!pending) {
|
|
2782
|
+
const expr = _marko_compiler.types.parenthesizedExpression(guard);
|
|
2783
|
+
tracking.pending.set(index, expr);
|
|
2784
|
+
return expr;
|
|
2785
|
+
}
|
|
2786
|
+
const hoisted = generateUid(`${isGuard ? "sg" : "si"}__${getDebugNamesAsIdentifier(params)}`);
|
|
2787
|
+
tracking.names.set(index, hoisted);
|
|
2788
|
+
tracking.pending.delete(index);
|
|
2789
|
+
state.declarators.push(_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(hoisted), guard));
|
|
2790
|
+
pending.expression = _marko_compiler.types.identifier(hoisted);
|
|
2791
|
+
return _marko_compiler.types.parenthesizedExpression(_marko_compiler.types.identifier(hoisted));
|
|
2775
2792
|
}
|
|
2776
2793
|
function isDynamicSerializeGuard(section, reason) {
|
|
2777
2794
|
return isReasonDynamic(reason) && !isCrossSection(section, reason);
|
|
@@ -2782,9 +2799,7 @@ function isCrossSection(section, reason) {
|
|
|
2782
2799
|
function createTypeState() {
|
|
2783
2800
|
return {
|
|
2784
2801
|
names: /* @__PURE__ */ new Map(),
|
|
2785
|
-
pending: /* @__PURE__ */ new Map()
|
|
2786
|
-
seenReasons: void 0,
|
|
2787
|
-
hoistedReasons: void 0
|
|
2802
|
+
pending: /* @__PURE__ */ new Map()
|
|
2788
2803
|
};
|
|
2789
2804
|
}
|
|
2790
2805
|
function hasDynamicSerializeReason(section) {
|
|
@@ -2920,9 +2935,7 @@ function forEachIdentifier(node, cb) {
|
|
|
2920
2935
|
if (prop.value.type === "AssignmentPattern") forEachIdentifier(prop.value.left, cb);
|
|
2921
2936
|
else forEachIdentifier(prop.value, cb);
|
|
2922
2937
|
break;
|
|
2923
|
-
case "RestElement":
|
|
2924
|
-
forEachIdentifier(prop.argument, cb);
|
|
2925
|
-
break;
|
|
2938
|
+
case "RestElement": forEachIdentifier(prop.argument, cb);
|
|
2926
2939
|
}
|
|
2927
2940
|
break;
|
|
2928
2941
|
case "ArrayPattern":
|
|
@@ -2933,14 +2946,10 @@ function forEachIdentifier(node, cb) {
|
|
|
2933
2946
|
case "AssignmentPattern":
|
|
2934
2947
|
forEachIdentifier(el.left, cb);
|
|
2935
2948
|
break;
|
|
2936
|
-
default:
|
|
2937
|
-
forEachIdentifier(el, cb);
|
|
2938
|
-
break;
|
|
2949
|
+
default: forEachIdentifier(el, cb);
|
|
2939
2950
|
}
|
|
2940
2951
|
break;
|
|
2941
|
-
case "Identifier":
|
|
2942
|
-
cb(node);
|
|
2943
|
-
break;
|
|
2952
|
+
case "Identifier": cb(node);
|
|
2944
2953
|
}
|
|
2945
2954
|
}
|
|
2946
2955
|
function forEachIdentifierPath(nodePath, cb) {
|
|
@@ -2952,9 +2961,11 @@ function forEachIdentifierPath(nodePath, cb) {
|
|
|
2952
2961
|
else forEachIdentifierPath(value, cb);
|
|
2953
2962
|
} else if (prop.isRestElement()) forEachIdentifierPath(prop.get("argument"), cb);
|
|
2954
2963
|
} else if (nodePath.isArrayPattern()) {
|
|
2955
|
-
for (const el of nodePath.get("elements")) if (el)
|
|
2956
|
-
|
|
2957
|
-
|
|
2964
|
+
for (const el of nodePath.get("elements")) if (el) {
|
|
2965
|
+
if (el.isRestElement()) forEachIdentifierPath(el.get("argument"), cb);
|
|
2966
|
+
else if (el.isAssignmentPattern()) forEachIdentifierPath(el.get("left"), cb);
|
|
2967
|
+
else forEachIdentifierPath(el, cb);
|
|
2968
|
+
}
|
|
2958
2969
|
}
|
|
2959
2970
|
}
|
|
2960
2971
|
//#endregion
|
|
@@ -3116,19 +3127,21 @@ function setSectionSerializedValue(section, prop, expression) {
|
|
|
3116
3127
|
}
|
|
3117
3128
|
function setBindingSerializedValue(section, binding, expression, prefix) {
|
|
3118
3129
|
const reason = getSerializeReason(section, binding, prefix);
|
|
3119
|
-
if (reason)
|
|
3120
|
-
|
|
3121
|
-
reason
|
|
3122
|
-
});
|
|
3123
|
-
else {
|
|
3124
|
-
const accessor = getPrefixedScopeAccessor(binding, prefix);
|
|
3125
|
-
getSerializedAccessors(section).set(accessor, {
|
|
3130
|
+
if (reason) {
|
|
3131
|
+
if (prefix === void 0) getSerializedAccessors(section).set(getScopeAccessor(binding), {
|
|
3126
3132
|
expression,
|
|
3127
3133
|
reason
|
|
3128
3134
|
});
|
|
3129
|
-
|
|
3130
|
-
const
|
|
3131
|
-
|
|
3135
|
+
else {
|
|
3136
|
+
const accessor = getPrefixedScopeAccessor(binding, prefix);
|
|
3137
|
+
getSerializedAccessors(section).set(accessor, {
|
|
3138
|
+
expression,
|
|
3139
|
+
reason
|
|
3140
|
+
});
|
|
3141
|
+
if (!isOptimize() && prefix === getAccessorPrefix().TagVariableChange) {
|
|
3142
|
+
const { root, access } = getDebugScopeAccess(binding);
|
|
3143
|
+
setSectionDebugVar(section, accessor, `${root.name + access}Change`, root.loc);
|
|
3144
|
+
}
|
|
3132
3145
|
}
|
|
3133
3146
|
}
|
|
3134
3147
|
}
|
|
@@ -3179,7 +3192,6 @@ function getSignal(section, referencedBindings, name) {
|
|
|
3179
3192
|
values: [],
|
|
3180
3193
|
intersection: void 0,
|
|
3181
3194
|
forwards: void 0,
|
|
3182
|
-
prepare: [],
|
|
3183
3195
|
render: [],
|
|
3184
3196
|
effect: [],
|
|
3185
3197
|
hasHTMLEffect: false,
|
|
@@ -3212,8 +3224,7 @@ function getSignal(section, referencedBindings, name) {
|
|
|
3212
3224
|
const render = getSignalFn(signal);
|
|
3213
3225
|
const closureSignalBuilder = getClosureSignalBuilder(section);
|
|
3214
3226
|
if (closureSignalBuilder && !isDynamicClosure(section, closure)) return closureSignalBuilder(closure, render);
|
|
3215
|
-
|
|
3216
|
-
return callRuntime("_closure_get", isOptimize() ? _marko_compiler.types.numericLiteral(getClosureAccessorId(closure)) : getScopeAccessorLiteral(closure, true), render, isImmediateOwner(section, closure) ? void 0 : _marko_compiler.types.arrowFunctionExpression([scopeIdentifier], getScopeExpression(section, closure.section)), changeable ? _marko_compiler.types.stringLiteral(getResumeRegisterId(section, closure, "subscribe")) : void 0, changeable && isOptimize() ? getScopeAccessorLiteral(closure, true) : void 0);
|
|
3227
|
+
return callRuntime("_closure_get", getClosureAccessorLiteral(closure), render, isImmediateOwner(section, closure) ? void 0 : _marko_compiler.types.arrowFunctionExpression([scopeIdentifier], getScopeExpression(section, closure.section)), isChangeableDynamicClosure(section, closure) ? _marko_compiler.types.stringLiteral(getResumeRegisterId(section, closure, "subscribe")) : void 0);
|
|
3217
3228
|
};
|
|
3218
3229
|
}
|
|
3219
3230
|
return signal;
|
|
@@ -3237,7 +3248,7 @@ function initValue(binding, isLet = false) {
|
|
|
3237
3248
|
return signal;
|
|
3238
3249
|
}
|
|
3239
3250
|
function signalHasStatements(signal) {
|
|
3240
|
-
if (signal.extraArgs || signal.forcePersist || signal.
|
|
3251
|
+
if (signal.extraArgs || signal.forcePersist || signal.render.length || signal.effect.length || signal.hasHTMLEffect || signal.values.length || signal.intersection) return true;
|
|
3241
3252
|
const binding = signal.referencedBindings;
|
|
3242
3253
|
if (binding) {
|
|
3243
3254
|
if (!Array.isArray(binding) && (binding.closureSections || binding.type === 0 || binding.section === signal.section && (binding.hoists || binding.aliases.size || hasNonConstantPropertyAlias(binding)))) return true;
|
|
@@ -3310,7 +3321,7 @@ function getSignalFn(signal) {
|
|
|
3310
3321
|
if (value.signal.inline) continue;
|
|
3311
3322
|
signal.render.push(_marko_compiler.types.expressionStatement(signalHasStatements(value.signal) ? _marko_compiler.types.callExpression(value.signal.identifier, [
|
|
3312
3323
|
scopeIdentifier,
|
|
3313
|
-
value.value,
|
|
3324
|
+
...value.value ? [value.value] : [],
|
|
3314
3325
|
...getTranslatedExtraArgs(value.signal)
|
|
3315
3326
|
]) : withLeadingComment(value.value, getDebugNames(value.signal.referencedBindings))));
|
|
3316
3327
|
}
|
|
@@ -3337,18 +3348,17 @@ function getSignalFn(signal) {
|
|
|
3337
3348
|
signal.render.push(_marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(effectIdentifier, [scopeIdentifier])));
|
|
3338
3349
|
}
|
|
3339
3350
|
if (isValue && getSerializeReason(section, binding)) signal.hasSideEffect = true;
|
|
3340
|
-
const render = signal.prepare.length ? signal.prepare.concat(signal.render) : signal.render;
|
|
3341
3351
|
if (!signal.hasSideEffect) {
|
|
3342
|
-
if (isValue && render.length === 1) {
|
|
3343
|
-
const first = render[0];
|
|
3352
|
+
if (isValue && signal.render.length === 1) {
|
|
3353
|
+
const first = signal.render[0];
|
|
3344
3354
|
if (first.type === "ExpressionStatement") {
|
|
3345
3355
|
const { expression } = first;
|
|
3346
3356
|
if (expression.type === "CallExpression" && expression.callee.type === "Identifier" && expression.arguments.length === 2 && expression.arguments[0] === scopeIdentifier && isOwnValueRead(expression.arguments[1], binding)) return expression.callee;
|
|
3347
3357
|
}
|
|
3348
3358
|
}
|
|
3349
|
-
return _marko_compiler.types.arrowFunctionExpression(isValue ? [scopeIdentifier, getSignalValueIdentifier(signal)] : [scopeIdentifier], toFirstExpressionOrBlock(render));
|
|
3359
|
+
return _marko_compiler.types.arrowFunctionExpression(isValue ? [scopeIdentifier, getSignalValueIdentifier(signal)] : [scopeIdentifier], toFirstExpressionOrBlock(signal.render));
|
|
3350
3360
|
}
|
|
3351
|
-
return toScopeFn(render);
|
|
3361
|
+
return toScopeFn(signal.render);
|
|
3352
3362
|
}
|
|
3353
3363
|
function toScopeFn(render) {
|
|
3354
3364
|
if (render.length === 1) {
|
|
@@ -3436,17 +3446,20 @@ function addValue(targetSection, referencedBindings, signal, value) {
|
|
|
3436
3446
|
signal,
|
|
3437
3447
|
value
|
|
3438
3448
|
});
|
|
3439
|
-
if (value
|
|
3449
|
+
if ((value?.extra)?.referencedBindingsInFunction) parentSignal.hasSideEffect = true;
|
|
3440
3450
|
}
|
|
3441
3451
|
function buildResumeRegisterKey(section, referencedBindings, type) {
|
|
3442
3452
|
let name = "";
|
|
3443
|
-
if (referencedBindings)
|
|
3444
|
-
|
|
3453
|
+
if (referencedBindings) {
|
|
3454
|
+
if (typeof referencedBindings === "string") name += `*${referencedBindings}`;
|
|
3455
|
+
else name = reduce(referencedBindings, appendBindingKey, name);
|
|
3456
|
+
}
|
|
3445
3457
|
return `${section.id}${name}${type ? "/" + type : ""}`;
|
|
3446
3458
|
}
|
|
3447
3459
|
function getResumeRegisterId(section, referencedBindings, type) {
|
|
3448
3460
|
const { markoOpts, opts: { filename } } = (0, _marko_compiler_babel_utils.getFile)();
|
|
3449
|
-
|
|
3461
|
+
const key = buildResumeRegisterKey(section, referencedBindings, type);
|
|
3462
|
+
return (0, _marko_compiler_babel_utils.getTemplateId)(markoOpts, filename, key);
|
|
3450
3463
|
}
|
|
3451
3464
|
function writeSignals(section) {
|
|
3452
3465
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -3625,7 +3638,7 @@ function writeHTMLResumeStatements(path) {
|
|
|
3625
3638
|
if (returnIdentifier !== void 0) body.push(_marko_compiler.types.returnStatement(returnIdentifier));
|
|
3626
3639
|
}
|
|
3627
3640
|
function getSetup(section) {
|
|
3628
|
-
return
|
|
3641
|
+
return getSignals(section).get(void 0);
|
|
3629
3642
|
}
|
|
3630
3643
|
function replaceRenderNode(node, signal) {
|
|
3631
3644
|
return replaceAssignedNode(node) || replaceBindingReadNode$1(node, signal) || replaceRegisteredFunctionNode$1(node);
|
|
@@ -3676,52 +3689,50 @@ function replaceAssignedNode(node) {
|
|
|
3676
3689
|
}
|
|
3677
3690
|
break;
|
|
3678
3691
|
}
|
|
3679
|
-
case "AssignmentExpression":
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
if (builtAssignment) return shortCircuits ? _marko_compiler.types.logicalExpression(operator.slice(0, -1), readAssigned(), builtAssignment) : builtAssignment;
|
|
3689
|
-
}
|
|
3690
|
-
return extra?.assignment && withLeadingComment(node.right, getDebugName(extra.assignment));
|
|
3692
|
+
case "AssignmentExpression": switch (node.left.type) {
|
|
3693
|
+
case "Identifier": {
|
|
3694
|
+
const { extra } = node.left;
|
|
3695
|
+
if (isAssignedBindingExtra(extra)) {
|
|
3696
|
+
const { operator } = node;
|
|
3697
|
+
const shortCircuits = operator === "||=" || operator === "&&=" || operator === "??=";
|
|
3698
|
+
const readAssigned = () => createScopeReadExpression(extra.assignment, extra.section);
|
|
3699
|
+
const builtAssignment = getBuildAssignment(extra)?.(extra.section, operator === "=" || shortCircuits ? node.right : _marko_compiler.types.binaryExpression(operator.slice(0, -1), readAssigned(), node.right));
|
|
3700
|
+
if (builtAssignment) return shortCircuits ? _marko_compiler.types.logicalExpression(operator.slice(0, -1), readAssigned(), builtAssignment) : builtAssignment;
|
|
3691
3701
|
}
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3702
|
+
return extra?.assignment && withLeadingComment(node.right, getDebugName(extra.assignment));
|
|
3703
|
+
}
|
|
3704
|
+
case "ArrayPattern":
|
|
3705
|
+
case "ObjectPattern": {
|
|
3706
|
+
let params;
|
|
3707
|
+
let assignments;
|
|
3708
|
+
forEachIdentifier(node.left, (id) => {
|
|
3709
|
+
const { extra } = id;
|
|
3710
|
+
if (isAssignedBindingExtra(extra)) {
|
|
3711
|
+
const buildAssignment = getBuildAssignment(extra);
|
|
3712
|
+
if (buildAssignment) {
|
|
3713
|
+
const uid = generateUid(id.name);
|
|
3714
|
+
const builtAssignment = buildAssignment(extra.section, _marko_compiler.types.identifier(uid));
|
|
3715
|
+
if (builtAssignment) {
|
|
3716
|
+
id.name = uid;
|
|
3717
|
+
(params ||= []).push(_marko_compiler.types.identifier(uid));
|
|
3718
|
+
(assignments ||= []).push(builtAssignment);
|
|
3719
|
+
return;
|
|
3709
3720
|
}
|
|
3710
3721
|
}
|
|
3711
|
-
if (extra?.assignment) (params ||= []).push(_marko_compiler.types.identifier(id.name));
|
|
3712
|
-
});
|
|
3713
|
-
if (assignments || params) {
|
|
3714
|
-
const resultId = generateUid("result");
|
|
3715
|
-
return _marko_compiler.types.callExpression(_marko_compiler.types.arrowFunctionExpression([_marko_compiler.types.identifier(resultId), ...params || []], _marko_compiler.types.sequenceExpression([
|
|
3716
|
-
_marko_compiler.types.assignmentExpression("=", node.left, _marko_compiler.types.identifier(resultId)),
|
|
3717
|
-
...assignments || [],
|
|
3718
|
-
_marko_compiler.types.identifier(resultId)
|
|
3719
|
-
])), [node.right]);
|
|
3720
3722
|
}
|
|
3721
|
-
|
|
3723
|
+
if (extra?.assignment) (params ||= []).push(_marko_compiler.types.identifier(id.name));
|
|
3724
|
+
});
|
|
3725
|
+
if (assignments || params) {
|
|
3726
|
+
const resultId = generateUid("result");
|
|
3727
|
+
return _marko_compiler.types.callExpression(_marko_compiler.types.arrowFunctionExpression([_marko_compiler.types.identifier(resultId), ...params || []], _marko_compiler.types.sequenceExpression([
|
|
3728
|
+
_marko_compiler.types.assignmentExpression("=", node.left, _marko_compiler.types.identifier(resultId)),
|
|
3729
|
+
...assignments || [],
|
|
3730
|
+
_marko_compiler.types.identifier(resultId)
|
|
3731
|
+
])), [node.right]);
|
|
3722
3732
|
}
|
|
3733
|
+
break;
|
|
3723
3734
|
}
|
|
3724
|
-
|
|
3735
|
+
}
|
|
3725
3736
|
}
|
|
3726
3737
|
}
|
|
3727
3738
|
function getChangeHandlerRead(binding, section) {
|
|
@@ -3906,9 +3917,11 @@ function resolveStructure(section) {
|
|
|
3906
3917
|
break;
|
|
3907
3918
|
case Child: {
|
|
3908
3919
|
const content = refContent(op.renderer);
|
|
3909
|
-
if (
|
|
3910
|
-
|
|
3911
|
-
|
|
3920
|
+
if (content) {
|
|
3921
|
+
if (textEdge && content.startType === 4) separate(resolved);
|
|
3922
|
+
textEdge = content.endType === 4 ? "child" : void 0;
|
|
3923
|
+
flushSteps(resolved);
|
|
3924
|
+
}
|
|
3912
3925
|
const template = op.renderer && resolveRef(op.renderer, "template");
|
|
3913
3926
|
if (template) resolved.writes.push(template, "");
|
|
3914
3927
|
resolved.walkComment.push(`<${op.name}${op.hasVar ? "/var" : ""}>`);
|
|
@@ -3939,7 +3952,7 @@ function resolveRef(ref, part) {
|
|
|
3939
3952
|
return ref.program.section === (0, _marko_compiler_babel_utils.getProgram)().node.extra.section ? _marko_compiler.types.identifier(name) : importOrSelfReferenceName((0, _marko_compiler_babel_utils.getFile)(), ref.path, name, `${ref.hint}_${part}`);
|
|
3940
3953
|
}
|
|
3941
3954
|
const [getSectionMeta] = createSectionState("SectionMeta", (section) => {
|
|
3942
|
-
if (!section.structure) return {
|
|
3955
|
+
if (!section.structure || section.pruned) return {
|
|
3943
3956
|
walks: void 0,
|
|
3944
3957
|
writes: void 0
|
|
3945
3958
|
};
|
|
@@ -4071,50 +4084,53 @@ var dom_default = { translate: {
|
|
|
4071
4084
|
const tagParamsIdentifier = tagParamsSignal && signalHasStatements(tagParamsSignal) ? tagParamsSignal.identifier : void 0;
|
|
4072
4085
|
const { writes } = getSectionMeta(childSection);
|
|
4073
4086
|
const walks = trimTrailingExits(getSectionMeta(childSection).walks);
|
|
4074
|
-
const setup = getSetup(childSection);
|
|
4075
4087
|
const written = writeSignals(childSection);
|
|
4088
|
+
const setup = getSetup(childSection);
|
|
4076
4089
|
const setupIdentifier = setup && written.has(setup) ? setup.identifier : void 0;
|
|
4077
|
-
if (!isSectionRendererElided(childSection))
|
|
4078
|
-
|
|
4079
|
-
walks,
|
|
4080
|
-
setupIdentifier,
|
|
4081
|
-
tagParamsIdentifier
|
|
4082
|
-
]);
|
|
4083
|
-
else {
|
|
4084
|
-
const registerReason = getSectionRegisterReasons(childSection);
|
|
4085
|
-
const registerId = getResumeRegisterId(childSection, "content");
|
|
4086
|
-
const objProps = [];
|
|
4087
|
-
forEach(childSection.localClosures, (closure) => {
|
|
4088
|
-
const closureSignal = getSignal(childSection, closure);
|
|
4089
|
-
const key = toPropertyName(getScopeAccessor(closure, true));
|
|
4090
|
-
if (signalHasStatements(closureSignal) || closureSignal.forcePersist) {
|
|
4091
|
-
const expr = getSignalFn(closureSignal);
|
|
4092
|
-
if (closureSignal.prependStatements) program.node.body.push(...closureSignal.prependStatements);
|
|
4093
|
-
if (_marko_compiler.types.isFunction(expr) && _marko_compiler.types.isBlockStatement(expr.body)) objProps.push(_marko_compiler.types.objectMethod("method", key, expr.params, expr.body));
|
|
4094
|
-
else objProps.push(_marko_compiler.types.objectProperty(key, expr));
|
|
4095
|
-
}
|
|
4096
|
-
});
|
|
4097
|
-
const registerWrapper = !!(registerReason && objProps.length);
|
|
4098
|
-
let renderer = callRuntime("_content", _marko_compiler.types.stringLiteral(registerId), ...replaceNullishAndEmptyFunctionsWith0([
|
|
4090
|
+
if (!isSectionRendererElided(childSection)) {
|
|
4091
|
+
if (getSectionParentIsOwner(childSection)) setBranchRendererArgs(childSection, [
|
|
4099
4092
|
writes,
|
|
4100
4093
|
walks,
|
|
4101
4094
|
setupIdentifier,
|
|
4102
|
-
tagParamsIdentifier
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4095
|
+
tagParamsIdentifier
|
|
4096
|
+
]);
|
|
4097
|
+
else {
|
|
4098
|
+
const registerReason = getSectionRegisterReasons(childSection);
|
|
4099
|
+
const registerId = getResumeRegisterId(childSection, "content");
|
|
4100
|
+
const objProps = [];
|
|
4101
|
+
forEach(childSection.localClosures, (closure) => {
|
|
4102
|
+
const closureSignal = getSignal(childSection, closure);
|
|
4103
|
+
const key = toPropertyName(getScopeAccessor(closure, true));
|
|
4104
|
+
if (signalHasStatements(closureSignal) || closureSignal.forcePersist) {
|
|
4105
|
+
const expr = getSignalFn(closureSignal);
|
|
4106
|
+
if (closureSignal.prependStatements) program.node.body.push(...closureSignal.prependStatements);
|
|
4107
|
+
if (_marko_compiler.types.isFunction(expr) && _marko_compiler.types.isBlockStatement(expr.body)) objProps.push(_marko_compiler.types.objectMethod("method", key, expr.params, expr.body));
|
|
4108
|
+
else objProps.push(_marko_compiler.types.objectProperty(key, expr));
|
|
4109
|
+
}
|
|
4110
|
+
});
|
|
4111
|
+
const registerWrapper = !!(registerReason && objProps.length);
|
|
4112
|
+
let renderer = callRuntime("_content", _marko_compiler.types.stringLiteral(registerId), ...replaceNullishAndEmptyFunctionsWith0([
|
|
4113
|
+
writes,
|
|
4114
|
+
walks,
|
|
4115
|
+
setupIdentifier,
|
|
4116
|
+
tagParamsIdentifier,
|
|
4117
|
+
childSection.hoisted || childSection.isHoistThrough ? getSectionInstancesAccessorLiteral(childSection) : void 0
|
|
4118
|
+
]));
|
|
4119
|
+
if (!registerReason || registerWrapper) renderer = _marko_compiler.types.addComment(renderer, "leading", "@__PURE__");
|
|
4120
|
+
if (objProps.length) renderer = callRuntime("_content_closures", renderer, _marko_compiler.types.objectExpression(objProps));
|
|
4121
|
+
program.node.body.push(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(childSection.name), renderer)]));
|
|
4122
|
+
if (registerReason && getContentClosures(childSection)) program.node.body.push(_marko_compiler.types.expressionStatement(callRuntime("_content_resume", _marko_compiler.types.identifier(childSection.name), registerWrapper && _marko_compiler.types.numericLiteral(1))));
|
|
4123
|
+
else if (registerWrapper) program.node.body.push(_marko_compiler.types.expressionStatement(registerRuntimeValue(registerId, _marko_compiler.types.identifier(childSection.name))));
|
|
4124
|
+
}
|
|
4110
4125
|
}
|
|
4111
4126
|
}
|
|
4112
4127
|
});
|
|
4113
4128
|
const written = writeSignals(section);
|
|
4114
4129
|
writeRegisteredFns();
|
|
4115
4130
|
const setup = getSetup(section);
|
|
4116
|
-
|
|
4117
|
-
if (
|
|
4131
|
+
const setupWritten = !!setup && written.has(setup);
|
|
4132
|
+
if (domExports.setupEmpty && setupWritten) throw program.buildCodeFrameError("Marko internal error: analysis marked this template's setup export as empty but translation produced statements for it. Please open an issue with a reproduction.");
|
|
4133
|
+
if (!setupWritten) program.node.body.unshift(_marko_compiler.types.exportNamedDeclaration(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(setupIdentifier, _marko_compiler.types.arrowFunctionExpression([], _marko_compiler.types.blockStatement([])))])));
|
|
4118
4134
|
writeStructureExports(program);
|
|
4119
4135
|
writeModuleRegistrations(program);
|
|
4120
4136
|
program.node.body.push(_marko_compiler.types.exportDefaultDeclaration(callRuntime("_template", _marko_compiler.types.stringLiteral((0, _marko_compiler_babel_utils.getFile)().metadata.marko.id), ...replaceNullishAndEmptyFunctionsWith0([
|
|
@@ -4173,8 +4189,10 @@ var html_default = { translate: {
|
|
|
4173
4189
|
for (const child of program.get("body")) if (!isStatic(child)) {
|
|
4174
4190
|
renderContent.push(child.node);
|
|
4175
4191
|
child.remove();
|
|
4176
|
-
} else if (child.isMarkoScriptlet())
|
|
4177
|
-
|
|
4192
|
+
} else if (child.isMarkoScriptlet()) {
|
|
4193
|
+
if (child.node.target && child.node.target !== "server") child.remove();
|
|
4194
|
+
else child.replaceWithMultiple(child.node.body);
|
|
4195
|
+
}
|
|
4178
4196
|
writeModuleRegistrations(program);
|
|
4179
4197
|
const contentId = usedSharedUid("content") && getTemplateContentName();
|
|
4180
4198
|
const contentFn = _marko_compiler.types.arrowFunctionExpression([_marko_compiler.types.identifier("input")], _marko_compiler.types.blockStatement(renderContent));
|
|
@@ -4220,9 +4238,7 @@ function replaceRegisteredFunctionNode(node) {
|
|
|
4220
4238
|
case "ArrowFunctionExpression":
|
|
4221
4239
|
case "FunctionExpression": return getRegisteredFnExpression(node);
|
|
4222
4240
|
case "BlockStatement":
|
|
4223
|
-
case "MarkoScriptlet":
|
|
4224
|
-
addRegisteredDeclarations(node.body);
|
|
4225
|
-
break;
|
|
4241
|
+
case "MarkoScriptlet": addRegisteredDeclarations(node.body);
|
|
4226
4242
|
}
|
|
4227
4243
|
}
|
|
4228
4244
|
function addRegisteredDeclarations(body) {
|
|
@@ -4261,9 +4277,7 @@ function injectTextCoercion(expr) {
|
|
|
4261
4277
|
injectTextCoercion(expr.consequent);
|
|
4262
4278
|
injectTextCoercion(expr.alternate);
|
|
4263
4279
|
break;
|
|
4264
|
-
case "TemplateLiteral":
|
|
4265
|
-
expr.expressions = expr.expressions.map((child) => toText(child));
|
|
4266
|
-
break;
|
|
4280
|
+
case "TemplateLiteral": expr.expressions = expr.expressions.map((child) => toText(child));
|
|
4267
4281
|
}
|
|
4268
4282
|
}
|
|
4269
4283
|
function toText(value) {
|
|
@@ -4331,7 +4345,7 @@ function getOnlyChildParentTagName(tag, branchSize = 1) {
|
|
|
4331
4345
|
const extra = tag.node.extra;
|
|
4332
4346
|
if (extra[kOnlyChildInParent] !== void 0) return extra[kOnlyChildInParent];
|
|
4333
4347
|
const parentTag = getParentTag(tag);
|
|
4334
|
-
return extra[kOnlyChildInParent] = parentTag && analyzeTagNameType(parentTag) === 0 && parentTag.node.name.type === "StringLiteral" && tag.parent.body.filter((node) => node.type !== "MarkoComment").length === branchSize ? parentTag.node.name.value : false;
|
|
4348
|
+
return extra[kOnlyChildInParent] = parentTag && analyzeTagNameType(parentTag) === 0 && parentTag.node.name.type === "StringLiteral" && !isPageElement(parentTag.node.name.value) && tag.parent.body.filter((node) => node.type !== "MarkoComment").length === branchSize ? parentTag.node.name.value : false;
|
|
4335
4349
|
}
|
|
4336
4350
|
function getOptimizedOnlyChildNodeBinding(tag, section, branchSize = 1) {
|
|
4337
4351
|
if (getOnlyChildParentTagName(tag, branchSize)) {
|
|
@@ -4680,32 +4694,34 @@ function analyzeAttributeTags(tag) {
|
|
|
4680
4694
|
const attrTagNodesByName = {};
|
|
4681
4695
|
const sampleAttrTagsForControlFlow = /* @__PURE__ */ new Map();
|
|
4682
4696
|
let chainGroup;
|
|
4683
|
-
for (const child of attrTags) if (child.isMarkoTag())
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
const
|
|
4692
|
-
|
|
4693
|
-
if (
|
|
4694
|
-
|
|
4695
|
-
|
|
4697
|
+
for (const child of attrTags) if (child.isMarkoTag()) {
|
|
4698
|
+
if ((0, _marko_compiler_babel_utils.isAttributeTag)(child)) {
|
|
4699
|
+
const name = getTagName(child);
|
|
4700
|
+
lookup[name] ||= createAttrTagMeta(name, [name]);
|
|
4701
|
+
(attrTagNodesByName[name] ||= []).push(child);
|
|
4702
|
+
analyzeAttributeTags(child);
|
|
4703
|
+
} else {
|
|
4704
|
+
let curGroup = isElseTag(child) ? chainGroup : void 0;
|
|
4705
|
+
for (const [name, isRepeated] of crawlAttrTags(child, attrTagNodesByName)) {
|
|
4706
|
+
const oldMeta = lookup[name];
|
|
4707
|
+
if (oldMeta) {
|
|
4708
|
+
if (!curGroup) curGroup = oldMeta.group;
|
|
4709
|
+
else if (curGroup !== oldMeta.group) for (const name of oldMeta.group) {
|
|
4710
|
+
lookup[name].group = curGroup;
|
|
4711
|
+
curGroup.push(name);
|
|
4712
|
+
}
|
|
4713
|
+
}
|
|
4714
|
+
let attrTagMeta = lookup[name];
|
|
4715
|
+
if (!attrTagMeta) {
|
|
4716
|
+
attrTagMeta = lookup[name] = createAttrTagMeta(name, curGroup ||= []);
|
|
4696
4717
|
curGroup.push(name);
|
|
4697
4718
|
}
|
|
4719
|
+
attrTagMeta.dynamic = true;
|
|
4720
|
+
if (isRepeated) attrTagMeta.repeated = true;
|
|
4721
|
+
sampleAttrTagsForControlFlow.set(child, name);
|
|
4698
4722
|
}
|
|
4699
|
-
|
|
4700
|
-
if (!attrTagMeta) {
|
|
4701
|
-
attrTagMeta = lookup[name] = createAttrTagMeta(name, curGroup ||= []);
|
|
4702
|
-
curGroup.push(name);
|
|
4703
|
-
}
|
|
4704
|
-
attrTagMeta.dynamic = true;
|
|
4705
|
-
if (isRepeated) attrTagMeta.repeated = true;
|
|
4706
|
-
sampleAttrTagsForControlFlow.set(child, name);
|
|
4723
|
+
chainGroup = curGroup;
|
|
4707
4724
|
}
|
|
4708
|
-
chainGroup = curGroup;
|
|
4709
4725
|
}
|
|
4710
4726
|
for (const [controlFlowTag, sampleAttrName] of sampleAttrTagsForControlFlow) (controlFlowTag.node.extra ??= {}).attributeTagGroup = lookup[sampleAttrName].group;
|
|
4711
4727
|
for (const name in attrTagNodesByName) {
|
|
@@ -4727,12 +4743,14 @@ function createAttrTagMeta(name, group) {
|
|
|
4727
4743
|
}
|
|
4728
4744
|
function crawlAttrTags(tag, attrTagNodesByName, attrTagNames = /* @__PURE__ */ new Map(), inLoop = (0, _marko_compiler_babel_utils.isLoopTag)(tag)) {
|
|
4729
4745
|
const attrTags = getAttrTagPaths(tag);
|
|
4730
|
-
for (const child of attrTags) if (child.isMarkoTag())
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4746
|
+
for (const child of attrTags) if (child.isMarkoTag()) {
|
|
4747
|
+
if ((0, _marko_compiler_babel_utils.isAttributeTag)(child)) {
|
|
4748
|
+
const tagName = getTagName(child);
|
|
4749
|
+
attrTagNames.set(tagName, inLoop || !!attrTagNames.get(tagName));
|
|
4750
|
+
(attrTagNodesByName[tagName] ||= []).push(child);
|
|
4751
|
+
analyzeAttributeTags(child);
|
|
4752
|
+
} else crawlAttrTags(child, attrTagNodesByName, attrTagNames, inLoop || (0, _marko_compiler_babel_utils.isLoopTag)(child));
|
|
4753
|
+
}
|
|
4736
4754
|
return attrTagNames;
|
|
4737
4755
|
}
|
|
4738
4756
|
function hasRepeatedDynamicAttrTags(attrTags) {
|
|
@@ -4765,7 +4783,7 @@ const contentProps = /* @__PURE__ */ new WeakSet();
|
|
|
4765
4783
|
function translateAttrs(tag, propTree = true, skip, statements = [], contentKey = "content") {
|
|
4766
4784
|
const contentProperties = [];
|
|
4767
4785
|
const attrTagLookup = tag.node.extra?.attributeTags;
|
|
4768
|
-
const seen =
|
|
4786
|
+
const seen = toSet(skip);
|
|
4769
4787
|
if (attrTagLookup) {
|
|
4770
4788
|
for (const name in attrTagLookup) {
|
|
4771
4789
|
const attrTagMeta = attrTagLookup[name];
|
|
@@ -4780,21 +4798,23 @@ function translateAttrs(tag, propTree = true, skip, statements = [], contentKey
|
|
|
4780
4798
|
const attrTags = getAttrTagPaths(tag);
|
|
4781
4799
|
for (let i = 0; i < attrTags.length; i++) {
|
|
4782
4800
|
const child = attrTags[i];
|
|
4783
|
-
if (child.isMarkoTag())
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4801
|
+
if (child.isMarkoTag()) {
|
|
4802
|
+
if ((0, _marko_compiler_babel_utils.isAttributeTag)(child)) {
|
|
4803
|
+
const attrTagMeta = attrTagLookup[getTagName(child)];
|
|
4804
|
+
if (propsUtil.has(skip, attrTagMeta.name)) continue;
|
|
4805
|
+
if (attrTagMeta.dynamic) i = addDynamicAttrTagStatements(attrTags, i, attrTagLookup, statements, propTree, contentKey);
|
|
4806
|
+
else {
|
|
4807
|
+
const translatedAttrTag = translateAttrs(child, getKnownFromPropTree(propTree, attrTagMeta.name), void 0, statements, contentKey);
|
|
4808
|
+
const prevProp = attrTagMeta.repeated ? findObjectProperty(attrTagMeta.name, contentProperties) : void 0;
|
|
4809
|
+
if (prevProp) prevProp.value = callRuntime("attrTags", prevProp.value, _marko_compiler.types.objectExpression(translatedAttrTag.properties));
|
|
4810
|
+
else contentProperties.push(toObjectProperty(attrTagMeta.name, callRuntime("attrTag", _marko_compiler.types.objectExpression(translatedAttrTag.properties))));
|
|
4811
|
+
}
|
|
4812
|
+
} else i = addDynamicAttrTagStatements(attrTags, i, attrTagLookup, statements, propTree, contentKey);
|
|
4813
|
+
}
|
|
4794
4814
|
}
|
|
4795
4815
|
}
|
|
4796
4816
|
if (!seen.has(contentKey) && getKnownFromPropTree(propTree, contentKey)) {
|
|
4797
|
-
const contentExpression = buildContent(tag.get("body"));
|
|
4817
|
+
const contentExpression = buildContent$1(tag.get("body"));
|
|
4798
4818
|
if (contentExpression) {
|
|
4799
4819
|
const contentProp = _marko_compiler.types.objectProperty(_marko_compiler.types.identifier(contentKey), contentExpression);
|
|
4800
4820
|
seen.add(contentKey);
|
|
@@ -4824,17 +4844,19 @@ function getTranslatedBodyContentProperty(props) {
|
|
|
4824
4844
|
}
|
|
4825
4845
|
function addDynamicAttrTagStatements(attrTags, index, attrTagLookup, statements, propTree, contentKey = "content") {
|
|
4826
4846
|
const tag = attrTags[index];
|
|
4827
|
-
if (tag.isMarkoTag()
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4847
|
+
if (tag.isMarkoTag() && !tag.node.extra.pruned) {
|
|
4848
|
+
if ((0, _marko_compiler_babel_utils.isAttributeTag)(tag)) {
|
|
4849
|
+
const attrTagMeta = attrTagLookup[getTagName(tag)];
|
|
4850
|
+
const attrTagExport = getKnownFromPropTree(propTree, attrTagMeta.name);
|
|
4851
|
+
if (attrTagExport && attrTagMeta.dynamic) {
|
|
4852
|
+
const translatedAttrTag = translateAttrs(tag, attrTagExport, void 0, statements, contentKey);
|
|
4853
|
+
if (attrTagMeta.repeated) statements.push(_marko_compiler.types.expressionStatement(_marko_compiler.types.assignmentExpression("=", getAttrTagIdentifier(attrTagMeta), callRuntime("attrTags", getAttrTagIdentifier(attrTagMeta), _marko_compiler.types.objectExpression(translatedAttrTag.properties)))));
|
|
4854
|
+
else statements.push(_marko_compiler.types.expressionStatement(_marko_compiler.types.assignmentExpression("=", getAttrTagIdentifier(attrTagMeta), callRuntime("attrTag", _marko_compiler.types.objectExpression(translatedAttrTag.properties)))));
|
|
4855
|
+
}
|
|
4856
|
+
} else switch (getTagName(tag)) {
|
|
4857
|
+
case "if": return translateIfAttrTag(attrTags, index, attrTagLookup, statements, propTree, contentKey);
|
|
4858
|
+
case "for": return translateForAttrTag(attrTags, index, attrTagLookup, statements, propTree, contentKey);
|
|
4859
|
+
}
|
|
4838
4860
|
}
|
|
4839
4861
|
return index;
|
|
4840
4862
|
}
|
|
@@ -4888,25 +4910,27 @@ function findObjectProperty(name, props) {
|
|
|
4888
4910
|
case "StringLiteral":
|
|
4889
4911
|
if (prop.key.value === name) return prop;
|
|
4890
4912
|
break;
|
|
4891
|
-
case "Identifier":
|
|
4892
|
-
if (prop.key.name === name) return prop;
|
|
4893
|
-
break;
|
|
4913
|
+
case "Identifier": if (prop.key.name === name) return prop;
|
|
4894
4914
|
}
|
|
4895
4915
|
return false;
|
|
4896
4916
|
}
|
|
4897
4917
|
function getConditionTestValue({ node: { attributes } }) {
|
|
4898
4918
|
return attributes.length === 1 ? attributes[0].value : void 0;
|
|
4899
4919
|
}
|
|
4900
|
-
function buildContent(body) {
|
|
4920
|
+
function buildContent$1(body) {
|
|
4901
4921
|
const bodySection = body.node.extra?.section;
|
|
4902
|
-
if (bodySection)
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4922
|
+
if (bodySection) {
|
|
4923
|
+
if (isOutputHTML()) {
|
|
4924
|
+
const serialized = getSectionRegisterReasons(bodySection);
|
|
4925
|
+
body.node.body.unshift(getScopeReasonStatement(bodySection));
|
|
4926
|
+
return callRuntime(serialized ? "_content_resume" : "_content", _marko_compiler.types.stringLiteral(getResumeRegisterId(bodySection, "content")), _marko_compiler.types.arrowFunctionExpression(body.node.params, _marko_compiler.types.blockStatement(body.node.body)), getScopeIdIdentifier(getSection(getAttributeTagParent(body.parentPath))), serialized && getRegisteredLocals(bodySection));
|
|
4927
|
+
} else {
|
|
4928
|
+
const renderer = getSectionRendererIdentifier(bodySection);
|
|
4929
|
+
if (renderer) {
|
|
4930
|
+
const localClosureValues = getLocalClosureValues(bodySection);
|
|
4931
|
+
return _marko_compiler.types.callExpression(renderer, localClosureValues ? [scopeIdentifier, localClosureValues] : [scopeIdentifier]);
|
|
4932
|
+
}
|
|
4933
|
+
}
|
|
4910
4934
|
}
|
|
4911
4935
|
}
|
|
4912
4936
|
function getRegisteredLocals(bodySection) {
|
|
@@ -4933,13 +4957,7 @@ var native_tag_default = {
|
|
|
4933
4957
|
const { node } = tag;
|
|
4934
4958
|
if (node.var && !_marko_compiler.types.isIdentifier(node.var)) throw tag.get("var").buildCodeFrameError("Tag variables on [native tags](https://markojs.com/docs/reference/native-tag) cannot be destructured.");
|
|
4935
4959
|
const tagName = getCanonicalTagName(tag);
|
|
4936
|
-
|
|
4937
|
-
case "html":
|
|
4938
|
-
case "body":
|
|
4939
|
-
case "head":
|
|
4940
|
-
(0, _marko_compiler_babel_utils.getProgram)().node.extra.page ??= true;
|
|
4941
|
-
break;
|
|
4942
|
-
}
|
|
4960
|
+
if (isPageElement(tagName)) (0, _marko_compiler_babel_utils.getProgram)().node.extra.page ??= true;
|
|
4943
4961
|
if (tagName === "option") assertOptionInSelectWithValue(tag);
|
|
4944
4962
|
const isTextOnly = isTextOnlyNativeTag(tag);
|
|
4945
4963
|
const seen = Object.create(null);
|
|
@@ -5032,13 +5050,13 @@ var native_tag_default = {
|
|
|
5032
5050
|
exprExtras = push(exprExtras, textPlaceholders.length === 1 ? textPlaceholders[0].extra ??= {} : mergeReferences(tagSection, textPlaceholders[0], textPlaceholders.slice(1)));
|
|
5033
5051
|
addSetupExpr(tagSection, textPlaceholders[0]);
|
|
5034
5052
|
}
|
|
5035
|
-
if (injectNonce)
|
|
5036
|
-
if (relatedControllable?.attrs[1])
|
|
5053
|
+
if (injectNonce) addSetupWork(tagSection);
|
|
5054
|
+
if (relatedControllable?.attrs[1]) addSetupWork(tagSection);
|
|
5037
5055
|
for (const name in seen) {
|
|
5038
5056
|
const attr = seen[name];
|
|
5039
5057
|
if (isEventHandler(name) || name === "content" || !evaluate(attr.value).confident) addSetupExpr(tagSection, attr.value);
|
|
5040
5058
|
}
|
|
5041
|
-
if (
|
|
5059
|
+
if (hasEventHandlers || isTagVarRead(tag)) addSerializeReason(tagSection, FORCED, nodeBinding);
|
|
5042
5060
|
trackDomVarReferences(tag, nodeBinding);
|
|
5043
5061
|
addSerializeExpr(tagSection, push(exprExtras, tagExtra), nodeBinding);
|
|
5044
5062
|
}
|
|
@@ -5064,9 +5082,7 @@ var native_tag_default = {
|
|
|
5064
5082
|
}
|
|
5065
5083
|
break;
|
|
5066
5084
|
}
|
|
5067
|
-
default:
|
|
5068
|
-
if (confident) write`${getHTMLRuntime()._attr(name, computed)}`;
|
|
5069
|
-
break;
|
|
5085
|
+
default: if (confident) write`${getHTMLRuntime()._attr(name, computed)}`;
|
|
5070
5086
|
}
|
|
5071
5087
|
}
|
|
5072
5088
|
write`>`;
|
|
@@ -5127,34 +5143,28 @@ var native_tag_default = {
|
|
|
5127
5143
|
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");
|
|
5128
5144
|
if (tagName === "select") {
|
|
5129
5145
|
if (staticControllable) htmlSelectArgs.set(tag.node, {
|
|
5130
|
-
|
|
5131
|
-
|
|
5146
|
+
helper: "_attr_select_value",
|
|
5147
|
+
args: [staticControllable.attrs[0]?.value || buildUndefined$1(), staticControllable.attrs[1]?.value || buildUndefined$1()]
|
|
5132
5148
|
});
|
|
5133
5149
|
else if (spreadExpression) {
|
|
5134
5150
|
const spreadIdentifier = generateUidIdentifier("select_input");
|
|
5135
5151
|
tag.insertBefore(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(spreadIdentifier, spreadExpression)]));
|
|
5136
5152
|
htmlSelectArgs.set(tag.node, {
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
serializeType: _marko_compiler.types.numericLiteral(1)
|
|
5153
|
+
helper: "_attrs_select_value",
|
|
5154
|
+
args: [spreadIdentifier]
|
|
5140
5155
|
});
|
|
5141
5156
|
spreadExpression = spreadIdentifier;
|
|
5142
5157
|
}
|
|
5143
5158
|
} else if (tagName === "textarea") {
|
|
5144
|
-
let value;
|
|
5145
|
-
let valueChange;
|
|
5146
5159
|
if (staticControllable) {
|
|
5147
|
-
value = staticControllable.attrs
|
|
5148
|
-
|
|
5160
|
+
const [value, valueChange] = staticControllable.attrs;
|
|
5161
|
+
writeAtStartOfBody = valueChange ? callRuntime("_attr_textarea_value", getScopeIdIdentifier(tagSection), visitAccessor, value?.value, valueChange.value) : callRuntime("_textarea_value", value.value);
|
|
5149
5162
|
} else if (spreadExpression) {
|
|
5150
5163
|
const spreadIdentifier = generateUidIdentifier("textarea_input");
|
|
5151
5164
|
tag.insertBefore(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(spreadIdentifier, spreadExpression)]));
|
|
5152
|
-
|
|
5153
|
-
valueChange = _marko_compiler.types.memberExpression(spreadIdentifier, _marko_compiler.types.identifier("valueChange"));
|
|
5165
|
+
writeAtStartOfBody = callRuntime("_attrs_textarea_value", getScopeIdIdentifier(tagSection), visitAccessor, spreadIdentifier);
|
|
5154
5166
|
spreadExpression = spreadIdentifier;
|
|
5155
5167
|
}
|
|
5156
|
-
if (valueChange) writeAtStartOfBody = callRuntime("_attr_textarea_value", getScopeIdIdentifier(tagSection), visitAccessor, value, valueChange, staticControllable ? void 0 : _marko_compiler.types.numericLiteral(1));
|
|
5157
|
-
else if (value) writeAtStartOfBody = callRuntime("_textarea_value", value);
|
|
5158
5168
|
}
|
|
5159
5169
|
for (const attr of staticAttrs) {
|
|
5160
5170
|
const { name, value } = attr;
|
|
@@ -5175,14 +5185,12 @@ var native_tag_default = {
|
|
|
5175
5185
|
}, (branch) => buildStringAttrAnd(helper, branch) || name === "class" && buildClassAttrExpression(branch) || callRuntime(helper, branch)))}`;
|
|
5176
5186
|
break;
|
|
5177
5187
|
}
|
|
5178
|
-
default:
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
}, (branch) => buildLogicalAttr(name, branch) || callRuntime("_attr", _marko_compiler.types.stringLiteral(name), branch)))}`;
|
|
5185
|
-
break;
|
|
5188
|
+
default: if (confident) write`${getHTMLRuntime()._attr(name, computed)}`;
|
|
5189
|
+
else if (isEventHandler(name)) addHTMLEffectCall(tagSection, valueReferences);
|
|
5190
|
+
else write`${factorAttrConditional(buildAttrExpression(value, (branch) => {
|
|
5191
|
+
const { confident, computed } = evaluate(branch);
|
|
5192
|
+
return confident ? getHTMLRuntime()._attr(name, computed) : void 0;
|
|
5193
|
+
}, (branch) => buildLogicalAttr(name, branch) || callRuntime("_attr", _marko_compiler.types.stringLiteral(name), branch)))}`;
|
|
5186
5194
|
}
|
|
5187
5195
|
}
|
|
5188
5196
|
const isOpenOnly = !!(tagDef && tagDef.parseOptions?.openTagOnly);
|
|
@@ -5190,8 +5198,10 @@ var native_tag_default = {
|
|
|
5190
5198
|
const spreadContent = !!spreadExpression && spreadRendersContent(tag, staticContentAttr);
|
|
5191
5199
|
if (spreadExpression) {
|
|
5192
5200
|
addHTMLEffectCall(tagSection, tagExtra.referencedBindings);
|
|
5193
|
-
if (!spreadContent)
|
|
5194
|
-
|
|
5201
|
+
if (!spreadContent) {
|
|
5202
|
+
if (skipExpression) write`${callRuntime("_attrs_partial", spreadExpression, skipExpression, visitAccessor, getScopeIdIdentifier(tagSection), _marko_compiler.types.stringLiteral(tagName))}`;
|
|
5203
|
+
else write`${callRuntime("_attrs", spreadExpression, visitAccessor, getScopeIdIdentifier(tagSection), _marko_compiler.types.stringLiteral(tagName))}`;
|
|
5204
|
+
}
|
|
5195
5205
|
}
|
|
5196
5206
|
if (isOpenOnly || isTextOnly) write`>`;
|
|
5197
5207
|
else if (staticContentAttr) {
|
|
@@ -5219,7 +5229,7 @@ var native_tag_default = {
|
|
|
5219
5229
|
if (selectArgs) {
|
|
5220
5230
|
if (!tagExtra[kSkipEndTag]) write`</${tagName}>`;
|
|
5221
5231
|
flushInto(tag);
|
|
5222
|
-
tag.insertBefore(_marko_compiler.types.expressionStatement(callRuntime(
|
|
5232
|
+
tag.insertBefore(_marko_compiler.types.expressionStatement(callRuntime(selectArgs.helper, getScopeIdIdentifier(tagSection), nodeBinding && getScopeAccessorLiteral(nodeBinding), ...selectArgs.args, _marko_compiler.types.arrowFunctionExpression([], _marko_compiler.types.blockStatement(tag.node.body.body)))));
|
|
5223
5233
|
} else if (isTextOnly) {
|
|
5224
5234
|
const rawTextHelper = getRawTextEscapeHelper(tagName);
|
|
5225
5235
|
if (rawTextHelper) {
|
|
@@ -5291,11 +5301,9 @@ var native_tag_default = {
|
|
|
5291
5301
|
}
|
|
5292
5302
|
break;
|
|
5293
5303
|
}
|
|
5294
|
-
default:
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
else addStatement("render", tagSection, valueReferences, _marko_compiler.types.expressionStatement(callRuntime("_attr", createScopeReadExpression(nodeBinding), _marko_compiler.types.stringLiteral(name), value)), true);
|
|
5298
|
-
break;
|
|
5304
|
+
default: if (confident) break;
|
|
5305
|
+
else if (isEventHandler(name)) addStatement("effect", tagSection, valueReferences, _marko_compiler.types.expressionStatement(callRuntime("_on", createScopeReadExpression(nodeBinding), _marko_compiler.types.stringLiteral(getEventHandlerName(name)), value)));
|
|
5306
|
+
else addStatement("render", tagSection, valueReferences, _marko_compiler.types.expressionStatement(callRuntime("_attr", createScopeReadExpression(nodeBinding), _marko_compiler.types.stringLiteral(name), value)), true);
|
|
5299
5307
|
}
|
|
5300
5308
|
}
|
|
5301
5309
|
if (spreadExpression) {
|
|
@@ -5314,10 +5322,12 @@ var native_tag_default = {
|
|
|
5314
5322
|
const nodeBinding = tag.node.extra[kNativeTagBinding];
|
|
5315
5323
|
const openTagOnly = (0, _marko_compiler_babel_utils.getTagDef)(tag)?.parseOptions?.openTagOnly;
|
|
5316
5324
|
const tagName = getCanonicalTagName(tag);
|
|
5317
|
-
if (!openTagOnly)
|
|
5318
|
-
|
|
5319
|
-
|
|
5320
|
-
|
|
5325
|
+
if (!openTagOnly) {
|
|
5326
|
+
if (tagName !== "textarea" && isTextOnlyNativeTag(tag)) {
|
|
5327
|
+
const textLiteral = bodyToTextLiteral(tag.node.body, tagName === "title");
|
|
5328
|
+
if (!_marko_compiler.types.isStringLiteral(textLiteral)) addStatement("render", getSection(tag), textLiteral.extra?.referencedBindings, _marko_compiler.types.expressionStatement(callRuntime("_text_content", createScopeReadExpression(nodeBinding), textLiteral)), true);
|
|
5329
|
+
} else tag.insertBefore(tag.node.body.body).forEach((child) => child.skip());
|
|
5330
|
+
}
|
|
5321
5331
|
tag.remove();
|
|
5322
5332
|
}
|
|
5323
5333
|
}
|
|
@@ -5379,13 +5389,11 @@ function getRelatedControllable(tagName, attrs) {
|
|
|
5379
5389
|
};
|
|
5380
5390
|
break;
|
|
5381
5391
|
case "details":
|
|
5382
|
-
case "dialog":
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
};
|
|
5388
|
-
break;
|
|
5392
|
+
case "dialog": if (attrs.open || attrs.openChange) return {
|
|
5393
|
+
special: false,
|
|
5394
|
+
helper: `_attr_${tagName}_open`,
|
|
5395
|
+
attrs: [attrs.open, attrs.openChange]
|
|
5396
|
+
};
|
|
5389
5397
|
}
|
|
5390
5398
|
}
|
|
5391
5399
|
function getInputValueMode(typeAttr) {
|
|
@@ -5511,10 +5519,13 @@ function warnCamelCaseStyleKeys(tag, attr) {
|
|
|
5511
5519
|
if (prop.type !== "ObjectProperty" || prop.computed) continue;
|
|
5512
5520
|
const { key } = prop;
|
|
5513
5521
|
const name = key.type === "Identifier" ? key.name : key.type === "StringLiteral" ? key.value : void 0;
|
|
5514
|
-
if (name && !name.startsWith("--") && !name.includes("-") && /[A-Z]/.test(name))
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5522
|
+
if (name && !name.startsWith("--") && !name.includes("-") && /[A-Z]/.test(name)) {
|
|
5523
|
+
const kebab = name.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase()).replace(/^ms-/, "-ms-");
|
|
5524
|
+
(0, _marko_compiler_babel_utils.diagnosticWarn)(tag, {
|
|
5525
|
+
label: `\`${name}\` is not a CSS property name; the [\`style=\` object](https://markojs.com/docs/reference/native-tag#style) writes keys out verbatim (unlike the camelCased DOM style API), so this renders as invalid CSS the browser ignores. Use the kebab-case name \`${kebab}\`.`,
|
|
5526
|
+
loc: key.loc ?? void 0
|
|
5527
|
+
});
|
|
5528
|
+
}
|
|
5518
5529
|
}
|
|
5519
5530
|
}
|
|
5520
5531
|
function assertNativeHandlerAttr(tag, attr) {
|
|
@@ -5660,9 +5671,7 @@ function trackDelimitedAttrValue(expr, meta) {
|
|
|
5660
5671
|
case "ArrayExpression":
|
|
5661
5672
|
trackDelimitedAttrArrayItems(expr, meta);
|
|
5662
5673
|
break;
|
|
5663
|
-
default:
|
|
5664
|
-
(meta.dynamicItems ||= []).push(expr);
|
|
5665
|
-
break;
|
|
5674
|
+
default: (meta.dynamicItems ||= []).push(expr);
|
|
5666
5675
|
}
|
|
5667
5676
|
}
|
|
5668
5677
|
function trackDelimitedAttrArrayItems(arr, meta) {
|
|
@@ -5745,6 +5754,14 @@ function controllableFeatureFor(tagName) {
|
|
|
5745
5754
|
function enableControllable(feature) {
|
|
5746
5755
|
if (feature) importRuntimeFeature(feature);
|
|
5747
5756
|
}
|
|
5757
|
+
const pageElements = /* @__PURE__ */ new Set([
|
|
5758
|
+
"html",
|
|
5759
|
+
"head",
|
|
5760
|
+
"body"
|
|
5761
|
+
]);
|
|
5762
|
+
function isPageElement(tagName) {
|
|
5763
|
+
return pageElements.has(tagName);
|
|
5764
|
+
}
|
|
5748
5765
|
//#endregion
|
|
5749
5766
|
//#region src/translator/util/branch-tag.ts
|
|
5750
5767
|
function getBranchSectionAccessor(nodeBinding) {
|
|
@@ -5779,7 +5796,7 @@ function getBranchEndArgs(tag, tagSection, nodeBinding, statefulReason, onlyChil
|
|
|
5779
5796
|
];
|
|
5780
5797
|
}
|
|
5781
5798
|
function isSingleNodeBranch(bodySection) {
|
|
5782
|
-
return !!(bodySection?.content?.singleChild && bodySection.content.startType
|
|
5799
|
+
return !!(bodySection?.content?.singleChild && bodySection.content.startType === 3);
|
|
5783
5800
|
}
|
|
5784
5801
|
//#endregion
|
|
5785
5802
|
//#region src/translator/util/to-first-statement-or-block.ts
|
|
@@ -5988,7 +6005,6 @@ function assertValidCondition(tag) {
|
|
|
5988
6005
|
case "else":
|
|
5989
6006
|
assertOptionalIfAttribute(tag);
|
|
5990
6007
|
assertHasPrecedingCondition(tag);
|
|
5991
|
-
break;
|
|
5992
6008
|
}
|
|
5993
6009
|
}
|
|
5994
6010
|
function assertHasPrecedingCondition(tag) {
|
|
@@ -6097,10 +6113,12 @@ function crawlSectionsAndSetBinding(tag, downstreamTag, binding, exprs, properti
|
|
|
6097
6113
|
const attrTagLookup = analyzeAttributeTags(tag);
|
|
6098
6114
|
if (!attrTagLookup) return;
|
|
6099
6115
|
const attrTags = getAttrTagPaths(tag);
|
|
6100
|
-
for (const child of attrTags) if (child.isMarkoTag())
|
|
6101
|
-
|
|
6102
|
-
|
|
6103
|
-
|
|
6116
|
+
for (const child of attrTags) if (child.isMarkoTag()) {
|
|
6117
|
+
if ((0, _marko_compiler_babel_utils.isAttributeTag)(child)) {
|
|
6118
|
+
const attrTagMeta = attrTagLookup[getTagName(child)];
|
|
6119
|
+
crawlSectionsAndSetBinding(child, downstreamTag, binding, exprs, concat(properties, attrTagMeta.name));
|
|
6120
|
+
} else crawlSectionsAndSetBinding(child, downstreamTag, binding, exprs, properties, true);
|
|
6121
|
+
}
|
|
6104
6122
|
}
|
|
6105
6123
|
//#endregion
|
|
6106
6124
|
//#region src/translator/util/translate-var.ts
|
|
@@ -6126,14 +6144,16 @@ function translateVar(tag, initialValue, kind = "const", statements) {
|
|
|
6126
6144
|
const restPath = id.parentPath;
|
|
6127
6145
|
if (restPath.type !== "RestElement") throw restPath.buildCodeFrameError("Invalid compiler state, found a rest binding outside of a rest element.");
|
|
6128
6146
|
let curPath = tag.parentPath;
|
|
6147
|
+
let prevPath = tag;
|
|
6129
6148
|
while (curPath) {
|
|
6130
6149
|
if (curPath.node.extra?.section === binding.section) {
|
|
6131
6150
|
const canonicalUpstreamAlias = getCanonicalBinding(binding.upstreamAlias);
|
|
6132
6151
|
const props = toArray(binding.excludeProperties, (name) => _marko_compiler.types.objectProperty(toPropertyName(name), generateUidIdentifier(name)));
|
|
6133
6152
|
props.push(restPath.node);
|
|
6134
|
-
curPath.insertBefore(_marko_compiler.types.variableDeclaration(kind, [_marko_compiler.types.variableDeclarator(_marko_compiler.types.objectPattern(props), canonicalUpstreamAlias.nullable ? _marko_compiler.types.logicalExpression("||", getDeclaredBindingExpression(canonicalUpstreamAlias), _marko_compiler.types.objectExpression([])) : getDeclaredBindingExpression(canonicalUpstreamAlias))]));
|
|
6153
|
+
(curPath.parentPath ? curPath : prevPath).insertBefore(_marko_compiler.types.variableDeclaration(kind, [_marko_compiler.types.variableDeclarator(_marko_compiler.types.objectPattern(props), canonicalUpstreamAlias.nullable ? _marko_compiler.types.logicalExpression("||", getDeclaredBindingExpression(canonicalUpstreamAlias), _marko_compiler.types.objectExpression([])) : getDeclaredBindingExpression(canonicalUpstreamAlias))]));
|
|
6135
6154
|
break;
|
|
6136
6155
|
}
|
|
6156
|
+
prevPath = curPath;
|
|
6137
6157
|
curPath = curPath.parentPath;
|
|
6138
6158
|
}
|
|
6139
6159
|
restPath.remove();
|
|
@@ -6168,14 +6188,14 @@ function knownTagAnalyze(tag, contentSection, propTree) {
|
|
|
6168
6188
|
trackParamsReferences(tagBody, 3);
|
|
6169
6189
|
getKnownTags(section).push(tagExtra);
|
|
6170
6190
|
tagExtra[kContentSection] = contentSection;
|
|
6171
|
-
if (
|
|
6191
|
+
if (contentSection.program === section.program) contentSection.callSections = sectionUtil.add(contentSection.callSections, section);
|
|
6172
6192
|
const varBinding = trackVarReferences(tag, 5);
|
|
6173
6193
|
const exprs = tagExtra[kKnownExprs] = analyzeParams(tagExtra, section, tag, propTree, attrExprs);
|
|
6174
6194
|
setTagDownstream(tag, propTree?.props?.[0]?.binding, exprs);
|
|
6175
6195
|
if (varBinding) {
|
|
6176
|
-
|
|
6196
|
+
addSetupWork(section);
|
|
6177
6197
|
const mutatesTagVar = !!(tag.node.var.type === "Identifier" && tag.scope.getBinding(tag.node.var.name)?.constantViolations.length);
|
|
6178
|
-
const varExpr = tagExtra.defineBodySection ? contentSection.returnValueExpr : mapParamReasonToExpr(exprs, contentSection.returnSerializeReason && (contentSection.returnSerializeReason.forced || !!contentSection.returnSerializeReason.state || contentSection.returnSerializeReason.param));
|
|
6198
|
+
const varExpr = isSameOrChildSection(contentSection, section) || (tagExtra.defineBodySection ? contentSection.returnValueExpr : mapParamReasonToExpr(exprs, contentSection.returnSerializeReason && (contentSection.returnSerializeReason.forced || !!contentSection.returnSerializeReason.state || contentSection.returnSerializeReason.param)));
|
|
6179
6199
|
varBinding.scopeOffset = tagExtra[kChildOffsetScopeBinding$1] = createBinding("#scopeOffset", 0, section);
|
|
6180
6200
|
setBindingDownstream(varBinding, varExpr);
|
|
6181
6201
|
if (mutatesTagVar || varExpr === true) addSerializeReason(section, FORCED, childScopeBinding);
|
|
@@ -6245,7 +6265,7 @@ function knownTagTranslateDOM(tag, propTree, getBindingIdentifier, callSetup) {
|
|
|
6245
6265
|
if (!isOptimize()) changeArgs.push(_marko_compiler.types.stringLiteral(varBinding.name));
|
|
6246
6266
|
return _marko_compiler.types.callExpression(importRuntime("_var_change"), changeArgs);
|
|
6247
6267
|
};
|
|
6248
|
-
addStatement("
|
|
6268
|
+
addStatement("render", tagSection, void 0, _marko_compiler.types.expressionStatement(callRuntime("_var", scopeIdentifier, getScopeAccessorLiteral(childScopeBinding, true), source.identifier)));
|
|
6249
6269
|
}
|
|
6250
6270
|
callSetup?.(tagSection, childScopeBinding);
|
|
6251
6271
|
if (propTree) writeParamsToSignals(tag, propTree, getTagName(tag) || "tag", {
|
|
@@ -6276,7 +6296,7 @@ function buildChildSerializeReason(section, childScopeBinding, reasonGroups) {
|
|
|
6276
6296
|
function analyzeParams(rootTagExtra, section, tag, propTree, rootAttrExprs) {
|
|
6277
6297
|
const inputExpr = {};
|
|
6278
6298
|
if (!propTree) {
|
|
6279
|
-
|
|
6299
|
+
dropAllTagNodes(tag.node);
|
|
6280
6300
|
return inputExpr;
|
|
6281
6301
|
}
|
|
6282
6302
|
if (!propTree.props || propTree.rest || tag.node.arguments?.some((node) => _marko_compiler.types.isSpreadElement(node))) {
|
|
@@ -6300,7 +6320,7 @@ function analyzeParams(rootTagExtra, section, tag, propTree, rootAttrExprs) {
|
|
|
6300
6320
|
else {
|
|
6301
6321
|
const args = tag.node.arguments;
|
|
6302
6322
|
tag.node.arguments = null;
|
|
6303
|
-
|
|
6323
|
+
dropAllTagNodes(tag.node);
|
|
6304
6324
|
tag.node.arguments = args;
|
|
6305
6325
|
}
|
|
6306
6326
|
return inputExpr;
|
|
@@ -6322,7 +6342,9 @@ function analyzeAttrs(rootTagExtra, section, tag, propTree, rootAttrExprs, rootE
|
|
|
6322
6342
|
const nodeReferencesByGroup = /* @__PURE__ */ new Map();
|
|
6323
6343
|
const analyzeDynamicAttrTagChildGroup = (group, child) => {
|
|
6324
6344
|
const referenceNodes = [];
|
|
6325
|
-
|
|
6345
|
+
const collectAttrTag = (attrTag) => collectAttrTagReferenceNodes(attrTag, attrTagLookup, propTree, referenceNodes, dropReferenceNodes);
|
|
6346
|
+
if ((0, _marko_compiler_babel_utils.isAttributeTag)(child)) collectAttrTag(child.node);
|
|
6347
|
+
else getAllTagReferenceNodes(child.node, referenceNodes, collectAttrTag);
|
|
6326
6348
|
const groupReferences = nodeReferencesByGroup.get(group);
|
|
6327
6349
|
if (groupReferences) groupReferences.referenceNodes = groupReferences.referenceNodes.concat(referenceNodes);
|
|
6328
6350
|
else nodeReferencesByGroup.set(group, {
|
|
@@ -6332,22 +6354,24 @@ function analyzeAttrs(rootTagExtra, section, tag, propTree, rootAttrExprs, rootE
|
|
|
6332
6354
|
};
|
|
6333
6355
|
for (const attrTagName in attrTagLookup) seen.add(attrTagLookup[attrTagName].name);
|
|
6334
6356
|
const attrTags = getAttrTagPaths(tag);
|
|
6335
|
-
for (const child of attrTags) if (child.isMarkoTag())
|
|
6336
|
-
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
|
|
6340
|
-
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
|
|
6344
|
-
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
|
|
6349
|
-
|
|
6350
|
-
|
|
6357
|
+
for (const child of attrTags) if (child.isMarkoTag()) {
|
|
6358
|
+
if ((0, _marko_compiler_babel_utils.isAttributeTag)(child)) {
|
|
6359
|
+
const attrTagMeta = attrTagLookup[getTagName(child)];
|
|
6360
|
+
const childAttrExport = getKnownFromPropTree(propTree, attrTagMeta.name);
|
|
6361
|
+
if (!childAttrExport) getAllAttrTagNodes(child.node, dropReferenceNodes);
|
|
6362
|
+
else if (attrTagMeta.dynamic) analyzeDynamicAttrTagChildGroup(attrTagMeta.group, child);
|
|
6363
|
+
else if (childAttrExport === true) {
|
|
6364
|
+
getAllTagReferenceNodes(child.node, restReferenceNodes ||= []);
|
|
6365
|
+
known[attrTagMeta.name] = { value: rootTagExtra };
|
|
6366
|
+
} else if (childAttrExport.props && !(attrTagMeta.repeated && childAttrExport.rest)) {
|
|
6367
|
+
if (remaining.delete(attrTagMeta.name)) known[attrTagMeta.name] = analyzeAttrs(rootTagExtra, section, child, childAttrExport, rootAttrExprs, rootExprs);
|
|
6368
|
+
else getAllAttrTagNodes(child.node, dropReferenceNodes);
|
|
6369
|
+
} else analyzeDynamicAttrTagChildGroup(attrTagMeta.group, child);
|
|
6370
|
+
} else {
|
|
6371
|
+
const group = child.node.extra.attributeTagGroup;
|
|
6372
|
+
if (hasGroupReads(group, attrTagLookup, propTree)) analyzeDynamicAttrTagChildGroup(group, child);
|
|
6373
|
+
else getAllAttrTagNodes(child.node, dropReferenceNodes);
|
|
6374
|
+
}
|
|
6351
6375
|
}
|
|
6352
6376
|
for (const [group, { firstTag: { node }, referenceNodes }] of nodeReferencesByGroup) {
|
|
6353
6377
|
let bindings;
|
|
@@ -6383,14 +6407,15 @@ function analyzeAttrs(rootTagExtra, section, tag, propTree, rootAttrExprs, rootE
|
|
|
6383
6407
|
}
|
|
6384
6408
|
}
|
|
6385
6409
|
const contentExport = getKnownFromPropTree(propTree, "content");
|
|
6386
|
-
if (contentExport
|
|
6410
|
+
if (!contentExport) dropContent(tag.node.body);
|
|
6411
|
+
else if (!seen.has("content")) {
|
|
6387
6412
|
if (getSectionForBody(tag.get("body"))) {
|
|
6388
6413
|
seen.add("content");
|
|
6389
6414
|
if (contentExport === true) known.content = { value: rootTagExtra };
|
|
6390
6415
|
else {
|
|
6391
6416
|
remaining.delete("content");
|
|
6392
6417
|
known.content = { value: void 0 };
|
|
6393
|
-
|
|
6418
|
+
addSetupWork(section);
|
|
6394
6419
|
}
|
|
6395
6420
|
}
|
|
6396
6421
|
}
|
|
@@ -6436,16 +6461,17 @@ function analyzeAttrs(rootTagExtra, section, tag, propTree, rootAttrExprs, rootE
|
|
|
6436
6461
|
addRead(propExtra, propExtra, propBinding, section, void 0);
|
|
6437
6462
|
setBindingDownstream(templateExportAttr === true ? propTree.rest.binding : templateExportAttr.binding, propExtra, rootExprs);
|
|
6438
6463
|
}
|
|
6439
|
-
else if (spreadReferenceNodes)
|
|
6440
|
-
|
|
6441
|
-
|
|
6442
|
-
|
|
6443
|
-
|
|
6464
|
+
else if (spreadReferenceNodes) {
|
|
6465
|
+
if (remaining.size || propTree.rest && !propTree.rest.props) {
|
|
6466
|
+
inputExpr.value = mergeReferences(section, tag.node, spreadReferenceNodes);
|
|
6467
|
+
setBindingDownstream(propTree.rest?.binding || propTree.binding, inputExpr.value, rootExprs);
|
|
6468
|
+
} else dropNodes(spreadReferenceNodes);
|
|
6469
|
+
} else {
|
|
6444
6470
|
if (restReferenceNodes) {
|
|
6445
6471
|
inputExpr.value = mergeReferences(section, tag.node, restReferenceNodes);
|
|
6446
6472
|
setBindingDownstream(propTree.rest.binding, inputExpr.value, rootExprs);
|
|
6447
6473
|
}
|
|
6448
|
-
if (remaining.size)
|
|
6474
|
+
if (remaining.size) addSetupWork(section);
|
|
6449
6475
|
if (propTree.rest && !propTree.rest.props) addSetupExpr(section, tag.node);
|
|
6450
6476
|
}
|
|
6451
6477
|
dropNodes(dropReferenceNodes);
|
|
@@ -6467,6 +6493,23 @@ function getSingleKnownSpread(attributes) {
|
|
|
6467
6493
|
binding
|
|
6468
6494
|
};
|
|
6469
6495
|
}
|
|
6496
|
+
function dropAllTagNodes(tag) {
|
|
6497
|
+
const nodes = [];
|
|
6498
|
+
dropContent(tag.body);
|
|
6499
|
+
dropNodes(getAllTagReferenceNodes(tag, nodes, (attrTag) => getAllAttrTagNodes(attrTag, nodes)));
|
|
6500
|
+
}
|
|
6501
|
+
function collectAttrTagReferenceNodes(attrTag, attrTagLookup, propTree, referenceNodes, dropReferenceNodes) {
|
|
6502
|
+
const attrTagExport = getKnownFromPropTree(propTree, attrTagLookup[attrTag.name.value].name);
|
|
6503
|
+
if (attrTagExport) {
|
|
6504
|
+
if (!getKnownFromPropTree(attrTagExport, "content")) dropContent(attrTag.body);
|
|
6505
|
+
getAllTagReferenceNodes(attrTag, referenceNodes, (nestedAttrTag) => collectAttrTagReferenceNodes(nestedAttrTag, attrTag.extra.attributeTags, attrTagExport, referenceNodes, dropReferenceNodes));
|
|
6506
|
+
} else getAllAttrTagNodes(attrTag, dropReferenceNodes);
|
|
6507
|
+
}
|
|
6508
|
+
function getAllAttrTagNodes(tag, nodes) {
|
|
6509
|
+
nodes.push(tag);
|
|
6510
|
+
if (!tag.body.attributeTags) dropContent(tag.body);
|
|
6511
|
+
return getAllTagReferenceNodes(tag, nodes, (attrTag) => getAllAttrTagNodes(attrTag, nodes));
|
|
6512
|
+
}
|
|
6470
6513
|
function writeParamsToSignals(tag, propTree, importAlias, info) {
|
|
6471
6514
|
if (!propTree.props || propTree.rest || tag.node.arguments?.some((node) => _marko_compiler.types.isSpreadElement(node))) {
|
|
6472
6515
|
const referencedBindings = tag.node.extra?.referencedBindings;
|
|
@@ -6493,15 +6536,16 @@ function writeParamsToSignals(tag, propTree, importAlias, info) {
|
|
|
6493
6536
|
}
|
|
6494
6537
|
function applyAttrObject(tag, propTree, tagInputIdentifier, info) {
|
|
6495
6538
|
const referencedBindings = tag.node.extra?.referencedBindings;
|
|
6496
|
-
const
|
|
6497
|
-
let translatedProps
|
|
6498
|
-
if (translatedAttrs.statements.length) addStatement("render", info.tagSection, referencedBindings, translatedAttrs.statements);
|
|
6539
|
+
const statements = [];
|
|
6540
|
+
let translatedProps;
|
|
6499
6541
|
if ((0, _marko_compiler_babel_utils.isAttributeTag)(tag)) {
|
|
6500
|
-
const
|
|
6501
|
-
const
|
|
6502
|
-
|
|
6503
|
-
|
|
6504
|
-
|
|
6542
|
+
const attrTagName = getTagName(tag);
|
|
6543
|
+
for (const attrTag of tag.parentPath.get("attributeTags")) if (attrTag.isMarkoTag() && getTagName(attrTag) === attrTagName) {
|
|
6544
|
+
const props = _marko_compiler.types.objectExpression(translateAttrs(attrTag, propTree, void 0, statements).properties);
|
|
6545
|
+
translatedProps = translatedProps ? callRuntime("attrTags", translatedProps, props) : callRuntime("attrTag", props);
|
|
6546
|
+
}
|
|
6547
|
+
} else translatedProps = propsToExpression(translateAttrs(tag, propTree, void 0, statements).properties);
|
|
6548
|
+
if (statements.length) addStatement("render", info.tagSection, referencedBindings, statements);
|
|
6505
6549
|
addStatement("render", info.tagSection, referencedBindings, _marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(tagInputIdentifier, [createScopeReadExpression(info.childScopeBinding, info.tagSection), translatedProps])), true);
|
|
6506
6550
|
}
|
|
6507
6551
|
function translateAttrTag(tag, attrTagMeta, info, statements) {
|
|
@@ -6532,7 +6576,7 @@ function writeAttrsToSignals(tag, propTree, importAlias, info) {
|
|
|
6532
6576
|
const seen = /* @__PURE__ */ new Set();
|
|
6533
6577
|
const tagReferencedBindings = tag.node.extra?.referencedBindings;
|
|
6534
6578
|
const remaining = new Set(getAllKnownPropNames(propTree));
|
|
6535
|
-
|
|
6579
|
+
const contentProps = [];
|
|
6536
6580
|
if (attrTagLookup) {
|
|
6537
6581
|
const attrTags = tag.get("attributeTags");
|
|
6538
6582
|
const statementsByGroup = /* @__PURE__ */ new Map();
|
|
@@ -6548,33 +6592,41 @@ function writeAttrsToSignals(tag, propTree, importAlias, info) {
|
|
|
6548
6592
|
}
|
|
6549
6593
|
return addDynamicAttrTagStatements(attrTags, index, attrTagLookup, statements, propTree);
|
|
6550
6594
|
};
|
|
6551
|
-
for (const attrTagName in attrTagLookup)
|
|
6595
|
+
for (const attrTagName in attrTagLookup) {
|
|
6596
|
+
const attrTagMeta = attrTagLookup[attrTagName];
|
|
6597
|
+
seen.add(attrTagMeta.name);
|
|
6598
|
+
if (attrTagMeta.dynamic && getKnownFromPropTree(propTree, attrTagMeta.name) === true) contentProps.push(toObjectProperty(attrTagMeta.name, getAttrTagIdentifier(attrTagMeta)));
|
|
6599
|
+
}
|
|
6552
6600
|
for (let i = 0; i < attrTags.length; i++) {
|
|
6553
6601
|
const child = attrTags[i];
|
|
6554
|
-
if (child.isMarkoTag())
|
|
6555
|
-
|
|
6556
|
-
|
|
6557
|
-
|
|
6558
|
-
|
|
6559
|
-
|
|
6560
|
-
|
|
6561
|
-
|
|
6562
|
-
|
|
6602
|
+
if (child.isMarkoTag()) {
|
|
6603
|
+
if ((0, _marko_compiler_babel_utils.isAttributeTag)(child)) {
|
|
6604
|
+
const attrTagMeta = attrTagLookup[getTagName(child)];
|
|
6605
|
+
const childAttrExport = getKnownFromPropTree(propTree, attrTagMeta.name);
|
|
6606
|
+
if (!childAttrExport) {} else if (attrTagMeta.dynamic) i = translateDynamicAttrTagChildInGroup(attrTagMeta.group, i);
|
|
6607
|
+
else if (childAttrExport === true) {
|
|
6608
|
+
const statements = [];
|
|
6609
|
+
const translatedAttrs = translateAttrTag(child, attrTagMeta, info, statements);
|
|
6610
|
+
addStatement("render", info.tagSection, tagReferencedBindings, statements);
|
|
6611
|
+
if (translatedAttrs) contentProps.push(toObjectProperty(attrTagMeta.name, translatedAttrs));
|
|
6612
|
+
} else if (attrTagMeta.repeated && (!childAttrExport.props || childAttrExport.rest)) {
|
|
6613
|
+
if (remaining.delete(attrTagMeta.name)) applyAttrObject(child, childAttrExport, info.getBindingIdentifier(childAttrExport.binding, `${importAlias}_${attrTagMeta.name}`), info);
|
|
6614
|
+
} else {
|
|
6615
|
+
remaining.delete(attrTagMeta.name);
|
|
6616
|
+
writeAttrsToSignals(child, childAttrExport, `${importAlias}_${attrTagMeta.name}`, info);
|
|
6617
|
+
}
|
|
6563
6618
|
} else {
|
|
6564
|
-
|
|
6565
|
-
|
|
6566
|
-
|
|
6567
|
-
|
|
6568
|
-
|
|
6569
|
-
|
|
6570
|
-
|
|
6571
|
-
|
|
6572
|
-
|
|
6573
|
-
|
|
6574
|
-
case "else-if": continue;
|
|
6619
|
+
const group = child.node.extra.attributeTagGroup;
|
|
6620
|
+
if (hasGroupReads(group, attrTagLookup, propTree)) i = translateDynamicAttrTagChildInGroup(group, i);
|
|
6621
|
+
else if (getTagName(child) === "if") while (++i < attrTags.length) {
|
|
6622
|
+
const nextTag = attrTags[i];
|
|
6623
|
+
switch (nextTag.isMarkoTag() && getTagName(nextTag)) {
|
|
6624
|
+
case "else":
|
|
6625
|
+
case "else-if": continue;
|
|
6626
|
+
}
|
|
6627
|
+
i--;
|
|
6628
|
+
break;
|
|
6575
6629
|
}
|
|
6576
|
-
i--;
|
|
6577
|
-
break;
|
|
6578
6630
|
}
|
|
6579
6631
|
}
|
|
6580
6632
|
}
|
|
@@ -6582,8 +6634,7 @@ function writeAttrsToSignals(tag, propTree, importAlias, info) {
|
|
|
6582
6634
|
const reads = getGroupReads(group, attrTagLookup, propTree);
|
|
6583
6635
|
const hasRest = reads.some(([, read]) => read === true);
|
|
6584
6636
|
addStatement("render", info.tagSection, hasRest ? tagReferencedBindings : referencedBindings, [_marko_compiler.types.variableDeclaration("let", reads.map(([attrTagMeta]) => _marko_compiler.types.variableDeclarator(getAttrTagIdentifier(attrTagMeta)))), ...statements]);
|
|
6585
|
-
for (const [attrTagMeta, read] of reads) if (read
|
|
6586
|
-
else {
|
|
6637
|
+
for (const [attrTagMeta, read] of reads) if (read !== true) {
|
|
6587
6638
|
remaining.delete(attrTagMeta.name);
|
|
6588
6639
|
addStatement("render", info.tagSection, hasRest ? tagReferencedBindings : referencedBindings, _marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(info.getBindingIdentifier(read.binding, `${importAlias}_${attrTagMeta.name}`), [createScopeReadExpression(info.childScopeBinding, info.tagSection), getAttrTagIdentifier(attrTagMeta)])));
|
|
6589
6640
|
}
|
|
@@ -6594,8 +6645,8 @@ function writeAttrsToSignals(tag, propTree, importAlias, info) {
|
|
|
6594
6645
|
const bodySection = getSectionForBody(tag.get("body"));
|
|
6595
6646
|
if (bodySection) {
|
|
6596
6647
|
seen.add("content");
|
|
6597
|
-
const bodyValue = _marko_compiler.types.callExpression(
|
|
6598
|
-
if (contentExport === true)
|
|
6648
|
+
const bodyValue = _marko_compiler.types.callExpression(getSectionRendererIdentifier(bodySection), [scopeIdentifier]);
|
|
6649
|
+
if (contentExport === true) contentProps.push(toObjectProperty("content", bodyValue));
|
|
6599
6650
|
else {
|
|
6600
6651
|
remaining.delete("content");
|
|
6601
6652
|
const directContent = !bodySection.params;
|
|
@@ -6604,7 +6655,8 @@ function writeAttrsToSignals(tag, propTree, importAlias, info) {
|
|
|
6604
6655
|
}
|
|
6605
6656
|
}
|
|
6606
6657
|
let knownSpread;
|
|
6607
|
-
let
|
|
6658
|
+
let hasSpread = false;
|
|
6659
|
+
const attrProps = [];
|
|
6608
6660
|
const staticAttrs = [];
|
|
6609
6661
|
const { attributes } = tag.node;
|
|
6610
6662
|
for (let i = attributes.length; i--;) {
|
|
@@ -6613,15 +6665,18 @@ function writeAttrsToSignals(tag, propTree, importAlias, info) {
|
|
|
6613
6665
|
const templateExportAttr = getKnownFromPropTree(propTree, attr.name);
|
|
6614
6666
|
if (!templateExportAttr || seen.has(attr.name)) continue;
|
|
6615
6667
|
seen.add(attr.name);
|
|
6616
|
-
if (
|
|
6617
|
-
else if (templateExportAttr === true) (restProps ||= []).push(toObjectProperty(attr.name, attr.value));
|
|
6668
|
+
if (hasSpread || templateExportAttr === true) attrProps.push(toObjectProperty(attr.name, attr.value));
|
|
6618
6669
|
else staticAttrs.push(attr);
|
|
6619
|
-
} else if (
|
|
6670
|
+
} else if (hasSpread) attrProps.push(_marko_compiler.types.spreadElement(attr.value));
|
|
6620
6671
|
else {
|
|
6621
6672
|
knownSpread = hasAllKnownProps(propTree) ? getSingleKnownSpread(attributes) : void 0;
|
|
6622
|
-
if (!knownSpread)
|
|
6673
|
+
if (!knownSpread) {
|
|
6674
|
+
hasSpread = true;
|
|
6675
|
+
attrProps.push(_marko_compiler.types.spreadElement(attr.value));
|
|
6676
|
+
}
|
|
6623
6677
|
}
|
|
6624
6678
|
}
|
|
6679
|
+
const inputProps = attrProps.reverse().concat(contentProps);
|
|
6625
6680
|
for (let i = staticAttrs.length; i--;) {
|
|
6626
6681
|
const attr = staticAttrs[i];
|
|
6627
6682
|
const childAttrExports = getKnownFromPropTree(propTree, attr.name);
|
|
@@ -6635,8 +6690,8 @@ function writeAttrsToSignals(tag, propTree, importAlias, info) {
|
|
|
6635
6690
|
const propBinding = knownSpread.binding.propertyAliases.get(prop);
|
|
6636
6691
|
addStatement("render", info.tagSection, propBinding, _marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(attrExportIdentifier, [createScopeReadExpression(info.childScopeBinding, info.tagSection), createScopeReadExpression(propBinding, info.tagSection)])), true);
|
|
6637
6692
|
}
|
|
6638
|
-
else if (
|
|
6639
|
-
const spreadExpr = propsToExpression(
|
|
6693
|
+
else if (hasSpread && (remaining.size || propTree.rest && !propTree.rest.props)) {
|
|
6694
|
+
const spreadExpr = propsToExpression(inputProps);
|
|
6640
6695
|
let spreadId = spreadExpr;
|
|
6641
6696
|
if (!isSimpleReference(spreadExpr)) {
|
|
6642
6697
|
spreadId = generateUidIdentifier(`${importAlias}_spread`);
|
|
@@ -6664,7 +6719,7 @@ function writeAttrsToSignals(tag, propTree, importAlias, info) {
|
|
|
6664
6719
|
const attrExportIdentifier = info.getBindingIdentifier(childAttrExports.binding, `${importAlias}_${name}`);
|
|
6665
6720
|
addStatement("render", info.tagSection, void 0, _marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(attrExportIdentifier, [createScopeReadExpression(info.childScopeBinding, info.tagSection)])));
|
|
6666
6721
|
}
|
|
6667
|
-
if (propTree.rest && !propTree.rest.props) addStatement("render", info.tagSection, tagReferencedBindings, _marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(info.getBindingIdentifier(propTree.rest.binding, importAlias + "_$rest"), [createScopeReadExpression(info.childScopeBinding, info.tagSection), _marko_compiler.types.objectExpression(
|
|
6722
|
+
if (propTree.rest && !propTree.rest.props) addStatement("render", info.tagSection, tagReferencedBindings, _marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(info.getBindingIdentifier(propTree.rest.binding, importAlias + "_$rest"), [createScopeReadExpression(info.childScopeBinding, info.tagSection), _marko_compiler.types.objectExpression(inputProps)])), true);
|
|
6668
6723
|
}
|
|
6669
6724
|
}
|
|
6670
6725
|
function callStatement(id, ...args) {
|
|
@@ -6714,7 +6769,7 @@ var custom_tag_default = {
|
|
|
6714
6769
|
if (childSection === programSection && getOrCreateSection(tag) === programSection) throw tag.get("name").buildCodeFrameError(`A template that renders itself outside a branch never terminates. Render \`<${getStaticTagName(tag.node)}>\` inside a branch that eventually stops, such as \`<if>\`.`);
|
|
6715
6770
|
if (childExtra.page) programExtra.page ??= true;
|
|
6716
6771
|
if (tagExtra.tagNameLoad) tagExtra[kLoadTagBinding] = createBinding("#text", 0, getOrCreateSection(tag));
|
|
6717
|
-
if (tagExtra.tagNameLoad || !childExtra.domExports?.setupEmpty)
|
|
6772
|
+
if (tagExtra.tagNameLoad || childSection !== programSection && !childExtra.domExports?.setupEmpty) addSetupWork(getOrCreateSection(tag));
|
|
6718
6773
|
knownTagAnalyze(tag, childSection, programSection === childSection ? programSection.params && getBindingPropTree(programSection.params) : childExtra.domExports?.params);
|
|
6719
6774
|
const tagName = getStaticTagName(tag.node);
|
|
6720
6775
|
if (tagExtra.tagNameLoad) {
|
|
@@ -6730,6 +6785,7 @@ var custom_tag_default = {
|
|
|
6730
6785
|
} },
|
|
6731
6786
|
translate: {
|
|
6732
6787
|
enter(tag) {
|
|
6788
|
+
removePrunedContent(tag);
|
|
6733
6789
|
if (isOutputHTML()) flushBefore(tag);
|
|
6734
6790
|
},
|
|
6735
6791
|
exit(tag) {
|
|
@@ -7118,31 +7174,33 @@ function getLiteralName(node) {
|
|
|
7118
7174
|
function getAssignmentInsertions(node, insertions) {
|
|
7119
7175
|
switch (node.type) {
|
|
7120
7176
|
case "ObjectPattern":
|
|
7121
|
-
for (const prop of node.properties) if (prop.type === "ObjectProperty")
|
|
7122
|
-
|
|
7123
|
-
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
|
|
7127
|
-
|
|
7128
|
-
|
|
7129
|
-
|
|
7130
|
-
|
|
7131
|
-
insertions = getElementInsertions(node.elements, insertions);
|
|
7177
|
+
for (const prop of node.properties) if (prop.type === "ObjectProperty") {
|
|
7178
|
+
if (prop.value.type === "AssignmentPattern") {
|
|
7179
|
+
const { left, right } = prop.value;
|
|
7180
|
+
const sourceName = generateUid(getLiteralName(left) || getLiteralName(prop.key) || "pattern");
|
|
7181
|
+
prop.shorthand = false;
|
|
7182
|
+
prop.value = _marko_compiler.types.identifier(sourceName);
|
|
7183
|
+
(insertions ||= []).push(toConstTag(left, toFallbackExpr(sourceName, right)));
|
|
7184
|
+
getAssignmentInsertions(left, insertions);
|
|
7185
|
+
} else insertions = getAssignmentInsertions(prop.value, insertions);
|
|
7186
|
+
}
|
|
7132
7187
|
break;
|
|
7188
|
+
case "ArrayPattern": insertions = getElementInsertions(node.elements, insertions);
|
|
7133
7189
|
}
|
|
7134
7190
|
return insertions;
|
|
7135
7191
|
}
|
|
7136
7192
|
function getElementInsertions(elements, insertions) {
|
|
7137
7193
|
for (let i = 0, len = elements.length; i < len; i++) {
|
|
7138
7194
|
const el = elements[i];
|
|
7139
|
-
if (el != null)
|
|
7140
|
-
|
|
7141
|
-
|
|
7142
|
-
|
|
7143
|
-
|
|
7144
|
-
|
|
7145
|
-
|
|
7195
|
+
if (el != null) {
|
|
7196
|
+
if (el.type === "AssignmentPattern") {
|
|
7197
|
+
const { left, right } = el;
|
|
7198
|
+
const sourceName = generateUid(getLiteralName(left) || "pattern");
|
|
7199
|
+
elements[i] = withPreviousLocation(_marko_compiler.types.identifier(sourceName), el);
|
|
7200
|
+
(insertions ||= []).push(toConstTag(left, toFallbackExpr(sourceName, right)));
|
|
7201
|
+
getAssignmentInsertions(left, insertions);
|
|
7202
|
+
} else insertions = getAssignmentInsertions(el, insertions);
|
|
7203
|
+
}
|
|
7146
7204
|
}
|
|
7147
7205
|
return insertions;
|
|
7148
7206
|
}
|
|
@@ -7196,9 +7254,10 @@ var program_default = {
|
|
|
7196
7254
|
if (paramsBinding && !paramsBinding.pruned) programExtra.domExports.params = getBindingPropTree(paramsBinding);
|
|
7197
7255
|
const section = programExtra.section;
|
|
7198
7256
|
forEachSection((childSection) => {
|
|
7199
|
-
programExtra.hasResumes ||= !!(childSection.serializeReason || childSection
|
|
7257
|
+
programExtra.hasResumes ||= !!(isOwnResumeReason(childSection.serializeReason) || childSection !== section && !isSectionRendererElided(childSection) && getSectionRegisterReasons(childSection));
|
|
7200
7258
|
});
|
|
7201
|
-
|
|
7259
|
+
finalizeSetupWork();
|
|
7260
|
+
if (!section.hasSetupWork) programExtra.domExports.setupEmpty = true;
|
|
7202
7261
|
}
|
|
7203
7262
|
},
|
|
7204
7263
|
translate: {
|
|
@@ -7409,6 +7468,10 @@ function getExistingPropertyAlias(binding, property) {
|
|
|
7409
7468
|
binding = binding.upstreamAlias;
|
|
7410
7469
|
}
|
|
7411
7470
|
}
|
|
7471
|
+
function isTagVarRead(tag) {
|
|
7472
|
+
const tagVar = tag.node.var;
|
|
7473
|
+
return !!tagVar && !!tag.scope.getBinding(tagVar.name)?.referencePaths.length;
|
|
7474
|
+
}
|
|
7412
7475
|
function trackDomVarReferences(tag, binding) {
|
|
7413
7476
|
const tagVar = tag.node.var;
|
|
7414
7477
|
if (!tagVar) return;
|
|
@@ -7676,8 +7739,10 @@ function mergeReferences(section, target, nodes) {
|
|
|
7676
7739
|
reads = concat(reads, additionalReads);
|
|
7677
7740
|
readsByExpression.delete(extra);
|
|
7678
7741
|
}
|
|
7679
|
-
if (additionalExprFnReads)
|
|
7680
|
-
|
|
7742
|
+
if (additionalExprFnReads) {
|
|
7743
|
+
if (exprFnReads) for (const [key, value] of additionalExprFnReads) exprFnReads.set(key, value);
|
|
7744
|
+
else fnReadsByExpression.set(targetExtra, exprFnReads = new Map(additionalExprFnReads));
|
|
7745
|
+
}
|
|
7681
7746
|
} else if (extra?.pruned)
|
|
7682
7747
|
/* v8 ignore next -- a dropped reference is never merged into another */
|
|
7683
7748
|
throw new Error("Cannot merged a dropped reference.");
|
|
@@ -7746,7 +7811,7 @@ function finalizeReferences() {
|
|
|
7746
7811
|
expr.referencedBindings = exprBindings.referencedBindings;
|
|
7747
7812
|
expr.lazyBindings = exprBindings.lazyBindings;
|
|
7748
7813
|
expr.globalBindings = exprBindings.globalBindings;
|
|
7749
|
-
if (!exprBindings.referencedBindings)
|
|
7814
|
+
if (!exprBindings.referencedBindings) addSetupWork(expr.section);
|
|
7750
7815
|
forEach(exprBindings.lazyBindings, (binding) => {
|
|
7751
7816
|
binding.forcePersist = true;
|
|
7752
7817
|
});
|
|
@@ -7795,7 +7860,6 @@ function finalizeReferences() {
|
|
|
7795
7860
|
let highestHoistSection;
|
|
7796
7861
|
forEach(binding.hoists, (hoistSection) => {
|
|
7797
7862
|
if (!highestHoistSection || hoistSection.depth < highestHoistSection.depth) highestHoistSection = hoistSection;
|
|
7798
|
-
hoistSection.hoistedTo = bindingUtil.add(hoistSection.hoistedTo, binding);
|
|
7799
7863
|
forceSerialize(binding);
|
|
7800
7864
|
});
|
|
7801
7865
|
binding.section.hoisted = bindingUtil.add(binding.section.hoisted, binding);
|
|
@@ -7837,6 +7901,7 @@ function finalizeReferences() {
|
|
|
7837
7901
|
addSerializeExpr(section.parent, section.upstreamExpression, section.sectionAccessor.binding);
|
|
7838
7902
|
}
|
|
7839
7903
|
});
|
|
7904
|
+
for (const finalize of getReferenceFinalizers()) finalize();
|
|
7840
7905
|
forEachSection(applySerializeExprs);
|
|
7841
7906
|
let reasonsVersion;
|
|
7842
7907
|
do {
|
|
@@ -7852,6 +7917,7 @@ function finalizeReferences() {
|
|
|
7852
7917
|
});
|
|
7853
7918
|
} while (reasonsVersion !== getSerializeReasonsVersion());
|
|
7854
7919
|
finalizeFunctionRegistry();
|
|
7920
|
+
const closureIdEnds = /* @__PURE__ */ new Map();
|
|
7855
7921
|
forEachSection((section) => {
|
|
7856
7922
|
const { id, bindings } = section;
|
|
7857
7923
|
const isOwnedBinding = ({ section }) => section.id === id;
|
|
@@ -7902,13 +7968,17 @@ function finalizeReferences() {
|
|
|
7902
7968
|
intersectionIndex++;
|
|
7903
7969
|
assignIntersectionId(intersection);
|
|
7904
7970
|
}
|
|
7971
|
+
let closureId = section.parent ? closureIdEnds.get(section.parent) : 0;
|
|
7905
7972
|
forEach(ownedBindings, (binding) => {
|
|
7906
|
-
if (binding.closureSections)
|
|
7973
|
+
if (binding.closureSections) {
|
|
7974
|
+
closureId = Math.max(closureId, nextId);
|
|
7975
|
+
closureAccessorIds.set(binding, closureId++);
|
|
7976
|
+
}
|
|
7907
7977
|
});
|
|
7978
|
+
closureIdEnds.set(section, closureId);
|
|
7908
7979
|
});
|
|
7909
7980
|
const programSection = (0, _marko_compiler_babel_utils.getProgram)().node.extra.section;
|
|
7910
7981
|
if (programSection.returnValueExpr) programSection.returnSerializeReason = getSerializeSourcesForExpr(programSection.returnValueExpr);
|
|
7911
|
-
for (const finalize of getReferenceFinalizers()) finalize();
|
|
7912
7982
|
readsByExpression.clear();
|
|
7913
7983
|
fnReadsByExpression.clear();
|
|
7914
7984
|
}
|
|
@@ -8171,6 +8241,7 @@ function addRead(exprExtra, extra, binding, section, getter) {
|
|
|
8171
8241
|
comparedTo: void 0,
|
|
8172
8242
|
deferred: false
|
|
8173
8243
|
};
|
|
8244
|
+
if (section.pruned) return read;
|
|
8174
8245
|
binding.reads.add(exprExtra);
|
|
8175
8246
|
exprExtra.section = section;
|
|
8176
8247
|
readsByExpression.set(exprExtra, push(readsByExpression.get(exprExtra), read));
|
|
@@ -8179,8 +8250,8 @@ function addRead(exprExtra, extra, binding, section, getter) {
|
|
|
8179
8250
|
function isEmitted(exprExtra) {
|
|
8180
8251
|
return !getCanonicalExtra(exprExtra).pruned;
|
|
8181
8252
|
}
|
|
8182
|
-
function inEmittedExpr({ exprRoot }) {
|
|
8183
|
-
return isEmitted(exprRoot);
|
|
8253
|
+
function inEmittedExpr({ exprRoot, section }) {
|
|
8254
|
+
return !section.pruned && isEmitted(exprRoot);
|
|
8184
8255
|
}
|
|
8185
8256
|
function isDroppableValue(expr) {
|
|
8186
8257
|
return !!expr.pure && !expr.merged && !expr.pruned;
|
|
@@ -8212,10 +8283,33 @@ function untrackExtra(exprExtra) {
|
|
|
8212
8283
|
getFunctionReadsByExpression().delete(exprExtra);
|
|
8213
8284
|
forEach(reads, (read) => {
|
|
8214
8285
|
read.binding.reads.delete(exprExtra);
|
|
8215
|
-
if (!exprExtra.pruned) read.binding.untracked = true;
|
|
8286
|
+
if (!exprExtra.pruned && !exprExtra.section.pruned) read.binding.untracked = true;
|
|
8216
8287
|
});
|
|
8217
8288
|
}
|
|
8218
8289
|
}
|
|
8290
|
+
function dropContent(body) {
|
|
8291
|
+
const bodyExtra = body.extra ??= {};
|
|
8292
|
+
bodyExtra.pruned = true;
|
|
8293
|
+
if (bodyExtra.section) bodyExtra.section.pruned = true;
|
|
8294
|
+
for (const param of body.params) untrackNode(param);
|
|
8295
|
+
dropChildren(body.body);
|
|
8296
|
+
}
|
|
8297
|
+
function dropChildren(children) {
|
|
8298
|
+
for (const child of children) switch (child.type) {
|
|
8299
|
+
case "MarkoTag":
|
|
8300
|
+
untrackNode(child.name);
|
|
8301
|
+
if (child.arguments) for (const arg of child.arguments) untrackNode(arg);
|
|
8302
|
+
if (child.var) untrackNode(child.var);
|
|
8303
|
+
for (const attr of child.attributes) untrackNode(attr.value);
|
|
8304
|
+
dropChildren(child.attributeTags);
|
|
8305
|
+
dropContent(child.body);
|
|
8306
|
+
break;
|
|
8307
|
+
case "MarkoPlaceholder":
|
|
8308
|
+
untrackNode(child.value);
|
|
8309
|
+
break;
|
|
8310
|
+
case "MarkoScriptlet": for (const statement of child.body) untrackNode(statement);
|
|
8311
|
+
}
|
|
8312
|
+
}
|
|
8219
8313
|
function isSerializedChangeHandlerRead(exprRoot) {
|
|
8220
8314
|
const markoRoot = getMarkoRoot(exprRoot);
|
|
8221
8315
|
if (!markoRoot?.isMarkoAttribute()) return false;
|
|
@@ -8231,6 +8325,7 @@ function addReadToExpression(root, binding, getter) {
|
|
|
8231
8325
|
const section = getOrCreateSection(exprRoot);
|
|
8232
8326
|
const rootExtra = exprRoot.node.extra ??= { section };
|
|
8233
8327
|
const exprExtra = getCanonicalExtra(rootExtra);
|
|
8328
|
+
if (exprExtra.pruned) return;
|
|
8234
8329
|
const extra = node.extra ??= {};
|
|
8235
8330
|
extra.exprRoot = rootExtra;
|
|
8236
8331
|
const read = addRead(exprExtra, extra, binding, section, getter);
|
|
@@ -8270,17 +8365,15 @@ function someUpstream(binding, test, arg) {
|
|
|
8270
8365
|
function isDirectAlias(binding) {
|
|
8271
8366
|
return binding.upstreamAlias !== void 0 && binding.property === void 0 && binding.excludeProperties === void 0;
|
|
8272
8367
|
}
|
|
8273
|
-
function getAllTagReferenceNodes(tag, referenceNodes = [],
|
|
8368
|
+
function getAllTagReferenceNodes(tag, referenceNodes = [], collectAttrTag) {
|
|
8274
8369
|
if (tag.arguments) for (const arg of tag.arguments) referenceNodes.push(arg);
|
|
8275
8370
|
for (const attr of tag.attributes) referenceNodes.push(attr.value);
|
|
8276
8371
|
for (const child of tag.body.attributeTags ? tag.body.body : tag.attributeTags) switch (child.type) {
|
|
8277
8372
|
case "MarkoTag":
|
|
8278
|
-
if (
|
|
8279
|
-
else getAllTagReferenceNodes(child, referenceNodes,
|
|
8280
|
-
break;
|
|
8281
|
-
case "MarkoScriptlet":
|
|
8282
|
-
for (const statement of child.body) referenceNodes.push(statement);
|
|
8373
|
+
if (collectAttrTag && _marko_compiler.types.isStringLiteral(child.name) && child.name.value[0] === "@") collectAttrTag(child);
|
|
8374
|
+
else getAllTagReferenceNodes(child, referenceNodes, collectAttrTag);
|
|
8283
8375
|
break;
|
|
8376
|
+
case "MarkoScriptlet": for (const statement of child.body) referenceNodes.push(statement);
|
|
8284
8377
|
}
|
|
8285
8378
|
return referenceNodes;
|
|
8286
8379
|
}
|
|
@@ -8307,8 +8400,15 @@ function getPrefixedScopeAccessor(binding, prefix) {
|
|
|
8307
8400
|
case getAccessorPrefix().ClosureScopes: return decodeAccessor(getClosureAccessorId(canonicalBinding));
|
|
8308
8401
|
case getAccessorPrefix().ClosureSignalIndex: return prefix + decodeAccessor(getClosureAccessorId(canonicalBinding));
|
|
8309
8402
|
}
|
|
8403
|
+
else if (prefix === getAccessorPrefix().ClosureScopes || prefix === getAccessorPrefix().ClosureSignalIndex) return prefix + getDebugClosureAccessor(binding);
|
|
8310
8404
|
return prefix + getScopeAccessor(binding);
|
|
8311
8405
|
}
|
|
8406
|
+
function getClosureAccessorLiteral(binding) {
|
|
8407
|
+
return isOptimize() ? _marko_compiler.types.numericLiteral(getClosureAccessorId(binding)) : _marko_compiler.types.stringLiteral(getDebugClosureAccessor(binding));
|
|
8408
|
+
}
|
|
8409
|
+
function getDebugClosureAccessor(binding) {
|
|
8410
|
+
return `${getScopeAccessor(binding)}/${getClosureAccessorId(binding)}`;
|
|
8411
|
+
}
|
|
8312
8412
|
function getClosureAccessorId(binding) {
|
|
8313
8413
|
const id = closureAccessorIds.get(getCanonicalBinding(binding));
|
|
8314
8414
|
/* v8 ignore next 5 -- analyze reserves an id for every closure binding */
|
|
@@ -8399,9 +8499,10 @@ function getReadReplacement(node, signal) {
|
|
|
8399
8499
|
let curNode = node;
|
|
8400
8500
|
let curBinding = readBinding;
|
|
8401
8501
|
let replaceMember;
|
|
8402
|
-
if (isOutputDOM())
|
|
8403
|
-
|
|
8404
|
-
|
|
8502
|
+
if (isOutputDOM()) {
|
|
8503
|
+
if (signal?.referencedBindings === readBinding && !signal.hasSideEffect) replacement = getSignalValueIdentifier(signal);
|
|
8504
|
+
else replacement = createScopeReadExpression(readBinding, extra.section);
|
|
8505
|
+
} else replacement = _marko_compiler.types.identifier(readBinding.name);
|
|
8405
8506
|
while (remaining && (curNode.type === "MemberExpression" || curNode.type === "OptionalMemberExpression")) {
|
|
8406
8507
|
const prop = at(props, --remaining);
|
|
8407
8508
|
if (getMemberExpressionPropString(curNode) !== prop) break;
|
|
@@ -8690,15 +8791,15 @@ function getAllSerializeReasonsForBinding(binding, properties) {
|
|
|
8690
8791
|
function getRegisterReasonForExtra(extra) {
|
|
8691
8792
|
if (extra.forceRegister) return FORCED;
|
|
8692
8793
|
const { reason, reads } = serializationForExtra(extra);
|
|
8693
|
-
|
|
8694
|
-
|
|
8695
|
-
|
|
8696
|
-
return
|
|
8794
|
+
if (reads) {
|
|
8795
|
+
for (const read of reads) if (read.forceRegister) return FORCED;
|
|
8796
|
+
}
|
|
8797
|
+
return reason;
|
|
8697
8798
|
}
|
|
8698
8799
|
function serializationForExtra(extra) {
|
|
8699
8800
|
if (extra.isEffect) return FORCED_SERIALIZATION;
|
|
8700
8801
|
const serialization = extraSerialization(extra);
|
|
8701
|
-
const reads = isReferencedExtra(extra) ?
|
|
8802
|
+
const reads = isReferencedExtra(extra) ? addSerializationRead(serialization.reads, extra) : serialization.reads;
|
|
8702
8803
|
return reads === serialization.reads ? serialization : {
|
|
8703
8804
|
reason: serialization.reason,
|
|
8704
8805
|
reads
|
|
@@ -8766,7 +8867,7 @@ function computeBindingSerialization(binding, properties) {
|
|
|
8766
8867
|
if (!(head === "content" && expr.nativeTagSpread && bindingUtil.has(expr.spreadFrom, binding))) serialization = mergeSerialization(serialization, FORCED_SERIALIZATION);
|
|
8767
8868
|
continue;
|
|
8768
8869
|
}
|
|
8769
|
-
const reads =
|
|
8870
|
+
const reads = addSerializationRead(serialization.reads, expr);
|
|
8770
8871
|
if (reads !== serialization.reads) serialization = {
|
|
8771
8872
|
reason: serialization.reason,
|
|
8772
8873
|
reads
|
|
@@ -8793,10 +8894,7 @@ function mergeSerialization(a, b) {
|
|
|
8793
8894
|
if (a === UNSERIALIZED) return b;
|
|
8794
8895
|
if (b === UNSERIALIZED) return a;
|
|
8795
8896
|
const reason = mergeSources(a.reason, b.reason);
|
|
8796
|
-
|
|
8797
|
-
forEach(b.reads, (read) => {
|
|
8798
|
-
reads = addUnique(reads, read);
|
|
8799
|
-
});
|
|
8897
|
+
const reads = unionSerializationReads(a.reads, b.reads);
|
|
8800
8898
|
if (reason === a.reason && reads === a.reads) return a;
|
|
8801
8899
|
if (reason === b.reason && reads === b.reads) return b;
|
|
8802
8900
|
return {
|
|
@@ -8804,6 +8902,15 @@ function mergeSerialization(a, b) {
|
|
|
8804
8902
|
reads
|
|
8805
8903
|
};
|
|
8806
8904
|
}
|
|
8905
|
+
function addSerializationRead(reads, read) {
|
|
8906
|
+
return reads?.has(read) ? reads : new Set(reads).add(read);
|
|
8907
|
+
}
|
|
8908
|
+
function unionSerializationReads(a, b) {
|
|
8909
|
+
if (!a || !b || a === b) return a || b;
|
|
8910
|
+
let result;
|
|
8911
|
+
for (const read of b) if (!a.has(read)) (result ??= new Set(a)).add(read);
|
|
8912
|
+
return result || a;
|
|
8913
|
+
}
|
|
8807
8914
|
function addNumericPropertiesUntil(props, len) {
|
|
8808
8915
|
let result = props;
|
|
8809
8916
|
for (let i = len; i--;) result = propsUtil.add(result, i + "");
|
|
@@ -8871,7 +8978,7 @@ var await_default = {
|
|
|
8871
8978
|
setBindingDownstream(paramsBinding, valueExtra);
|
|
8872
8979
|
}
|
|
8873
8980
|
bodySection.upstreamExpression = valueAttr.value.extra;
|
|
8874
|
-
|
|
8981
|
+
addSetupWork(section);
|
|
8875
8982
|
visit(tag, 37);
|
|
8876
8983
|
enterShallow(tag);
|
|
8877
8984
|
},
|
|
@@ -9126,7 +9233,9 @@ var define_default = {
|
|
|
9126
9233
|
if (bodySection && hasDirectReferences) {
|
|
9127
9234
|
const signal = getSignal(bodySection, void 0);
|
|
9128
9235
|
signal.build = () => {
|
|
9129
|
-
|
|
9236
|
+
const hasStatements = signalHasStatements(signal);
|
|
9237
|
+
if (hasStatements && !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.");
|
|
9238
|
+
if (bodySection.hasSetupWork) return callRuntime("_child_setup", hasStatements ? getSignalFn(signal) : _marko_compiler.types.arrowFunctionExpression([], _marko_compiler.types.numericLiteral(0)));
|
|
9130
9239
|
};
|
|
9131
9240
|
}
|
|
9132
9241
|
if (bodySection && allDirectReferences) {
|
|
@@ -9152,7 +9261,7 @@ var define_default = {
|
|
|
9152
9261
|
//#endregion
|
|
9153
9262
|
//#region src/translator/core/effect.ts
|
|
9154
9263
|
var effect_default = {
|
|
9155
|
-
migrate:
|
|
9264
|
+
migrate: (tag) => {
|
|
9156
9265
|
if (tag.node.body.body.length) throw tag.get("name").buildCodeFrameError("The `<effect>` tag has been replaced by [`<script>`](https://markojs.com/docs/reference/core-tag#script), which runs its body as code. Rename it to `<script>`.");
|
|
9157
9266
|
(0, _marko_compiler_babel_utils.assertNoArgs)(tag);
|
|
9158
9267
|
(0, _marko_compiler_babel_utils.assertNoParams)(tag);
|
|
@@ -9166,7 +9275,7 @@ var effect_default = {
|
|
|
9166
9275
|
tag.replaceWith(_marko_compiler.types.markoTag(withPreviousLocation(_marko_compiler.types.stringLiteral("script"), node.name), node.attributes, node.body, node.arguments, node.var, node.attributeTags));
|
|
9167
9276
|
}
|
|
9168
9277
|
});
|
|
9169
|
-
}
|
|
9278
|
+
},
|
|
9170
9279
|
attributes: {},
|
|
9171
9280
|
types: runtime_info_default.name + "/tags/effect.d.marko"
|
|
9172
9281
|
};
|
|
@@ -9221,7 +9330,7 @@ var html_comment_default = {
|
|
|
9221
9330
|
const tagExtra = mergeReferences(tagSection, tag.node, referenceNodes);
|
|
9222
9331
|
nodeBinding = tagExtra[kNodeBinding$1] = createBinding("#comment", 0, tagSection, void 0, void 0, void 0, void 0, !!tagVar);
|
|
9223
9332
|
trackDomVarReferences(tag, nodeBinding);
|
|
9224
|
-
if (
|
|
9333
|
+
if (isTagVarRead(tag)) addSerializeReason(tagSection, FORCED, nodeBinding);
|
|
9225
9334
|
addSerializeExpr(tagSection, tagExtra, nodeBinding);
|
|
9226
9335
|
}
|
|
9227
9336
|
const write = writeTo(tag);
|
|
@@ -9242,9 +9351,10 @@ var html_comment_default = {
|
|
|
9242
9351
|
if (isOutputHTML()) {
|
|
9243
9352
|
const { body } = tag.node.body;
|
|
9244
9353
|
write`<!--`;
|
|
9245
|
-
if (nodeBinding && isEmptiableCommentBody(body))
|
|
9246
|
-
|
|
9247
|
-
|
|
9354
|
+
if (nodeBinding && isEmptiableCommentBody(body)) {
|
|
9355
|
+
if (body.length) write`${_marko_compiler.types.logicalExpression("||", buildCommentValue(body), _marko_compiler.types.stringLiteral(" "))}`;
|
|
9356
|
+
else write` `;
|
|
9357
|
+
} else for (const child of body) if (_marko_compiler.types.isMarkoText(child)) write`${escapeCommentText(child.value)}`;
|
|
9248
9358
|
else if (_marko_compiler.types.isMarkoPlaceholder(child)) write`${callRuntime(child.escape ? "_escape_comment" : "_unescaped", child.value)}`;
|
|
9249
9359
|
write`-->`;
|
|
9250
9360
|
} else {
|
|
@@ -9381,22 +9491,24 @@ var let_default = {
|
|
|
9381
9491
|
const tagVar = node.var;
|
|
9382
9492
|
let valueAttr;
|
|
9383
9493
|
let valueChangeAttr;
|
|
9384
|
-
for (const attr of node.attributes) if (_marko_compiler.types.isMarkoAttribute(attr))
|
|
9385
|
-
if (
|
|
9386
|
-
|
|
9387
|
-
|
|
9388
|
-
|
|
9389
|
-
|
|
9390
|
-
|
|
9391
|
-
|
|
9392
|
-
|
|
9393
|
-
|
|
9394
|
-
|
|
9395
|
-
|
|
9396
|
-
|
|
9397
|
-
|
|
9398
|
-
|
|
9399
|
-
|
|
9494
|
+
for (const attr of node.attributes) if (_marko_compiler.types.isMarkoAttribute(attr)) {
|
|
9495
|
+
if (attr.name === "value") {
|
|
9496
|
+
if (valueAttr) throw tag.hub.buildError(attr, "Invalid duplicate value attribute.");
|
|
9497
|
+
valueAttr = attr;
|
|
9498
|
+
} else if (attr.name === "valueChange") {
|
|
9499
|
+
if (valueChangeAttr) throw tag.hub.buildError(attr, "Invalid duplicate valueChange attribute.");
|
|
9500
|
+
valueChangeAttr = attr;
|
|
9501
|
+
} else {
|
|
9502
|
+
const start = attr.loc?.start;
|
|
9503
|
+
const end = attr.loc?.end;
|
|
9504
|
+
let msg = "The [`<let>` tag](https://markojs.com/docs/reference/core-tag#let) only supports the [`value=` attribute](https://markojs.com/docs/reference/language#shorthand-value) and its change handler.";
|
|
9505
|
+
if (!tagVar && /^[A-Za-z_$][\w$]*$/.test(attr.name)) msg += ` To declare reactive state, the variable goes after a slash: \`<let/${attr.name}=...>\`. For a one time module level value, prefix a plain JavaScript statement with \`static\`.`;
|
|
9506
|
+
if (start == null || end == null) throw tag.get("name").buildCodeFrameError(msg);
|
|
9507
|
+
else throw tag.hub.buildError({ loc: {
|
|
9508
|
+
start,
|
|
9509
|
+
end
|
|
9510
|
+
} }, msg, Error);
|
|
9511
|
+
}
|
|
9400
9512
|
}
|
|
9401
9513
|
(0, _marko_compiler_babel_utils.assertNoArgs)(tag);
|
|
9402
9514
|
(0, _marko_compiler_babel_utils.assertNoParams)(tag);
|
|
@@ -9525,6 +9637,7 @@ var log_default = {
|
|
|
9525
9637
|
};
|
|
9526
9638
|
//#endregion
|
|
9527
9639
|
//#region src/translator/core/script.ts
|
|
9640
|
+
const htmlScriptTagAlternateMsg = " For a native html [`<script>` tag](https://markojs.com/docs/reference/core-tag#script) use the `html-script` core tag instead.";
|
|
9528
9641
|
var script_default = {
|
|
9529
9642
|
parse(tag) {
|
|
9530
9643
|
const { node } = tag;
|
|
@@ -9532,7 +9645,7 @@ var script_default = {
|
|
|
9532
9645
|
if (body.length) {
|
|
9533
9646
|
let code = "";
|
|
9534
9647
|
for (const child of body) {
|
|
9535
|
-
if (child.type !== "MarkoText") throw (0, _marko_compiler_babel_utils.getFile)().hub.buildError(child, "Unexpected content in [`<script>` tag](https://markojs.com/docs/reference/core-tag#script). Only javascript and typescript is supported.
|
|
9648
|
+
if (child.type !== "MarkoText") throw (0, _marko_compiler_babel_utils.getFile)().hub.buildError(child, "Unexpected content in [`<script>` tag](https://markojs.com/docs/reference/core-tag#script). Only javascript and typescript is supported." + htmlScriptTagAlternateMsg, SyntaxError);
|
|
9536
9649
|
code += child.value;
|
|
9537
9650
|
}
|
|
9538
9651
|
const start = body[0]?.start;
|
|
@@ -9551,7 +9664,7 @@ var script_default = {
|
|
|
9551
9664
|
(0, _marko_compiler_babel_utils.assertNoParams)(tag);
|
|
9552
9665
|
assertNoBodyContent(tag);
|
|
9553
9666
|
(0, _marko_compiler_babel_utils.assertNoAttributeTags)(tag);
|
|
9554
|
-
if (node.var) throw tag.hub.buildError(node.var, "The [`<script>` tag](https://markojs.com/docs/reference/core-tag#script) does not support a tag variable reference.
|
|
9667
|
+
if (node.var) throw tag.hub.buildError(node.var, "The [`<script>` tag](https://markojs.com/docs/reference/core-tag#script) does not support a tag variable reference." + htmlScriptTagAlternateMsg);
|
|
9555
9668
|
let seenValueAttr = false;
|
|
9556
9669
|
for (const attr of node.attributes) if (attr.type === "MarkoAttribute" && attr.name === "value") {
|
|
9557
9670
|
if (seenValueAttr) throw tag.hub.buildError(attr, "Invalid duplicate value attribute.");
|
|
@@ -9561,7 +9674,7 @@ var script_default = {
|
|
|
9561
9674
|
addSetupExpr(getOrCreateSection(tag), attr.value);
|
|
9562
9675
|
(0, _marko_compiler_babel_utils.getProgram)().node.extra.isInteractive = true;
|
|
9563
9676
|
}
|
|
9564
|
-
} else throw tag.hub.buildError(attr, "The [`<script>` tag](https://markojs.com/docs/reference/core-tag#script) does not support html attributes.
|
|
9677
|
+
} else throw tag.hub.buildError(attr, "The [`<script>` tag](https://markojs.com/docs/reference/core-tag#script) does not support html attributes." + htmlScriptTagAlternateMsg);
|
|
9565
9678
|
if (!seenValueAttr) dropNodes(getAllTagReferenceNodes(node));
|
|
9566
9679
|
},
|
|
9567
9680
|
translate: { exit(tag) {
|
|
@@ -9578,16 +9691,18 @@ var script_default = {
|
|
|
9578
9691
|
if (isOutputDOM()) {
|
|
9579
9692
|
const isFunction = _marko_compiler.types.isFunctionExpression(value) || _marko_compiler.types.isArrowFunctionExpression(value);
|
|
9580
9693
|
let inlineBody = null;
|
|
9581
|
-
if (isFunction)
|
|
9582
|
-
if (
|
|
9583
|
-
|
|
9584
|
-
|
|
9585
|
-
|
|
9586
|
-
|
|
9694
|
+
if (isFunction) {
|
|
9695
|
+
if (value.async || value.generator) {} else if (_marko_compiler.types.isBlockStatement(value.body)) {
|
|
9696
|
+
if (!traverseContains(value.body, isReturnStatement)) {
|
|
9697
|
+
let hasDeclaration = false;
|
|
9698
|
+
for (const child of value.body.body) if (_marko_compiler.types.isDeclaration(child)) {
|
|
9699
|
+
hasDeclaration = true;
|
|
9700
|
+
break;
|
|
9701
|
+
}
|
|
9702
|
+
inlineBody = hasDeclaration ? value.body : value.body.body;
|
|
9587
9703
|
}
|
|
9588
|
-
|
|
9589
|
-
|
|
9590
|
-
} else inlineBody = _marko_compiler.types.expressionStatement(value.body);
|
|
9704
|
+
} else inlineBody = _marko_compiler.types.expressionStatement(value.body);
|
|
9705
|
+
}
|
|
9591
9706
|
addStatement("effect", section, referencedBindings, inlineBody || _marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(value, [])));
|
|
9592
9707
|
} else addHTMLEffectCall(section, referencedBindings);
|
|
9593
9708
|
tag.remove();
|
|
@@ -9676,7 +9791,7 @@ var show_default = {
|
|
|
9676
9791
|
if (tagExtra[kStaticDisplay] === void 0) {
|
|
9677
9792
|
mergeReferences(tagSection, tag.node, [display]);
|
|
9678
9793
|
addSerializeExpr(tagSection, tagExtra, kStatefulReason);
|
|
9679
|
-
} else
|
|
9794
|
+
} else addSetupWork(tagSection);
|
|
9680
9795
|
},
|
|
9681
9796
|
exit(tag) {
|
|
9682
9797
|
const tagExtra = tag.node.extra;
|
|
@@ -9807,6 +9922,9 @@ function assertHasValueAttribute(tag) {
|
|
|
9807
9922
|
//#endregion
|
|
9808
9923
|
//#region src/translator/core/static.ts
|
|
9809
9924
|
var static_default = createStatementTag("static");
|
|
9925
|
+
//#endregion
|
|
9926
|
+
//#region src/translator/util/style-interpolation.ts
|
|
9927
|
+
const htmlStyleTagAlternateMsg = " For a native html [`<style>` tag](https://markojs.com/docs/reference/core-tag#style) use the `html-style` core tag instead.";
|
|
9810
9928
|
function checkStyleInterpolations(tag) {
|
|
9811
9929
|
const { body } = tag.node.body;
|
|
9812
9930
|
let stringQuote = "";
|
|
@@ -9877,7 +9995,6 @@ function checkStyleInterpolations(tag) {
|
|
|
9877
9995
|
case "}":
|
|
9878
9996
|
endRun(false);
|
|
9879
9997
|
if (blockDepth) blockDepth--;
|
|
9880
|
-
break;
|
|
9881
9998
|
}
|
|
9882
9999
|
}
|
|
9883
10000
|
}
|
|
@@ -9916,7 +10033,7 @@ var style_default = {
|
|
|
9916
10033
|
if (importPath) addAssetImport(importPath);
|
|
9917
10034
|
if (names) {
|
|
9918
10035
|
analyzeDynamicStyle(tag, names);
|
|
9919
|
-
|
|
10036
|
+
addSetupWork(getOrCreateSection(tag));
|
|
9920
10037
|
visit(tag, 32);
|
|
9921
10038
|
enterShallow(tag);
|
|
9922
10039
|
writeTo(tag)`<style></style>`;
|
|
@@ -9953,7 +10070,7 @@ function collectDynamicStyleNames(tag) {
|
|
|
9953
10070
|
const index = programDynamicStyleNameCounts.get(program) ?? 0;
|
|
9954
10071
|
programDynamicStyleNameCounts.set(program, index + 1);
|
|
9955
10072
|
(names ??= []).push(dynamicStyleName(index));
|
|
9956
|
-
} else if (!_marko_compiler.types.isMarkoText(child)) throw tag.hub.buildError(child, "The [`<style>` tag](https://markojs.com/docs/reference/core-tag#style) only supports text and `${...}` interpolations.
|
|
10073
|
+
} else if (!_marko_compiler.types.isMarkoText(child)) throw tag.hub.buildError(child, "The [`<style>` tag](https://markojs.com/docs/reference/core-tag#style) only supports text and `${...}` interpolations." + htmlStyleTagAlternateMsg);
|
|
9957
10074
|
return names;
|
|
9958
10075
|
}
|
|
9959
10076
|
const styleNameUnsafeReg = /[^a-zA-Z0-9_]/g;
|
|
@@ -9977,7 +10094,7 @@ function assertNoStyleAttributes(tag) {
|
|
|
9977
10094
|
const extClass = (STYLE_EXT_REG.exec(node.rawValue || "")?.[1]?.slice(1))?.replace(/\./g, " ");
|
|
9978
10095
|
for (const attr of node.attributes) {
|
|
9979
10096
|
if (attr.start == null && attr.type === "MarkoAttribute" && attr.name === "class" && attr.value.type === "StringLiteral" && attr.value.value === extClass) continue;
|
|
9980
|
-
throw tag.hub.buildError(attr.value, "The `style` does not support html attributes.
|
|
10097
|
+
throw tag.hub.buildError(attr.value, "The `style` does not support html attributes." + htmlStyleTagAlternateMsg);
|
|
9981
10098
|
}
|
|
9982
10099
|
}
|
|
9983
10100
|
function translateHTML(tag) {
|
|
@@ -10096,15 +10213,21 @@ var try_default = {
|
|
|
10096
10213
|
(0, _marko_compiler_babel_utils.assertNoAttributes)(tag);
|
|
10097
10214
|
const attrTags = analyzeAttributeTags(tag);
|
|
10098
10215
|
if (attrTags) {
|
|
10099
|
-
for (const name in attrTags)
|
|
10100
|
-
|
|
10101
|
-
|
|
10216
|
+
for (const name in attrTags) {
|
|
10217
|
+
if (name !== "@placeholder" && name !== "@catch") {
|
|
10218
|
+
const suggestion = name[1] === "p" ? "`<@placeholder>`" : "`<@catch>`";
|
|
10219
|
+
throw tag.buildCodeFrameError(`The [\`<try>\` tag](https://markojs.com/docs/reference/core-tag#try) only supports the \`<@placeholder>\` and \`<@catch>\` attribute tags, but received \`<${name}>\`. Did you mean ${suggestion}?`);
|
|
10220
|
+
}
|
|
10221
|
+
const { dynamic, repeated } = attrTags[name];
|
|
10222
|
+
if (dynamic || repeated) throw tag.get("name").buildCodeFrameError(dynamic ? `The [\`<try>\` tag](https://markojs.com/docs/reference/core-tag#try) needs its \`<${name}>\` written directly inside it, not within control flow such as \`<if>\` or \`<for>\`.` : `The [\`<try>\` tag](https://markojs.com/docs/reference/core-tag#try) takes a single \`<${name}>\`.`);
|
|
10102
10223
|
}
|
|
10224
|
+
for (const child of tag.get("attributeTags")) if (child.isMarkoTag() && (child.node.attributes.length || child.node.arguments)) throw child.get("name").buildCodeFrameError(`The [\`<try>\` tag](https://markojs.com/docs/reference/core-tag#try)'s \`<${getTagName(child)}>\` takes no attributes, only content.`);
|
|
10103
10225
|
}
|
|
10104
10226
|
const section = getOrCreateSection(tag);
|
|
10105
10227
|
const tagExtra = mergeReferences(section, tag.node, getAllTagReferenceNodes(tag.node));
|
|
10106
10228
|
tagExtra.nodeBinding = createBinding("#text", 0, section);
|
|
10107
10229
|
if (!tag.node.body.body.length) throw tag.get("name").buildCodeFrameError("The [`<try>` tag](https://markojs.com/docs/reference/core-tag#try) requires [body content](https://markojs.com/docs/reference/language#tag-content).");
|
|
10230
|
+
if (!attrTags) throw tag.get("name").buildCodeFrameError("The [`<try>` tag](https://markojs.com/docs/reference/core-tag#try) needs a `<@catch>` to handle errors or a `<@placeholder>` to show while its content is pending. Without either it has no effect, so render its content directly.");
|
|
10108
10231
|
const bodySection = startSection(tag.get("body"));
|
|
10109
10232
|
if (bodySection) {
|
|
10110
10233
|
bodySection.upstreamExpression = tagExtra;
|
|
@@ -10124,18 +10247,16 @@ var try_default = {
|
|
|
10124
10247
|
flushBefore(tag);
|
|
10125
10248
|
},
|
|
10126
10249
|
exit(tag) {
|
|
10127
|
-
const { node } = tag;
|
|
10128
10250
|
const section = getSection(tag);
|
|
10129
|
-
const tagExtra = node.extra;
|
|
10130
10251
|
const tagBody = tag.get("body");
|
|
10131
|
-
const
|
|
10132
|
-
const
|
|
10133
|
-
const
|
|
10134
|
-
|
|
10252
|
+
const nodeRef = tag.node.extra.nodeBinding;
|
|
10253
|
+
const catchTag = getAttrTag(tag, "@catch");
|
|
10254
|
+
const placeholderTag = getAttrTag(tag, "@placeholder");
|
|
10255
|
+
const catchSection = catchTag && getSectionForBody(catchTag.get("body"));
|
|
10256
|
+
const placeholderSection = placeholderTag && getSectionForBody(placeholderTag.get("body"));
|
|
10135
10257
|
flushInto(tag);
|
|
10136
10258
|
writeHTMLResumeStatements(tagBody);
|
|
10137
|
-
tag.
|
|
10138
|
-
tag.replaceWith(_marko_compiler.types.expressionStatement(callRuntime("_try", getScopeIdIdentifier(section), getScopeAccessorLiteral(nodeRef), contentProp?.value, propsToExpression(translatedAttrs.properties))))[0].skip();
|
|
10259
|
+
tag.replaceWith(_marko_compiler.types.expressionStatement(callRuntime("_try", getScopeIdIdentifier(section), getScopeAccessorLiteral(nodeRef), buildContent(tagBody), placeholderSection && buildContent(placeholderTag.get("body")), catchTag && (catchSection ? buildContent(catchTag.get("body")) : _marko_compiler.types.arrowFunctionExpression([], _marko_compiler.types.blockStatement([]))), placeholderSection && _marko_compiler.types.stringLiteral(getResumeRegisterId(placeholderSection, "content")), catchTag && _marko_compiler.types.stringLiteral(catchSection ? getResumeRegisterId(catchSection, "content") : getEmptyCatchId(section, nodeRef)))))[0].skip();
|
|
10139
10260
|
}
|
|
10140
10261
|
},
|
|
10141
10262
|
dom: {
|
|
@@ -10143,24 +10264,33 @@ var try_default = {
|
|
|
10143
10264
|
setSectionParentIsOwner(getSectionForBody(tag.get("body")), true);
|
|
10144
10265
|
},
|
|
10145
10266
|
exit(tag) {
|
|
10146
|
-
const
|
|
10147
|
-
const tagExtra = node.extra;
|
|
10148
|
-
const nodeRef = tagExtra.nodeBinding;
|
|
10149
|
-
const referencedBindings = tagExtra.referencedBindings;
|
|
10150
|
-
const translatedAttrs = translateAttrs(tag);
|
|
10151
|
-
const contentProp = getTranslatedBodyContentProperty(translatedAttrs.properties);
|
|
10152
|
-
if (contentProp) translatedAttrs.properties.splice(translatedAttrs.properties.indexOf(contentProp), 1);
|
|
10267
|
+
const nodeRef = tag.node.extra.nodeBinding;
|
|
10153
10268
|
const section = getSection(tag);
|
|
10154
10269
|
const bodySection = getSectionForBody(tag.get("body"));
|
|
10270
|
+
const catchTag = getAttrTag(tag, "@catch");
|
|
10271
|
+
const catchSection = catchTag && getSectionForBody(catchTag.get("body"));
|
|
10272
|
+
const placeholderTag = getAttrTag(tag, "@placeholder");
|
|
10273
|
+
const placeholderSection = placeholderTag && getSectionForBody(placeholderTag.get("body"));
|
|
10274
|
+
const emptyCatchId = catchTag && !catchSection && getEmptyCatchId(section, nodeRef);
|
|
10155
10275
|
const signal = getSignal(section, nodeRef, "try");
|
|
10156
|
-
const hasPlaceholder = !!tag.node.extra?.attributeTags?.["@placeholder"];
|
|
10157
10276
|
signal.build = () => {
|
|
10158
10277
|
importRuntimeFeature("catch");
|
|
10159
|
-
if (
|
|
10160
|
-
|
|
10278
|
+
if (placeholderSection) importRuntimeFeature("placeholder");
|
|
10279
|
+
let catchContent = catchSection && _marko_compiler.types.identifier(catchSection.name);
|
|
10280
|
+
if (emptyCatchId) {
|
|
10281
|
+
catchContent = _marko_compiler.types.identifier(`${signal.identifier.name}__catch`);
|
|
10282
|
+
(signal.prependStatements ||= []).push(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(catchContent, callRuntime("_content", _marko_compiler.types.stringLiteral(emptyCatchId)))]));
|
|
10283
|
+
}
|
|
10284
|
+
const [template, walks, setup] = getBranchRendererArgs(bodySection);
|
|
10285
|
+
return callRuntime("_try", getScopeAccessorLiteral(nodeRef, true), ...replaceNullishAndEmptyFunctionsWith0([
|
|
10286
|
+
template,
|
|
10287
|
+
walks,
|
|
10288
|
+
setup,
|
|
10289
|
+
placeholderSection && _marko_compiler.types.identifier(placeholderSection.name),
|
|
10290
|
+
catchContent
|
|
10291
|
+
]));
|
|
10161
10292
|
};
|
|
10162
|
-
|
|
10163
|
-
addValue(section, referencedBindings, signal, propsToExpression(translatedAttrs.properties));
|
|
10293
|
+
addValue(section, void 0, signal);
|
|
10164
10294
|
tag.remove();
|
|
10165
10295
|
}
|
|
10166
10296
|
}
|
|
@@ -10172,6 +10302,15 @@ var try_default = {
|
|
|
10172
10302
|
}],
|
|
10173
10303
|
types: runtime_info_default.name + "/tags/try.d.marko"
|
|
10174
10304
|
};
|
|
10305
|
+
function getAttrTag(tag, name) {
|
|
10306
|
+
for (const child of tag.get("attributeTags")) if (child.isMarkoTag() && getTagName(child) === name) return name === "@catch" || getSectionForBody(child.get("body")) ? child : void 0;
|
|
10307
|
+
}
|
|
10308
|
+
function buildContent(body) {
|
|
10309
|
+
return _marko_compiler.types.arrowFunctionExpression(body.node.params, _marko_compiler.types.blockStatement([getScopeReasonStatement(getSectionForBody(body)), ...body.node.body]));
|
|
10310
|
+
}
|
|
10311
|
+
function getEmptyCatchId(section, nodeRef) {
|
|
10312
|
+
return getResumeRegisterId(section, nodeRef, "catch");
|
|
10313
|
+
}
|
|
10175
10314
|
//#endregion
|
|
10176
10315
|
//#region src/translator/core/index.ts
|
|
10177
10316
|
var core_default = {
|
|
@@ -10349,11 +10488,12 @@ function translateExit(placeholder) {
|
|
|
10349
10488
|
const section = getSection(placeholder);
|
|
10350
10489
|
const siblingText = extra[kSiblingText];
|
|
10351
10490
|
const markerSerializeReason = nodeBinding && getSerializeReason(section, nodeBinding);
|
|
10352
|
-
if (isHTML)
|
|
10353
|
-
|
|
10354
|
-
|
|
10355
|
-
|
|
10356
|
-
|
|
10491
|
+
if (isHTML) {
|
|
10492
|
+
if (markerSerializeReason) {
|
|
10493
|
+
const guard = getSerializeGuard(section, markerSerializeReason, true);
|
|
10494
|
+
write`${callRuntime(node.escape ? "_text_resume" : "_html_resume", getScopeIdIdentifier(section), getScopeAccessorLiteral(nodeBinding), value, siblingText === 1 ? guard ? _marko_compiler.types.binaryExpression("*", guard, _marko_compiler.types.numericLiteral(2)) : _marko_compiler.types.numericLiteral(2) : guard)}`;
|
|
10495
|
+
} else write`${method === "_escape" ? buildEscapedTextExpression(value) : callRuntime(method, value)}`;
|
|
10496
|
+
} else addStatement("render", section, valueExtra.referencedBindings, _marko_compiler.types.expressionStatement(method === "_text" ? callRuntime("_text", createScopeReadExpression(nodeBinding), value) : callRuntime("_html", scopeIdentifier, value, getScopeAccessorLiteral(nodeBinding))), true);
|
|
10357
10497
|
}
|
|
10358
10498
|
placeholder.remove();
|
|
10359
10499
|
}
|
|
@@ -10431,10 +10571,8 @@ var referenced_identifier_default = {
|
|
|
10431
10571
|
const { name } = identifier.node;
|
|
10432
10572
|
if (identifier.scope.hasBinding(name)) return;
|
|
10433
10573
|
switch (name) {
|
|
10434
|
-
case "out":
|
|
10435
|
-
|
|
10436
|
-
else throw identifier.buildCodeFrameError("Only `out.global` is supported for compatibility.");
|
|
10437
|
-
break;
|
|
10574
|
+
case "out": if (_marko_compiler.types.isMemberExpression(identifier.parent) && _marko_compiler.types.isIdentifier(identifier.parent.property) && identifier.parent.property.name === "global") identifier.parentPath.replaceWith(_marko_compiler.types.identifier("$global"));
|
|
10575
|
+
else throw identifier.buildCodeFrameError("Only `out.global` is supported for compatibility.");
|
|
10438
10576
|
}
|
|
10439
10577
|
},
|
|
10440
10578
|
analyze(identifier) {
|
|
@@ -10461,30 +10599,36 @@ var referenced_identifier_default = {
|
|
|
10461
10599
|
const globalRead = _marko_compiler.types.memberExpression(scopeIdentifier, _marko_compiler.types.identifier(getAccessorProp().Global));
|
|
10462
10600
|
const key = !isOptimize() && getSignalGlobalKey(identifier);
|
|
10463
10601
|
if (key) identifier.parentPath.replaceWith(callRuntime("_global_read", globalRead, _marko_compiler.types.stringLiteral(key)));
|
|
10464
|
-
else identifier
|
|
10602
|
+
else replaceWithExtra(identifier, globalRead);
|
|
10465
10603
|
break;
|
|
10466
10604
|
}
|
|
10467
|
-
case "$signal": if (isOutputHTML()) identifier
|
|
10605
|
+
case "$signal": if (isOutputHTML()) replaceWithExtra(identifier, _marko_compiler.types.callExpression(_marko_compiler.types.arrowFunctionExpression([], _marko_compiler.types.blockStatement([_marko_compiler.types.throwStatement(_marko_compiler.types.newExpression(_marko_compiler.types.identifier("Error"), [_marko_compiler.types.stringLiteral("Cannot use $signal in a server render.")]))])), []));
|
|
10468
10606
|
else {
|
|
10469
|
-
const section = getSection(identifier);
|
|
10470
10607
|
const exprRoot = identifier.node.extra.exprRoot;
|
|
10608
|
+
const canonicalExtra = getCanonicalExtra(exprRoot);
|
|
10609
|
+
if (canonicalExtra.pruned) break;
|
|
10610
|
+
const section = getSection(identifier);
|
|
10471
10611
|
const exprId = exprRoot.abortId;
|
|
10472
10612
|
const resetEmitted = getAbortResetEmitted(section);
|
|
10473
10613
|
if (!resetEmitted.has(exprRoot)) {
|
|
10474
10614
|
resetEmitted.add(exprRoot);
|
|
10475
|
-
addStatement("render", section,
|
|
10615
|
+
addStatement("render", section, canonicalExtra.referencedBindings, _marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(importRuntime("$signalReset"), [scopeIdentifier, _marko_compiler.types.numericLiteral(exprId)])));
|
|
10476
10616
|
}
|
|
10477
10617
|
identifier.replaceWith(_marko_compiler.types.callExpression(importRuntime("$signal"), [scopeIdentifier, _marko_compiler.types.numericLiteral(exprId)]));
|
|
10478
10618
|
}
|
|
10479
10619
|
}
|
|
10480
10620
|
}
|
|
10481
10621
|
};
|
|
10622
|
+
function replaceWithExtra(path, replacement) {
|
|
10623
|
+
replacement.extra = path.node.extra;
|
|
10624
|
+
path.replaceWith(replacement);
|
|
10625
|
+
}
|
|
10482
10626
|
function getSignalGlobalKey(identifier) {
|
|
10483
10627
|
const { parent } = identifier;
|
|
10484
10628
|
if (!_marko_compiler.types.isMemberExpression(parent) || parent.computed || !_marko_compiler.types.isIdentifier(parent.property) || parent.object !== identifier.node) return;
|
|
10485
10629
|
const { name } = parent.property;
|
|
10486
10630
|
if (name === "runtimeId" || name === "renderId") return;
|
|
10487
|
-
return getExprRoot(identifier).node.extra
|
|
10631
|
+
return getCanonicalExtra(getExprRoot(identifier).node.extra).referencedBindings ? name : void 0;
|
|
10488
10632
|
}
|
|
10489
10633
|
//#endregion
|
|
10490
10634
|
//#region src/translator/visitors/scriptlet.ts
|
|
@@ -10504,11 +10648,12 @@ var scriptlet_default = {
|
|
|
10504
10648
|
if (node.target && node.target !== (isHTML ? "server" : "client")) {
|
|
10505
10649
|
const ids = Object.keys(scriptlet.getOuterBindingIdentifiers());
|
|
10506
10650
|
const decl = ids.length && _marko_compiler.types.variableDeclaration("var", ids.map((key) => _marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(key))));
|
|
10507
|
-
if (decl)
|
|
10508
|
-
|
|
10509
|
-
|
|
10510
|
-
|
|
10511
|
-
|
|
10651
|
+
if (decl) {
|
|
10652
|
+
if (isHTML) {
|
|
10653
|
+
scriptlet.node.target = null;
|
|
10654
|
+
scriptlet.node.body = [decl];
|
|
10655
|
+
} else scriptlet.replaceWith(decl);
|
|
10656
|
+
} else scriptlet.remove();
|
|
10512
10657
|
return;
|
|
10513
10658
|
}
|
|
10514
10659
|
if (isHTML) {} else {
|
|
@@ -10532,6 +10677,11 @@ var attribute_tag_default = {
|
|
|
10532
10677
|
} },
|
|
10533
10678
|
translate: {
|
|
10534
10679
|
enter(tag) {
|
|
10680
|
+
if (tag.node.extra.pruned) {
|
|
10681
|
+
tag.remove();
|
|
10682
|
+
return;
|
|
10683
|
+
}
|
|
10684
|
+
removePrunedContent(tag);
|
|
10535
10685
|
if (isOutputHTML()) flushBefore(tag);
|
|
10536
10686
|
},
|
|
10537
10687
|
exit(tag) {
|
|
@@ -10562,7 +10712,6 @@ var dynamic_tag_default = {
|
|
|
10562
10712
|
const { node } = tag;
|
|
10563
10713
|
const definedBodySection = node.extra?.defineBodySection;
|
|
10564
10714
|
if (definedBodySection) {
|
|
10565
|
-
addSetupStatement(getOrCreateSection(tag));
|
|
10566
10715
|
knownTagAnalyze(tag, definedBodySection, definedBodySection.params && getBindingPropTree(definedBodySection.params));
|
|
10567
10716
|
child(tag, getStaticTagName(tag.node), {
|
|
10568
10717
|
kind: SectionRef,
|
|
@@ -10604,6 +10753,7 @@ var dynamic_tag_default = {
|
|
|
10604
10753
|
tag.remove();
|
|
10605
10754
|
return;
|
|
10606
10755
|
}
|
|
10756
|
+
removePrunedContent(tag);
|
|
10607
10757
|
if (isOutputHTML()) flushBefore(tag);
|
|
10608
10758
|
},
|
|
10609
10759
|
exit(tag) {
|
|
@@ -10616,8 +10766,7 @@ var dynamic_tag_default = {
|
|
|
10616
10766
|
if (isOutputHTML()) knownTagTranslateHTML(tag, _marko_compiler.types.memberExpression(tag.node.name, _marko_compiler.types.identifier("content")), definedBodySection, propTree);
|
|
10617
10767
|
else {
|
|
10618
10768
|
knownTagTranslateDOM(tag, propTree, (binding, preferredName, directContent) => directContent && binding.directContentExport ? _marko_compiler.types.identifier(binding.directContentExport) : getSignal(definedBodySection, binding, preferredName).identifier, (section, childBinding) => {
|
|
10619
|
-
|
|
10620
|
-
if (signalHasStatements(signal)) addStatement("render", section, void 0, _marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(_marko_compiler.types.memberExpression(signal.identifier, _marko_compiler.types.identifier("_")), [createScopeReadExpression(childBinding, section), getScopeExpression(section, definedBodySection.parent)])));
|
|
10769
|
+
if (definedBodySection.hasSetupWork) addStatement("render", section, void 0, _marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(_marko_compiler.types.memberExpression(getSignal(definedBodySection, void 0).identifier, _marko_compiler.types.identifier("_")), [createScopeReadExpression(childBinding, section), getScopeExpression(section, definedBodySection.parent)])));
|
|
10621
10770
|
else if (definedBodySection.readsOwner) addStatement("render", section, void 0, _marko_compiler.types.expressionStatement(_marko_compiler.types.assignmentExpression("=", toMemberExpression(createScopeReadExpression(childBinding, section), getAccessorProp().Owner), getScopeExpression(section, definedBodySection.parent))));
|
|
10622
10771
|
});
|
|
10623
10772
|
tag.remove();
|
|
@@ -10703,7 +10852,7 @@ var dynamic_tag_default = {
|
|
|
10703
10852
|
};
|
|
10704
10853
|
}
|
|
10705
10854
|
signal.build = () => {
|
|
10706
|
-
return callRuntime("_dynamic_tag", getScopeAccessorLiteral(nodeBinding, true), bodySection &&
|
|
10855
|
+
return callRuntime("_dynamic_tag", getScopeAccessorLiteral(nodeBinding, true), bodySection && getSectionRendererIdentifier(bodySection), tagVarSignal ? _marko_compiler.types.arrowFunctionExpression([], tagVarSignal.identifier) : void 0, hasTagArgs && _marko_compiler.types.numericLiteral(1));
|
|
10707
10856
|
};
|
|
10708
10857
|
const directBinding = tagExtra.referencedBindings;
|
|
10709
10858
|
if (directBinding && !Array.isArray(directBinding) && directBinding.directContentExport) (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(directBinding.directContentExport), callRuntime("_dynamic_tag_content", getScopeAccessorLiteral(nodeBinding, true)))])));
|
|
@@ -10736,7 +10885,7 @@ function enableDynamicTagVar(tag) {
|
|
|
10736
10885
|
importRuntimeFeature("dynamic-tag-var");
|
|
10737
10886
|
if (!tag.node.var.extra.binding.pruned) {
|
|
10738
10887
|
const accessor = getScopeAccessorLiteral(tag.node.extra.nodeBinding, true);
|
|
10739
|
-
if (addRuntimeOnce(`
|
|
10888
|
+
if (addRuntimeOnce(`_dynamic_tag_var_resume ${accessor.value}`)) (0, _marko_compiler_babel_utils.getProgram)().node.body.push(_marko_compiler.types.expressionStatement(callRuntime("_dynamic_tag_var_resume", accessor)));
|
|
10740
10889
|
}
|
|
10741
10890
|
}
|
|
10742
10891
|
function enableDynamicTagResume(tag) {
|
|
@@ -10755,7 +10904,7 @@ function getDynamicTagInputBindings(tagExtra) {
|
|
|
10755
10904
|
for (const childExtra of tagExtra.tagNameTemplates || []) {
|
|
10756
10905
|
if (childExtra.featureType === "class") return;
|
|
10757
10906
|
const inputBinding = childExtra.domExports?.params?.props?.[0]?.binding;
|
|
10758
|
-
if (inputBinding) inputBindings =
|
|
10907
|
+
if (inputBinding) inputBindings = concat(inputBindings, inputBinding);
|
|
10759
10908
|
}
|
|
10760
10909
|
return inputBindings;
|
|
10761
10910
|
}
|
|
@@ -10796,9 +10945,7 @@ var tag_default = {
|
|
|
10796
10945
|
case 3:
|
|
10797
10946
|
attribute_tag_default.analyze.enter(tag);
|
|
10798
10947
|
break;
|
|
10799
|
-
case 2:
|
|
10800
|
-
dynamic_tag_default.analyze.enter(tag);
|
|
10801
|
-
break;
|
|
10948
|
+
case 2: dynamic_tag_default.analyze.enter(tag);
|
|
10802
10949
|
}
|
|
10803
10950
|
} catch (err) {
|
|
10804
10951
|
(tag.node.extra ??= {}).analyzeFailed = true;
|
|
@@ -10843,9 +10990,7 @@ var tag_default = {
|
|
|
10843
10990
|
case 2:
|
|
10844
10991
|
dynamic_tag_default.translate.enter(tag);
|
|
10845
10992
|
break;
|
|
10846
|
-
case 3:
|
|
10847
|
-
attribute_tag_default.translate.enter(tag);
|
|
10848
|
-
break;
|
|
10993
|
+
case 3: attribute_tag_default.translate.enter(tag);
|
|
10849
10994
|
}
|
|
10850
10995
|
},
|
|
10851
10996
|
exit(tag) {
|
|
@@ -10864,9 +11009,7 @@ var tag_default = {
|
|
|
10864
11009
|
case 2:
|
|
10865
11010
|
dynamic_tag_default.translate.exit(tag);
|
|
10866
11011
|
break;
|
|
10867
|
-
case 3:
|
|
10868
|
-
attribute_tag_default.translate.exit(tag);
|
|
10869
|
-
break;
|
|
11012
|
+
case 3: attribute_tag_default.translate.exit(tag);
|
|
10870
11013
|
}
|
|
10871
11014
|
}
|
|
10872
11015
|
}
|
|
@@ -10890,7 +11033,7 @@ var text_default = {
|
|
|
10890
11033
|
function buildAggregateError(file, rootMsg, ...paths) {
|
|
10891
11034
|
const err = /* @__PURE__ */ new SyntaxError();
|
|
10892
11035
|
const fileName = path.default.relative(_marko_compiler_modules.cwd, file.opts.filename);
|
|
10893
|
-
const finalMsg = `${rootMsg}:\n\n${paths.map(([msg, path$
|
|
11036
|
+
const finalMsg = `${rootMsg}:\n\n${paths.map(([msg, path$11]) => `\x1b[90m${msg} at ${getFileNameWithLoc(fileName, path$11)}:\x1b[0m\n${getFrame(file, path$11)}`).join("\n\n")}`;
|
|
10894
11037
|
if (!("MARKO_DEBUG" in process.env)) err.stack = finalMsg;
|
|
10895
11038
|
Object.defineProperty(err, "message", {
|
|
10896
11039
|
get() {
|
|
@@ -10953,9 +11096,7 @@ function scanBody(state, body) {
|
|
|
10953
11096
|
case "MarkoScriptlet":
|
|
10954
11097
|
if (!child.node.static) addFeature(state, Class, "Scriptlet", child);
|
|
10955
11098
|
break;
|
|
10956
|
-
case "MarkoClass":
|
|
10957
|
-
addFeature(state, Class, "Class block", child.get("body"));
|
|
10958
|
-
break;
|
|
11099
|
+
case "MarkoClass": addFeature(state, Class, "Class block", child.get("body"));
|
|
10959
11100
|
}
|
|
10960
11101
|
}
|
|
10961
11102
|
function scanTag(state, tag) {
|
|
@@ -11039,30 +11180,31 @@ function createInteropTranslator(translate5) {
|
|
|
11039
11180
|
build(entryFile) {
|
|
11040
11181
|
const state = entryFile[kState];
|
|
11041
11182
|
if (!state) throw entryFile.path.buildCodeFrameError("Unable to build hydrate code, no files were visited before finalizing the build");
|
|
11042
|
-
if (state.has5)
|
|
11043
|
-
|
|
11044
|
-
|
|
11045
|
-
|
|
11046
|
-
|
|
11047
|
-
|
|
11048
|
-
|
|
11049
|
-
|
|
11050
|
-
|
|
11051
|
-
|
|
11052
|
-
|
|
11053
|
-
|
|
11054
|
-
|
|
11055
|
-
|
|
11056
|
-
|
|
11057
|
-
|
|
11058
|
-
|
|
11059
|
-
|
|
11060
|
-
|
|
11061
|
-
|
|
11062
|
-
|
|
11063
|
-
|
|
11064
|
-
|
|
11065
|
-
|
|
11183
|
+
if (state.has5) {
|
|
11184
|
+
if (state.has6) {
|
|
11185
|
+
const filename = entryFile.opts.filename;
|
|
11186
|
+
const baseName = `./${path.default.basename(filename)}`;
|
|
11187
|
+
const generatorOpts = {
|
|
11188
|
+
...entryFile.opts.generatorOpts,
|
|
11189
|
+
sourceMaps: false
|
|
11190
|
+
};
|
|
11191
|
+
const { resolveVirtualDependency } = entryFile.markoOpts;
|
|
11192
|
+
const importHydrateProgram = (name, statements) => {
|
|
11193
|
+
return _marko_compiler.types.importDeclaration([_marko_compiler.types.importDefaultSpecifier(_marko_compiler.types.identifier(`init${name}`))], _marko_compiler.types.stringLiteral(resolveVirtualDependency(filename, {
|
|
11194
|
+
code: (0, _marko_compiler_internal_babel.generator)(_marko_compiler.types.program(statements), generatorOpts).code,
|
|
11195
|
+
virtualPath: `${baseName}.hydrate-${name}.js`
|
|
11196
|
+
})));
|
|
11197
|
+
};
|
|
11198
|
+
return [
|
|
11199
|
+
...state.needsCompat ? [_marko_compiler.types.importDeclaration([], _marko_compiler.types.stringLiteral(getCompatRuntimeFile()))] : [],
|
|
11200
|
+
...Array.from(state.compatFiles, (compatFile) => _marko_compiler.types.importDeclaration([], _marko_compiler.types.stringLiteral(compatFile))),
|
|
11201
|
+
importHydrateProgram("6", builder.build(entryFile, true)),
|
|
11202
|
+
importHydrateProgram("5", translate5.internalEntryBuilder.build(entryFile, true)),
|
|
11203
|
+
_marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(_marko_compiler.types.identifier("init6"), [])),
|
|
11204
|
+
_marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(_marko_compiler.types.identifier("init5"), []))
|
|
11205
|
+
];
|
|
11206
|
+
} else return translate5.internalEntryBuilder.build(entryFile);
|
|
11207
|
+
} else return builder.build(entryFile);
|
|
11066
11208
|
},
|
|
11067
11209
|
visit(file, entryFile, visitChild) {
|
|
11068
11210
|
const state = entryFile[kState] ||= {
|
|
@@ -11160,11 +11302,12 @@ function mergeObjects(a, b, cb) {
|
|
|
11160
11302
|
const value = cb(key, aValue, bValue);
|
|
11161
11303
|
if (value !== void 0) merged[key] = value;
|
|
11162
11304
|
};
|
|
11163
|
-
if (a)
|
|
11164
|
-
|
|
11165
|
-
|
|
11166
|
-
|
|
11167
|
-
|
|
11305
|
+
if (a) {
|
|
11306
|
+
if (b) {
|
|
11307
|
+
for (const key in a) assign(key, a[key], b[key]);
|
|
11308
|
+
for (const key in b) if (!(key in a)) assign(key, void 0, b[key]);
|
|
11309
|
+
} else for (const key in a) assign(key, a[key], void 0);
|
|
11310
|
+
} else if (b) for (const key in b) assign(key, void 0, b[key]);
|
|
11168
11311
|
return merged;
|
|
11169
11312
|
}
|
|
11170
11313
|
function normalizeTagDef(tagDef) {
|
|
@@ -11190,34 +11333,9 @@ function normalizeVisitor(visitor) {
|
|
|
11190
11333
|
return visitor?.default ?? visitor;
|
|
11191
11334
|
}
|
|
11192
11335
|
function normalizeVisit(visitor) {
|
|
11193
|
-
if (Array.isArray(visitor))
|
|
11194
|
-
let merged;
|
|
11195
|
-
for (const entry of visitor) merged = sequenceVisit(merged, normalizeVisit(entry));
|
|
11196
|
-
return merged;
|
|
11197
|
-
}
|
|
11336
|
+
if (Array.isArray(visitor)) throw new Error("A core tag's hook must be a single visitor for the interop merge, not a list.");
|
|
11198
11337
|
return typeof visitor === "function" ? visitor : normalizeVisitor(visitor);
|
|
11199
11338
|
}
|
|
11200
|
-
function sequenceVisit(first, second) {
|
|
11201
|
-
if (!first || !second) return first || second;
|
|
11202
|
-
const enterFirst = getVisitorEnter(first);
|
|
11203
|
-
const enterSecond = getVisitorEnter(second);
|
|
11204
|
-
const enter = (enterFirst || enterSecond) && function enter(path$11, state) {
|
|
11205
|
-
const { node } = path$11;
|
|
11206
|
-
enterFirst?.call(this, path$11, state);
|
|
11207
|
-
if (path$11.node === node) enterSecond?.call(this, path$11, state);
|
|
11208
|
-
};
|
|
11209
|
-
const exitFirst = getVisitorExit(first);
|
|
11210
|
-
const exitSecond = getVisitorExit(second);
|
|
11211
|
-
const exit = (exitFirst || exitSecond) && function exit(path$12, state) {
|
|
11212
|
-
const { node } = path$12;
|
|
11213
|
-
exitFirst?.call(this, path$12, state);
|
|
11214
|
-
if (path$12.node === node) exitSecond?.call(this, path$12, state);
|
|
11215
|
-
};
|
|
11216
|
-
return exit ? enter ? {
|
|
11217
|
-
enter,
|
|
11218
|
-
exit
|
|
11219
|
-
} : { exit } : enter;
|
|
11220
|
-
}
|
|
11221
11339
|
function getVisitorEnter(visit) {
|
|
11222
11340
|
return typeof visit === "function" ? visit : visit?.enter;
|
|
11223
11341
|
}
|