marko 6.0.97 → 6.0.99
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/helpers.d.ts +1 -0
- package/dist/debug/dom.js +20 -41
- package/dist/debug/dom.mjs +20 -41
- package/dist/dom/renderer.d.ts +1 -1
- package/dist/dom/signals.d.ts +9 -9
- package/dist/dom.d.ts +1 -0
- package/dist/dom.js +21 -36
- package/dist/dom.mjs +21 -36
- package/dist/translator/index.js +193 -249
- package/dist/translator/util/get-root.d.ts +1 -0
- package/package.json +1 -1
package/dist/translator/index.js
CHANGED
|
@@ -719,6 +719,20 @@ function getFnRoot(path5) {
|
|
|
719
719
|
}
|
|
720
720
|
return fnPath;
|
|
721
721
|
}
|
|
722
|
+
function getFnParent(path5) {
|
|
723
|
+
let curPath = path5;
|
|
724
|
+
while (!isMarko(curPath)) {
|
|
725
|
+
if (isFunction(curPath)) {
|
|
726
|
+
return curPath;
|
|
727
|
+
}
|
|
728
|
+
const parentPath = curPath.parentPath;
|
|
729
|
+
if (parentPath) {
|
|
730
|
+
curPath = parentPath;
|
|
731
|
+
} else {
|
|
732
|
+
break;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
722
736
|
function getDeclarationRoot(path5) {
|
|
723
737
|
let curPath = path5;
|
|
724
738
|
let declPath;
|
|
@@ -3130,45 +3144,6 @@ function getDeclaredBindingExpression(binding) {
|
|
|
3130
3144
|
|
|
3131
3145
|
// src/translator/util/scope-read.ts
|
|
3132
3146
|
var import_compiler19 = require("@marko/compiler");
|
|
3133
|
-
function createScopeReadPattern(section, referencedBindings) {
|
|
3134
|
-
const rootDepth = section.depth;
|
|
3135
|
-
const rootPattern = import_compiler19.types.objectPattern([]);
|
|
3136
|
-
let nestedPatterns;
|
|
3137
|
-
forEach(referencedBindings, (ref) => {
|
|
3138
|
-
const propertyValue = ref.name;
|
|
3139
|
-
if (!isValidPropertyIdentifier(propertyValue)) return;
|
|
3140
|
-
const propertyKey = getScopeAccessor(ref);
|
|
3141
|
-
const isShorthand = propertyKey === propertyValue;
|
|
3142
|
-
let pattern = rootPattern;
|
|
3143
|
-
if (ref.section !== section && ref.type !== 4 /* local */) {
|
|
3144
|
-
if (!nestedPatterns) nestedPatterns = [rootPattern];
|
|
3145
|
-
const relativeDepth = rootDepth - ref.section.depth;
|
|
3146
|
-
let i = nestedPatterns.length;
|
|
3147
|
-
let prev = nestedPatterns[i - 1];
|
|
3148
|
-
for (; i <= relativeDepth; i++) {
|
|
3149
|
-
const nestedPattern = import_compiler19.types.objectPattern([]);
|
|
3150
|
-
prev.properties.push(
|
|
3151
|
-
import_compiler19.types.objectProperty(
|
|
3152
|
-
import_compiler19.types.identifier(getAccessorProp().Owner),
|
|
3153
|
-
nestedPattern
|
|
3154
|
-
)
|
|
3155
|
-
);
|
|
3156
|
-
nestedPatterns.push(nestedPattern);
|
|
3157
|
-
prev = nestedPattern;
|
|
3158
|
-
}
|
|
3159
|
-
pattern = nestedPatterns[relativeDepth];
|
|
3160
|
-
}
|
|
3161
|
-
pattern.properties.push(
|
|
3162
|
-
import_compiler19.types.objectProperty(
|
|
3163
|
-
toPropertyName(propertyKey),
|
|
3164
|
-
import_compiler19.types.identifier(propertyValue),
|
|
3165
|
-
false,
|
|
3166
|
-
isShorthand
|
|
3167
|
-
)
|
|
3168
|
-
);
|
|
3169
|
-
});
|
|
3170
|
-
return rootPattern;
|
|
3171
|
-
}
|
|
3172
3147
|
function getScopeExpression(section, targetSection) {
|
|
3173
3148
|
let scope = scopeIdentifier ?? import_compiler19.types.identifier("undefined");
|
|
3174
3149
|
const diff = section.depth - targetSection.depth;
|
|
@@ -3183,7 +3158,7 @@ function getScopeExpression(section, targetSection) {
|
|
|
3183
3158
|
function createScopeReadExpression(section, reference) {
|
|
3184
3159
|
const propName = toPropertyName(getScopeAccessor(reference));
|
|
3185
3160
|
return import_compiler19.types.memberExpression(
|
|
3186
|
-
getScopeExpression(section, reference.section),
|
|
3161
|
+
reference.type === 4 /* local */ ? scopeIdentifier : getScopeExpression(section, reference.section),
|
|
3187
3162
|
propName,
|
|
3188
3163
|
propName.type !== "Identifier"
|
|
3189
3164
|
);
|
|
@@ -3393,20 +3368,10 @@ function signalHasStatements(signal) {
|
|
|
3393
3368
|
function getSignalFn(signal) {
|
|
3394
3369
|
const section = signal.section;
|
|
3395
3370
|
const binding = signal.referencedBindings;
|
|
3396
|
-
const params = [scopeIdentifier];
|
|
3397
3371
|
const isIntersection = Array.isArray(binding);
|
|
3398
3372
|
const isBinding = binding && !isIntersection;
|
|
3399
3373
|
const isValue = isBinding && binding.section === section;
|
|
3400
3374
|
const assertsHoists = isValue && binding.hoists.size && !isOptimize();
|
|
3401
|
-
if (isBinding && (signal.renderReferencedBindings || assertsHoists || binding.aliases.size || binding.propertyAliases.size)) {
|
|
3402
|
-
const valueParam = import_compiler22.types.identifier(binding.name);
|
|
3403
|
-
if (binding.loc) {
|
|
3404
|
-
valueParam.loc = binding.loc;
|
|
3405
|
-
valueParam.start = binding.loc.start.index;
|
|
3406
|
-
valueParam.end = binding.loc.end.index;
|
|
3407
|
-
}
|
|
3408
|
-
params.push(valueParam);
|
|
3409
|
-
}
|
|
3410
3375
|
if (isValue) {
|
|
3411
3376
|
for (const alias of binding.aliases) {
|
|
3412
3377
|
const aliasSignal = getSignal(alias.section, alias);
|
|
@@ -3438,7 +3403,7 @@ function getSignalFn(signal) {
|
|
|
3438
3403
|
...getTranslatedExtraArgs(aliasSignal)
|
|
3439
3404
|
])
|
|
3440
3405
|
),
|
|
3441
|
-
[
|
|
3406
|
+
[createScopeReadExpression(binding.section, binding)]
|
|
3442
3407
|
)
|
|
3443
3408
|
)
|
|
3444
3409
|
);
|
|
@@ -3447,7 +3412,7 @@ function getSignalFn(signal) {
|
|
|
3447
3412
|
import_compiler22.types.expressionStatement(
|
|
3448
3413
|
import_compiler22.types.callExpression(aliasSignal.identifier, [
|
|
3449
3414
|
scopeIdentifier,
|
|
3450
|
-
|
|
3415
|
+
createScopeReadExpression(binding.section, binding),
|
|
3451
3416
|
...getTranslatedExtraArgs(aliasSignal)
|
|
3452
3417
|
])
|
|
3453
3418
|
)
|
|
@@ -3462,7 +3427,7 @@ function getSignalFn(signal) {
|
|
|
3462
3427
|
import_compiler22.types.callExpression(aliasSignal.identifier, [
|
|
3463
3428
|
scopeIdentifier,
|
|
3464
3429
|
toMemberExpression(
|
|
3465
|
-
|
|
3430
|
+
createScopeReadExpression(binding.section, binding),
|
|
3466
3431
|
key,
|
|
3467
3432
|
binding.nullable
|
|
3468
3433
|
),
|
|
@@ -3474,7 +3439,10 @@ function getSignalFn(signal) {
|
|
|
3474
3439
|
if (assertsHoists) {
|
|
3475
3440
|
signal.render.push(
|
|
3476
3441
|
import_compiler22.types.expressionStatement(
|
|
3477
|
-
callRuntime(
|
|
3442
|
+
callRuntime(
|
|
3443
|
+
"_assert_hoist",
|
|
3444
|
+
createScopeReadExpression(binding.section, binding)
|
|
3445
|
+
)
|
|
3478
3446
|
)
|
|
3479
3447
|
);
|
|
3480
3448
|
}
|
|
@@ -3556,42 +3524,25 @@ function getSignalFn(signal) {
|
|
|
3556
3524
|
)
|
|
3557
3525
|
);
|
|
3558
3526
|
}
|
|
3559
|
-
if (isIntersection && signal.renderReferencedBindings) {
|
|
3560
|
-
signal.render.unshift(
|
|
3561
|
-
import_compiler22.types.variableDeclaration("let", [
|
|
3562
|
-
import_compiler22.types.variableDeclarator(
|
|
3563
|
-
createScopeReadPattern(section, signal.renderReferencedBindings),
|
|
3564
|
-
scopeIdentifier
|
|
3565
|
-
)
|
|
3566
|
-
])
|
|
3567
|
-
);
|
|
3568
|
-
}
|
|
3569
3527
|
if (signal.render.length === 1) {
|
|
3570
3528
|
const render = signal.render[0];
|
|
3571
3529
|
if (render.type === "ExpressionStatement") {
|
|
3572
3530
|
const { expression } = render;
|
|
3573
3531
|
if (expression.type === "CallExpression") {
|
|
3574
3532
|
const args = expression.arguments;
|
|
3575
|
-
if (
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
const param = params[i];
|
|
3579
|
-
const arg = args[i];
|
|
3580
|
-
if (arg.type !== "Identifier" || param.type !== "Identifier" || param.name !== arg.name) {
|
|
3581
|
-
break;
|
|
3582
|
-
}
|
|
3583
|
-
}
|
|
3584
|
-
if (i === -1) {
|
|
3585
|
-
if (expression.callee.type === "MemberExpression" && expression.callee.property.type === "Identifier" && expression.callee.property.name === "_") {
|
|
3586
|
-
return expression.callee.object;
|
|
3587
|
-
}
|
|
3588
|
-
return expression.callee;
|
|
3533
|
+
if (args.length === 1 && args[0].type === "Identifier" && args[0].name === scopeIdentifier.name) {
|
|
3534
|
+
if (expression.callee.type === "MemberExpression" && expression.callee.property.type === "Identifier" && expression.callee.property.name === "_") {
|
|
3535
|
+
return expression.callee.object;
|
|
3589
3536
|
}
|
|
3537
|
+
return expression.callee;
|
|
3590
3538
|
}
|
|
3591
3539
|
}
|
|
3592
3540
|
}
|
|
3593
3541
|
}
|
|
3594
|
-
return import_compiler22.types.arrowFunctionExpression(
|
|
3542
|
+
return import_compiler22.types.arrowFunctionExpression(
|
|
3543
|
+
[scopeIdentifier],
|
|
3544
|
+
import_compiler22.types.blockStatement(signal.render)
|
|
3545
|
+
);
|
|
3595
3546
|
}
|
|
3596
3547
|
var hasTranslatedExtraArgs = /* @__PURE__ */ new WeakSet();
|
|
3597
3548
|
var emptyExtraArgs = [];
|
|
@@ -3758,11 +3709,11 @@ function writeSignals(section) {
|
|
|
3758
3709
|
writeSignal(signal);
|
|
3759
3710
|
}
|
|
3760
3711
|
function writeSignal(signal) {
|
|
3761
|
-
if (
|
|
3712
|
+
if (seen.has(signal)) return;
|
|
3762
3713
|
seen.add(signal);
|
|
3763
|
-
for (const
|
|
3764
|
-
writeSignal(
|
|
3765
|
-
traverseReplace(
|
|
3714
|
+
for (const value of signal.values) {
|
|
3715
|
+
writeSignal(value.signal);
|
|
3716
|
+
traverseReplace(value, "value", replaceRenderNode);
|
|
3766
3717
|
}
|
|
3767
3718
|
forEach(signal.intersection, writeSignal);
|
|
3768
3719
|
traverseReplace(signal, "render", replaceRenderNode);
|
|
@@ -3772,11 +3723,6 @@ function writeSignals(section) {
|
|
|
3772
3723
|
const effectIdentifier = import_compiler22.types.identifier(
|
|
3773
3724
|
`${signal.identifier.name}__script`
|
|
3774
3725
|
);
|
|
3775
|
-
const referencedBindings = signal.effectReferencedBindings;
|
|
3776
|
-
const referencesScope = traverseContains(
|
|
3777
|
-
signal.effect,
|
|
3778
|
-
isScopeIdentifier
|
|
3779
|
-
);
|
|
3780
3726
|
effectDeclarator = import_compiler22.types.variableDeclarator(
|
|
3781
3727
|
effectIdentifier,
|
|
3782
3728
|
callRuntime(
|
|
@@ -3785,45 +3731,47 @@ function writeSignals(section) {
|
|
|
3785
3731
|
getResumeRegisterId(section, signal.referencedBindings)
|
|
3786
3732
|
),
|
|
3787
3733
|
import_compiler22.types.arrowFunctionExpression(
|
|
3788
|
-
|
|
3789
|
-
scopeIdentifier,
|
|
3790
|
-
createScopeReadPattern(section, referencedBindings)
|
|
3791
|
-
] : [createScopeReadPattern(section, referencedBindings)] : referencesScope ? [scopeIdentifier] : [],
|
|
3734
|
+
[scopeIdentifier],
|
|
3792
3735
|
toFirstExpressionOrBlock(signal.effect)
|
|
3793
3736
|
)
|
|
3794
3737
|
)
|
|
3795
3738
|
);
|
|
3796
3739
|
}
|
|
3797
|
-
let
|
|
3798
|
-
if (
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
signal.identifier,
|
|
3816
|
-
value.
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3740
|
+
let signalDeclaration;
|
|
3741
|
+
if (signal.build) {
|
|
3742
|
+
let value = signal.build();
|
|
3743
|
+
if (!value || !signal.register && import_compiler22.types.isFunction(value) && import_compiler22.types.isBlockStatement(value.body) && !value.body.body.length) {
|
|
3744
|
+
return;
|
|
3745
|
+
}
|
|
3746
|
+
if (import_compiler22.types.isCallExpression(value)) {
|
|
3747
|
+
replaceNullishAndEmptyFunctionsWith0(value.arguments);
|
|
3748
|
+
}
|
|
3749
|
+
if (signal.register) {
|
|
3750
|
+
value = callRuntime(
|
|
3751
|
+
"_var_resume",
|
|
3752
|
+
import_compiler22.types.stringLiteral(
|
|
3753
|
+
getResumeRegisterId(section, signal.referencedBindings, "var")
|
|
3754
|
+
),
|
|
3755
|
+
value
|
|
3756
|
+
);
|
|
3757
|
+
}
|
|
3758
|
+
const signalDeclarator = import_compiler22.types.variableDeclarator(signal.identifier, value);
|
|
3759
|
+
signalDeclaration = !section.parent && !signal.referencedBindings && (import_compiler22.types.isFunctionExpression(value) || import_compiler22.types.isArrowFunctionExpression(value)) ? import_compiler22.types.functionDeclaration(
|
|
3760
|
+
signal.identifier,
|
|
3761
|
+
value.params,
|
|
3762
|
+
import_compiler22.types.isExpression(value.body) ? import_compiler22.types.blockStatement([import_compiler22.types.expressionStatement(value.body)]) : value.body
|
|
3763
|
+
) : import_compiler22.types.variableDeclaration("const", [signalDeclarator]);
|
|
3764
|
+
if (signal.export) {
|
|
3765
|
+
signalDeclaration = import_compiler22.types.exportNamedDeclaration(signalDeclaration);
|
|
3766
|
+
}
|
|
3821
3767
|
}
|
|
3822
3768
|
const signalStatements = signal.prependStatements || [];
|
|
3823
3769
|
if (effectDeclarator) {
|
|
3824
3770
|
signalStatements.push(import_compiler22.types.variableDeclaration("const", [effectDeclarator]));
|
|
3825
3771
|
}
|
|
3826
|
-
|
|
3772
|
+
if (signalDeclaration) {
|
|
3773
|
+
signalStatements.push(signalDeclaration);
|
|
3774
|
+
}
|
|
3827
3775
|
(0, import_babel_utils15.getProgram)().node.body.push(...signalStatements);
|
|
3828
3776
|
}
|
|
3829
3777
|
}
|
|
@@ -3898,25 +3846,10 @@ function writeRegisteredFns() {
|
|
|
3898
3846
|
if (registeredFns) {
|
|
3899
3847
|
for (const registeredFn of registeredFns) {
|
|
3900
3848
|
let fn;
|
|
3901
|
-
|
|
3902
|
-
scopeIdentifier,
|
|
3903
|
-
import_compiler22.types.assignmentPattern(
|
|
3904
|
-
createScopeReadPattern(
|
|
3905
|
-
registeredFn.section,
|
|
3906
|
-
registeredFn.referencedBindings
|
|
3907
|
-
),
|
|
3908
|
-
scopeIdentifier
|
|
3909
|
-
)
|
|
3910
|
-
] : [
|
|
3911
|
-
createScopeReadPattern(
|
|
3912
|
-
registeredFn.section,
|
|
3913
|
-
registeredFn.referencedBindings
|
|
3914
|
-
)
|
|
3915
|
-
] : registeredFn.referencesScope ? [scopeIdentifier] : void 0;
|
|
3916
|
-
if (params) {
|
|
3849
|
+
if (registeredFn.referencedBindings || registeredFn.referencesScope) {
|
|
3917
3850
|
fn = import_compiler22.types.functionDeclaration(
|
|
3918
3851
|
import_compiler22.types.identifier(registeredFn.id),
|
|
3919
|
-
|
|
3852
|
+
[scopeIdentifier],
|
|
3920
3853
|
import_compiler22.types.blockStatement(toReturnedFunction(registeredFn.node))
|
|
3921
3854
|
);
|
|
3922
3855
|
} else if (registeredFn.node.type === "FunctionDeclaration" && registeredFn.node.id?.name === registeredFn.id) {
|
|
@@ -4168,32 +4101,34 @@ var updateExpressions = /* @__PURE__ */ new WeakSet();
|
|
|
4168
4101
|
function replaceAssignedNode(node) {
|
|
4169
4102
|
switch (node.type) {
|
|
4170
4103
|
case "ExpressionStatement": {
|
|
4171
|
-
if (node.expression.type === "
|
|
4172
|
-
node.expression = node.expression.
|
|
4173
|
-
|
|
4104
|
+
if (node.expression.type === "BinaryExpression" && updateExpressions.delete(node.expression)) {
|
|
4105
|
+
node.expression = node.expression.left;
|
|
4106
|
+
}
|
|
4107
|
+
if (node.expression.type === "CallExpression" && updateExpressions.delete(node.expression)) {
|
|
4108
|
+
node.expression.callee = node.expression.arguments[0];
|
|
4109
|
+
node.expression.arguments = [node.expression.arguments[1]];
|
|
4174
4110
|
}
|
|
4175
4111
|
break;
|
|
4176
4112
|
}
|
|
4177
4113
|
case "UpdateExpression": {
|
|
4178
4114
|
const { extra } = node.argument;
|
|
4179
4115
|
if (isAssignedBindingExtra(extra)) {
|
|
4180
|
-
|
|
4116
|
+
let builtAssignment = getBuildAssignment(extra)?.(
|
|
4181
4117
|
extra.section,
|
|
4182
|
-
|
|
4118
|
+
import_compiler22.types.binaryExpression(
|
|
4119
|
+
node.operator === "++" ? "+" : "-",
|
|
4120
|
+
createScopeReadExpression(extra.section, extra.assignment),
|
|
4121
|
+
import_compiler22.types.numericLiteral(1)
|
|
4122
|
+
)
|
|
4183
4123
|
);
|
|
4184
4124
|
if (builtAssignment) {
|
|
4185
4125
|
if (!node.prefix) {
|
|
4186
|
-
|
|
4187
|
-
|
|
4126
|
+
builtAssignment = import_compiler22.types.binaryExpression(
|
|
4127
|
+
node.operator === "++" ? "-" : "+",
|
|
4188
4128
|
builtAssignment,
|
|
4189
|
-
import_compiler22.types.
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
import_compiler22.types.numericLiteral(1)
|
|
4193
|
-
)
|
|
4194
|
-
]);
|
|
4195
|
-
updateExpressions.add(replacement);
|
|
4196
|
-
return replacement;
|
|
4129
|
+
import_compiler22.types.numericLiteral(1)
|
|
4130
|
+
);
|
|
4131
|
+
updateExpressions.add(builtAssignment);
|
|
4197
4132
|
}
|
|
4198
4133
|
return builtAssignment;
|
|
4199
4134
|
}
|
|
@@ -4207,15 +4142,15 @@ function replaceAssignedNode(node) {
|
|
|
4207
4142
|
if (isAssignedBindingExtra(extra)) {
|
|
4208
4143
|
return getBuildAssignment(extra)?.(
|
|
4209
4144
|
extra.section,
|
|
4210
|
-
|
|
4211
|
-
extra.assignmentFunction.referencedBindingsInFunction,
|
|
4212
|
-
extra.assignment
|
|
4213
|
-
) ? node : node.operator === "=" ? node.right : import_compiler22.types.binaryExpression(
|
|
4145
|
+
node.operator === "=" ? node.right : import_compiler22.types.binaryExpression(
|
|
4214
4146
|
node.operator.slice(
|
|
4215
4147
|
0,
|
|
4216
4148
|
-1
|
|
4217
4149
|
),
|
|
4218
|
-
|
|
4150
|
+
createScopeReadExpression(
|
|
4151
|
+
extra.section,
|
|
4152
|
+
extra.assignment
|
|
4153
|
+
),
|
|
4219
4154
|
node.right
|
|
4220
4155
|
)
|
|
4221
4156
|
) || extra?.assignment && withLeadingComment(node.right, getDebugName(extra.assignment));
|
|
@@ -4237,12 +4172,7 @@ function replaceAssignedNode(node) {
|
|
|
4237
4172
|
import_compiler22.types.identifier(uid)
|
|
4238
4173
|
);
|
|
4239
4174
|
if (builtAssignment) {
|
|
4240
|
-
|
|
4241
|
-
extra.assignmentFunction.referencedBindingsInFunction,
|
|
4242
|
-
extra.assignment
|
|
4243
|
-
)) {
|
|
4244
|
-
id.name = uid;
|
|
4245
|
-
}
|
|
4175
|
+
id.name = uid;
|
|
4246
4176
|
(params ||= []).push(import_compiler22.types.identifier(uid));
|
|
4247
4177
|
(assignments ||= []).push(builtAssignment);
|
|
4248
4178
|
return;
|
|
@@ -4280,8 +4210,14 @@ function replaceAssignedNode(node) {
|
|
|
4280
4210
|
function getBuildAssignment(extra) {
|
|
4281
4211
|
const { assignmentTo, assignment } = extra;
|
|
4282
4212
|
if (assignmentTo) {
|
|
4283
|
-
return (
|
|
4284
|
-
|
|
4213
|
+
return (section, value) => {
|
|
4214
|
+
const replacement = callRuntime(
|
|
4215
|
+
"_call",
|
|
4216
|
+
createScopeReadExpression(section, assignmentTo),
|
|
4217
|
+
value
|
|
4218
|
+
);
|
|
4219
|
+
updateExpressions.add(replacement);
|
|
4220
|
+
return replacement;
|
|
4285
4221
|
};
|
|
4286
4222
|
}
|
|
4287
4223
|
return getSignal(assignment.section, assignment).buildAssignment;
|
|
@@ -6306,7 +6242,7 @@ var for_default = {
|
|
|
6306
6242
|
const params = node.body.params;
|
|
6307
6243
|
const statements = [];
|
|
6308
6244
|
const bodyStatements = node.body.body;
|
|
6309
|
-
const
|
|
6245
|
+
const singleChild = bodySection.content?.singleChild && bodySection.content.startType !== 4 /* Text */;
|
|
6310
6246
|
const branchSerializeReason = getSerializeReason(
|
|
6311
6247
|
bodySection,
|
|
6312
6248
|
kBranchSerializeReason
|
|
@@ -6327,7 +6263,7 @@ var for_default = {
|
|
|
6327
6263
|
const statefulSerializeArg = getSerializeGuard(
|
|
6328
6264
|
tagSection,
|
|
6329
6265
|
getSerializeReason(tagSection, kStatefulReason),
|
|
6330
|
-
!(skipParentEnd ||
|
|
6266
|
+
!(skipParentEnd || singleChild)
|
|
6331
6267
|
);
|
|
6332
6268
|
const markerSerializeArg = getSerializeGuard(
|
|
6333
6269
|
tagSection,
|
|
@@ -6350,7 +6286,7 @@ var for_default = {
|
|
|
6350
6286
|
getParentTag(tag).node.extra[kSkipEndTag] = true;
|
|
6351
6287
|
forTagArgs.push(import_compiler32.types.stringLiteral(`</${onlyChildParentTagName}>`));
|
|
6352
6288
|
}
|
|
6353
|
-
if (
|
|
6289
|
+
if (singleChild) {
|
|
6354
6290
|
if (!skipParentEnd) {
|
|
6355
6291
|
forTagArgs.push(import_compiler32.types.numericLiteral(0));
|
|
6356
6292
|
}
|
|
@@ -6389,10 +6325,9 @@ var for_default = {
|
|
|
6389
6325
|
const tagExtra = node.extra;
|
|
6390
6326
|
const { referencedBindings } = tagExtra;
|
|
6391
6327
|
const nodeRef = getOptimizedOnlyChildNodeBinding(tag, tagSection);
|
|
6392
|
-
setClosureSignalBuilder(tag, (
|
|
6328
|
+
setClosureSignalBuilder(tag, (_closure, render) => {
|
|
6393
6329
|
return callRuntime(
|
|
6394
6330
|
"_for_closure",
|
|
6395
|
-
getScopeAccessorLiteral(closure),
|
|
6396
6331
|
getScopeAccessorLiteral(nodeRef),
|
|
6397
6332
|
render
|
|
6398
6333
|
);
|
|
@@ -7998,25 +7933,28 @@ function trackReferencesForBinding(babelBinding, binding) {
|
|
|
7998
7933
|
}
|
|
7999
7934
|
}
|
|
8000
7935
|
function trackAssignment(assignment, binding) {
|
|
8001
|
-
const
|
|
7936
|
+
const fnParent = getFnParent(assignment);
|
|
7937
|
+
if (!fnParent) {
|
|
7938
|
+
throw assignment.buildCodeFrameError(
|
|
7939
|
+
`Assignments to a tag ${binding.type === 3 /* param */ ? "parameter" : "variable"} must be within a script or function.`
|
|
7940
|
+
);
|
|
7941
|
+
}
|
|
7942
|
+
const fnRoot = getFnRoot(fnParent);
|
|
7943
|
+
const fnExtra = fnRoot && (fnRoot.node.extra ??= {});
|
|
8002
7944
|
const section = getOrCreateSection(assignment);
|
|
8003
7945
|
setReferencesScope(assignment);
|
|
8004
7946
|
forEachIdentifierPath(assignment, (id) => {
|
|
8005
7947
|
if (id.node.name === binding.name) {
|
|
8006
|
-
if (!fnRoot) {
|
|
8007
|
-
throw id.buildCodeFrameError(
|
|
8008
|
-
`Assignments to a tag ${binding.type === 3 /* param */ ? "parameter" : "variable"} must be within a script or function.`
|
|
8009
|
-
);
|
|
8010
|
-
}
|
|
8011
|
-
const fnExtra = fnRoot && (fnRoot.node.extra ??= {});
|
|
8012
7948
|
const idExtra = id.node.extra ??= {};
|
|
8013
7949
|
idExtra.assignment = binding;
|
|
8014
|
-
idExtra.assignmentFunction = fnExtra;
|
|
8015
|
-
fnExtra.section = idExtra.section = section;
|
|
8016
7950
|
binding.assignmentSections = sectionUtil.add(
|
|
8017
7951
|
binding.assignmentSections,
|
|
8018
7952
|
section
|
|
8019
7953
|
);
|
|
7954
|
+
if (fnExtra) {
|
|
7955
|
+
idExtra.assignmentFunction = fnExtra;
|
|
7956
|
+
fnExtra.section = idExtra.section = section;
|
|
7957
|
+
}
|
|
8020
7958
|
if (binding.upstreamAlias && binding.property !== void 0) {
|
|
8021
7959
|
const changePropName = binding.property + "Change";
|
|
8022
7960
|
const changeBinding = binding.upstreamAlias.propertyAliases.get(changePropName) || createBinding(
|
|
@@ -8780,78 +8718,74 @@ function getSectionInstancesAccessorLiteral(section) {
|
|
|
8780
8718
|
}
|
|
8781
8719
|
function getReadReplacement(node) {
|
|
8782
8720
|
const { extra } = node;
|
|
8783
|
-
if (!extra) return;
|
|
8784
|
-
|
|
8785
|
-
let replacement;
|
|
8721
|
+
if (!extra || extra.assignment) return;
|
|
8722
|
+
const { read, binding } = extra;
|
|
8786
8723
|
if (read) {
|
|
8724
|
+
const readBinding = read.binding;
|
|
8725
|
+
let replacement;
|
|
8787
8726
|
if (read.props === void 0) {
|
|
8788
|
-
|
|
8789
|
-
|
|
8790
|
-
|
|
8791
|
-
binding = void 0;
|
|
8792
|
-
}
|
|
8793
|
-
}
|
|
8794
|
-
if (binding) {
|
|
8795
|
-
if (node.type === "Identifier") {
|
|
8796
|
-
if (binding.type === 0 /* dom */) {
|
|
8797
|
-
if (binding.section.domGetterBindings.has(binding) && isOutputDOM()) {
|
|
8798
|
-
replacement = import_compiler35.types.callExpression(getBindingGetterIdentifier(binding), [
|
|
8799
|
-
getScopeExpression(node.extra.section, binding.section)
|
|
8800
|
-
]);
|
|
8801
|
-
}
|
|
8802
|
-
} else if (binding.type === 6 /* hoist */) {
|
|
8803
|
-
if (node.extra?.[kIsInvoked]) {
|
|
8804
|
-
if (isOutputDOM()) {
|
|
8727
|
+
if (isOutputDOM()) {
|
|
8728
|
+
if (readBinding.type === 0 /* dom */) {
|
|
8729
|
+
if (!extra[kIsInvoked] && readBinding.section.domGetterBindings.has(readBinding)) {
|
|
8805
8730
|
replacement = import_compiler35.types.callExpression(
|
|
8806
|
-
getBindingGetterIdentifier(
|
|
8807
|
-
[getScopeExpression(
|
|
8731
|
+
getBindingGetterIdentifier(readBinding),
|
|
8732
|
+
[getScopeExpression(extra.section, readBinding.section)]
|
|
8808
8733
|
);
|
|
8809
8734
|
}
|
|
8735
|
+
} else if (readBinding.type === 6 /* hoist */ && extra[kIsInvoked]) {
|
|
8736
|
+
replacement = import_compiler35.types.callExpression(
|
|
8737
|
+
getBindingGetterIdentifier(readBinding),
|
|
8738
|
+
[getScopeExpression(extra.section, readBinding.section)]
|
|
8739
|
+
);
|
|
8810
8740
|
} else {
|
|
8811
|
-
replacement =
|
|
8741
|
+
replacement = createScopeReadExpression(extra.section, readBinding);
|
|
8742
|
+
}
|
|
8743
|
+
} else {
|
|
8744
|
+
if (node.type !== "Identifier") {
|
|
8745
|
+
replacement = import_compiler35.types.identifier(readBinding.name);
|
|
8746
|
+
} else if (readBinding.name !== node.name && readBinding.type !== 0 /* dom */ && (readBinding.type !== 6 /* hoist */ || !extra[kIsInvoked])) {
|
|
8747
|
+
node.name = readBinding.name;
|
|
8812
8748
|
}
|
|
8813
|
-
} else if (binding.name !== node.name) {
|
|
8814
|
-
node.name = binding.name;
|
|
8815
8749
|
}
|
|
8816
8750
|
} else {
|
|
8817
|
-
|
|
8818
|
-
|
|
8819
|
-
|
|
8820
|
-
|
|
8821
|
-
|
|
8822
|
-
|
|
8823
|
-
|
|
8824
|
-
|
|
8825
|
-
|
|
8826
|
-
|
|
8827
|
-
|
|
8828
|
-
|
|
8829
|
-
|
|
8830
|
-
|
|
8831
|
-
|
|
8832
|
-
|
|
8833
|
-
|
|
8834
|
-
|
|
8835
|
-
|
|
8836
|
-
|
|
8837
|
-
|
|
8838
|
-
|
|
8839
|
-
|
|
8840
|
-
|
|
8841
|
-
|
|
8842
|
-
|
|
8843
|
-
|
|
8844
|
-
replaceMember.
|
|
8845
|
-
|
|
8751
|
+
const props = read.props ? Array.isArray(read.props) ? read.props.slice() : [read.props] : [];
|
|
8752
|
+
let curNode = node;
|
|
8753
|
+
let curBinding = read.binding;
|
|
8754
|
+
let replaceMember;
|
|
8755
|
+
replacement = isOutputDOM() ? createScopeReadExpression(extra.section, read.binding) : import_compiler35.types.identifier(read.binding.name);
|
|
8756
|
+
while (props.length && (curNode.type === "MemberExpression" || curNode.type === "OptionalMemberExpression")) {
|
|
8757
|
+
const prop = props.pop();
|
|
8758
|
+
const memberProp = getMemberExpressionPropString(curNode);
|
|
8759
|
+
if (memberProp !== prop) break;
|
|
8760
|
+
replaceMember = curNode;
|
|
8761
|
+
curNode = curNode.object;
|
|
8762
|
+
}
|
|
8763
|
+
for (const prop of props) {
|
|
8764
|
+
if (curBinding) {
|
|
8765
|
+
curBinding = curBinding.propertyAliases.get(prop);
|
|
8766
|
+
}
|
|
8767
|
+
replacement = toMemberExpression(
|
|
8768
|
+
replacement,
|
|
8769
|
+
prop,
|
|
8770
|
+
!!curBinding?.nullable
|
|
8771
|
+
);
|
|
8772
|
+
}
|
|
8773
|
+
if (replaceMember) {
|
|
8774
|
+
if (read.binding.nullable && replaceMember.object.type !== replacement.type) {
|
|
8775
|
+
replaceMember.type = "OptionalMemberExpression";
|
|
8776
|
+
replaceMember.optional = true;
|
|
8777
|
+
}
|
|
8778
|
+
replaceMember.object = withPreviousLocation(
|
|
8779
|
+
replacement,
|
|
8780
|
+
replaceMember.object
|
|
8781
|
+
);
|
|
8782
|
+
replacement = void 0;
|
|
8846
8783
|
}
|
|
8847
|
-
replaceMember.object = withPreviousLocation(
|
|
8848
|
-
replacement,
|
|
8849
|
-
replaceMember.object
|
|
8850
|
-
);
|
|
8851
|
-
replacement = void 0;
|
|
8852
8784
|
}
|
|
8785
|
+
return replacement && withPreviousLocation(replacement, node);
|
|
8786
|
+
} else if (binding && node.type == "Identifier" && node.name !== binding.name) {
|
|
8787
|
+
node.name = binding.name;
|
|
8853
8788
|
}
|
|
8854
|
-
return replacement && withPreviousLocation(replacement, node);
|
|
8855
8789
|
}
|
|
8856
8790
|
function pruneBinding(bindings, binding) {
|
|
8857
8791
|
let shouldPrune = !binding.downstreamExpressions.size;
|
|
@@ -8939,14 +8873,23 @@ function resolveReferencedBindings(expr, reads, intersectionsBySection) {
|
|
|
8939
8873
|
const rootBindings = getRootBindings(reads);
|
|
8940
8874
|
for (const read of reads) {
|
|
8941
8875
|
let { binding } = read;
|
|
8942
|
-
if (read.node
|
|
8943
|
-
|
|
8876
|
+
if (read.node) {
|
|
8877
|
+
const readExtra = read.node.extra ??= {};
|
|
8878
|
+
if (readExtra.assignmentTo !== binding) {
|
|
8879
|
+
readExtra.section = expr.section;
|
|
8880
|
+
({ binding } = readExtra.read ??= resolveExpressionReference(
|
|
8881
|
+
rootBindings,
|
|
8882
|
+
binding
|
|
8883
|
+
));
|
|
8884
|
+
}
|
|
8944
8885
|
}
|
|
8945
8886
|
referencedBindings = bindingUtil.add(referencedBindings, binding);
|
|
8946
8887
|
}
|
|
8947
8888
|
} else if (reads) {
|
|
8948
8889
|
if (reads.node) {
|
|
8949
|
-
|
|
8890
|
+
const readExtra = reads.node.extra ??= {};
|
|
8891
|
+
readExtra.section = expr.section;
|
|
8892
|
+
readExtra.read = createRead(reads.binding, void 0);
|
|
8950
8893
|
}
|
|
8951
8894
|
referencedBindings = reads.binding;
|
|
8952
8895
|
}
|
|
@@ -10488,10 +10431,8 @@ var IfTag = {
|
|
|
10488
10431
|
binding: nodeBinding,
|
|
10489
10432
|
prefix: getAccessorPrefix().ConditionalScope
|
|
10490
10433
|
};
|
|
10491
|
-
let singleNodeOptimization = true;
|
|
10492
10434
|
for (const [branchTag, branchBodySection] of branches) {
|
|
10493
10435
|
if (branchBodySection) {
|
|
10494
|
-
singleNodeOptimization &&= branchBodySection.content === null || branchBodySection.content?.singleChild && branchBodySection.content.startType !== 4 /* Text */;
|
|
10495
10436
|
branchBodySection.isBranch = true;
|
|
10496
10437
|
branchBodySection.upstreamExpression = ifTagExtra;
|
|
10497
10438
|
branchBodySection.sectionAccessor = sectionAccessor;
|
|
@@ -10501,7 +10442,6 @@ var IfTag = {
|
|
|
10501
10442
|
}
|
|
10502
10443
|
}
|
|
10503
10444
|
mergeReferences(ifTagSection, ifTag.node, mergeReferenceNodes);
|
|
10504
|
-
ifTagExtra.singleNodeOptimization = singleNodeOptimization;
|
|
10505
10445
|
addSerializeExpr(ifTagSection, ifTagExtra, kStatefulReason2);
|
|
10506
10446
|
}
|
|
10507
10447
|
},
|
|
@@ -10532,8 +10472,6 @@ var IfTag = {
|
|
|
10532
10472
|
const branches = getBranches(tag);
|
|
10533
10473
|
const [ifTag] = branches[0];
|
|
10534
10474
|
const ifTagSection = getSection(ifTag);
|
|
10535
|
-
const ifTagExtra = ifTag.node.extra;
|
|
10536
|
-
const singleNodeOptimization = ifTagExtra.singleNodeOptimization;
|
|
10537
10475
|
const nodeBinding = getOptimizedOnlyChildNodeBinding(
|
|
10538
10476
|
ifTag,
|
|
10539
10477
|
ifTagSection
|
|
@@ -10546,6 +10484,13 @@ var IfTag = {
|
|
|
10546
10484
|
const nextTag = tag.getNextSibling();
|
|
10547
10485
|
let branchSerializeReasons;
|
|
10548
10486
|
let statement;
|
|
10487
|
+
let singleChild = true;
|
|
10488
|
+
for (const [, branchBody] of branches) {
|
|
10489
|
+
if (!(branchBody?.content?.singleChild && branchBody.content.startType !== 4 /* Text */)) {
|
|
10490
|
+
singleChild = false;
|
|
10491
|
+
break;
|
|
10492
|
+
}
|
|
10493
|
+
}
|
|
10549
10494
|
for (let i = branches.length; i--; ) {
|
|
10550
10495
|
const [branchTag, branchBody] = branches[i];
|
|
10551
10496
|
const bodyStatements = branchTag.node.body.body;
|
|
@@ -10594,7 +10539,7 @@ var IfTag = {
|
|
|
10594
10539
|
const statefulSerializeArg = getSerializeGuard(
|
|
10595
10540
|
ifTagSection,
|
|
10596
10541
|
getSerializeReason(ifTagSection, kStatefulReason2),
|
|
10597
|
-
!(skipParentEnd ||
|
|
10542
|
+
!(skipParentEnd || singleChild)
|
|
10598
10543
|
);
|
|
10599
10544
|
const markerSerializeArg = getSerializeGuard(
|
|
10600
10545
|
ifTagSection,
|
|
@@ -10618,8 +10563,8 @@ var IfTag = {
|
|
|
10618
10563
|
),
|
|
10619
10564
|
markerSerializeArg,
|
|
10620
10565
|
statefulSerializeArg,
|
|
10621
|
-
skipParentEnd ? import_compiler48.types.stringLiteral(`</${onlyChildParentTagName}>`) :
|
|
10622
|
-
|
|
10566
|
+
skipParentEnd ? import_compiler48.types.stringLiteral(`</${onlyChildParentTagName}>`) : singleChild ? import_compiler48.types.numericLiteral(0) : void 0,
|
|
10567
|
+
singleChild ? import_compiler48.types.numericLiteral(1) : void 0
|
|
10623
10568
|
)
|
|
10624
10569
|
);
|
|
10625
10570
|
}
|
|
@@ -10656,10 +10601,9 @@ var IfTag = {
|
|
|
10656
10601
|
const consequent = import_compiler48.types.numericLiteral(branchBodySection ? i : -1);
|
|
10657
10602
|
if (branchBodySection) {
|
|
10658
10603
|
rendererIdentifiers.push(import_compiler48.types.identifier(branchBodySection.name));
|
|
10659
|
-
setClosureSignalBuilder(branchTag, (
|
|
10604
|
+
setClosureSignalBuilder(branchTag, (_closure, render) => {
|
|
10660
10605
|
return callRuntime(
|
|
10661
10606
|
"_if_closure",
|
|
10662
|
-
getScopeAccessorLiteral(closure),
|
|
10663
10607
|
getScopeAccessorLiteral(nodeRef),
|
|
10664
10608
|
import_compiler48.types.numericLiteral(i),
|
|
10665
10609
|
render
|