marko 6.0.0-next.3.50 → 6.0.0-next.3.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/types.d.ts +6 -7
- package/dist/debug/dom.js +103 -69
- package/dist/debug/dom.mjs +103 -69
- package/dist/dom/compat.d.ts +1 -1
- package/dist/dom/renderer.d.ts +9 -6
- package/dist/dom/signals.d.ts +5 -9
- package/dist/dom.d.ts +1 -1
- package/dist/dom.js +103 -76
- package/dist/dom.mjs +103 -76
- package/dist/translator/index.js +194 -142
- package/dist/translator/util/references.d.ts +3 -2
- package/dist/translator/util/sections.d.ts +6 -1
- package/dist/translator/util/signals.d.ts +2 -3
- package/package.json +1 -1
package/dist/translator/index.js
CHANGED
@@ -656,6 +656,7 @@ var pureFunctions = [
|
|
656
656
|
"createContent",
|
657
657
|
"createTemplate",
|
658
658
|
"dynamicClosure",
|
659
|
+
"dynamicClosureRead",
|
659
660
|
"intersection",
|
660
661
|
"loopClosure",
|
661
662
|
"loopIn",
|
@@ -902,6 +903,9 @@ function find(data, cb) {
|
|
902
903
|
}
|
903
904
|
}
|
904
905
|
}
|
906
|
+
function map(data, cb) {
|
907
|
+
return data ? Array.isArray(data) ? data.map(cb) : [cb(data, 0)] : [];
|
908
|
+
}
|
905
909
|
function findSorted(compare, data, item) {
|
906
910
|
let max = data.length;
|
907
911
|
let pos = 0;
|
@@ -978,17 +982,17 @@ function joinRepeatable(compare, a, b) {
|
|
978
982
|
|
979
983
|
// src/translator/util/state.ts
|
980
984
|
var createProgramState = (init) => {
|
981
|
-
const
|
985
|
+
const map2 = /* @__PURE__ */ new WeakMap();
|
982
986
|
return [
|
983
987
|
() => {
|
984
|
-
let state =
|
988
|
+
let state = map2.get(currentProgramPath);
|
985
989
|
if (!state) {
|
986
|
-
|
990
|
+
map2.set(currentProgramPath, state = init());
|
987
991
|
}
|
988
992
|
return state;
|
989
993
|
},
|
990
994
|
(value) => {
|
991
|
-
|
995
|
+
map2.set(currentProgramPath, value);
|
992
996
|
}
|
993
997
|
];
|
994
998
|
};
|
@@ -1125,6 +1129,9 @@ function analyzeExpressionTagName(name2, extra) {
|
|
1125
1129
|
}
|
1126
1130
|
|
1127
1131
|
// src/translator/util/sections.ts
|
1132
|
+
var sectionUtil = new Sorted(function compareSections(a, b) {
|
1133
|
+
return a.id - b.id;
|
1134
|
+
});
|
1128
1135
|
function startSection(path5) {
|
1129
1136
|
const extra = path5.node.extra ??= {};
|
1130
1137
|
let section = extra.section;
|
@@ -1146,7 +1153,8 @@ function startSection(path5) {
|
|
1146
1153
|
parent: parentSection,
|
1147
1154
|
sectionAccessor: void 0,
|
1148
1155
|
params: void 0,
|
1149
|
-
|
1156
|
+
referencedClosures: void 0,
|
1157
|
+
referencedHoists: void 0,
|
1150
1158
|
bindings: void 0,
|
1151
1159
|
hoisted: void 0,
|
1152
1160
|
isHoistThrough: void 0,
|
@@ -1288,10 +1296,16 @@ var isSerializedSection = (section) => {
|
|
1288
1296
|
};
|
1289
1297
|
var checkStatefulClosures = (section, immediateOnly) => {
|
1290
1298
|
return !!find(
|
1291
|
-
section.
|
1299
|
+
section.referencedClosures,
|
1292
1300
|
(closure) => (!immediateOnly || section.parent === closure.section) && isStatefulReferences(closure)
|
1293
1301
|
);
|
1294
1302
|
};
|
1303
|
+
function isImmediateOwner(section, binding) {
|
1304
|
+
return section.parent?.id === binding.section.id;
|
1305
|
+
}
|
1306
|
+
function isDynamicClosure(section, closure) {
|
1307
|
+
return !section.isBranch || !isImmediateOwner(section, closure);
|
1308
|
+
}
|
1295
1309
|
function isSameOrChildSection(section, other) {
|
1296
1310
|
do {
|
1297
1311
|
if (other === section) {
|
@@ -2058,7 +2072,17 @@ var [getSerializedScopeProperties] = createSectionState("serializedScopeProperti
|
|
2058
2072
|
function setSerializedProperty(section, key, value) {
|
2059
2073
|
getSerializedScopeProperties(section).set(key, value);
|
2060
2074
|
}
|
2061
|
-
var [
|
2075
|
+
var [getSectionWriteScopeBuilder, setSectionWriteScopeBuilder] = createSectionState(
|
2076
|
+
"sectionWriteScopeBuilder"
|
2077
|
+
);
|
2078
|
+
function addWriteScopeBuilder(section, builder) {
|
2079
|
+
const prev = getSectionWriteScopeBuilder(section);
|
2080
|
+
setSectionWriteScopeBuilder(
|
2081
|
+
section,
|
2082
|
+
prev ? (expr) => builder(prev(expr)) : builder
|
2083
|
+
);
|
2084
|
+
}
|
2085
|
+
var htmlDynamicClosureInstancesIdentifier = /* @__PURE__ */ new WeakMap();
|
2062
2086
|
var [getHTMLSectionStatements] = createSectionState(
|
2063
2087
|
"htmlScopeStatements",
|
2064
2088
|
() => []
|
@@ -2100,7 +2124,6 @@ function getSignal(section, referencedBindings, name2 = generateSignalName(refer
|
|
2100
2124
|
effect: [],
|
2101
2125
|
effectReferencedBindings: void 0,
|
2102
2126
|
subscribers: [],
|
2103
|
-
closures: /* @__PURE__ */ new Map(),
|
2104
2127
|
hasDownstreamIntersections: () => {
|
2105
2128
|
let hasDownstreamIntersections = !!signal.intersection;
|
2106
2129
|
if (!hasDownstreamIntersections) {
|
@@ -2152,53 +2175,22 @@ function getSignal(section, referencedBindings, name2 = generateSignalName(refer
|
|
2152
2175
|
scopeOffset && getScopeAccessorLiteral(scopeOffset)
|
2153
2176
|
);
|
2154
2177
|
};
|
2155
|
-
} else if (referencedBindings.section !== section && bindingUtil.find(section.
|
2156
|
-
getSignal(referencedBindings.section, referencedBindings).closures.set(
|
2157
|
-
section,
|
2158
|
-
signal
|
2159
|
-
);
|
2178
|
+
} else if (referencedBindings.section !== section && bindingUtil.find(section.referencedClosures, referencedBindings)) {
|
2160
2179
|
signal.build = () => {
|
2161
|
-
const builder = getClosureSignalBuilder(section);
|
2162
|
-
const ownerScope = getScopeExpression(
|
2163
|
-
section,
|
2164
|
-
referencedBindings.section
|
2165
|
-
);
|
2166
|
-
const isImmediateOwner = ownerScope.object === scopeIdentifier;
|
2167
|
-
const isDynamicClosure = !isImmediateOwner || !builder;
|
2168
2180
|
const render = getSignalFn(signal, [
|
2169
2181
|
scopeIdentifier,
|
2170
2182
|
import_compiler17.types.identifier(referencedBindings.name)
|
2171
2183
|
]);
|
2172
|
-
return isDynamicClosure
|
2173
|
-
"
|
2174
|
-
import_compiler17.types.stringLiteral(
|
2175
|
-
getResumeRegisterId(
|
2176
|
-
section,
|
2177
|
-
signal.referencedBindings,
|
2178
|
-
"subscriber"
|
2179
|
-
)
|
2180
|
-
),
|
2181
|
-
getScopeAccessorLiteral(referencedBindings),
|
2182
|
-
render,
|
2183
|
-
isImmediateOwner ? void 0 : import_compiler17.types.arrowFunctionExpression([scopeIdentifier], ownerScope)
|
2184
|
-
) : callRuntime(
|
2185
|
-
"dynamicClosure",
|
2184
|
+
return isDynamicClosure(section, referencedBindings) ? callRuntime(
|
2185
|
+
"dynamicClosureRead",
|
2186
2186
|
getScopeAccessorLiteral(referencedBindings),
|
2187
2187
|
render,
|
2188
|
-
isImmediateOwner ? void 0 : import_compiler17.types.arrowFunctionExpression(
|
2189
|
-
|
2190
|
-
|
2191
|
-
addStatement(
|
2192
|
-
"render",
|
2193
|
-
section,
|
2194
|
-
void 0,
|
2195
|
-
import_compiler17.types.expressionStatement(
|
2196
|
-
import_compiler17.types.callExpression(
|
2197
|
-
import_compiler17.types.memberExpression(signal.identifier, import_compiler17.types.identifier("_")),
|
2198
|
-
[scopeIdentifier]
|
2188
|
+
isImmediateOwner(section, referencedBindings) ? void 0 : import_compiler17.types.arrowFunctionExpression(
|
2189
|
+
[scopeIdentifier],
|
2190
|
+
getScopeExpression(section, referencedBindings.section)
|
2199
2191
|
)
|
2200
|
-
)
|
2201
|
-
|
2192
|
+
) : getClosureSignalBuilder(section)(referencedBindings, render);
|
2193
|
+
};
|
2202
2194
|
}
|
2203
2195
|
}
|
2204
2196
|
return signal;
|
@@ -2283,17 +2275,47 @@ function getSignalFn(signal, params, referencedBindings) {
|
|
2283
2275
|
);
|
2284
2276
|
});
|
2285
2277
|
if (isValueSignal) {
|
2286
|
-
|
2287
|
-
|
2288
|
-
)
|
2289
|
-
|
2290
|
-
|
2291
|
-
|
2292
|
-
|
2293
|
-
|
2294
|
-
|
2295
|
-
|
2278
|
+
let dynamicClosureArgs;
|
2279
|
+
let dynamicClosureSignalIdentifier;
|
2280
|
+
forEach(binding.closureSections, (closureSection) => {
|
2281
|
+
if (isStatefulReferences(binding)) {
|
2282
|
+
if (isDynamicClosure(closureSection, binding)) {
|
2283
|
+
if (!dynamicClosureArgs) {
|
2284
|
+
dynamicClosureArgs = [];
|
2285
|
+
dynamicClosureSignalIdentifier = currentProgramPath.scope.generateUidIdentifier(
|
2286
|
+
signal.identifier.name + "_closure"
|
2287
|
+
);
|
2288
|
+
signal.render.push(
|
2289
|
+
import_compiler17.types.expressionStatement(
|
2290
|
+
import_compiler17.types.callExpression(dynamicClosureSignalIdentifier, [
|
2291
|
+
scopeIdentifier2
|
2292
|
+
])
|
2293
|
+
)
|
2294
|
+
);
|
2295
|
+
}
|
2296
|
+
dynamicClosureArgs.push(
|
2297
|
+
getSignal(closureSection, binding).identifier
|
2298
|
+
);
|
2299
|
+
} else {
|
2300
|
+
signal.render.push(
|
2301
|
+
import_compiler17.types.expressionStatement(
|
2302
|
+
import_compiler17.types.callExpression(getSignal(closureSection, binding).identifier, [
|
2303
|
+
scopeIdentifier2
|
2304
|
+
])
|
2305
|
+
)
|
2306
|
+
);
|
2307
|
+
}
|
2296
2308
|
}
|
2309
|
+
});
|
2310
|
+
if (dynamicClosureSignalIdentifier) {
|
2311
|
+
(signal.prependStatements ||= []).push(
|
2312
|
+
import_compiler17.types.variableDeclaration("const", [
|
2313
|
+
import_compiler17.types.variableDeclarator(
|
2314
|
+
dynamicClosureSignalIdentifier,
|
2315
|
+
callRuntime("dynamicClosure", ...dynamicClosureArgs)
|
2316
|
+
)
|
2317
|
+
])
|
2318
|
+
);
|
2297
2319
|
}
|
2298
2320
|
}
|
2299
2321
|
if (signal.effect.length) {
|
@@ -2468,7 +2490,7 @@ function writeSignals(section) {
|
|
2468
2490
|
while (currentSection && currentSection !== hoistedBinding.section) {
|
2469
2491
|
const parentSection = currentSection.parent;
|
2470
2492
|
if (parentSection) {
|
2471
|
-
accessors.push(
|
2493
|
+
accessors.push(getSectionInstancesAccessorLiteral(currentSection));
|
2472
2494
|
}
|
2473
2495
|
currentSection = parentSection;
|
2474
2496
|
}
|
@@ -2556,13 +2578,12 @@ function writeSignals(section) {
|
|
2556
2578
|
if (signal.export) {
|
2557
2579
|
signalDeclaration = import_compiler17.types.exportNamedDeclaration(signalDeclaration);
|
2558
2580
|
}
|
2559
|
-
|
2560
|
-
|
2561
|
-
|
2562
|
-
|
2563
|
-
|
2564
|
-
|
2565
|
-
);
|
2581
|
+
const signalStatements = signal.prependStatements || [];
|
2582
|
+
if (effectDeclarator) {
|
2583
|
+
signalStatements.push(import_compiler17.types.variableDeclaration("const", [effectDeclarator]));
|
2584
|
+
}
|
2585
|
+
signalStatements.push(signalDeclaration);
|
2586
|
+
currentProgramPath.pushContainer("body", signalStatements);
|
2566
2587
|
}
|
2567
2588
|
}
|
2568
2589
|
function writeRegisteredFns() {
|
@@ -2654,9 +2675,9 @@ function writeHTMLResumeStatements(path5) {
|
|
2654
2675
|
if (!section) return;
|
2655
2676
|
const allSignals = Array.from(getSignals(section).values());
|
2656
2677
|
const scopeIdIdentifier = getScopeIdIdentifier(section);
|
2657
|
-
|
2678
|
+
const serializeOwnersUntilBindingSection = (binding) => {
|
2658
2679
|
let currentSection = section;
|
2659
|
-
while (currentSection !==
|
2680
|
+
while (currentSection !== binding.section) {
|
2660
2681
|
const currentSerialized = getSerializedScopeProperties(currentSection);
|
2661
2682
|
currentSection = currentSection.parent;
|
2662
2683
|
if (!currentSerialized.has("_")) {
|
@@ -2669,38 +2690,45 @@ function writeHTMLResumeStatements(path5) {
|
|
2669
2690
|
);
|
2670
2691
|
}
|
2671
2692
|
}
|
2672
|
-
}
|
2673
|
-
forEach(section.
|
2693
|
+
};
|
2694
|
+
forEach(section.assignments, serializeOwnersUntilBindingSection);
|
2695
|
+
forEach(section.referencedHoists, serializeOwnersUntilBindingSection);
|
2696
|
+
forEach(section.referencedClosures, (closure) => {
|
2674
2697
|
if (isStatefulReferences(closure)) {
|
2675
|
-
|
2676
|
-
|
2677
|
-
|
2678
|
-
|
2679
|
-
|
2680
|
-
|
2681
|
-
|
2682
|
-
|
2683
|
-
|
2684
|
-
|
2698
|
+
serializeOwnersUntilBindingSection(closure);
|
2699
|
+
setForceResumeScope(closure.section);
|
2700
|
+
if (isDynamicClosure(section, closure)) {
|
2701
|
+
const closureSignal = getSignal(closure.section, closure);
|
2702
|
+
let identifier = htmlDynamicClosureInstancesIdentifier.get(closureSignal);
|
2703
|
+
if (!identifier) {
|
2704
|
+
htmlDynamicClosureInstancesIdentifier.set(
|
2705
|
+
closureSignal,
|
2706
|
+
identifier = currentProgramPath.scope.generateUidIdentifier(
|
2707
|
+
closureSignal.identifier.name + "_closures"
|
2685
2708
|
)
|
2686
2709
|
);
|
2687
|
-
|
2688
|
-
|
2689
|
-
|
2690
|
-
|
2691
|
-
|
2692
|
-
if (isDynamicClosure) {
|
2693
|
-
path5.pushContainer(
|
2694
|
-
"body",
|
2695
|
-
import_compiler17.types.expressionStatement(
|
2696
|
-
callRuntime(
|
2697
|
-
"writeEffect",
|
2698
|
-
scopeIdIdentifier,
|
2699
|
-
import_compiler17.types.stringLiteral(
|
2700
|
-
getResumeRegisterId(section, closure, "subscriber")
|
2710
|
+
getHTMLSectionStatements(closure.section).push(
|
2711
|
+
import_compiler17.types.variableDeclaration("const", [
|
2712
|
+
import_compiler17.types.variableDeclarator(
|
2713
|
+
identifier,
|
2714
|
+
import_compiler17.types.newExpression(import_compiler17.types.identifier("Set"), [])
|
2701
2715
|
)
|
2702
|
-
)
|
2703
|
-
)
|
2716
|
+
])
|
2717
|
+
);
|
2718
|
+
setSerializedProperty(
|
2719
|
+
closure.section,
|
2720
|
+
getScopeAccessor(closure) + "!" /* ClosureScopes */,
|
2721
|
+
identifier
|
2722
|
+
);
|
2723
|
+
}
|
2724
|
+
setSerializedProperty(
|
2725
|
+
section,
|
2726
|
+
getScopeAccessor(closure) + "(" /* ClosureSignalIndex */,
|
2727
|
+
import_compiler17.types.numericLiteral(getDynamicClosureIndex(closure, section))
|
2728
|
+
);
|
2729
|
+
addWriteScopeBuilder(
|
2730
|
+
section,
|
2731
|
+
(expr) => callRuntime("writeSubscribe", identifier, expr)
|
2704
2732
|
);
|
2705
2733
|
}
|
2706
2734
|
}
|
@@ -2744,13 +2772,13 @@ function writeHTMLResumeStatements(path5) {
|
|
2744
2772
|
)
|
2745
2773
|
])
|
2746
2774
|
);
|
2747
|
-
|
2775
|
+
addWriteScopeBuilder(
|
2748
2776
|
currentSection,
|
2749
|
-
subscribersIdentifier
|
2777
|
+
(expr) => callRuntime("writeSubscribe", subscribersIdentifier, expr)
|
2750
2778
|
);
|
2751
2779
|
setSerializedProperty(
|
2752
2780
|
parentSection,
|
2753
|
-
|
2781
|
+
getSectionInstancesAccessor(currentSection),
|
2754
2782
|
subscribersIdentifier
|
2755
2783
|
);
|
2756
2784
|
}
|
@@ -2794,8 +2822,8 @@ function writeHTMLResumeStatements(path5) {
|
|
2794
2822
|
for (const [key, value] of serializedLookup) {
|
2795
2823
|
serializedProperties.push(toObjectProperty(key, value));
|
2796
2824
|
}
|
2797
|
-
const
|
2798
|
-
if (serializedProperties.length || forceResumeScope(section)
|
2825
|
+
const writeScopeBuilder = getSectionWriteScopeBuilder(section);
|
2826
|
+
if (writeScopeBuilder || serializedProperties.length || forceResumeScope(section)) {
|
2799
2827
|
for (const prop of serializedProperties) {
|
2800
2828
|
if (prop.key.type === "Identifier" && prop.value.type === "Identifier" && prop.key.name === prop.value.name) {
|
2801
2829
|
prop.shorthand = true;
|
@@ -2842,15 +2870,11 @@ function writeHTMLResumeStatements(path5) {
|
|
2842
2870
|
path5.pushContainer(
|
2843
2871
|
"body",
|
2844
2872
|
import_compiler17.types.expressionStatement(
|
2845
|
-
|
2846
|
-
"writeSubscribe",
|
2847
|
-
subscriberIdentifier,
|
2848
|
-
callRuntime("writeScope", ...writeScopeArgs)
|
2849
|
-
) : callRuntime("writeScope", ...writeScopeArgs)
|
2873
|
+
writeScopeBuilder ? writeScopeBuilder(callRuntime("writeScope", ...writeScopeArgs)) : callRuntime("writeScope", ...writeScopeArgs)
|
2850
2874
|
)
|
2851
2875
|
);
|
2852
2876
|
}
|
2853
|
-
const resumeClosestBranch2 = !section.isBranch && (section.hasAbortSignal || !!section.
|
2877
|
+
const resumeClosestBranch2 = !section.isBranch && (section.hasAbortSignal || !!section.referencedClosures || !!find(section.bindings, (binding) => binding.type === 1 /* let */));
|
2854
2878
|
if (resumeClosestBranch2) {
|
2855
2879
|
path5.pushContainer(
|
2856
2880
|
"body",
|
@@ -3040,6 +3064,17 @@ function getRegisteredFnExpression(node) {
|
|
3040
3064
|
}
|
3041
3065
|
}
|
3042
3066
|
}
|
3067
|
+
function getDynamicClosureIndex(closure, closureSection) {
|
3068
|
+
let index = 0;
|
3069
|
+
find(closure.closureSections, (section) => {
|
3070
|
+
if (section === closureSection) return true;
|
3071
|
+
if (isDynamicClosure(section, closure)) {
|
3072
|
+
index++;
|
3073
|
+
}
|
3074
|
+
return false;
|
3075
|
+
});
|
3076
|
+
return index;
|
3077
|
+
}
|
3043
3078
|
|
3044
3079
|
// src/translator/visitors/program/dom.ts
|
3045
3080
|
var dom_default = {
|
@@ -3062,15 +3097,32 @@ var dom_default = {
|
|
3062
3097
|
if (childSection !== section) {
|
3063
3098
|
const tagParamsSignal = childSection.params && initValue(childSection.params);
|
3064
3099
|
const { walks: walks2, writes: writes2, setup: setup2 } = getSectionMeta(childSection);
|
3065
|
-
const params = tagParamsSignal?.identifier && import_compiler18.types.arrowFunctionExpression([], tagParamsSignal.identifier);
|
3066
3100
|
const identifier = import_compiler18.types.identifier(childSection.name);
|
3101
|
+
const referencedClosures = childSection.referencedClosures ? import_compiler18.types.arrowFunctionExpression(
|
3102
|
+
[scopeIdentifier],
|
3103
|
+
toFirstExpressionOrBlock(
|
3104
|
+
map(childSection.referencedClosures, (closure) => {
|
3105
|
+
const closureSignal = getSignal(childSection, closure);
|
3106
|
+
return import_compiler18.types.expressionStatement(
|
3107
|
+
import_compiler18.types.callExpression(
|
3108
|
+
isDynamicClosure(childSection, closure) ? closureSignal.identifier : import_compiler18.types.memberExpression(
|
3109
|
+
closureSignal.identifier,
|
3110
|
+
import_compiler18.types.identifier("_")
|
3111
|
+
),
|
3112
|
+
[scopeIdentifier]
|
3113
|
+
)
|
3114
|
+
);
|
3115
|
+
})
|
3116
|
+
)
|
3117
|
+
) : void 0;
|
3067
3118
|
const renderer = getSectionParentIsOwner(childSection) ? callRuntime(
|
3068
3119
|
"createRenderer",
|
3069
3120
|
...replaceNullishAndEmptyFunctionsWith0([
|
3070
3121
|
writes2,
|
3071
3122
|
walks2,
|
3072
3123
|
setup2,
|
3073
|
-
|
3124
|
+
tagParamsSignal?.identifier,
|
3125
|
+
referencedClosures
|
3074
3126
|
])
|
3075
3127
|
) : callRuntime(
|
3076
3128
|
isSerializedSection(childSection) ? "registerContent" : "createContent",
|
@@ -3079,8 +3131,9 @@ var dom_default = {
|
|
3079
3131
|
writes2,
|
3080
3132
|
walks2,
|
3081
3133
|
setup2,
|
3082
|
-
|
3083
|
-
|
3134
|
+
tagParamsSignal?.identifier,
|
3135
|
+
referencedClosures,
|
3136
|
+
childSection.hoisted || childSection.isHoistThrough ? getSectionInstancesAccessorLiteral(childSection) : void 0
|
3084
3137
|
])
|
3085
3138
|
);
|
3086
3139
|
writeSignals(childSection);
|
@@ -3511,6 +3564,7 @@ function createBinding(name2, type, section, upstreamAlias, upstreamExpression,
|
|
3511
3564
|
section,
|
3512
3565
|
property,
|
3513
3566
|
declared,
|
3567
|
+
closureSections: void 0,
|
3514
3568
|
excludeProperties: void 0,
|
3515
3569
|
serialize: false,
|
3516
3570
|
aliases: /* @__PURE__ */ new Set(),
|
@@ -3622,12 +3676,10 @@ function trackHoistedReference(referencePath, binding) {
|
|
3622
3676
|
} else {
|
3623
3677
|
trackReference(referencePath, hoistedBinding);
|
3624
3678
|
}
|
3625
|
-
|
3626
|
-
referenceSection.
|
3627
|
-
|
3628
|
-
|
3629
|
-
);
|
3630
|
-
}
|
3679
|
+
referenceSection.referencedHoists = bindingUtil.add(
|
3680
|
+
referenceSection.referencedHoists,
|
3681
|
+
hoistedBinding
|
3682
|
+
);
|
3631
3683
|
}
|
3632
3684
|
function trackReferencesForBinding(babelBinding) {
|
3633
3685
|
const { identifier, referencePaths, constantViolations } = babelBinding;
|
@@ -3914,7 +3966,14 @@ function finalizeReferences() {
|
|
3914
3966
|
section: section2
|
3915
3967
|
} of binding.downstreamExpressions) {
|
3916
3968
|
if (section2 !== binding.section) {
|
3917
|
-
|
3969
|
+
binding.closureSections = sectionUtil.add(
|
3970
|
+
binding.closureSections,
|
3971
|
+
section2
|
3972
|
+
);
|
3973
|
+
section2.referencedClosures = bindingUtil.add(
|
3974
|
+
section2.referencedClosures,
|
3975
|
+
binding
|
3976
|
+
);
|
3918
3977
|
}
|
3919
3978
|
if (isEffect) {
|
3920
3979
|
forEach(referencedBindings, (bindingReference) => {
|
@@ -3944,7 +4003,7 @@ function finalizeReferences() {
|
|
3944
4003
|
}
|
3945
4004
|
}
|
3946
4005
|
}
|
3947
|
-
forEach(section.
|
4006
|
+
forEach(section.referencedClosures, (binding) => {
|
3948
4007
|
if (!binding.serialize) {
|
3949
4008
|
let serialize = false;
|
3950
4009
|
const sourceSection = binding.section;
|
@@ -4102,11 +4161,11 @@ function getScopeAccessor(binding, includeId) {
|
|
4102
4161
|
}
|
4103
4162
|
return binding.name + (includeId || binding.type === 0 /* dom */ ? `/${binding.id}` : "");
|
4104
4163
|
}
|
4105
|
-
function
|
4106
|
-
return section.sectionAccessor ? getScopeAccessor(section.sectionAccessor.binding) + section.sectionAccessor.suffix : section.id + "
|
4164
|
+
function getSectionInstancesAccessor(section) {
|
4165
|
+
return section.sectionAccessor ? getScopeAccessor(section.sectionAccessor.binding) + section.sectionAccessor.suffix : section.id + "!" /* ClosureScopes */;
|
4107
4166
|
}
|
4108
|
-
function
|
4109
|
-
const accessor =
|
4167
|
+
function getSectionInstancesAccessorLiteral(section) {
|
4168
|
+
const accessor = getSectionInstancesAccessor(section);
|
4110
4169
|
return accessor ? typeof accessor === "number" ? import_compiler22.types.numericLiteral(accessor) : import_compiler22.types.stringLiteral(accessor) : void 0;
|
4111
4170
|
}
|
4112
4171
|
function getReadReplacement(node) {
|
@@ -5443,7 +5502,7 @@ var for_default = {
|
|
5443
5502
|
const statements = [];
|
5444
5503
|
const bodyStatements = node.body.body;
|
5445
5504
|
const hasStatefulClosures = checkStatefulClosures(bodySection, true);
|
5446
|
-
const hasHoists = bodySection.hoisted || bodySection.isHoistThrough;
|
5505
|
+
const hasHoists = bodySection.hoisted || bodySection.isHoistThrough || bodySection.referencedHoists;
|
5447
5506
|
const singleNodeOptimization = bodySection.content === null || bodySection.content.singleChild && bodySection.content.startType !== 4 /* Text */;
|
5448
5507
|
let keyExpression;
|
5449
5508
|
if (isStateful && onlyChildInParentOptimization) {
|
@@ -5536,8 +5595,6 @@ var for_default = {
|
|
5536
5595
|
);
|
5537
5596
|
}
|
5538
5597
|
flushInto(tag);
|
5539
|
-
setClosureSignalBuilder(tag, () => {
|
5540
|
-
});
|
5541
5598
|
writeHTMLResumeStatements(tagBody);
|
5542
5599
|
const forTagArgs = getBaseArgsInForTag(forType, forAttrs);
|
5543
5600
|
const forTagHTMLRuntime = isStateful ? forTypeToHTMLResumeRuntime(forType, singleNodeOptimization) : forTypeToRuntime(forType);
|
@@ -5585,12 +5642,10 @@ var for_default = {
|
|
5585
5642
|
const tagExtra = node.extra;
|
5586
5643
|
const { referencedBindings } = tagExtra;
|
5587
5644
|
const nodeRef2 = getOptimizedOnlyChildNodeRef(tag, tagSection);
|
5588
|
-
setClosureSignalBuilder(tag, (
|
5645
|
+
setClosureSignalBuilder(tag, (closure, render) => {
|
5589
5646
|
return callRuntime(
|
5590
5647
|
"loopClosure",
|
5591
|
-
getScopeAccessorLiteral(
|
5592
|
-
closureSignal.referencedBindings
|
5593
|
-
),
|
5648
|
+
getScopeAccessorLiteral(closure),
|
5594
5649
|
getScopeAccessorLiteral(nodeRef2),
|
5595
5650
|
render
|
5596
5651
|
);
|
@@ -7339,14 +7394,12 @@ var IfTag = {
|
|
7339
7394
|
const isStateful = isStatefulReferences(rootExtra.referencedBindings);
|
7340
7395
|
const singleNodeOptimization = rootExtra.singleNodeOptimization;
|
7341
7396
|
const hasStatefulClosures = bodySection && checkStatefulClosures(bodySection, true);
|
7342
|
-
const hasHoists = bodySection && (bodySection.hoisted || bodySection.isHoistThrough);
|
7397
|
+
const hasHoists = bodySection && (bodySection.hoisted || bodySection.isHoistThrough || bodySection.referencedHoists);
|
7343
7398
|
if (bodySection) {
|
7344
7399
|
if (isStateful || hasStatefulClosures || hasHoists) {
|
7345
7400
|
setForceResumeScope(bodySection);
|
7346
7401
|
}
|
7347
7402
|
flushInto(tag);
|
7348
|
-
setClosureSignalBuilder(tag, () => {
|
7349
|
-
});
|
7350
7403
|
writeHTMLResumeStatements(tagBody);
|
7351
7404
|
}
|
7352
7405
|
if (isLast) {
|
@@ -7367,6 +7420,7 @@ var IfTag = {
|
|
7367
7420
|
branchBodySection,
|
7368
7421
|
true
|
7369
7422
|
);
|
7423
|
+
const branchHasHoists = branchBodySection.hoisted || branchBodySection.isHoistThrough || branchBodySection.referencedHoists;
|
7370
7424
|
if (isStateful) {
|
7371
7425
|
bodyStatements.push(
|
7372
7426
|
import_compiler40.types.expressionStatement(
|
@@ -7378,7 +7432,7 @@ var IfTag = {
|
|
7378
7432
|
)
|
7379
7433
|
);
|
7380
7434
|
}
|
7381
|
-
if (isStateful || branchHasStatefulClosures ||
|
7435
|
+
if (isStateful || branchHasStatefulClosures || branchHasHoists) {
|
7382
7436
|
bodyStatements.push(
|
7383
7437
|
import_compiler40.types.expressionStatement(
|
7384
7438
|
import_compiler40.types.assignmentExpression(
|
@@ -7482,12 +7536,10 @@ var IfTag = {
|
|
7482
7536
|
const consequent = import_compiler40.types.numericLiteral(branchBodySection ? i : -1);
|
7483
7537
|
if (branchBodySection) {
|
7484
7538
|
rendererIdentifiers.push(import_compiler40.types.identifier(branchBodySection.name));
|
7485
|
-
setClosureSignalBuilder(branchTag, (
|
7539
|
+
setClosureSignalBuilder(branchTag, (closure, render) => {
|
7486
7540
|
return callRuntime(
|
7487
7541
|
"conditionalClosure",
|
7488
|
-
getScopeAccessorLiteral(
|
7489
|
-
closureSignal.referencedBindings
|
7490
|
-
),
|
7542
|
+
getScopeAccessorLiteral(closure),
|
7491
7543
|
getScopeAccessorLiteral(nodeRef2),
|
7492
7544
|
import_compiler40.types.numericLiteral(i),
|
7493
7545
|
render
|
@@ -8136,27 +8188,27 @@ var style_default = {
|
|
8136
8188
|
const start = (0, import_babel_utils36.getStart)(file, markoText);
|
8137
8189
|
const end = (0, import_babel_utils36.getEnd)(file, markoText);
|
8138
8190
|
let code = markoText.value;
|
8139
|
-
let
|
8191
|
+
let map2;
|
8140
8192
|
if (resolveVirtualDependency && sourceMaps && start !== null && end !== null) {
|
8141
8193
|
const magicString = new import_magic_string.default(file.code, { filename });
|
8142
8194
|
magicString.remove(0, start);
|
8143
8195
|
magicString.remove(end, file.code.length);
|
8144
|
-
|
8196
|
+
map2 = magicString.generateMap({
|
8145
8197
|
source: filename,
|
8146
8198
|
includeContent: true
|
8147
8199
|
});
|
8148
8200
|
if (sourceMaps === "inline" || sourceMaps === "both") {
|
8149
8201
|
code += `
|
8150
|
-
/*# sourceMappingURL=${
|
8202
|
+
/*# sourceMappingURL=${map2.toUrl()}*/`;
|
8151
8203
|
if (sourceMaps === "inline") {
|
8152
|
-
|
8204
|
+
map2 = void 0;
|
8153
8205
|
}
|
8154
8206
|
}
|
8155
8207
|
}
|
8156
8208
|
const importPath = resolveVirtualDependency?.(filename, {
|
8157
8209
|
virtualPath: `./${import_path3.default.basename(filename) + ext}`,
|
8158
8210
|
code,
|
8159
|
-
map
|
8211
|
+
map: map2
|
8160
8212
|
});
|
8161
8213
|
if (importPath) {
|
8162
8214
|
if (!node.var) {
|
@@ -19,6 +19,7 @@ export type Binding = {
|
|
19
19
|
type: BindingType;
|
20
20
|
loc: t.SourceLocation | null;
|
21
21
|
section: Section;
|
22
|
+
closureSections: Opt<Section>;
|
22
23
|
serialize: boolean;
|
23
24
|
aliases: Set<Binding>;
|
24
25
|
hoists: Map<Section, Binding>;
|
@@ -79,8 +80,8 @@ export declare function getCanonicalBinding(binding?: Binding): Binding | undefi
|
|
79
80
|
export declare function getAllTagReferenceNodes(tag: t.MarkoTag, referenceNodes?: t.Node[]): t.Node[];
|
80
81
|
export declare function getScopeAccessorLiteral(binding: Binding, includeId?: boolean): t.StringLiteral | t.NumericLiteral;
|
81
82
|
export declare function getScopeAccessor(binding: Binding, includeId?: boolean): string;
|
82
|
-
export declare function
|
83
|
-
export declare function
|
83
|
+
export declare function getSectionInstancesAccessor(section: Section): string;
|
84
|
+
export declare function getSectionInstancesAccessorLiteral(section: Section): t.StringLiteral | t.NumericLiteral | undefined;
|
84
85
|
export declare function getReadReplacement(node: t.Identifier | t.MemberExpression): t.Node | undefined;
|
85
86
|
export interface ReferencedExtra extends t.NodeExtra {
|
86
87
|
section: Section;
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { types as t } from "@marko/compiler";
|
2
|
+
import { Sorted } from "./optional";
|
2
3
|
import type { Binding, ReferencedBindings } from "./references";
|
3
4
|
export declare enum ContentType {
|
4
5
|
Comment = 0,
|
@@ -18,7 +19,8 @@ export interface Section {
|
|
18
19
|
suffix: string;
|
19
20
|
} | undefined;
|
20
21
|
params: undefined | Binding;
|
21
|
-
|
22
|
+
referencedClosures: ReferencedBindings;
|
23
|
+
referencedHoists: ReferencedBindings;
|
22
24
|
bindings: ReferencedBindings;
|
23
25
|
hoisted: ReferencedBindings;
|
24
26
|
isHoistThrough: true | undefined;
|
@@ -42,6 +44,7 @@ declare module "@marko/compiler/dist/types" {
|
|
42
44
|
section?: Section;
|
43
45
|
}
|
44
46
|
}
|
47
|
+
export declare const sectionUtil: Sorted<Section>;
|
45
48
|
export declare function startSection(path: t.NodePath<t.MarkoTagBody | t.Program>): Section | undefined;
|
46
49
|
export declare function getOrCreateSection(path: t.NodePath<any>): Section;
|
47
50
|
export declare function getSectionForBody(body: t.NodePath<t.MarkoTagBody | t.Program>): Section | undefined;
|
@@ -56,5 +59,7 @@ export declare function getNodeContentType(path: t.NodePath<t.Statement>, extraM
|
|
56
59
|
export declare const isSerializedSection: (section: Section) => boolean;
|
57
60
|
export declare const isStatefulSection: (section: Section) => boolean;
|
58
61
|
export declare const checkStatefulClosures: (section: Section, immediateOnly: boolean) => boolean;
|
62
|
+
export declare function isImmediateOwner(section: Section, binding: Binding): boolean;
|
63
|
+
export declare function isDynamicClosure(section: Section, closure: Binding): boolean;
|
59
64
|
export declare function isSameOrChildSection(section: Section, other: Section): boolean;
|
60
65
|
export declare function getCommonSection(section: Section, other: Section): Section;
|