marko 6.0.134 → 6.0.136
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
|
@@ -3626,7 +3626,13 @@ function getSignalFn(signal) {
|
|
|
3626
3626
|
...getTranslatedExtraArgs(aliasSignal)
|
|
3627
3627
|
])
|
|
3628
3628
|
),
|
|
3629
|
-
[
|
|
3629
|
+
[
|
|
3630
|
+
binding.nullable ? import_compiler22.types.logicalExpression(
|
|
3631
|
+
"||",
|
|
3632
|
+
createScopeReadExpression(binding),
|
|
3633
|
+
import_compiler22.types.objectExpression([])
|
|
3634
|
+
) : createScopeReadExpression(binding)
|
|
3635
|
+
]
|
|
3630
3636
|
)
|
|
3631
3637
|
)
|
|
3632
3638
|
);
|
|
@@ -4399,23 +4405,20 @@ function replaceAssignedNode(node) {
|
|
|
4399
4405
|
switch (node.left.type) {
|
|
4400
4406
|
case "Identifier": {
|
|
4401
4407
|
const { extra } = node.left;
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
node.operator
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
) || extra?.assignment && withLeadingComment(node.right, getDebugName(extra.assignment));
|
|
4417
|
-
}
|
|
4418
|
-
break;
|
|
4408
|
+
return isAssignedBindingExtra(extra) && getBuildAssignment(extra)?.(
|
|
4409
|
+
extra.section,
|
|
4410
|
+
node.operator === "=" ? node.right : import_compiler22.types.binaryExpression(
|
|
4411
|
+
node.operator.slice(
|
|
4412
|
+
0,
|
|
4413
|
+
-1
|
|
4414
|
+
),
|
|
4415
|
+
createScopeReadExpression(
|
|
4416
|
+
extra.assignment,
|
|
4417
|
+
extra.section
|
|
4418
|
+
),
|
|
4419
|
+
node.right
|
|
4420
|
+
)
|
|
4421
|
+
) || extra?.assignment && withLeadingComment(node.right, getDebugName(extra.assignment));
|
|
4419
4422
|
}
|
|
4420
4423
|
case "ArrayPattern":
|
|
4421
4424
|
case "ObjectPattern": {
|
|
@@ -4443,7 +4446,7 @@ function replaceAssignedNode(node) {
|
|
|
4443
4446
|
(params ||= []).push(import_compiler22.types.identifier(id.name));
|
|
4444
4447
|
}
|
|
4445
4448
|
});
|
|
4446
|
-
if (assignments) {
|
|
4449
|
+
if (assignments || params) {
|
|
4447
4450
|
const resultId = generateUid("result");
|
|
4448
4451
|
return import_compiler22.types.callExpression(
|
|
4449
4452
|
import_compiler22.types.arrowFunctionExpression(
|
|
@@ -4454,7 +4457,7 @@ function replaceAssignedNode(node) {
|
|
|
4454
4457
|
node.left,
|
|
4455
4458
|
import_compiler22.types.identifier(resultId)
|
|
4456
4459
|
),
|
|
4457
|
-
...assignments,
|
|
4460
|
+
...assignments || [],
|
|
4458
4461
|
import_compiler22.types.identifier(resultId)
|
|
4459
4462
|
])
|
|
4460
4463
|
),
|
|
@@ -5583,34 +5586,77 @@ function translateVar(tag, initialValue, kind = "const") {
|
|
|
5583
5586
|
if (!tagVar) {
|
|
5584
5587
|
return;
|
|
5585
5588
|
}
|
|
5589
|
+
const tagSection = getOrCreateSection(tag);
|
|
5586
5590
|
forEachIdentifierPath(tag.get("var"), (id) => {
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5591
|
+
if (id.node === tagVar) return;
|
|
5592
|
+
const idExtra = id.node.extra;
|
|
5593
|
+
if (!idExtra) return;
|
|
5594
|
+
const binding = idExtra.binding;
|
|
5595
|
+
if (!binding?.upstreamAlias) return;
|
|
5596
|
+
if (binding.assignmentSections && binding.property !== void 0) {
|
|
5597
|
+
const changeName = binding.property + "Change";
|
|
5598
|
+
const changeBinding = binding.upstreamAlias.propertyAliases.get(changeName);
|
|
5599
|
+
if (changeBinding && changeName !== changeBinding.name) {
|
|
5600
|
+
const pattern = getDestructurePattern(id);
|
|
5601
|
+
if (pattern) {
|
|
5602
|
+
pattern.unshiftContainer(
|
|
5603
|
+
"properties",
|
|
5604
|
+
import_compiler32.types.objectProperty(
|
|
5605
|
+
import_compiler32.types.identifier(changeName),
|
|
5606
|
+
import_compiler32.types.identifier(changeBinding.name)
|
|
5607
|
+
)
|
|
5608
|
+
);
|
|
5609
|
+
const lastProperty = pattern.get("properties").at(-1);
|
|
5610
|
+
if (lastProperty?.node.type === "RestElement") {
|
|
5611
|
+
const restBinding = lastProperty.node.argument.extra?.binding;
|
|
5612
|
+
if (restBinding) {
|
|
5613
|
+
restBinding.excludeProperties = propsUtil.add(
|
|
5614
|
+
restBinding.excludeProperties,
|
|
5615
|
+
changeName
|
|
5616
|
+
);
|
|
5617
|
+
}
|
|
5618
|
+
}
|
|
5619
|
+
}
|
|
5620
|
+
}
|
|
5590
5621
|
}
|
|
5591
|
-
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
pattern.unshiftContainer(
|
|
5597
|
-
"properties",
|
|
5598
|
-
import_compiler32.types.objectProperty(
|
|
5599
|
-
import_compiler32.types.identifier(changeName),
|
|
5600
|
-
import_compiler32.types.identifier(changeBinding.name)
|
|
5601
|
-
)
|
|
5622
|
+
if (binding.section !== tagSection && binding.excludeProperties !== void 0 && getSerializeReason(binding.section, binding)) {
|
|
5623
|
+
const restPath = id.parentPath;
|
|
5624
|
+
if (restPath.type !== "RestElement") {
|
|
5625
|
+
throw restPath.buildCodeFrameError(
|
|
5626
|
+
"Invalid compiler state, found a rest binding outside of a rest element."
|
|
5602
5627
|
);
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5628
|
+
}
|
|
5629
|
+
let curPath = tag.parentPath;
|
|
5630
|
+
while (curPath) {
|
|
5631
|
+
if (curPath.node.extra?.section === binding.section) {
|
|
5632
|
+
const canonicalUpstreamAlias = getCanonicalBinding(
|
|
5633
|
+
binding.upstreamAlias
|
|
5634
|
+
);
|
|
5635
|
+
const props = toArray(
|
|
5636
|
+
binding.excludeProperties,
|
|
5637
|
+
(name2) => import_compiler32.types.objectProperty(
|
|
5638
|
+
toPropertyName(name2),
|
|
5639
|
+
generateUidIdentifier(name2)
|
|
5640
|
+
)
|
|
5641
|
+
);
|
|
5642
|
+
props.push(restPath.node);
|
|
5643
|
+
curPath.insertBefore(
|
|
5644
|
+
import_compiler32.types.variableDeclaration(kind, [
|
|
5645
|
+
import_compiler32.types.variableDeclarator(
|
|
5646
|
+
import_compiler32.types.objectPattern(props),
|
|
5647
|
+
canonicalUpstreamAlias.nullable ? import_compiler32.types.logicalExpression(
|
|
5648
|
+
"||",
|
|
5649
|
+
getDeclaredBindingExpression(canonicalUpstreamAlias),
|
|
5650
|
+
import_compiler32.types.objectExpression([])
|
|
5651
|
+
) : getDeclaredBindingExpression(canonicalUpstreamAlias)
|
|
5652
|
+
)
|
|
5653
|
+
])
|
|
5654
|
+
);
|
|
5655
|
+
break;
|
|
5612
5656
|
}
|
|
5657
|
+
curPath = curPath.parentPath;
|
|
5613
5658
|
}
|
|
5659
|
+
restPath.remove();
|
|
5614
5660
|
}
|
|
5615
5661
|
});
|
|
5616
5662
|
tag.insertBefore(
|
|
@@ -8485,8 +8531,11 @@ var kIsInvoked = Symbol("hoist is invoked");
|
|
|
8485
8531
|
var kBranchSerializeReason = Symbol("branch serialize reason");
|
|
8486
8532
|
var [getBindings] = createProgramState(() => /* @__PURE__ */ new Set());
|
|
8487
8533
|
var [getNextBindingId, setNextBindingId] = createProgramState(() => 0);
|
|
8488
|
-
function createBinding(name2, type,
|
|
8534
|
+
function createBinding(name2, type, refSection, upstreamAlias, property, excludeProperties, loc = null, refDeclared = false) {
|
|
8489
8535
|
const id = getNextBindingId();
|
|
8536
|
+
const section = upstreamAlias ? upstreamAlias.section : refSection;
|
|
8537
|
+
const sameSection = refSection === section;
|
|
8538
|
+
const declared = sameSection && refDeclared;
|
|
8490
8539
|
const binding = {
|
|
8491
8540
|
id,
|
|
8492
8541
|
name: name2,
|
|
@@ -8507,7 +8556,7 @@ function createBinding(name2, type, section, upstreamAlias, property, excludePro
|
|
|
8507
8556
|
scopeOffset: void 0,
|
|
8508
8557
|
scopeAccessor: void 0,
|
|
8509
8558
|
export: void 0,
|
|
8510
|
-
nullable: excludeProperties === void 0,
|
|
8559
|
+
nullable: !sameSection || excludeProperties === void 0,
|
|
8511
8560
|
pruned: void 0
|
|
8512
8561
|
};
|
|
8513
8562
|
if (property) {
|
|
@@ -8581,6 +8630,7 @@ function trackDomVarReferences(tag, binding) {
|
|
|
8581
8630
|
function trackVarReferences(tag, type, upstreamAlias) {
|
|
8582
8631
|
const tagVar = tag.node.var;
|
|
8583
8632
|
if (tagVar) {
|
|
8633
|
+
const section = getOrCreateSection(tag);
|
|
8584
8634
|
let canonicalUpstreamAlias = upstreamAlias && getCanonicalBinding(upstreamAlias);
|
|
8585
8635
|
if (canonicalUpstreamAlias) {
|
|
8586
8636
|
const { excludeProperties } = canonicalUpstreamAlias;
|
|
@@ -8591,7 +8641,7 @@ function trackVarReferences(tag, type, upstreamAlias) {
|
|
|
8591
8641
|
tagVar,
|
|
8592
8642
|
canonicalUpstreamAlias.type,
|
|
8593
8643
|
tag.scope,
|
|
8594
|
-
|
|
8644
|
+
section,
|
|
8595
8645
|
canonicalUpstreamAlias,
|
|
8596
8646
|
void 0,
|
|
8597
8647
|
excludeProperties
|
|
@@ -8602,7 +8652,7 @@ function trackVarReferences(tag, type, upstreamAlias) {
|
|
|
8602
8652
|
tagVar,
|
|
8603
8653
|
type,
|
|
8604
8654
|
tag.scope,
|
|
8605
|
-
|
|
8655
|
+
section,
|
|
8606
8656
|
void 0,
|
|
8607
8657
|
void 0,
|
|
8608
8658
|
void 0
|
|
@@ -8761,6 +8811,7 @@ function trackAssignment(assignment, binding) {
|
|
|
8761
8811
|
if (id.node.name === binding.name) {
|
|
8762
8812
|
const idExtra = id.node.extra ??= {};
|
|
8763
8813
|
idExtra.assignment = binding;
|
|
8814
|
+
idExtra.section = section;
|
|
8764
8815
|
binding.assignmentSections = sectionUtil.add(
|
|
8765
8816
|
binding.assignmentSections,
|
|
8766
8817
|
section
|
|
@@ -90,7 +90,7 @@ declare module "@marko/compiler/dist/types" {
|
|
|
90
90
|
interface FunctionExpressionExtra extends FunctionExtra {
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
export declare function createBinding(name: string, type: Binding["type"],
|
|
93
|
+
export declare function createBinding(name: string, type: Binding["type"], refSection: Section, upstreamAlias?: Binding["upstreamAlias"], property?: string, excludeProperties?: Opt<string>, loc?: t.SourceLocation | null, refDeclared?: boolean): Binding;
|
|
94
94
|
export declare function getOrCreatePropertyAlias(binding: Binding, property: string): Binding;
|
|
95
95
|
export declare function trackDomVarReferences(tag: t.NodePath<t.MarkoTag>, binding: Binding): Binding | undefined;
|
|
96
96
|
export declare function trackVarReferences(tag: t.NodePath<t.MarkoTag>, type: BindingType, upstreamAlias?: Binding["upstreamAlias"]): Binding | undefined;
|