marko 6.0.33 → 6.0.35

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.
@@ -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 && !binding.property;
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
- signal.render.push(
3195
- import_compiler20.types.expressionStatement(
3196
- import_compiler20.types.callExpression(aliasSignal.identifier, [
3197
- scopeIdentifier,
3198
- import_compiler20.types.identifier(binding.name),
3199
- ...getTranslatedExtraArgs(aliasSignal)
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 && !signal.referencedBindings.property && import_compiler20.types.isFunction(value) && import_compiler20.types.isBlockStatement(value.body) && !value.body.body.length
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: void 0,
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: true
4455
+ nullable: excludeProperties === void 0
4420
4456
  };
4421
4457
  if (property) {
4422
4458
  if (declared) upstreamAlias.nullable = false;
@@ -4438,15 +4474,20 @@ function createBinding(name2, type, section, upstreamAlias, property, loc = null
4438
4474
  function trackVarReferences(tag, type, upstreamAlias) {
4439
4475
  const tagVar = tag.node.var;
4440
4476
  if (tagVar) {
4441
- const canonicalUpstreamAlias = getCanonicalBinding(upstreamAlias);
4477
+ let canonicalUpstreamAlias = getCanonicalBinding(upstreamAlias);
4442
4478
  if (canonicalUpstreamAlias) {
4479
+ const { excludeProperties } = canonicalUpstreamAlias;
4480
+ if (excludeProperties !== void 0) {
4481
+ canonicalUpstreamAlias = canonicalUpstreamAlias.upstreamAlias;
4482
+ }
4443
4483
  createBindingsAndTrackReferences(
4444
4484
  tagVar,
4445
4485
  canonicalUpstreamAlias.type,
4446
4486
  tag.scope,
4447
4487
  canonicalUpstreamAlias.section,
4448
4488
  canonicalUpstreamAlias,
4449
- void 0
4489
+ void 0,
4490
+ excludeProperties
4450
4491
  );
4451
4492
  return canonicalUpstreamAlias;
4452
4493
  }
@@ -4456,6 +4497,7 @@ function trackVarReferences(tag, type, upstreamAlias) {
4456
4497
  tag.scope,
4457
4498
  getOrCreateSection(tag),
4458
4499
  void 0,
4500
+ void 0,
4459
4501
  void 0
4460
4502
  );
4461
4503
  return tagVar.extra?.binding;
@@ -4481,14 +4523,28 @@ function trackParamsReferences(body, type, upstreamAlias) {
4481
4523
  ));
4482
4524
  section.params = paramsBinding;
4483
4525
  for (let i = 0; i < params.length; i++) {
4484
- createBindingsAndTrackReferences(
4485
- params[i],
4486
- type,
4487
- body.scope,
4488
- section,
4489
- paramsBinding,
4490
- i + ""
4491
- );
4526
+ const param = params[i];
4527
+ if (param.type === "RestElement") {
4528
+ createBindingsAndTrackReferences(
4529
+ param.argument,
4530
+ type,
4531
+ body.scope,
4532
+ section,
4533
+ paramsBinding,
4534
+ void 0,
4535
+ addNumericPropertiesUntil(void 0, i - 1)
4536
+ );
4537
+ } else {
4538
+ createBindingsAndTrackReferences(
4539
+ param,
4540
+ type,
4541
+ body.scope,
4542
+ section,
4543
+ paramsBinding,
4544
+ i + "",
4545
+ void 0
4546
+ );
4547
+ }
4492
4548
  }
4493
4549
  return paramsBinding;
4494
4550
  }
@@ -4508,6 +4564,7 @@ function trackHoistedReference(referencePath, binding) {
4508
4564
  hoistSection,
4509
4565
  void 0,
4510
4566
  void 0,
4567
+ void 0,
4511
4568
  binding.loc,
4512
4569
  true
4513
4570
  )
@@ -4572,6 +4629,7 @@ function trackAssignment(assignment, binding) {
4572
4629
  binding.section,
4573
4630
  binding.upstreamAlias,
4574
4631
  changePropName,
4632
+ void 0,
4575
4633
  id.node.loc,
4576
4634
  true
4577
4635
  );
@@ -4593,7 +4651,7 @@ function setReferencesScope(path5) {
4593
4651
  (fnRoot.node.extra ??= {}).referencesScope = true;
4594
4652
  }
4595
4653
  }
4596
- function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAlias, property) {
4654
+ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAlias, property, excludeProperties) {
4597
4655
  switch (lVal.type) {
4598
4656
  case "Identifier":
4599
4657
  trackReferencesForBinding(
@@ -4604,6 +4662,7 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4604
4662
  section,
4605
4663
  upstreamAlias,
4606
4664
  property,
4665
+ excludeProperties,
4607
4666
  lVal.loc,
4608
4667
  true
4609
4668
  )
@@ -4616,8 +4675,10 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4616
4675
  section,
4617
4676
  upstreamAlias,
4618
4677
  property,
4678
+ excludeProperties,
4619
4679
  lVal.loc
4620
4680
  ));
4681
+ const hasRest = lVal.properties[lVal.properties.length - 1]?.type === "RestElement";
4621
4682
  for (const prop of lVal.properties) {
4622
4683
  if (prop.type === "RestElement") {
4623
4684
  createBindingsAndTrackReferences(
@@ -4626,7 +4687,8 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4626
4687
  scope,
4627
4688
  section,
4628
4689
  patternBinding,
4629
- property
4690
+ property,
4691
+ excludeProperties
4630
4692
  );
4631
4693
  } else {
4632
4694
  let key;
@@ -4637,13 +4699,17 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4637
4699
  } else {
4638
4700
  throw new Error("computed keys not supported in object pattern");
4639
4701
  }
4702
+ if (hasRest) {
4703
+ excludeProperties = propsUtil.add(excludeProperties, key);
4704
+ }
4640
4705
  createBindingsAndTrackReferences(
4641
4706
  prop.value,
4642
4707
  type,
4643
4708
  scope,
4644
4709
  section,
4645
4710
  patternBinding,
4646
- key
4711
+ key,
4712
+ void 0
4647
4713
  );
4648
4714
  }
4649
4715
  }
@@ -4656,6 +4722,7 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4656
4722
  section,
4657
4723
  upstreamAlias,
4658
4724
  property,
4725
+ excludeProperties,
4659
4726
  lVal.loc
4660
4727
  ));
