marko 6.0.33 → 6.0.34
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
@@ -897,6 +897,9 @@ var Sorted = class {
|
|
897
897
|
}
|
898
898
|
}
|
899
899
|
}
|
900
|
+
has(data, item) {
|
901
|
+
return this.findIndex(data, item) !== -1;
|
902
|
+
}
|
900
903
|
findIndex(data, item) {
|
901
904
|
if (data) {
|
902
905
|
if (Array.isArray(data)) {
|
@@ -2990,7 +2993,7 @@ var return_default = {
|
|
2990
2993
|
var import_compiler18 = require("@marko/compiler");
|
2991
2994
|
function getDeclaredBindingExpression(binding) {
|
2992
2995
|
const canonicalBinding = getCanonicalBinding(binding);
|
2993
|
-
if (canonicalBinding.declared || !canonicalBinding.upstreamAlias) {
|
2996
|
+
if (canonicalBinding.declared || !canonicalBinding.upstreamAlias || canonicalBinding.excludeProperties !== void 0) {
|
2994
2997
|
return import_compiler18.types.identifier(canonicalBinding.name);
|
2995
2998
|
} else if (canonicalBinding.property !== void 0) {
|
2996
2999
|
return toMemberExpression(
|
@@ -3148,7 +3151,7 @@ function initValue(binding, runtimeHelper = "value") {
|
|
3148
3151
|
signal.build = () => {
|
3149
3152
|
const fn = getSignalFn(signal);
|
3150
3153
|
const isParamBinding = !binding.upstreamAlias && (binding.type === 3 /* param */ || binding.type === 4 /* local */ || binding.type === 2 /* input */);
|
3151
|
-
const isNakedAlias = binding.upstreamAlias &&
|
3154
|
+
const isNakedAlias = binding.upstreamAlias && binding.property === void 0 && binding.excludeProperties === void 0;
|
3152
3155
|
const needsGuard = !isNakedAlias && (binding.closureSections || binding.downstreamExpressions.size || fn.type === "ArrowFunctionExpression" && fn.body.body.length > 0);
|
3153
3156
|
const needsCache = needsGuard || signal.intersection;
|
3154
3157
|
const needsMarks = isParamBinding || signal.intersection;
|
@@ -3191,15 +3194,48 @@ function getSignalFn(signal) {
|
|
3191
3194
|
for (const alias of binding.aliases) {
|
3192
3195
|
const aliasSignal = getSignal(alias.section, alias);
|
3193
3196
|
if (aliasSignal.render.length || aliasSignal.values.length || aliasSignal.effect.length) {
|
3194
|
-
|
3195
|
-
|
3196
|
-
|
3197
|
-
|
3198
|
-
|
3199
|
-
|
3200
|
-
|
3201
|
-
|
3202
|
-
|
3197
|
+
if (alias.excludeProperties !== void 0) {
|
3198
|
+
const props = [];
|
3199
|
+
const aliasId = import_compiler20.types.identifier(alias.name);
|
3200
|
+
forEach(alias.excludeProperties, (name2) => {
|
3201
|
+
const propId = toPropertyName(name2);
|
3202
|
+
const shorthand = propId.type === "Identifier";
|
3203
|
+
props.push(
|
3204
|
+
import_compiler20.types.objectProperty(
|
3205
|
+
propId,
|
3206
|
+
propId.type === "Identifier" ? propId : import_compiler20.types.objectPattern([]),
|
3207
|
+
false,
|
3208
|
+
shorthand
|
3209
|
+
)
|
3210
|
+
);
|
3211
|
+
});
|
3212
|
+
props.push(import_compiler20.types.restElement(aliasId));
|
3213
|
+
signal.render.push(
|
3214
|
+
import_compiler20.types.expressionStatement(
|
3215
|
+
import_compiler20.types.callExpression(
|
3216
|
+
import_compiler20.types.arrowFunctionExpression(
|
3217
|
+
[import_compiler20.types.objectPattern(props)],
|
3218
|
+
import_compiler20.types.callExpression(aliasSignal.identifier, [
|
3219
|
+
scopeIdentifier,
|
3220
|
+
aliasId,
|
3221
|
+
...getTranslatedExtraArgs(aliasSignal)
|
3222
|
+
])
|
3223
|
+
),
|
3224
|
+
[import_compiler20.types.identifier(binding.name)]
|
3225
|
+
)
|
3226
|
+
)
|
3227
|
+
);
|
3228
|
+
} else {
|
3229
|
+
signal.render.push(
|
3230
|
+
import_compiler20.types.expressionStatement(
|
3231
|
+
import_compiler20.types.callExpression(aliasSignal.identifier, [
|
3232
|
+
scopeIdentifier,
|
3233
|
+
import_compiler20.types.identifier(binding.name),
|
3234
|
+
...getTranslatedExtraArgs(aliasSignal)
|
3235
|
+
])
|
3236
|
+
)
|
3237
|
+
);
|
3238
|
+
}
|
3203
3239
|
}
|
3204
3240
|
}
|
3205
3241
|
for (const [key, alias] of binding.propertyAliases) {
|
@@ -3221,7 +3257,7 @@ function getSignalFn(signal) {
|
|
3221
3257
|
}
|
3222
3258
|
for (const value of signal.values) {
|
3223
3259
|
const valSignal = value.signal;
|
3224
|
-
if (!valSignal.referencedBindings || Array.isArray(valSignal.referencedBindings) || !valSignal.referencedBindings.upstreamAlias || valSignal.referencedBindings.property || valSignal.effect.length || valSignal.render.length || valSignal.values.length) {
|
3260
|
+
if (!valSignal.referencedBindings || Array.isArray(valSignal.referencedBindings) || !valSignal.referencedBindings.upstreamAlias || valSignal.referencedBindings.property !== void 0 || valSignal.referencedBindings.excludeProperties !== void 0 || valSignal.effect.length || valSignal.render.length || valSignal.values.length) {
|
3225
3261
|
signal.render.push(
|
3226
3262
|
import_compiler20.types.expressionStatement(
|
3227
3263
|
import_compiler20.types.callExpression(value.signal.identifier, [
|
@@ -3315,7 +3351,7 @@ function getSignalFn(signal) {
|
|
3315
3351
|
for (; i--; ) {
|
3316
3352
|
const param = params[i];
|
3317
3353
|
const arg = args[i];
|
3318
|
-
if (arg.type !== "Identifier" || param.name !== arg.name) {
|
3354
|
+
if (arg.type !== "Identifier" || param.type !== "Identifier" || param.name !== arg.name) {
|
3319
3355
|
break;
|
3320
3356
|
}
|
3321
3357
|
}
|
@@ -3346,7 +3382,7 @@ function getTranslatedExtraArgs(signal) {
|
|
3346
3382
|
function subscribe(references, subscriber) {
|
3347
3383
|
if (references) {
|
3348
3384
|
forEach(references, (binding) => {
|
3349
|
-
const source = binding.property === void 0 && binding.upstreamAlias || binding;
|
3385
|
+
const source = binding.property === void 0 && binding.excludeProperties === void 0 && binding.upstreamAlias || binding;
|
3350
3386
|
const providerSignal = getSignal(subscriber.section, source);
|
3351
3387
|
providerSignal.intersection = push(
|
3352
3388
|
providerSignal.intersection,
|
@@ -3521,7 +3557,7 @@ function writeSignals(section) {
|
|
3521
3557
|
// It's possible for aliases to render nothing
|
3522
3558
|
// if they're only consumed in effects/closures.
|
3523
3559
|
// This ignores writing out those signals in that case.
|
3524
|
-
signal.referencedBindings && !Array.isArray(signal.referencedBindings) && signal.referencedBindings.upstreamAlias &&
|
3560
|
+
signal.referencedBindings && !Array.isArray(signal.referencedBindings) && signal.referencedBindings.upstreamAlias && signal.referencedBindings.property === void 0 && signal.referencedBindings.excludeProperties === void 0 && import_compiler20.types.isFunction(value) && import_compiler20.types.isBlockStatement(value.body) && !value.body.body.length
|
3525
3561
|
) {
|
3526
3562
|
return;
|
3527
3563
|
}
|
@@ -4395,7 +4431,7 @@ var kIsInvoked = Symbol("hoist is invoked");
|
|
4395
4431
|
var kBranchSerializeReason = Symbol("branch serialize reason");
|
4396
4432
|
var [getBindings] = createProgramState(() => /* @__PURE__ */ new Set());
|
4397
4433
|
var [getNextBindingId, setNextBindingId] = createProgramState(() => 0);
|
4398
|
-
function createBinding(name2, type, section, upstreamAlias, property, loc = null, declared = false) {
|
4434
|
+
function createBinding(name2, type, section, upstreamAlias, property, excludeProperties, loc = null, declared = false) {
|
4399
4435
|
const id = getNextBindingId();
|
4400
4436
|
const binding = {
|
4401
4437
|
id,
|
@@ -4407,7 +4443,7 @@ function createBinding(name2, type, section, upstreamAlias, property, loc = null
|
|
4407
4443
|
declared,
|
4408
4444
|
closureSections: void 0,
|
4409
4445
|
assignmentSections: void 0,
|
4410
|
-
excludeProperties
|
4446
|
+
excludeProperties,
|
4411
4447
|
sources: void 0,
|
4412
4448
|
aliases: /* @__PURE__ */ new Set(),
|
4413
4449
|
hoists: /* @__PURE__ */ new Map(),
|
@@ -4416,7 +4452,7 @@ function createBinding(name2, type, section, upstreamAlias, property, loc = null
|
|
4416
4452
|
downstreamExpressions: /* @__PURE__ */ new Set(),
|
4417
4453
|
scopeOffset: void 0,
|
4418
4454
|
export: void 0,
|
4419
|
-
nullable:
|
4455
|
+
nullable: excludeProperties === void 0
|
4420
4456
|
};
|
4421
4457
|
if (property) {
|
4422
4458
|
if (declared) upstreamAlias.nullable = false;
|
@@ -4446,6 +4482,7 @@ function trackVarReferences(tag, type, upstreamAlias) {
|
|
4446
4482
|
tag.scope,
|
4447
4483
|
canonicalUpstreamAlias.section,
|
4448
4484
|
canonicalUpstreamAlias,
|
4485
|
+
void 0,
|
4449
4486
|
void 0
|
4450
4487
|
);
|
4451
4488
|
return canonicalUpstreamAlias;
|
@@ -4456,6 +4493,7 @@ function trackVarReferences(tag, type, upstreamAlias) {
|
|
4456
4493
|
tag.scope,
|
4457
4494
|
getOrCreateSection(tag),
|
4458
4495
|
void 0,
|
4496
|
+
void 0,
|
4459
4497
|
void 0
|
4460
4498
|
);
|
4461
4499
|
return tagVar.extra?.binding;
|
@@ -4481,14 +4519,28 @@ function trackParamsReferences(body, type, upstreamAlias) {
|
|
4481
4519
|
));
|
4482
4520
|
section.params = paramsBinding;
|
4483
4521
|
for (let i = 0; i < params.length; i++) {
|
4484
|
-
|
4485
|
-
|
4486
|
-
|
4487
|
-
|
4488
|
-
|
4489
|
-
|
4490
|
-
|
4491
|
-
|
4522
|
+
const param = params[i];
|
4523
|
+
if (param.type === "RestElement") {
|
4524
|
+
createBindingsAndTrackReferences(
|
4525
|
+
param.argument,
|
4526
|
+
type,
|
4527
|
+
body.scope,
|
4528
|
+
section,
|
4529
|
+
paramsBinding,
|
4530
|
+
void 0,
|
4531
|
+
addNumericPropertiesUntil(void 0, i - 1)
|
4532
|
+
);
|
4533
|
+
} else {
|
4534
|
+
createBindingsAndTrackReferences(
|
4535
|
+
param,
|
4536
|
+
type,
|
4537
|
+
body.scope,
|
4538
|
+
section,
|
4539
|
+
paramsBinding,
|
4540
|
+
i + "",
|
4541
|
+
void 0
|
4542
|
+
);
|
4543
|
+
}
|
4492
4544
|
}
|
4493
4545
|
return paramsBinding;
|
4494
4546
|
}
|
@@ -4508,6 +4560,7 @@ function trackHoistedReference(referencePath, binding) {
|
|
4508
4560
|
hoistSection,
|
4509
4561
|
void 0,
|
4510
4562
|
void 0,
|
4563
|
+
void 0,
|
4511
4564
|
binding.loc,
|
4512
4565
|
true
|
4513
4566
|
)
|
@@ -4572,6 +4625,7 @@ function trackAssignment(assignment, binding) {
|
|
4572
4625
|
binding.section,
|
4573
4626
|
binding.upstreamAlias,
|
4574
4627
|
changePropName,
|
4628
|
+
void 0,
|
4575
4629
|
id.node.loc,
|
4576
4630
|
true
|
4577
4631
|
);
|
@@ -4593,7 +4647,7 @@ function setReferencesScope(path5) {
|
|
4593
4647
|
(fnRoot.node.extra ??= {}).referencesScope = true;
|
4594
4648
|
}
|
4595
4649
|
}
|
4596
|
-
function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAlias, property) {
|
4650
|
+
function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAlias, property, excludeProperties) {
|
4597
4651
|
switch (lVal.type) {
|
4598
4652
|
case "Identifier":
|
4599
4653
|
trackReferencesForBinding(
|
@@ -4604,6 +4658,7 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
|
|
4604
4658
|
section,
|
4605
4659
|
upstreamAlias,
|
4606
4660
|
property,
|
4661
|
+
excludeProperties,
|
4607
4662
|
lVal.loc,
|
4608
4663
|
true
|
4609
4664
|
)
|
@@ -4616,8 +4671,10 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
|
|
4616
4671
|
section,
|
4617
4672
|
upstreamAlias,
|
4618
4673
|
property,
|
4674
|
+
excludeProperties,
|
4619
4675
|
lVal.loc
|
4620
4676
|
));
|
4677
|
+
const hasRest = lVal.properties[lVal.properties.length - 1]?.type === "RestElement";
|
4621
4678
|
for (const prop of lVal.properties) {
|
4622
4679
|
if (prop.type === "RestElement") {
|
4623
4680
|
createBindingsAndTrackReferences(
|
@@ -4626,7 +4683,8 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
|
|
4626
4683
|
scope,
|
4627
4684
|
section,
|
4628
4685
|
patternBinding,
|
4629
|
-
property
|
4686
|
+
property,
|
4687
|
+
excludeProperties
|
4630
4688
|
);
|
4631
4689
|
} else {
|
4632
4690
|
let key;
|
@@ -4637,13 +4695,17 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
|
|
4637
4695
|
} else {
|
4638
4696
|
throw new Error("computed keys not supported in object pattern");
|
4639
4697
|
}
|
4698
|
+
if (hasRest) {
|
4699
|
+
excludeProperties = propsUtil.add(excludeProperties, key);
|
4700
|
+
}
|
4640
4701
|
createBindingsAndTrackReferences(
|
4641
4702
|
prop.value,
|
4642
4703
|
type,
|
4643
4704
|
scope,
|
4644
4705
|
section,
|
4645
4706
|
patternBinding,
|
4646
|
-
key
|
4707
|
+
key,
|
4708
|
+
void 0
|
4647
4709
|
);
|
4648
4710
|
}
|
4649
4711
|
}
|
@@ -4656,6 +4718,7 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
|
|
4656
4718
|
section,
|
4657
4719
|
upstreamAlias,
|
4658
4720
|
property,
|
4721
|
+
excludeProperties,
|
4659
4722
|
lVal.loc
|
4660
4723
|
));
|
4661
4724
|
let i = -1;
|
@@ -4663,13 +4726,18 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
|
|
4663
4726
|
i++;
|
4664
4727
|
if (element) {
|
4665
4728
|
if (element.type === "RestElement") {
|
4729
|
+
excludeProperties = addNumericPropertiesUntil(
|
4730
|
+
excludeProperties,
|
4731
|
+
i - 1
|
4732
|
+
);
|
4666
4733
|
createBindingsAndTrackReferences(
|
4667
4734
|
element.argument,
|
4668
4735
|
type,
|
4669
4736
|
scope,
|
4670
4737
|
section,
|
4671
4738
|
patternBinding,
|
4672
|
-
property
|
4739
|
+
property,
|
4740
|
+
excludeProperties
|
4673
4741
|
);
|
4674
4742
|
} else {
|
4675
4743
|
createBindingsAndTrackReferences(
|
@@ -4678,7 +4746,8 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
|
|
4678
4746
|
scope,
|
4679
4747
|
section,
|
4680
4748
|
patternBinding,
|
4681
|
-
`${i}
|
4749
|
+
`${i}`,
|
4750
|
+
void 0
|
4682
4751
|
);
|
4683
4752
|
}
|
4684
4753
|
}
|
@@ -4692,7 +4761,8 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
|
|
4692
4761
|
scope,
|
4693
4762
|
section,
|
4694
4763
|
upstreamAlias,
|
4695
|
-
property
|
4764
|
+
property,
|
4765
|
+
void 0
|
4696
4766
|
);
|
4697
4767
|
break;
|
4698
4768
|
}
|
@@ -4706,6 +4776,9 @@ function trackReference(referencePath, binding) {
|
|
4706
4776
|
if (!import_compiler24.types.isMemberExpression(parent)) break;
|
4707
4777
|
const prop = getMemberExpressionPropString(parent);
|
4708
4778
|
if (prop === void 0) break;
|
4779
|
+
if (reference.upstreamAlias && reference.excludeProperties !== void 0 && !propsUtil.has(reference.excludeProperties, prop)) {
|
4780
|
+
reference = reference.upstreamAlias;
|
4781
|
+
}
|
4709
4782
|
if (reference.propertyAliases.has(prop)) {
|
4710
4783
|
root = root.parentPath;
|
4711
4784
|
reference = reference.propertyAliases.get(prop);
|
@@ -5166,6 +5239,9 @@ function mergeSources(a, b) {
|
|
5166
5239
|
var bindingUtil = new Sorted(function compareBindings(a, b) {
|
5167
5240
|
return a === b ? 0 : a.section.id - b.section.id || a.type !== b.type && (a.type === 0 /* dom */ || b.type === 0 /* dom */) ? a.type - b.type || a.id - b.id : a.id - b.id;
|
5168
5241
|
});
|
5242
|
+
var propsUtil = new Sorted(function compareProps(a, b) {
|
5243
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
5244
|
+
});
|
5169
5245
|
var [getReadsByExpression] = createProgramState(
|
5170
5246
|
() => /* @__PURE__ */ new Map()
|
5171
5247
|
);
|
@@ -5201,7 +5277,11 @@ function dropReferences(node) {
|
|
5201
5277
|
}
|
5202
5278
|
}
|
5203
5279
|
function getCanonicalBinding(binding) {
|
5204
|
-
|
5280
|
+
const alias = binding?.upstreamAlias;
|
5281
|
+
if (alias && binding.property === void 0 && binding.excludeProperties === void 0) {
|
5282
|
+
return alias;
|
5283
|
+
}
|
5284
|
+
return binding;
|
5205
5285
|
}
|
5206
5286
|
function getAllTagReferenceNodes(tag, referenceNodes = []) {
|
5207
5287
|
if (tag.arguments) {
|
@@ -5245,7 +5325,7 @@ function getScopeAccessor(binding, includeId) {
|
|
5245
5325
|
function getDebugScopeAccess(binding) {
|
5246
5326
|
let root = binding;
|
5247
5327
|
let access = "";
|
5248
|
-
while (!(root.loc || root.declared) && root.upstreamAlias) {
|
5328
|
+
while (!(root.loc || root.declared) && root.upstreamAlias && root.excludeProperties === void 0) {
|
5249
5329
|
if (root.property !== void 0) {
|
5250
5330
|
access = toAccess(root.property) + access;
|
5251
5331
|
}
|
@@ -5400,7 +5480,12 @@ function isSupersetSources(a, b) {
|
|
5400
5480
|
return bindingUtil.isSuperset(a.sources.state, b.sources.state) && bindingUtil.isSuperset(a.sources.input, b.sources.input);
|
5401
5481
|
}
|
5402
5482
|
function getCanonicalProperty(binding) {
|
5403
|
-
|
5483
|
+
if (binding.property !== void 0) {
|
5484
|
+
return binding.property;
|
5485
|
+
}
|
5486
|
+
if (binding.upstreamAlias && binding.excludeProperties === void 0) {
|
5487
|
+
return binding.upstreamAlias.property;
|
5488
|
+
}
|
5404
5489
|
}
|
5405
5490
|
function createRead(binding, props) {
|
5406
5491
|
return { binding, props };
|
@@ -5428,6 +5513,13 @@ function isAssignedBindingExtra(extra) {
|
|
5428
5513
|
function isRegisteredFnExtra(extra) {
|
5429
5514
|
return isReferencedExtra(extra) && extra.registerId !== void 0;
|
5430
5515
|
}
|
5516
|
+
function addNumericPropertiesUntil(props, len) {
|
5517
|
+
let result = props;
|
5518
|
+
for (let i = len; i--; ) {
|
5519
|
+
result = propsUtil.add(result, i + "");
|
5520
|
+
}
|
5521
|
+
return result;
|
5522
|
+
}
|
5431
5523
|
|
5432
5524
|
// src/translator/core/await.ts
|
5433
5525
|
var kDOMBinding = Symbol("await tag dom binding");
|
@@ -8,6 +8,7 @@ export declare class Sorted<T> {
|
|
8
8
|
add<U extends NonNullable<T>>(data: Opt<U>, item: U): OneMany<U>;
|
9
9
|
union<U extends NonNullable<T>>(a: Opt<U>, b: Opt<U>): Opt<U>;
|
10
10
|
find<U extends NonNullable<T>>(data: Opt<U>, item: U): U | undefined;
|
11
|
+
has<U extends NonNullable<T>>(data: Opt<U>, item: U): boolean;
|
11
12
|
findIndex<U extends NonNullable<T>>(data: Opt<U>, item: U): number;
|
12
13
|
isSuperset<U extends NonNullable<T>>(superset: Opt<U>, subset: Opt<U>): boolean;
|
13
14
|
}
|
@@ -32,7 +32,7 @@ export interface Binding {
|
|
32
32
|
hoists: Map<Section, Binding>;
|
33
33
|
property: string | undefined;
|
34
34
|
propertyAliases: Map<string, Binding>;
|
35
|
-
excludeProperties:
|
35
|
+
excludeProperties: Opt<string>;
|
36
36
|
upstreamAlias: Binding | undefined;
|
37
37
|
downstreamExpressions: Set<ReferencedExtra>;
|
38
38
|
scopeOffset: Binding | undefined;
|
@@ -70,7 +70,7 @@ declare module "@marko/compiler/dist/types" {
|
|
70
70
|
interface FunctionExpressionExtra extends FunctionExtra {
|
71
71
|
}
|
72
72
|
}
|
73
|
-
export declare function createBinding(name: string, type: Binding["type"], section: Section, upstreamAlias?: Binding["upstreamAlias"], property?: string, loc?: t.SourceLocation | null, declared?: boolean): Binding;
|
73
|
+
export declare function createBinding(name: string, type: Binding["type"], section: Section, upstreamAlias?: Binding["upstreamAlias"], property?: string, excludeProperties?: Opt<string>, loc?: t.SourceLocation | null, declared?: boolean): Binding;
|
74
74
|
export declare function trackVarReferences(tag: t.NodePath<t.MarkoTag>, type: BindingType, upstreamAlias?: Binding["upstreamAlias"]): Binding | undefined;
|
75
75
|
export declare function trackParamsReferences(body: t.NodePath<t.MarkoTagBody | t.Program>, type: BindingType, upstreamAlias?: Binding["upstreamAlias"]): Binding | undefined;
|
76
76
|
export declare function trackHoistedReference(referencePath: t.NodePath<t.Identifier>, binding: Binding): void;
|