marko 6.0.32 → 6.0.33
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/translator/index.js
CHANGED
@@ -538,6 +538,36 @@ function forEachIdentifier(node, cb) {
|
|
538
538
|
break;
|
539
539
|
}
|
540
540
|
}
|
541
|
+
function forEachIdentifierPath(nodePath, cb) {
|
542
|
+
if (nodePath.isIdentifier()) {
|
543
|
+
cb(nodePath);
|
544
|
+
} else if (nodePath.isObjectPattern()) {
|
545
|
+
for (const prop of nodePath.get("properties")) {
|
546
|
+
if (prop.isObjectProperty()) {
|
547
|
+
const value = prop.get("value");
|
548
|
+
if (value.isAssignmentPattern()) {
|
549
|
+
forEachIdentifierPath(value.get("left"), cb);
|
550
|
+
} else {
|
551
|
+
forEachIdentifierPath(value, cb);
|
552
|
+
}
|
553
|
+
} else if (prop.isRestElement()) {
|
554
|
+
forEachIdentifierPath(prop.get("argument"), cb);
|
555
|
+
}
|
556
|
+
}
|
557
|
+
} else if (nodePath.isArrayPattern()) {
|
558
|
+
for (const el of nodePath.get("elements")) {
|
559
|
+
if (el) {
|
560
|
+
if (el.isRestElement()) {
|
561
|
+
forEachIdentifierPath(el.get("argument"), cb);
|
562
|
+
} else if (el.isAssignmentPattern()) {
|
563
|
+
forEachIdentifierPath(el.get("left"), cb);
|
564
|
+
} else {
|
565
|
+
forEachIdentifierPath(el, cb);
|
566
|
+
}
|
567
|
+
}
|
568
|
+
}
|
569
|
+
}
|
570
|
+
}
|
541
571
|
|
542
572
|
// src/translator/util/generate-uid.ts
|
543
573
|
var import_compiler3 = require("@marko/compiler");
|
@@ -3884,10 +3914,7 @@ function replaceAssignedNode(node) {
|
|
3884
3914
|
case "UpdateExpression": {
|
3885
3915
|
const { extra } = node.argument;
|
3886
3916
|
if (isAssignedBindingExtra(extra)) {
|
3887
|
-
const
|
3888
|
-
extra.assignment.section,
|
3889
|
-
extra.assignment
|
3890
|
-
);
|
3917
|
+
const buildAssignment = getBuildAssignment(extra);
|
3891
3918
|
if (buildAssignment) {
|
3892
3919
|
const replacement = buildAssignment(
|
3893
3920
|
extra.section,
|
@@ -3910,10 +3937,7 @@ function replaceAssignedNode(node) {
|
|
3910
3937
|
case "Identifier": {
|
3911
3938
|
const { extra } = node.left;
|
3912
3939
|
if (isAssignedBindingExtra(extra)) {
|
3913
|
-
const
|
3914
|
-
extra.assignment.section,
|
3915
|
-
extra.assignment
|
3916
|
-
);
|
3940
|
+
const buildAssignment = getBuildAssignment(extra);
|
3917
3941
|
if (buildAssignment) {
|
3918
3942
|
return buildAssignment(
|
3919
3943
|
extra.section,
|
@@ -3937,15 +3961,12 @@ function replaceAssignedNode(node) {
|
|
3937
3961
|
forEachIdentifier(node.left, (id) => {
|
3938
3962
|
const { extra } = id;
|
3939
3963
|
if (isAssignedBindingExtra(extra)) {
|
3940
|
-
const
|
3941
|
-
|
3942
|
-
extra.assignment
|
3943
|
-
);
|
3944
|
-
if (signal?.buildAssignment) {
|
3964
|
+
const buildAssignment = getBuildAssignment(extra);
|
3965
|
+
if (buildAssignment) {
|
3945
3966
|
id.name = generateUid(id.name);
|
3946
3967
|
(params ||= []).push(import_compiler20.types.identifier(id.name));
|
3947
3968
|
(assignments ||= []).push(
|
3948
|
-
|
3969
|
+
buildAssignment(extra.section, import_compiler20.types.identifier(id.name))
|
3949
3970
|
);
|
3950
3971
|
}
|
3951
3972
|
}
|
@@ -3974,6 +3995,15 @@ function replaceAssignedNode(node) {
|
|
3974
3995
|
break;
|
3975
3996
|
}
|
3976
3997
|
}
|
3998
|
+
function getBuildAssignment(extra) {
|
3999
|
+
const { assignmentTo, assignment } = extra;
|
4000
|
+
if (assignmentTo) {
|
4001
|
+
return (_section, value) => {
|
4002
|
+
return import_compiler20.types.callExpression(import_compiler20.types.identifier(assignmentTo.name), [value]);
|
4003
|
+
};
|
4004
|
+
}
|
4005
|
+
return getSignal(assignment.section, assignment).buildAssignment;
|
4006
|
+
}
|
3977
4007
|
var registeredFnsForProgram = /* @__PURE__ */ new WeakMap();
|
3978
4008
|
function replaceRegisteredFunctionNode2(node) {
|
3979
4009
|
switch (node.type) {
|
@@ -4531,9 +4561,23 @@ function trackReferencesForBinding(babelBinding, binding) {
|
|
4531
4561
|
function trackAssignment(assignment, binding) {
|
4532
4562
|
const section = getOrCreateSection(assignment);
|
4533
4563
|
setReferencesScope(assignment);
|
4534
|
-
|
4535
|
-
if (id.name === binding.name) {
|
4536
|
-
const extra = id.extra ??= {};
|
4564
|
+
forEachIdentifierPath(assignment, (id) => {
|
4565
|
+
if (id.node.name === binding.name) {
|
4566
|
+
const extra = id.node.extra ??= {};
|
4567
|
+
if (binding.upstreamAlias && binding.property !== void 0) {
|
4568
|
+
const changePropName = binding.property + "Change";
|
4569
|
+
const changeBinding = binding.upstreamAlias.propertyAliases.get(changePropName) || createBinding(
|
4570
|
+
generateUid(changePropName),
|
4571
|
+
5 /* derived */,
|
4572
|
+
binding.section,
|
4573
|
+
binding.upstreamAlias,
|
4574
|
+
changePropName,
|
4575
|
+
id.node.loc,
|
4576
|
+
true
|
4577
|
+
);
|
4578
|
+
extra.assignmentTo = changeBinding;
|
4579
|
+
addReadToExpression(id, changeBinding);
|
4580
|
+
}
|
4537
4581
|
binding.assignmentSections = sectionUtil.add(
|
4538
4582
|
binding.assignmentSections,
|
4539
4583
|
section
|
@@ -4680,21 +4724,7 @@ function trackReference(referencePath, binding) {
|
|
4680
4724
|
prop
|
4681
4725
|
);
|
4682
4726
|
}
|
4683
|
-
|
4684
|
-
const exprRoot = getExprRoot(fnRoot || root);
|
4685
|
-
const { section } = addReadToExpression(exprRoot, reference, root.node);
|
4686
|
-
if (fnRoot) {
|
4687
|
-
const readsByFn = getReadsByFunction();
|
4688
|
-
const fnExtra = fnRoot.node.extra ??= {};
|
4689
|
-
fnExtra.section = section;
|
4690
|
-
readsByFn.set(
|
4691
|
-
fnExtra,
|
4692
|
-
push(readsByFn.get(fnExtra), {
|
4693
|
-
binding: reference,
|
4694
|
-
node: root.node
|
4695
|
-
})
|
4696
|
-
);
|
4697
|
-
}
|
4727
|
+
addReadToExpression(root, reference);
|
4698
4728
|
}
|
4699
4729
|
var [getMergedReferences] = createProgramState(
|
4700
4730
|
() => /* @__PURE__ */ new Map()
|
@@ -5142,15 +5172,24 @@ var [getReadsByExpression] = createProgramState(
|
|
5142
5172
|
var [getReadsByFunction] = createProgramState(
|
5143
5173
|
() => /* @__PURE__ */ new Map()
|
5144
5174
|
);
|
5145
|
-
function addReadToExpression(
|
5146
|
-
const
|
5175
|
+
function addReadToExpression(root, binding) {
|
5176
|
+
const { node } = root;
|
5177
|
+
const fnRoot = getFnRoot(root);
|
5178
|
+
const exprRoot = getExprRoot(fnRoot || root);
|
5179
|
+
const exprExtra = exprRoot.node.extra ??= {};
|
5147
5180
|
const readsByExpression = getReadsByExpression();
|
5148
|
-
exprExtra.section = getOrCreateSection(
|
5181
|
+
const section = exprExtra.section = getOrCreateSection(exprRoot);
|
5182
|
+
const read = { binding, node };
|
5149
5183
|
readsByExpression.set(
|
5150
5184
|
exprExtra,
|
5151
|
-
push(readsByExpression.get(exprExtra),
|
5185
|
+
push(readsByExpression.get(exprExtra), read)
|
5152
5186
|
);
|
5153
|
-
|
5187
|
+
if (fnRoot) {
|
5188
|
+
const readsByFn = getReadsByFunction();
|
5189
|
+
const fnExtra = fnRoot.node.extra ??= {};
|
5190
|
+
fnExtra.section = section;
|
5191
|
+
readsByFn.set(fnExtra, push(readsByFn.get(fnExtra), read));
|
5192
|
+
}
|
5154
5193
|
}
|
5155
5194
|
function dropReferences(node) {
|
5156
5195
|
if (Array.isArray(node)) {
|
@@ -5561,10 +5600,36 @@ function translateVar(tag, initialValue, kind = "const") {
|
|
5561
5600
|
if (!tagVar) {
|
5562
5601
|
return;
|
5563
5602
|
}
|
5603
|
+
forEachIdentifierPath(tag.get("var"), (id) => {
|
5604
|
+
const binding = id.node.extra?.binding;
|
5605
|
+
if (!binding || !binding.upstreamAlias || !binding.assignmentSections || id.node === tagVar) {
|
5606
|
+
return;
|
5607
|
+
}
|
5608
|
+
const changeName = binding.name + "Change";
|
5609
|
+
const changeBinding = binding.upstreamAlias.propertyAliases.get(changeName);
|
5610
|
+
if (changeBinding && changeName !== changeBinding.name) {
|
5611
|
+
getDestructurePattern(id)?.pushContainer(
|
5612
|
+
"properties",
|
5613
|
+
import_compiler27.types.objectProperty(
|
5614
|
+
import_compiler27.types.identifier(changeName),
|
5615
|
+
import_compiler27.types.identifier(changeBinding.name)
|
5616
|
+
)
|
5617
|
+
);
|
5618
|
+
}
|
5619
|
+
});
|
5564
5620
|
tag.insertBefore(
|
5565
5621
|
import_compiler27.types.variableDeclaration(kind, [import_compiler27.types.variableDeclarator(tagVar, initialValue)])
|
5566
5622
|
);
|
5567
5623
|
}
|
5624
|
+
function getDestructurePattern(id) {
|
5625
|
+
let cur = id;
|
5626
|
+
while (cur) {
|
5627
|
+
if (cur.node.type === "ObjectPattern") {
|
5628
|
+
return cur;
|
5629
|
+
}
|
5630
|
+
cur = cur.parentPath;
|
5631
|
+
}
|
5632
|
+
}
|
5568
5633
|
|
5569
5634
|
// src/translator/core/const.ts
|
5570
5635
|
var const_default = {
|
@@ -1,2 +1,3 @@
|
|
1
1
|
import type { types as t } from "@marko/compiler";
|
2
2
|
export declare function forEachIdentifier(node: t.Node, cb: (identifier: t.Identifier) => void): void;
|
3
|
+
export declare function forEachIdentifierPath(nodePath: t.NodePath<any>, cb: (identifier: t.NodePath<t.Identifier>) => void): void;
|
@@ -51,6 +51,7 @@ declare module "@marko/compiler/dist/types" {
|
|
51
51
|
referencedBindings?: ReferencedBindings;
|
52
52
|
binding?: Binding;
|
53
53
|
assignment?: Binding;
|
54
|
+
assignmentTo?: Binding;
|
54
55
|
read?: {
|
55
56
|
binding: Binding;
|
56
57
|
props: Opt<string>;
|
@@ -86,7 +87,6 @@ export declare function createSources(state: Sources["state"], input: Sources["i
|
|
86
87
|
export declare function compareSources(a: Sources, b: Sources): number;
|
87
88
|
export declare function mergeSources(a: undefined | Sources, b: undefined | Sources): Sources | undefined;
|
88
89
|
export declare const bindingUtil: Sorted<Binding>;
|
89
|
-
export declare function addReadToExpression(path: t.NodePath, binding: Binding, node?: t.Identifier | t.MemberExpression): ReferencedExtra;
|
90
90
|
export declare function dropReferences(node: t.Node | t.Node[]): void;
|
91
91
|
export declare function getCanonicalBinding(binding?: Binding): Binding | undefined;
|
92
92
|
export declare function getAllTagReferenceNodes(tag: t.MarkoTag, referenceNodes?: t.Node[]): t.Node[];
|