marko 6.0.98 → 6.0.100

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.
@@ -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
- [import_compiler22.types.identifier(binding.name)]
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
- import_compiler22.types.identifier(binding.name),
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
- import_compiler22.types.identifier(binding.name),
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("_assert_hoist", import_compiler22.types.identifier(binding.name))
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 (params.length >= args.length) {
3576
- let i = args.length;
3577
- for (; i--; ) {
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(params, import_compiler22.types.blockStatement(signal.render));
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 (!signal.build || seen.has(signal)) return;
3712
+ if (seen.has(signal)) return;
3762
3713
  seen.add(signal);
3763
- for (const value2 of signal.values) {
3764
- writeSignal(value2.signal);
3765
- traverseReplace(value2, "value", replaceRenderNode);
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
- referencedBindings ? referencesScope ? [
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 value = signal.build();
3798
- if (!value || !signal.register && import_compiler22.types.isFunction(value) && import_compiler22.types.isBlockStatement(value.body) && !value.body.body.length) {
3799
- return;
3800
- }
3801
- if (import_compiler22.types.isCallExpression(value)) {
3802
- replaceNullishAndEmptyFunctionsWith0(value.arguments);
3803
- }
3804
- if (signal.register) {
3805
- value = callRuntime(
3806
- "_var_resume",
3807
- import_compiler22.types.stringLiteral(
3808
- getResumeRegisterId(section, signal.referencedBindings, "var")
3809
- ),
3810
- value
3811
- );
3812
- }
3813
- const signalDeclarator = import_compiler22.types.variableDeclarator(signal.identifier, value);
3814
- let signalDeclaration = !section.parent && !signal.referencedBindings && (import_compiler22.types.isFunctionExpression(value) || import_compiler22.types.isArrowFunctionExpression(value)) ? import_compiler22.types.functionDeclaration(
3815
- signal.identifier,
3816
- value.params,
3817
- import_compiler22.types.isExpression(value.body) ? import_compiler22.types.blockStatement([import_compiler22.types.expressionStatement(value.body)]) : value.body
3818
- ) : import_compiler22.types.variableDeclaration("const", [signalDeclarator]);
3819
- if (signal.export) {
3820
- signalDeclaration = import_compiler22.types.exportNamedDeclaration(signalDeclaration);
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
- signalStatements.push(signalDeclaration);
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
- const params = registeredFn.referencedBindings ? registeredFn.referencesScope ? [
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
- params,
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 === "SequenceExpression" && updateExpressions.delete(node.expression)) {
4172
- node.expression = node.expression.expressions[0];
4173
- return node;
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
- const builtAssignment = getBuildAssignment(extra)?.(
4116
+ let builtAssignment = getBuildAssignment(extra)?.(
4181
4117
  extra.section,
4182
- node
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
- node.prefix = true;
4187
- const replacement = import_compiler22.types.sequenceExpression([
4126
+ builtAssignment = import_compiler22.types.binaryExpression(
4127
+ node.operator === "++" ? "-" : "+",
4188
4128
  builtAssignment,
4189
- import_compiler22.types.binaryExpression(
4190
- node.operator === "++" ? "-" : "+",
4191
- node.argument,
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
- bindingUtil.has(
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
- node.left,
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
- if (!bindingUtil.has(
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 (_section, value) => {
4284
- return import_compiler22.types.callExpression(import_compiler22.types.identifier(assignmentTo.name), [value]);
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;
@@ -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, (closure, render) => {
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 fnRoot = getFnRoot(assignment);
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(
@@ -8546,6 +8484,8 @@ function resolveBindingSources(binding) {
8546
8484
  binding.sources = aliasRoot2.sources;
8547
8485
  } else if (binding.assignmentSections) {
8548
8486
  binding.sources = createSources(binding, void 0);
8487
+ } else {
8488
+ resolveDerivedSources(binding);
8549
8489
  }
8550
8490
  return;
8551
8491
  }
@@ -8780,78 +8720,74 @@ function getSectionInstancesAccessorLiteral(section) {
8780
8720
  }
8781
8721
  function getReadReplacement(node) {
8782
8722
  const { extra } = node;
8783
- if (!extra) return;
8784
- let { binding, read } = extra;
8785
- let replacement;
8723
+ if (!extra || extra.assignment) return;
8724
+ const { read, binding } = extra;
8786
8725
  if (read) {
8726
+ const readBinding = read.binding;
8727
+ let replacement;
8787
8728
  if (read.props === void 0) {
8788
- binding = read.binding;
8789
- read = void 0;
8790
- } else {
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()) {
8729
+ if (isOutputDOM()) {
8730
+ if (readBinding.type === 0 /* dom */) {
8731
+ if (!extra[kIsInvoked] && readBinding.section.domGetterBindings.has(readBinding)) {
8805
8732
  replacement = import_compiler35.types.callExpression(
8806
- getBindingGetterIdentifier(binding),
8807
- [getScopeExpression(node.extra.section, binding.section)]
8733
+ getBindingGetterIdentifier(readBinding),
8734
+ [getScopeExpression(extra.section, readBinding.section)]
8808
8735
  );
8809
8736
  }
8737
+ } else if (readBinding.type === 6 /* hoist */ && extra[kIsInvoked]) {
8738
+ replacement = import_compiler35.types.callExpression(
8739
+ getBindingGetterIdentifier(readBinding),
8740
+ [getScopeExpression(extra.section, readBinding.section)]
8741
+ );
8810
8742
  } else {
8811
- replacement = import_compiler35.types.identifier(binding.name);
8743
+ replacement = createScopeReadExpression(extra.section, readBinding);
8744
+ }
8745
+ } else {
8746
+ if (node.type !== "Identifier") {
8747
+ replacement = import_compiler35.types.identifier(readBinding.name);
8748
+ } else if (readBinding.name !== node.name && readBinding.type !== 0 /* dom */ && (readBinding.type !== 6 /* hoist */ || !extra[kIsInvoked])) {
8749
+ node.name = readBinding.name;
8812
8750
  }
8813
- } else if (binding.name !== node.name) {
8814
- node.name = binding.name;
8815
8751
  }
8816
8752
  } else {
8817
- replacement = import_compiler35.types.identifier(binding.name);
8818
- }
8819
- } else if (read) {
8820
- const props = read.props ? Array.isArray(read.props) ? read.props.slice() : [read.props] : [];
8821
- let curNode = node;
8822
- let curBinding = read.binding;
8823
- let replaceMember;
8824
- replacement = import_compiler35.types.identifier(read.binding.name);
8825
- while (props.length && (curNode.type === "MemberExpression" || curNode.type === "OptionalMemberExpression")) {
8826
- const prop = props.pop();
8827
- const memberProp = getMemberExpressionPropString(curNode);
8828
- if (memberProp !== prop) break;
8829
- replaceMember = curNode;
8830
- curNode = curNode.object;
8831
- }
8832
- for (const prop of props) {
8833
- if (curBinding) {
8834
- curBinding = curBinding.propertyAliases.get(prop);
8835
- }
8836
- replacement = toMemberExpression(
8837
- replacement,
8838
- prop,
8839
- !!curBinding?.nullable
8840
- );
8841
- }
8842
- if (replaceMember) {
8843
- if (read.binding.nullable && replaceMember.object.type !== replacement.type) {
8844
- replaceMember.type = "OptionalMemberExpression";
8845
- replaceMember.optional = true;
8753
+ const props = read.props ? Array.isArray(read.props) ? read.props.slice() : [read.props] : [];
8754
+ let curNode = node;
8755
+ let curBinding = read.binding;
8756
+ let replaceMember;
8757
+ replacement = isOutputDOM() ? createScopeReadExpression(extra.section, read.binding) : import_compiler35.types.identifier(read.binding.name);
8758
+ while (props.length && (curNode.type === "MemberExpression" || curNode.type === "OptionalMemberExpression")) {
8759
+ const prop = props.pop();
8760
+ const memberProp = getMemberExpressionPropString(curNode);
8761
+ if (memberProp !== prop) break;
8762
+ replaceMember = curNode;
8763
+ curNode = curNode.object;
8764
+ }
8765
+ for (const prop of props) {
8766
+ if (curBinding) {
8767
+ curBinding = curBinding.propertyAliases.get(prop);
8768
+ }
8769
+ replacement = toMemberExpression(
8770
+ replacement,
8771
+ prop,
8772
+ !!curBinding?.nullable
8773
+ );
8774
+ }
8775
+ if (replaceMember) {
8776
+ if (read.binding.nullable && replaceMember.object.type !== replacement.type) {
8777
+ replaceMember.type = "OptionalMemberExpression";
8778
+ replaceMember.optional = true;
8779
+ }
8780
+ replaceMember.object = withPreviousLocation(
8781
+ replacement,
8782
+ replaceMember.object
8783
+ );
8784
+ replacement = void 0;
8846
8785
  }
8847
- replaceMember.object = withPreviousLocation(
8848
- replacement,
8849
- replaceMember.object
8850
- );
8851
- replacement = void 0;
8852
8786
  }
8787
+ return replacement && withPreviousLocation(replacement, node);
8788
+ } else if (binding && node.type == "Identifier" && node.name !== binding.name) {
8789
+ node.name = binding.name;
8853
8790
  }
8854
- return replacement && withPreviousLocation(replacement, node);
8855
8791
  }
8856
8792
  function pruneBinding(bindings, binding) {
8857
8793
  let shouldPrune = !binding.downstreamExpressions.size;
@@ -8939,14 +8875,23 @@ function resolveReferencedBindings(expr, reads, intersectionsBySection) {
8939
8875
  const rootBindings = getRootBindings(reads);
8940
8876
  for (const read of reads) {
8941
8877
  let { binding } = read;
8942
- if (read.node && read.node.extra?.assignmentTo !== binding) {
8943
- ({ binding } = (read.node.extra ??= {}).read ??= resolveExpressionReference(rootBindings, binding));
8878
+ if (read.node) {
8879
+ const readExtra = read.node.extra ??= {};
8880
+ if (readExtra.assignmentTo !== binding) {
8881
+ readExtra.section = expr.section;
8882
+ ({ binding } = readExtra.read ??= resolveExpressionReference(
8883
+ rootBindings,
8884
+ binding
8885
+ ));
8886
+ }
8944
8887
  }
8945
8888
  referencedBindings = bindingUtil.add(referencedBindings, binding);
8946
8889
  }
8947
8890
  } else if (reads) {
8948
8891
  if (reads.node) {
8949
- (reads.node.extra ??= {}).read = createRead(reads.binding, void 0);
8892
+ const readExtra = reads.node.extra ??= {};
8893
+ readExtra.section = expr.section;
8894
+ readExtra.read = createRead(reads.binding, void 0);
8950
8895
  }
8951
8896
  referencedBindings = reads.binding;
8952
8897
  }
@@ -9284,7 +9229,7 @@ var const_default = {
9284
9229
  }
9285
9230
  }
9286
9231
  if (!valueExtra.nullable) binding.nullable = false;
9287
- setBindingDownstream(binding, valueExtra);
9232
+ if (!upstreamAlias) setBindingDownstream(binding, valueExtra);
9288
9233
  }
9289
9234
  },
9290
9235
  translate: {
@@ -10658,10 +10603,9 @@ var IfTag = {
10658
10603
  const consequent = import_compiler48.types.numericLiteral(branchBodySection ? i : -1);
10659
10604
  if (branchBodySection) {
10660
10605
  rendererIdentifiers.push(import_compiler48.types.identifier(branchBodySection.name));
10661
- setClosureSignalBuilder(branchTag, (closure, render) => {
10606
+ setClosureSignalBuilder(branchTag, (_closure, render) => {
10662
10607
  return callRuntime(
10663
10608
  "_if_closure",
10664
- getScopeAccessorLiteral(closure),
10665
10609
  getScopeAccessorLiteral(nodeRef),
10666
10610
  import_compiler48.types.numericLiteral(i),
10667
10611
  render
@@ -10888,17 +10832,20 @@ var let_default = {
10888
10832
  }
10889
10833
  const tagSection = getOrCreateSection(tag);
10890
10834
  const binding = trackVarReferences(tag, 1 /* let */);
10891
- mergeReferences(tagSection, tag.node, [
10835
+ const tagExtra = mergeReferences(tagSection, tag.node, [
10892
10836
  valueAttr?.value,
10893
10837
  valueChangeAttr?.value
10894
10838
  ]);
10895
10839
  if (valueChangeAttr) {
10840
+ setBindingDownstream(binding, tagExtra);
10896
10841
  addSerializeReason(
10897
10842
  tagSection,
10898
10843
  true,
10899
10844
  binding,
10900
10845
  getAccessorPrefix().TagVariableChange
10901
10846
  );
10847
+ } else {
10848
+ setBindingDownstream(binding, false);
10902
10849
  }
10903
10850
  },
10904
10851
  translate: {