4661
4728
  let i = -1;
@@ -4663,13 +4730,18 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4663
4730
  i++;
4664
4731
  if (element) {
4665
4732
  if (element.type === "RestElement") {
4733
+ excludeProperties = addNumericPropertiesUntil(
4734
+ excludeProperties,
4735
+ i - 1
4736
+ );
4666
4737
  createBindingsAndTrackReferences(
4667
4738
  element.argument,
4668
4739
  type,
4669
4740
  scope,
4670
4741
  section,
4671
4742
  patternBinding,
4672
- property
4743
+ property,
4744
+ excludeProperties
4673
4745
  );
4674
4746
  } else {
4675
4747
  createBindingsAndTrackReferences(
@@ -4678,7 +4750,8 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4678
4750
  scope,
4679
4751
  section,
4680
4752
  patternBinding,
4681
- `${i}`
4753
+ `${i}`,
4754
+ void 0
4682
4755
  );
4683
4756
  }
4684
4757
  }
@@ -4692,7 +4765,8 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4692
4765
  scope,
4693
4766
  section,
4694
4767
  upstreamAlias,
4695
- property
4768
+ property,
4769
+ void 0
4696
4770
  );
4697
4771
  break;
4698
4772
  }
@@ -4706,6 +4780,9 @@ function trackReference(referencePath, binding) {
4706
4780
  if (!import_compiler24.types.isMemberExpression(parent)) break;
4707
4781
  const prop = getMemberExpressionPropString(parent);
4708
4782
  if (prop === void 0) break;
4783
+ if (reference.upstreamAlias && reference.excludeProperties !== void 0 && !propsUtil.has(reference.excludeProperties, prop)) {
4784
+ reference = reference.upstreamAlias;
4785
+ }
4709
4786
  if (reference.propertyAliases.has(prop)) {
4710
4787
  root = root.parentPath;
4711
4788
  reference = reference.propertyAliases.get(prop);
@@ -5166,6 +5243,9 @@ function mergeSources(a, b) {
5166
5243
  var bindingUtil = new Sorted(function compareBindings(a, b) {
5167
5244
  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
5245
  });
5246
+ var propsUtil = new Sorted(function compareProps(a, b) {
5247
+ return a < b ? -1 : a > b ? 1 : 0;
5248
+ });
5169
5249
  var [getReadsByExpression] = createProgramState(
5170
5250
  () => /* @__PURE__ */ new Map()
5171
5251
  );
@@ -5201,7 +5281,11 @@ function dropReferences(node) {
5201
5281
  }
5202
5282
  }
5203
5283
  function getCanonicalBinding(binding) {
5204
- return binding && (binding.property ? binding : binding.upstreamAlias || binding);
5284
+ const alias = binding?.upstreamAlias;
5285
+ if (alias && binding.property === void 0 && binding.excludeProperties === void 0) {
5286
+ return alias;
5287
+ }
5288
+ return binding;
5205
5289
  }
5206
5290
  function getAllTagReferenceNodes(tag, referenceNodes = []) {
5207
5291
  if (tag.arguments) {
@@ -5245,7 +5329,7 @@ function getScopeAccessor(binding, includeId) {
5245
5329
  function getDebugScopeAccess(binding) {
5246
5330
  let root = binding;
5247
5331
  let access = "";
5248
- while (!(root.loc || root.declared) && root.upstreamAlias) {
5332
+ while (!(root.loc || root.declared) && root.upstreamAlias && root.excludeProperties === void 0) {
5249
5333
  if (root.property !== void 0) {
5250
5334
  access = toAccess(root.property) + access;
5251
5335
  }
@@ -5400,7 +5484,12 @@ function isSupersetSources(a, b) {
5400
5484
  return bindingUtil.isSuperset(a.sources.state, b.sources.state) && bindingUtil.isSuperset(a.sources.input, b.sources.input);
5401
5485
  }
5402
5486
  function getCanonicalProperty(binding) {
5403
- return binding.property ?? binding.upstreamAlias?.property;
5487
+ if (binding.property !== void 0) {
5488
+ return binding.property;
5489
+ }
5490
+ if (binding.upstreamAlias && binding.excludeProperties === void 0) {
5491
+ return binding.upstreamAlias.property;
5492
+ }
5404
5493
  }
5405
5494
  function createRead(binding, props) {
5406
5495
  return { binding, props };
@@ -5428,6 +5517,13 @@ function isAssignedBindingExtra(extra) {
5428
5517
  function isRegisteredFnExtra(extra) {
5429
5518
  return isReferencedExtra(extra) && extra.registerId !== void 0;
5430
5519
  }
5520
+ function addNumericPropertiesUntil(props, len) {
5521
+ let result = props;
5522
+ for (let i = len; i--; ) {
5523
+ result = propsUtil.add(result, i + "");
5524
+ }
5525
+ return result;
5526
+ }
5431
5527
 
5432
5528
  // src/translator/core/await.ts
5433
5529
  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: undefined | string[];
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.33",
3
+ "version": "6.0.35",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",