marko 6.1.2 → 6.1.3
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/debug/dom.js +32 -11
- package/dist/debug/dom.mjs +32 -12
- package/dist/debug/html.js +91 -151
- package/dist/debug/html.mjs +91 -151
- package/dist/dom/queue.d.ts +1 -0
- package/dist/dom/signals.d.ts +4 -3
- package/dist/dom.d.ts +1 -1
- package/dist/dom.js +18 -9
- package/dist/dom.mjs +18 -9
- package/dist/html/inlined-runtimes.d.ts +1 -1
- package/dist/html/inlined-runtimes.debug.d.ts +1 -1
- package/dist/html.js +68 -82
- package/dist/html.mjs +68 -82
- package/dist/translator/index.js +56 -38
- package/dist/translator/util/references.d.ts +1 -5
- package/package.json +1 -1
package/dist/translator/index.js
CHANGED
|
@@ -1364,7 +1364,7 @@ function analyzeExpressionTagName(name, extra) {
|
|
|
1364
1364
|
if (binding.kind === "module") {
|
|
1365
1365
|
const decl = binding.path.parent;
|
|
1366
1366
|
if (MARKO_FILE_REG.test(decl.source.value) && decl.specifiers.some((it) => _marko_compiler.types.isImportDefaultSpecifier(it))) {
|
|
1367
|
-
const resolvedImport =
|
|
1367
|
+
const resolvedImport = decl.extra?.tagImport || decl.source.value;
|
|
1368
1368
|
if (type === void 0) {
|
|
1369
1369
|
type = 1;
|
|
1370
1370
|
tagNameImported = resolvedImport;
|
|
@@ -2159,6 +2159,7 @@ const pureDOMFunctions = new Set([
|
|
|
2159
2159
|
"_for_to",
|
|
2160
2160
|
"_for_until",
|
|
2161
2161
|
"_let",
|
|
2162
|
+
"_let_change",
|
|
2162
2163
|
"_const"
|
|
2163
2164
|
]);
|
|
2164
2165
|
function importRuntime(name) {
|
|
@@ -2167,10 +2168,7 @@ function importRuntime(name) {
|
|
|
2167
2168
|
}
|
|
2168
2169
|
function callRuntime(name, ...args) {
|
|
2169
2170
|
const callExpression = _marko_compiler.types.callExpression(importRuntime(name), filterArguments(args));
|
|
2170
|
-
if (isOutputDOM() && pureDOMFunctions.has(name)) callExpression
|
|
2171
|
-
type: "CommentBlock",
|
|
2172
|
-
value: ` @__PURE__ `
|
|
2173
|
-
}];
|
|
2171
|
+
if (isOutputDOM() && pureDOMFunctions.has(name)) return _marko_compiler.types.addComment(callExpression, "leading", "@__PURE__");
|
|
2174
2172
|
return callExpression;
|
|
2175
2173
|
}
|
|
2176
2174
|
function getHTMLRuntime() {
|
|
@@ -2943,7 +2941,7 @@ function initValue(binding, isLet = false) {
|
|
|
2943
2941
|
signal.build = () => {
|
|
2944
2942
|
const fn = getSignalFn(signal);
|
|
2945
2943
|
if (binding.upstreamAlias && binding.property === void 0 && binding.excludeProperties === void 0 || !signal.hasSideEffect || !signalHasStatements(signal)) return fn;
|
|
2946
|
-
return callRuntime(isLet ? "_let" : "_const", getScopeAccessorLiteral(binding, true, isLet), fn);
|
|
2944
|
+
return callRuntime(isLet ? signal.extraArgs ? "_let_change" : "_let" : "_const", getScopeAccessorLiteral(binding, true, isLet), fn);
|
|
2947
2945
|
};
|
|
2948
2946
|
for (const alias of binding.aliases) if (alias.type !== 6) initValue(alias);
|
|
2949
2947
|
for (const alias of binding.propertyAliases.values()) if (alias.type !== 6) initValue(alias);
|
|
@@ -2966,19 +2964,24 @@ function getSignalFn(signal) {
|
|
|
2966
2964
|
for (const alias of binding.aliases) {
|
|
2967
2965
|
const aliasSignal = getSignal(alias.section, alias);
|
|
2968
2966
|
if (signalHasStatements(aliasSignal)) if (alias.excludeProperties !== void 0) {
|
|
2969
|
-
const props = [];
|
|
2970
2967
|
const aliasId = _marko_compiler.types.identifier(alias.name);
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
props
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2968
|
+
let pattern;
|
|
2969
|
+
if (alias.restOffset) pattern = _marko_compiler.types.arrayPattern(new Array(alias.restOffset).fill(null).concat(_marko_compiler.types.restElement(aliasId)));
|
|
2970
|
+
else {
|
|
2971
|
+
const props = [];
|
|
2972
|
+
forEach(alias.excludeProperties, (name) => {
|
|
2973
|
+
const propId = toPropertyName(name);
|
|
2974
|
+
const shorthand = propId.type === "Identifier" && _marko_compiler.types.isValidIdentifier(name);
|
|
2975
|
+
props.push(_marko_compiler.types.objectProperty(propId, shorthand ? propId : generateUidIdentifier(name), false, shorthand));
|
|
2976
|
+
});
|
|
2977
|
+
props.push(_marko_compiler.types.restElement(aliasId));
|
|
2978
|
+
pattern = _marko_compiler.types.objectPattern(props);
|
|
2979
|
+
}
|
|
2980
|
+
signal.render.push(_marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(_marko_compiler.types.arrowFunctionExpression([pattern], _marko_compiler.types.callExpression(aliasSignal.identifier, [
|
|
2978
2981
|
scopeIdentifier,
|
|
2979
2982
|
aliasId,
|
|
2980
2983
|
...getTranslatedExtraArgs(aliasSignal)
|
|
2981
|
-
])), [binding.nullable ? _marko_compiler.types.logicalExpression("||", createScopeReadExpression(binding), _marko_compiler.types.objectExpression([])) : createScopeReadExpression(binding)])));
|
|
2984
|
+
])), [binding.nullable ? _marko_compiler.types.logicalExpression("||", createScopeReadExpression(binding), alias.restOffset ? _marko_compiler.types.arrayExpression([]) : _marko_compiler.types.objectExpression([])) : createScopeReadExpression(binding)])));
|
|
2982
2985
|
} else signal.render.push(_marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(aliasSignal.identifier, [
|
|
2983
2986
|
scopeIdentifier,
|
|
2984
2987
|
createScopeReadExpression(binding),
|
|
@@ -5655,6 +5658,7 @@ function createBinding(name, type, refSection, upstreamAlias, property, excludeP
|
|
|
5655
5658
|
getters: /* @__PURE__ */ new Map(),
|
|
5656
5659
|
propertyAliases: /* @__PURE__ */ new Map(),
|
|
5657
5660
|
upstreamAlias,
|
|
5661
|
+
restOffset: void 0,
|
|
5658
5662
|
scopeOffset: void 0,
|
|
5659
5663
|
scopeAccessor: void 0,
|
|
5660
5664
|
export: void 0,
|
|
@@ -5725,7 +5729,7 @@ function trackParamsReferences(body, type) {
|
|
|
5725
5729
|
if (bodySection) bodySection.params = paramsBinding;
|
|
5726
5730
|
for (let i = 0; i < params.length; i++) {
|
|
5727
5731
|
const param = params[i];
|
|
5728
|
-
if (param.type === "RestElement") createBindingsAndTrackReferences(param.argument, type, body.scope, section, paramsBinding, void 0, i > 0 ? addNumericPropertiesUntil(void 0, i
|
|
5732
|
+
if (param.type === "RestElement") createBindingsAndTrackReferences(param.argument, type, body.scope, section, paramsBinding, void 0, i > 0 ? addNumericPropertiesUntil(void 0, i) : void 0, i);
|
|
5729
5733
|
else if (_marko_compiler.types.isLVal(param)) createBindingsAndTrackReferences(param, type, body.scope, section, paramsBinding, i + "", void 0);
|
|
5730
5734
|
}
|
|
5731
5735
|
return paramsBinding;
|
|
@@ -5815,11 +5819,14 @@ function setReferencesScope(path) {
|
|
|
5815
5819
|
const fnRoot = getFnRoot(path);
|
|
5816
5820
|
if (fnRoot) (fnRoot.node.extra ??= {}).referencesScope = true;
|
|
5817
5821
|
}
|
|
5818
|
-
function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAlias, property, excludeProperties) {
|
|
5822
|
+
function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAlias, property, excludeProperties, restOffset) {
|
|
5819
5823
|
switch (lVal.type) {
|
|
5820
|
-
case "Identifier":
|
|
5821
|
-
|
|
5824
|
+
case "Identifier": {
|
|
5825
|
+
const binding = (lVal.extra ??= {}).binding = createBinding(lVal.name, type, section, upstreamAlias, property, excludeProperties, lVal.loc, true);
|
|
5826
|
+
if (restOffset) binding.restOffset = restOffset;
|
|
5827
|
+
trackReferencesForBinding(scope.getBinding(lVal.name), binding);
|
|
5822
5828
|
break;
|
|
5829
|
+
}
|
|
5823
5830
|
case "ObjectPattern": {
|
|
5824
5831
|
const patternBinding = (property ? upstreamAlias.propertyAliases.get(property) : upstreamAlias) || ((lVal.extra ??= {}).binding = createBinding(generateUid(property || "pattern"), type, section, upstreamAlias, property, excludeProperties, lVal.loc));
|
|
5825
5832
|
const hasRest = lVal.properties[lVal.properties.length - 1]?.type === "RestElement";
|
|
@@ -5844,8 +5851,8 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
|
|
|
5844
5851
|
i++;
|
|
5845
5852
|
if (element) {
|
|
5846
5853
|
if (element.type === "RestElement") {
|
|
5847
|
-
excludeProperties = i > 0 ? addNumericPropertiesUntil(excludeProperties, i
|
|
5848
|
-
createBindingsAndTrackReferences(element.argument, type, scope, section, patternBinding, property, excludeProperties);
|
|
5854
|
+
excludeProperties = i > 0 ? addNumericPropertiesUntil(excludeProperties, i) : void 0;
|
|
5855
|
+
createBindingsAndTrackReferences(element.argument, type, scope, section, patternBinding, property, excludeProperties, i);
|
|
5849
5856
|
} else if (_marko_compiler.types.isLVal(element)) createBindingsAndTrackReferences(element, type, scope, section, patternBinding, `${i}`, void 0);
|
|
5850
5857
|
}
|
|
5851
5858
|
}
|
|
@@ -5859,9 +5866,16 @@ function trackReference(referencePath, binding) {
|
|
|
5859
5866
|
while (true) {
|
|
5860
5867
|
const { parent } = root;
|
|
5861
5868
|
if (!_marko_compiler.types.isMemberExpression(parent) && !_marko_compiler.types.isOptionalMemberExpression(parent)) break;
|
|
5862
|
-
|
|
5869
|
+
let prop = getMemberExpressionPropString(parent);
|
|
5863
5870
|
if (prop === void 0) break;
|
|
5864
|
-
if (reference.upstreamAlias && reference.excludeProperties !== void 0
|
|
5871
|
+
if (reference.upstreamAlias && reference.excludeProperties !== void 0) {
|
|
5872
|
+
if (reference.restOffset) {
|
|
5873
|
+
if (/^\d+$/.test(prop)) {
|
|
5874
|
+
prop = `${+prop + reference.restOffset}`;
|
|
5875
|
+
reference = reference.upstreamAlias;
|
|
5876
|
+
}
|
|
5877
|
+
} else if (!propsUtil.has(reference.excludeProperties, prop)) reference = reference.upstreamAlias;
|
|
5878
|
+
}
|
|
5865
5879
|
if (isInvokedFunction(root.parentPath) && !isEventOrChangeHandler(prop)) break;
|
|
5866
5880
|
root = root.parentPath;
|
|
5867
5881
|
reference = getOrCreatePropertyAlias(reference, prop);
|
|
@@ -5925,8 +5939,7 @@ function finalizeReferences() {
|
|
|
5925
5939
|
for (const [expr, reads] of readsByExpression) if (isReferencedExtra(expr)) {
|
|
5926
5940
|
const exprBindings = resolveReferencedBindings(expr, reads, intersectionsBySection);
|
|
5927
5941
|
expr.referencedBindings = exprBindings.referencedBindings;
|
|
5928
|
-
expr.
|
|
5929
|
-
expr.hoistedBindings = expr.section.referencedHoists = exprBindings.hoistedBindings;
|
|
5942
|
+
if (exprBindings.hoistedBindings) expr.section.referencedHoists = bindingUtil.union(expr.section.referencedHoists, exprBindings.hoistedBindings);
|
|
5930
5943
|
if (expr.isEffect) {
|
|
5931
5944
|
forEach(exprBindings.referencedBindings, (binding) => {
|
|
5932
5945
|
addSerializeReason(binding.section, true, binding);
|
|
@@ -5941,7 +5954,6 @@ function finalizeReferences() {
|
|
|
5941
5954
|
const fnBindings = fn === expr ? exprBindings : resolveReferencedBindingsInFunction(exprBindings.allBindings, fnReads);
|
|
5942
5955
|
fn.referencedBindingsInFunction = fnBindings.referencedBindings;
|
|
5943
5956
|
fn.constantBindingsInFunction = fnBindings.constantBindings;
|
|
5944
|
-
fn.hoistedBindingsInFunction = fnBindings.hoistedBindings;
|
|
5945
5957
|
}
|
|
5946
5958
|
}
|
|
5947
5959
|
}
|
|
@@ -6069,10 +6081,22 @@ function finalizeReferences() {
|
|
|
6069
6081
|
finalizeParamSerializeReasonGroups(section);
|
|
6070
6082
|
});
|
|
6071
6083
|
forEachSection((section) => {
|
|
6072
|
-
let intersectionIndex = 0;
|
|
6073
|
-
const intersections = intersectionsBySection.get(section) || [];
|
|
6074
6084
|
const { id, bindings } = section;
|
|
6075
6085
|
const isOwnedBinding = ({ section }) => section.id === id;
|
|
6086
|
+
let intersections = intersectionsBySection.get(section) || [];
|
|
6087
|
+
if (intersections.length) {
|
|
6088
|
+
const anchors = /* @__PURE__ */ new Map();
|
|
6089
|
+
for (const intersection of intersections) for (let i = intersection.length; i--;) if (isOwnedBinding(intersection[i])) {
|
|
6090
|
+
anchors.set(intersection, intersection[i]);
|
|
6091
|
+
break;
|
|
6092
|
+
}
|
|
6093
|
+
intersections = [...intersections].sort((a, b) => {
|
|
6094
|
+
const aAnchor = anchors.get(a);
|
|
6095
|
+
const bAnchor = anchors.get(b);
|
|
6096
|
+
return aAnchor ? bAnchor ? bindingUtil.compare(aAnchor, bAnchor) : -1 : bAnchor ? 1 : 0;
|
|
6097
|
+
});
|
|
6098
|
+
}
|
|
6099
|
+
let intersectionIndex = 0;
|
|
6076
6100
|
let lastBindingIndex = 0;
|
|
6077
6101
|
let intersection;
|
|
6078
6102
|
forEach(filter(bindings, isOwnedBinding), (binding, bindingIndex) => {
|
|
@@ -6421,27 +6445,21 @@ function pruneBinding(binding) {
|
|
|
6421
6445
|
function resolveReferencedBindingsInFunction(refs, reads) {
|
|
6422
6446
|
let referencedBindings;
|
|
6423
6447
|
let constantBindings;
|
|
6424
|
-
let hoistedBindings;
|
|
6425
6448
|
if (reads) if (Array.isArray(reads)) for (const read of reads) {
|
|
6426
6449
|
const { getter, binding } = read;
|
|
6427
|
-
if (getter) {
|
|
6428
|
-
if (getter.hoisted && bindingUtil.find(refs, binding)) hoistedBindings = bindingUtil.add(hoistedBindings, binding);
|
|
6429
|
-
} else if (binding.type === 6) {
|
|
6450
|
+
if (getter) {} else if (binding.type === 6) {
|
|
6430
6451
|
if (bindingUtil.find(refs, binding)) constantBindings = bindingUtil.add(constantBindings, binding);
|
|
6431
6452
|
} else if (binding.type !== 0) referencedBindings = bindingUtil.add(referencedBindings, findClosestReference(read.binding, refs));
|
|
6432
6453
|
}
|
|
6433
6454
|
else {
|
|
6434
6455
|
const { getter, binding } = reads;
|
|
6435
|
-
if (getter) {
|
|
6436
|
-
if (getter.hoisted && bindingUtil.find(refs, binding)) hoistedBindings = binding;
|
|
6437
|
-
} else if (binding.type === 6) {
|
|
6456
|
+
if (getter) {} else if (binding.type === 6) {
|
|
6438
6457
|
if (bindingUtil.find(refs, binding)) constantBindings = binding;
|
|
6439
6458
|
} else if (binding.type !== 0) referencedBindings = findClosestReference(binding, refs);
|
|
6440
6459
|
}
|
|
6441
6460
|
return {
|
|
6442
6461
|
referencedBindings,
|
|
6443
|
-
constantBindings
|
|
6444
|
-
hoistedBindings
|
|
6462
|
+
constantBindings
|
|
6445
6463
|
};
|
|
6446
6464
|
}
|
|
6447
6465
|
function findClosestReference(from, refs) {
|
|
@@ -6538,7 +6556,7 @@ function resolveReferencedBindings(expr, reads, intersectionsBySection) {
|
|
|
6538
6556
|
}
|
|
6539
6557
|
if (referencedBindings && constantBindings) {
|
|
6540
6558
|
const intersections = intersectionsBySection.get(expr.section) || [];
|
|
6541
|
-
const combined =
|
|
6559
|
+
const combined = bindingUtil.union(referencedBindings, constantBindings);
|
|
6542
6560
|
if (!findSorted(compareIntersections, intersections, combined)) intersectionsBySection.set(expr.section, addSorted(compareIntersections, intersections, combined));
|
|
6543
6561
|
}
|
|
6544
6562
|
return {
|
|
@@ -3,7 +3,6 @@ import { type Many, type Opt, Sorted } from "./optional";
|
|
|
3
3
|
import { type Section } from "./sections";
|
|
4
4
|
import { type SerializeReason } from "./serialize-reasons";
|
|
5
5
|
import { type Signal } from "./signals";
|
|
6
|
-
declare const kIsInvoked: unique symbol;
|
|
7
6
|
export declare const kBranchSerializeReason: unique symbol;
|
|
8
7
|
export type Aliases = undefined | Binding | {
|
|
9
8
|
[property: string]: Aliases;
|
|
@@ -39,6 +38,7 @@ export interface Binding {
|
|
|
39
38
|
propertyAliases: Map<string, Binding>;
|
|
40
39
|
excludeProperties: Opt<string>;
|
|
41
40
|
upstreamAlias: Binding | undefined;
|
|
41
|
+
restOffset: number | undefined;
|
|
42
42
|
scopeOffset: Binding | undefined;
|
|
43
43
|
scopeAccessor: string | undefined;
|
|
44
44
|
export: string | undefined;
|
|
@@ -76,8 +76,6 @@ declare module "@marko/compiler/dist/types" {
|
|
|
76
76
|
interface NodeExtra {
|
|
77
77
|
section?: Section;
|
|
78
78
|
referencedBindings?: ReferencedBindings;
|
|
79
|
-
constantBindings?: ReferencedBindings;
|
|
80
|
-
hoistedBindings?: ReferencedBindings;
|
|
81
79
|
downstream?: Opt<Binding>;
|
|
82
80
|
binding?: Binding;
|
|
83
81
|
assignment?: Binding;
|
|
@@ -87,13 +85,11 @@ declare module "@marko/compiler/dist/types" {
|
|
|
87
85
|
isEffect?: true;
|
|
88
86
|
spreadFrom?: Binding;
|
|
89
87
|
merged?: NodeExtra;
|
|
90
|
-
[kIsInvoked]?: true;
|
|
91
88
|
}
|
|
92
89
|
interface FunctionExtra {
|
|
93
90
|
referencesScope?: boolean;
|
|
94
91
|
referencedBindingsInFunction?: ReferencedBindings;
|
|
95
92
|
constantBindingsInFunction?: ReferencedBindings;
|
|
96
|
-
hoistedBindingsInFunction?: ReferencedBindings;
|
|
97
93
|
name?: string;
|
|
98
94
|
registerId?: string;
|
|
99
95
|
registerReason?: SerializeReason;
|