marko 6.0.32 → 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.
@@ -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");
@@ -867,6 +897,9 @@ var Sorted = class {
867
897
  }
868
898
  }
869
899
  }
900
+ has(data, item) {
901
+ return this.findIndex(data, item) !== -1;
902
+ }
870
903
  findIndex(data, item) {
871
904
  if (data) {
872
905
  if (Array.isArray(data)) {
@@ -2960,7 +2993,7 @@ var return_default = {
2960
2993
  var import_compiler18 = require("@marko/compiler");
2961
2994
  function getDeclaredBindingExpression(binding) {
2962
2995
  const canonicalBinding = getCanonicalBinding(binding);
2963
- if (canonicalBinding.declared || !canonicalBinding.upstreamAlias) {
2996
+ if (canonicalBinding.declared || !canonicalBinding.upstreamAlias || canonicalBinding.excludeProperties !== void 0) {
2964
2997
  return import_compiler18.types.identifier(canonicalBinding.name);
2965
2998
  } else if (canonicalBinding.property !== void 0) {
2966
2999
  return toMemberExpression(
@@ -3118,7 +3151,7 @@ function initValue(binding, runtimeHelper = "value") {
3118
3151
  signal.build = () => {
3119
3152
  const fn = getSignalFn(signal);
3120
3153
  const isParamBinding = !binding.upstreamAlias && (binding.type === 3 /* param */ || binding.type === 4 /* local */ || binding.type === 2 /* input */);
3121
- const isNakedAlias = binding.upstreamAlias && !binding.property;
3154
+ const isNakedAlias = binding.upstreamAlias && binding.property === void 0 && binding.excludeProperties === void 0;
3122
3155
  const needsGuard = !isNakedAlias && (binding.closureSections || binding.downstreamExpressions.size || fn.type === "ArrowFunctionExpression" && fn.body.body.length > 0);
3123
3156
  const needsCache = needsGuard || signal.intersection;
3124
3157
  const needsMarks = isParamBinding || signal.intersection;
@@ -3161,15 +3194,48 @@ function getSignalFn(signal) {
3161
3194
  for (const alias of binding.aliases) {
3162
3195
  const aliasSignal = getSignal(alias.section, alias);
3163
3196
  if (aliasSignal.render.length || aliasSignal.values.length || aliasSignal.effect.length) {
3164
- signal.render.push(
3165
- import_compiler20.types.expressionStatement(
3166
- import_compiler20.types.callExpression(aliasSignal.identifier, [
3167
- scopeIdentifier,
3168
- import_compiler20.types.identifier(binding.name),
3169
- ...getTranslatedExtraArgs(aliasSignal)
3170
- ])
3171
- )
3172
- );
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
+ }
3173
3239
  }
3174
3240
  }
3175
3241
  for (const [key, alias] of binding.propertyAliases) {
@@ -3191,7 +3257,7 @@ function getSignalFn(signal) {
3191
3257
  }
3192
3258
  for (const value of signal.values) {
3193
3259
  const valSignal = value.signal;
3194
- 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) {
3195
3261
  signal.render.push(
3196
3262
  import_compiler20.types.expressionStatement(
3197
3263
  import_compiler20.types.callExpression(value.signal.identifier, [
@@ -3285,7 +3351,7 @@ function getSignalFn(signal) {
3285
3351
  for (; i--; ) {
3286
3352
  const param = params[i];
3287
3353
  const arg = args[i];
3288
- if (arg.type !== "Identifier" || param.name !== arg.name) {
3354
+ if (arg.type !== "Identifier" || param.type !== "Identifier" || param.name !== arg.name) {
3289
3355
  break;
3290
3356
  }
3291
3357
  }
@@ -3316,7 +3382,7 @@ function getTranslatedExtraArgs(signal) {
3316
3382
  function subscribe(references, subscriber) {
3317
3383
  if (references) {
3318
3384
  forEach(references, (binding) => {
3319
- const source = binding.property === void 0 && binding.upstreamAlias || binding;
3385
+ const source = binding.property === void 0 && binding.excludeProperties === void 0 && binding.upstreamAlias || binding;
3320
3386
  const providerSignal = getSignal(subscriber.section, source);
3321
3387
  providerSignal.intersection = push(
3322
3388
  providerSignal.intersection,
@@ -3491,7 +3557,7 @@ function writeSignals(section) {
3491
3557
  // It's possible for aliases to render nothing
3492
3558
  // if they're only consumed in effects/closures.
3493
3559
  // This ignores writing out those signals in that case.
3494
- 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
3495
3561
  ) {
3496
3562
  return;
3497
3563
  }
@@ -3884,10 +3950,7 @@ function replaceAssignedNode(node) {
3884
3950
  case "UpdateExpression": {
3885
3951
  const { extra } = node.argument;
3886
3952
  if (isAssignedBindingExtra(extra)) {
3887
- const { buildAssignment } = getSignal(
3888
- extra.assignment.section,
3889
- extra.assignment
3890
- );
3953
+ const buildAssignment = getBuildAssignment(extra);
3891
3954
  if (buildAssignment) {
3892
3955
  const replacement = buildAssignment(
3893
3956
  extra.section,
@@ -3910,10 +3973,7 @@ function replaceAssignedNode(node) {
3910
3973
  case "Identifier": {
3911
3974
  const { extra } = node.left;
3912
3975
  if (isAssignedBindingExtra(extra)) {
3913
- const { buildAssignment } = getSignal(
3914
- extra.assignment.section,
3915
- extra.assignment
3916
- );
3976
+ const buildAssignment = getBuildAssignment(extra);
3917
3977
  if (buildAssignment) {
3918
3978
  return buildAssignment(
3919
3979
  extra.section,
@@ -3937,15 +3997,12 @@ function replaceAssignedNode(node) {
3937
3997
  forEachIdentifier(node.left, (id) => {
3938
3998
  const { extra } = id;
3939
3999
  if (isAssignedBindingExtra(extra)) {
3940
- const signal = getSignal(
3941
- extra.assignment.section,
3942
- extra.assignment
3943
- );
3944
- if (signal?.buildAssignment) {
4000
+ const buildAssignment = getBuildAssignment(extra);
4001
+ if (buildAssignment) {
3945
4002
  id.name = generateUid(id.name);
3946
4003
  (params ||= []).push(import_compiler20.types.identifier(id.name));
3947
4004
  (assignments ||= []).push(
3948
- signal.buildAssignment(extra.section, import_compiler20.types.identifier(id.name))
4005
+ buildAssignment(extra.section, import_compiler20.types.identifier(id.name))
3949
4006
  );
3950
4007
  }
3951
4008
  }
@@ -3974,6 +4031,15 @@ function replaceAssignedNode(node) {
3974
4031
  break;
3975
4032
  }
3976
4033
  }
4034
+ function getBuildAssignment(extra) {
4035
+ const { assignmentTo, assignment } = extra;
4036
+ if (assignmentTo) {
4037
+ return (_section, value) => {
4038
+ return import_compiler20.types.callExpression(import_compiler20.types.identifier(assignmentTo.name), [value]);
4039
+ };
4040
+ }
4041
+ return getSignal(assignment.section, assignment).buildAssignment;
4042
+ }
3977
4043
  var registeredFnsForProgram = /* @__PURE__ */ new WeakMap();
3978
4044
  function replaceRegisteredFunctionNode2(node) {
3979
4045
  switch (node.type) {
@@ -4365,7 +4431,7 @@ var kIsInvoked = Symbol("hoist is invoked");
4365
4431
  var kBranchSerializeReason = Symbol("branch serialize reason");
4366
4432
  var [getBindings] = createProgramState(() => /* @__PURE__ */ new Set());
4367
4433
  var [getNextBindingId, setNextBindingId] = createProgramState(() => 0);
4368
- function createBinding(name2, type, section, upstreamAlias, property, loc = null, declared = false) {
4434
+ function createBinding(name2, type, section, upstreamAlias, property, excludeProperties, loc = null, declared = false) {
4369
4435
  const id = getNextBindingId();
4370
4436
  const binding = {
4371
4437
  id,
@@ -4377,7 +4443,7 @@ function createBinding(name2, type, section, upstreamAlias, property, loc = null
4377
4443
  declared,
4378
4444
  closureSections: void 0,
4379
4445
  assignmentSections: void 0,
4380
- excludeProperties: void 0,
4446
+ excludeProperties,
4381
4447
  sources: void 0,
4382
4448
  aliases: /* @__PURE__ */ new Set(),
4383
4449
  hoists: /* @__PURE__ */ new Map(),
@@ -4386,7 +4452,7 @@ function createBinding(name2, type, section, upstreamAlias, property, loc = null
4386
4452
  downstreamExpressions: /* @__PURE__ */ new Set(),
4387
4453
  scopeOffset: void 0,
4388
4454
  export: void 0,
4389
- nullable: true
4455
+ nullable: excludeProperties === void 0
4390
4456
  };
4391
4457
  if (property) {
4392
4458
  if (declared) upstreamAlias.nullable = false;
@@ -4416,6 +4482,7 @@ function trackVarReferences(tag, type, upstreamAlias) {
4416
4482
  tag.scope,
4417
4483
  canonicalUpstreamAlias.section,
4418
4484
  canonicalUpstreamAlias,
4485
+ void 0,
4419
4486
  void 0
4420
4487
  );
4421
4488
  return canonicalUpstreamAlias;
@@ -4426,6 +4493,7 @@ function trackVarReferences(tag, type, upstreamAlias) {
4426
4493
  tag.scope,
4427
4494
  getOrCreateSection(tag),
4428
4495
  void 0,
4496
+ void 0,
4429
4497
  void 0
4430
4498
  );
4431
4499
  return tagVar.extra?.binding;
@@ -4451,14 +4519,28 @@ function trackParamsReferences(body, type, upstreamAlias) {
4451
4519
  ));
4452
4520
  section.params = paramsBinding;
4453
4521
  for (let i = 0; i < params.length; i++) {
4454
- createBindingsAndTrackReferences(
4455
- params[i],
4456
- type,
4457
- body.scope,
4458
- section,
4459
- paramsBinding,
4460
- i + ""
4461
- );
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
+ }
4462
4544
  }
4463
4545
  return paramsBinding;
4464
4546
  }
@@ -4478,6 +4560,7 @@ function trackHoistedReference(referencePath, binding) {
4478
4560
  hoistSection,
4479
4561
  void 0,
4480
4562
  void 0,
4563
+ void 0,
4481
4564
  binding.loc,
4482
4565
  true
4483
4566
  )
@@ -4531,9 +4614,24 @@ function trackReferencesForBinding(babelBinding, binding) {
4531
4614
  function trackAssignment(assignment, binding) {
4532
4615
  const section = getOrCreateSection(assignment);
4533
4616
  setReferencesScope(assignment);
4534
- forEachIdentifier(assignment.node, (id) => {
4535
- if (id.name === binding.name) {
4536
- const extra = id.extra ??= {};
4617
+ forEachIdentifierPath(assignment, (id) => {
4618
+ if (id.node.name === binding.name) {
4619
+ const extra = id.node.extra ??= {};
4620
+ if (binding.upstreamAlias && binding.property !== void 0) {
4621
+ const changePropName = binding.property + "Change";
4622
+ const changeBinding = binding.upstreamAlias.propertyAliases.get(changePropName) || createBinding(
4623
+ generateUid(changePropName),
4624
+ 5 /* derived */,
4625
+ binding.section,
4626
+ binding.upstreamAlias,
4627
+ changePropName,
4628
+ void 0,
4629
+ id.node.loc,
4630
+ true
4631
+ );
4632
+ extra.assignmentTo = changeBinding;
4633
+ addReadToExpression(id, changeBinding);
4634
+ }
4537
4635
  binding.assignmentSections = sectionUtil.add(
4538
4636
  binding.assignmentSections,
4539
4637
  section
@@ -4549,7 +4647,7 @@ function setReferencesScope(path5) {
4549
4647
  (fnRoot.node.extra ??= {}).referencesScope = true;
4550
4648
  }
4551
4649
  }
4552
- function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAlias, property) {
4650
+ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAlias, property, excludeProperties) {
4553
4651
  switch (lVal.type) {
4554
4652
  case "Identifier":
4555
4653
  trackReferencesForBinding(
@@ -4560,6 +4658,7 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4560
4658
  section,
4561
4659
  upstreamAlias,
4562
4660
  property,
4661
+ excludeProperties,
4563
4662
  lVal.loc,
4564
4663
  true
4565
4664
  )
@@ -4572,8 +4671,10 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4572
4671
  section,
4573
4672
  upstreamAlias,
4574
4673
  property,
4674
+ excludeProperties,
4575
4675
  lVal.loc
4576
4676
  ));
4677
+ const hasRest = lVal.properties[lVal.properties.length - 1]?.type === "RestElement";
4577
4678
  for (const prop of lVal.properties) {
4578
4679
  if (prop.type === "RestElement") {
4579
4680
  createBindingsAndTrackReferences(
@@ -4582,7 +4683,8 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4582
4683
  scope,
4583
4684
  section,
4584
4685
  patternBinding,
4585
- property
4686
+ property,
4687
+ excludeProperties
4586
4688
  );
4587
4689
  } else {
4588
4690
  let key;
@@ -4593,13 +4695,17 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4593
4695
  } else {
4594
4696
  throw new Error("computed keys not supported in object pattern");
4595
4697
  }
4698
+ if (hasRest) {
4699
+ excludeProperties = propsUtil.add(excludeProperties, key);
4700
+ }
4596
4701
  createBindingsAndTrackReferences(
4597
4702
  prop.value,
4598
4703
  type,
4599
4704
  scope,
4600
4705
  section,
4601
4706
  patternBinding,
4602
- key
4707
+ key,
4708
+ void 0
4603
4709
  );
4604
4710
  }
4605
4711
  }
@@ -4612,6 +4718,7 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4612
4718
  section,
4613
4719
  upstreamAlias,
4614
4720
  property,
4721
+ excludeProperties,
4615
4722
  lVal.loc
4616
4723
  ));
4617
4724
  let i = -1;
@@ -4619,13 +4726,18 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4619
4726
  i++;
4620
4727
  if (element) {
4621
4728
  if (element.type === "RestElement") {
4729
+ excludeProperties = addNumericPropertiesUntil(
4730
+ excludeProperties,
4731
+ i - 1
4732
+ );
4622
4733
  createBindingsAndTrackReferences(
4623
4734
  element.argument,
4624
4735
  type,
4625
4736
  scope,
4626
4737
  section,
4627
4738
  patternBinding,
4628
- property
4739
+ property,
4740
+ excludeProperties
4629
4741
  );
4630
4742
  } else {
4631
4743
  createBindingsAndTrackReferences(
@@ -4634,7 +4746,8 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4634
4746
  scope,
4635
4747
  section,
4636
4748
  patternBinding,
4637
- `${i}`
4749
+ `${i}`,
4750
+ void 0
4638
4751
  );
4639
4752
  }
4640
4753
  }
@@ -4648,7 +4761,8 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
4648
4761
  scope,
4649
4762
  section,
4650
4763
  upstreamAlias,
4651
- property
4764
+ property,
4765
+ void 0
4652
4766
  );
4653
4767
  break;
4654
4768
  }
@@ -4662,6 +4776,9 @@ function trackReference(referencePath, binding) {
4662
4776
  if (!import_compiler24.types.isMemberExpression(parent)) break;
4663
4777
  const prop = getMemberExpressionPropString(parent);
4664
4778
  if (prop === void 0) break;
4779
+ if (reference.upstreamAlias && reference.excludeProperties !== void 0 && !propsUtil.has(reference.excludeProperties, prop)) {
4780
+ reference = reference.upstreamAlias;
4781
+ }
4665
4782
  if (reference.propertyAliases.has(prop)) {
4666
4783
  root = root.parentPath;
4667
4784
  reference = reference.propertyAliases.get(prop);
@@ -4680,21 +4797,7 @@ function trackReference(referencePath, binding) {
4680
4797
  prop
4681
4798
  );
4682
4799
  }
4683
- const fnRoot = getFnRoot(root);
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
- }
4800
+ addReadToExpression(root, reference);
4698
4801
  }
4699
4802
  var [getMergedReferences] = createProgramState(
4700
4803
  () => /* @__PURE__ */ new Map()
@@ -5136,21 +5239,33 @@ function mergeSources(a, b) {
5136
5239
  var bindingUtil = new Sorted(function compareBindings(a, b) {
5137
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;
5138
5241
  });
5242
+ var propsUtil = new Sorted(function compareProps(a, b) {
5243
+ return a < b ? -1 : a > b ? 1 : 0;
5244
+ });
5139
5245
  var [getReadsByExpression] = createProgramState(
5140
5246
  () => /* @__PURE__ */ new Map()
5141
5247
  );
5142
5248
  var [getReadsByFunction] = createProgramState(
5143
5249
  () => /* @__PURE__ */ new Map()
5144
5250
  );
5145
- function addReadToExpression(path5, binding, node) {
5146
- const exprExtra = path5.node.extra ??= {};
5251
+ function addReadToExpression(root, binding) {
5252
+ const { node } = root;
5253
+ const fnRoot = getFnRoot(root);
5254
+ const exprRoot = getExprRoot(fnRoot || root);
5255
+ const exprExtra = exprRoot.node.extra ??= {};
5147
5256
  const readsByExpression = getReadsByExpression();
5148
- exprExtra.section = getOrCreateSection(path5);
5257
+ const section = exprExtra.section = getOrCreateSection(exprRoot);
5258
+ const read = { binding, node };
5149
5259
  readsByExpression.set(
5150
5260
  exprExtra,
5151
- push(readsByExpression.get(exprExtra), { binding, node })
5261
+ push(readsByExpression.get(exprExtra), read)
5152
5262
  );
5153
- return exprExtra;
5263
+ if (fnRoot) {
5264
+ const readsByFn = getReadsByFunction();
5265
+ const fnExtra = fnRoot.node.extra ??= {};
5266
+ fnExtra.section = section;
5267
+ readsByFn.set(fnExtra, push(readsByFn.get(fnExtra), read));
5268
+ }
5154
5269
  }
5155
5270
  function dropReferences(node) {
5156
5271
  if (Array.isArray(node)) {
@@ -5162,7 +5277,11 @@ function dropReferences(node) {
5162
5277
  }
5163
5278
  }
5164
5279
  function getCanonicalBinding(binding) {
5165
- return binding && (binding.property ? binding : binding.upstreamAlias || binding);
5280
+ const alias = binding?.upstreamAlias;
5281
+ if (alias && binding.property === void 0 && binding.excludeProperties === void 0) {
5282
+ return alias;
5283
+ }
5284
+ return binding;
5166
5285
  }
5167
5286
  function getAllTagReferenceNodes(tag, referenceNodes = []) {
5168
5287
  if (tag.arguments) {
@@ -5206,7 +5325,7 @@ function getScopeAccessor(binding, includeId) {
5206
5325
  function getDebugScopeAccess(binding) {
5207
5326
  let root = binding;
5208
5327
  let access = "";
5209
- while (!(root.loc || root.declared) && root.upstreamAlias) {
5328
+ while (!(root.loc || root.declared) && root.upstreamAlias && root.excludeProperties === void 0) {
5210
5329
  if (root.property !== void 0) {
5211
5330
  access = toAccess(root.property) + access;
5212
5331
  }
@@ -5361,7 +5480,12 @@ function isSupersetSources(a, b) {
5361
5480
  return bindingUtil.isSuperset(a.sources.state, b.sources.state) && bindingUtil.isSuperset(a.sources.input, b.sources.input);
5362
5481
  }
5363
5482
  function getCanonicalProperty(binding) {
5364
- return binding.property ?? binding.upstreamAlias?.property;
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
+ }
5365
5489
  }
5366
5490
  function createRead(binding, props) {
5367
5491
  return { binding, props };
@@ -5389,6 +5513,13 @@ function isAssignedBindingExtra(extra) {
5389
5513
  function isRegisteredFnExtra(extra) {
5390
5514
  return isReferencedExtra(extra) && extra.registerId !== void 0;
5391
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
+ }
5392
5523
 
5393
5524
  // src/translator/core/await.ts
5394
5525
  var kDOMBinding = Symbol("await tag dom binding");
@@ -5561,10 +5692,36 @@ function translateVar(tag, initialValue, kind = "const") {
5561
5692
  if (!tagVar) {
5562
5693
  return;
5563
5694
  }
5695
+ forEachIdentifierPath(tag.get("var"), (id) => {
5696
+ const binding = id.node.extra?.binding;
5697
+ if (!binding || !binding.upstreamAlias || !binding.assignmentSections || id.node === tagVar) {
5698
+ return;
5699
+ }
5700
+ const changeName = binding.name + "Change";
5701
+ const changeBinding = binding.upstreamAlias.propertyAliases.get(changeName);
5702
+ if (changeBinding && changeName !== changeBinding.name) {
5703
+ getDestructurePattern(id)?.pushContainer(
5704
+ "properties",
5705
+ import_compiler27.types.objectProperty(
5706
+ import_compiler27.types.identifier(changeName),
5707
+ import_compiler27.types.identifier(changeBinding.name)
5708
+ )
5709
+ );
5710
+ }
5711
+ });
5564
5712
  tag.insertBefore(
5565
5713
  import_compiler27.types.variableDeclaration(kind, [import_compiler27.types.variableDeclarator(tagVar, initialValue)])
5566
5714
  );
5567
5715
  }
5716
+ function getDestructurePattern(id) {
5717
+ let cur = id;
5718
+ while (cur) {
5719
+ if (cur.node.type === "ObjectPattern") {
5720
+ return cur;
5721
+ }
5722
+ cur = cur.parentPath;
5723
+ }
5724
+ }
5568
5725
 
5569
5726
  // src/translator/core/const.ts
5570
5727
  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;
@@ -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;
@@ -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>;
@@ -69,7 +70,7 @@ declare module "@marko/compiler/dist/types" {
69
70
  interface FunctionExpressionExtra extends FunctionExtra {
70
71
  }
71
72
  }
72
- 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;
73
74
  export declare function trackVarReferences(tag: t.NodePath<t.MarkoTag>, type: BindingType, upstreamAlias?: Binding["upstreamAlias"]): Binding | undefined;
74
75
  export declare function trackParamsReferences(body: t.NodePath<t.MarkoTagBody | t.Program>, type: BindingType, upstreamAlias?: Binding["upstreamAlias"]): Binding | undefined;
75
76
  export declare function trackHoistedReference(referencePath: t.NodePath<t.Identifier>, binding: Binding): void;
@@ -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[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.32",
3
+ "version": "6.0.34",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",