marko 6.0.92 → 6.0.94

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.
@@ -1639,6 +1639,7 @@ function startSection(path5) {
1639
1639
  referencedClosures: void 0,
1640
1640
  referencedHoists: void 0,
1641
1641
  bindings: void 0,
1642
+ domGetterBindings: /* @__PURE__ */ new Map(),
1642
1643
  hoisted: void 0,
1643
1644
  isHoistThrough: void 0,
1644
1645
  serializeReason: void 0,
@@ -3276,14 +3277,17 @@ var [getHTMLSectionStatements] = createSectionState(
3276
3277
  "htmlScopeStatements",
3277
3278
  () => []
3278
3279
  );
3279
- var [getHoistFunctionsIdsMap] = createSectionState("hoistFunctionsIdsMap", () => /* @__PURE__ */ new Map());
3280
- function getHoistFunctionIdentifier(hoistedBinding) {
3281
- const idsMap = getHoistFunctionsIdsMap(hoistedBinding.section);
3282
- let identifier = idsMap.get(hoistedBinding);
3280
+ var [getBindingGetterIdMap] = createSectionState(
3281
+ "bindingGetterIdMap",
3282
+ () => /* @__PURE__ */ new Map()
3283
+ );
3284
+ function getBindingGetterIdentifier(binding) {
3285
+ const idsMap = getBindingGetterIdMap(binding.section);
3286
+ let identifier = idsMap.get(binding);
3283
3287
  if (!identifier) {
3284
3288
  idsMap.set(
3285
- hoistedBinding,
3286
- identifier = generateUidIdentifier(`get${hoistedBinding.name}`)
3289
+ binding,
3290
+ identifier = generateUidIdentifier(`get${binding.name}`)
3287
3291
  );
3288
3292
  }
3289
3293
  return identifier;
@@ -3392,7 +3396,8 @@ function getSignalFn(signal) {
3392
3396
  const isIntersection = Array.isArray(binding);
3393
3397
  const isBinding = binding && !isIntersection;
3394
3398
  const isValue = isBinding && binding.section === section;
3395
- if (isBinding && (signal.renderReferencedBindings || binding.aliases.size || binding.propertyAliases.size)) {
3399
+ const assertsHoists = isValue && binding.hoists.size && !isOptimize();
3400
+ if (isBinding && (signal.renderReferencedBindings || assertsHoists || binding.aliases.size || binding.propertyAliases.size)) {
3396
3401
  const valueParam = import_compiler22.types.identifier(binding.name);
3397
3402
  if (binding.loc) {
3398
3403
  valueParam.loc = binding.loc;
@@ -3465,6 +3470,13 @@ function getSignalFn(signal) {
3465
3470
  )
3466
3471
  );
3467
3472
  }
3473
+ if (assertsHoists) {
3474
+ signal.render.push(
3475
+ import_compiler22.types.expressionStatement(
3476
+ callRuntime("_assert_hoist", import_compiler22.types.identifier(binding.name))
3477
+ )
3478
+ );
3479
+ }
3468
3480
  }
3469
3481
  for (const value of signal.values) {
3470
3482
  if (signalHasStatements(value.signal)) {
@@ -3740,6 +3752,7 @@ function getRegisterUID(section, name2) {
3740
3752
  function writeSignals(section) {
3741
3753
  const seen = /* @__PURE__ */ new Set();
3742
3754
  writeHoists(section);
3755
+ writeDomGetters(section);
3743
3756
  for (const signal of getSignals(section).values()) {
3744
3757
  writeSignal(signal);
3745
3758
  }
@@ -3813,6 +3826,24 @@ function writeSignals(section) {
3813
3826
  (0, import_babel_utils15.getProgram)().node.body.push(...signalStatements);
3814
3827
  }
3815
3828
  }
3829
+ function writeDomGetters(section) {
3830
+ for (const [binding, registerId] of section.domGetterBindings) {
3831
+ (0, import_babel_utils15.getProgram)().node.body.push(
3832
+ import_compiler22.types.variableDeclaration("const", [
3833
+ import_compiler22.types.variableDeclarator(
3834
+ getBindingGetterIdentifier(binding),
3835
+ callRuntime(
3836
+ "_el",
3837
+ import_compiler22.types.stringLiteral(registerId),
3838
+ import_compiler22.types.stringLiteral(
3839
+ getAccessorPrefix().Getter + getScopeAccessorLiteral(binding).value
3840
+ )
3841
+ )
3842
+ )
3843
+ ])
3844
+ );
3845
+ }
3846
+ }
3816
3847
  function writeHoists(section) {
3817
3848
  forEach(section.hoisted, (binding) => {
3818
3849
  for (const hoistedBinding of binding.hoists.values()) {
@@ -3829,7 +3860,7 @@ function writeHoists(section) {
3829
3860
  }
3830
3861
  currentSection = parentSection;
3831
3862
  }
3832
- const hoistIdentifier = getHoistFunctionIdentifier(hoistedBinding);
3863
+ const hoistIdentifier = getBindingGetterIdentifier(hoistedBinding);
3833
3864
  (0, import_babel_utils15.getProgram)().node.body.push(
3834
3865
  import_compiler22.types.variableDeclaration("const", [
3835
3866
  import_compiler22.types.variableDeclarator(
@@ -3967,66 +3998,6 @@ function writeHTMLResumeStatements(path5) {
3967
3998
  }
3968
3999
  }
3969
4000
  });
3970
- const sectionDynamicSubscribers = /* @__PURE__ */ new Set();
3971
- forEach(section.hoisted, (binding) => {
3972
- for (const hoistedBinding of binding.hoists.values()) {
3973
- if (hoistedBinding.downstreamExpressions.size) {
3974
- getHTMLSectionStatements(hoistedBinding.section).push(
3975
- import_compiler22.types.variableDeclaration("const", [
3976
- import_compiler22.types.variableDeclarator(
3977
- import_compiler22.types.identifier(hoistedBinding.name),
3978
- callRuntime(
3979
- "_hoist",
3980
- getScopeIdIdentifier(hoistedBinding.section),
3981
- import_compiler22.types.stringLiteral(
3982
- getResumeRegisterId(
3983
- hoistedBinding.section,
3984
- hoistedBinding,
3985
- "hoist"
3986
- )
3987
- )
3988
- )
3989
- )
3990
- ])
3991
- );
3992
- }
3993
- let currentSection = section;
3994
- while (currentSection && currentSection !== hoistedBinding.section) {
3995
- const parentSection = currentSection.parent;
3996
- if (!currentSection.sectionAccessor && !sectionDynamicSubscribers.has(currentSection)) {
3997
- const subscribersIdentifier = generateUidIdentifier(
3998
- `${currentSection.name}__subscribers`
3999
- );
4000
- sectionDynamicSubscribers.add(currentSection);
4001
- getHTMLSectionStatements(parentSection).push(
4002
- import_compiler22.types.variableDeclaration("const", [
4003
- import_compiler22.types.variableDeclarator(
4004
- subscribersIdentifier,
4005
- import_compiler22.types.newExpression(import_compiler22.types.identifier("Set"), [])
4006
- )
4007
- ])
4008
- );
4009
- addWriteScopeBuilder(
4010
- currentSection,
4011
- (expr) => callRuntime("_subscribe", subscribersIdentifier, expr)
4012
- );
4013
- setSerializedValue(
4014
- parentSection,
4015
- getSectionInstancesAccessor(currentSection),
4016
- subscribersIdentifier
4017
- );
4018
- }
4019
- currentSection = parentSection;
4020
- }
4021
- }
4022
- if (binding.hoists.size && binding.type !== 0 /* dom */) {
4023
- setBindingSerializedValue(
4024
- section,
4025
- binding,
4026
- getDeclaredBindingExpression(binding)
4027
- );
4028
- }
4029
- });
4030
4001
  for (let i = allSignals.length; i--; ) {
4031
4002
  if (allSignals[i].effect.length) {
4032
4003
  const signalRefs = allSignals[i].referencedBindings;
@@ -4149,6 +4120,17 @@ function writeHTMLResumeStatements(path5) {
4149
4120
  ...additionalStatements
4150
4121
  );
4151
4122
  }
4123
+ if (debug) {
4124
+ forEach(section.bindings, (binding) => {
4125
+ if (binding.hoists.size && binding.type !== 0 /* dom */) {
4126
+ body.push(
4127
+ import_compiler22.types.expressionStatement(
4128
+ callRuntime("_assert_hoist", import_compiler22.types.identifier(binding.name))
4129
+ )
4130
+ );
4131
+ }
4132
+ });
4133
+ }
4152
4134
  const returnIdentifier = getSectionReturnValueIdentifier(section);
4153
4135
  if (returnIdentifier !== void 0) {
4154
4136
  body.push(import_compiler22.types.returnStatement(returnIdentifier));
@@ -4170,6 +4152,15 @@ function replaceBindingReadNode(node) {
4170
4152
  case "OptionalMemberExpression": {
4171
4153
  return getReadReplacement(node);
4172
4154
  }
4155
+ case "CallExpression": {
4156
+ const { extra } = node.callee;
4157
+ const binding = extra?.read?.binding;
4158
+ if (binding?.type === 0 /* dom */) {
4159
+ const replacement = createScopeReadExpression(extra.section, binding);
4160
+ return isOptimize() ? replacement : callRuntime("_el_read", replacement);
4161
+ }
4162
+ break;
4163
+ }
4173
4164
  }
4174
4165
  }
4175
4166
  var updateExpressions = /* @__PURE__ */ new WeakSet();
@@ -4509,6 +4500,70 @@ function getTemplateContentName() {
4509
4500
  }
4510
4501
  var html_default = {
4511
4502
  translate: {
4503
+ enter() {
4504
+ forEachSection((section) => {
4505
+ const sectionDynamicSubscribers = /* @__PURE__ */ new Set();
4506
+ forEach(section.hoisted, (binding) => {
4507
+ for (const hoistedBinding of binding.hoists.values()) {
4508
+ if (hoistedBinding.downstreamExpressions.size) {
4509
+ getHTMLSectionStatements(hoistedBinding.section).push(
4510
+ import_compiler24.types.variableDeclaration("const", [
4511
+ import_compiler24.types.variableDeclarator(
4512
+ import_compiler24.types.identifier(hoistedBinding.name),
4513
+ callRuntime(
4514
+ "_hoist",
4515
+ getScopeIdIdentifier(hoistedBinding.section),
4516
+ import_compiler24.types.stringLiteral(
4517
+ getResumeRegisterId(
4518
+ hoistedBinding.section,
4519
+ hoistedBinding,
4520
+ "hoist"
4521
+ )
4522
+ )
4523
+ )
4524
+ )
4525
+ ])
4526
+ );
4527
+ }
4528
+ let currentSection = section;
4529
+ while (currentSection && currentSection !== hoistedBinding.section) {
4530
+ const parentSection = currentSection.parent;
4531
+ if (!currentSection.sectionAccessor && !sectionDynamicSubscribers.has(currentSection)) {
4532
+ const subscribersIdentifier = generateUidIdentifier(
4533
+ `${currentSection.name}__subscribers`
4534
+ );
4535
+ sectionDynamicSubscribers.add(currentSection);
4536
+ getHTMLSectionStatements(parentSection).push(
4537
+ import_compiler24.types.variableDeclaration("const", [
4538
+ import_compiler24.types.variableDeclarator(
4539
+ subscribersIdentifier,
4540
+ import_compiler24.types.newExpression(import_compiler24.types.identifier("Set"), [])
4541
+ )
4542
+ ])
4543
+ );
4544
+ addWriteScopeBuilder(
4545
+ currentSection,
4546
+ (expr) => callRuntime("_subscribe", subscribersIdentifier, expr)
4547
+ );
4548
+ setSerializedValue(
4549
+ parentSection,
4550
+ getSectionInstancesAccessor(currentSection),
4551
+ subscribersIdentifier
4552
+ );
4553
+ }
4554
+ currentSection = parentSection;
4555
+ }
4556
+ }
4557
+ if (binding.hoists.size && binding.type !== 0 /* dom */) {
4558
+ setBindingSerializedValue(
4559
+ section,
4560
+ binding,
4561
+ getDeclaredBindingExpression(binding)
4562
+ );
4563
+ }
4564
+ });
4565
+ });
4566
+ },
4512
4567
  exit(program) {
4513
4568
  flushInto(program);
4514
4569
  writeHTMLResumeStatements(program);
@@ -4583,6 +4638,24 @@ function replaceBindingReadNode2(node) {
4583
4638
  if (extra && !(extra.read && !extra.read.binding.declared || extra.binding && !extra.binding.declared)) {
4584
4639
  return getReadReplacement(node);
4585
4640
  }
4641
+ break;
4642
+ }
4643
+ case "CallExpression": {
4644
+ const binding = node.callee.extra?.read?.binding;
4645
+ if (binding && (binding.type === 6 /* hoist */ || binding.type === 0 /* dom */)) {
4646
+ return import_compiler24.types.callExpression(
4647
+ import_compiler24.types.arrowFunctionExpression(
4648
+ [import_compiler24.types.cloneNode(node.callee)],
4649
+ node
4650
+ ),
4651
+ [
4652
+ importRuntime(
4653
+ binding.type === 0 /* dom */ ? "_el_read_error" : "_hoist_read_error"
4654
+ )
4655
+ ]
4656
+ );
4657
+ }
4658
+ break;
4586
4659
  }
4587
4660
  }
4588
4661
  }
@@ -5013,6 +5086,9 @@ var program_default = {
5013
5086
  program.skip();
5014
5087
  return;
5015
5088
  }
5089
+ if (isOutputHTML()) {
5090
+ html_default.translate.enter();
5091
+ }
5016
5092
  },
5017
5093
  exit(program) {
5018
5094
  if (isOutputHTML()) {
@@ -5258,6 +5334,27 @@ function translateVar(tag, initialValue, kind = "const") {
5258
5334
  import_compiler29.types.variableDeclaration(kind, [import_compiler29.types.variableDeclarator(tagVar, initialValue)])
5259
5335
  );
5260
5336
  }
5337
+ function translateDomVar(tag, binding) {
5338
+ if (binding && tag.node.var) {
5339
+ const tagSection = getSection(tag);
5340
+ const registerId = tagSection.domGetterBindings.get(binding);
5341
+ if (registerId) {
5342
+ tag.parentPath.unshiftContainer(
5343
+ "body",
5344
+ import_compiler29.types.variableDeclaration("const", [
5345
+ import_compiler29.types.variableDeclarator(
5346
+ tag.node.var,
5347
+ callRuntime(
5348
+ "_el",
5349
+ getScopeIdIdentifier(tagSection),
5350
+ import_compiler29.types.stringLiteral(registerId)
5351
+ )
5352
+ )
5353
+ ])
5354
+ );
5355
+ }
5356
+ }
5357
+ }
5261
5358
  function getDestructurePattern(id) {
5262
5359
  let cur = id;
5263
5360
  while (cur) {
@@ -5271,7 +5368,6 @@ function getDestructurePattern(id) {
5271
5368
  // src/translator/visitors/tag/native-tag.ts
5272
5369
  var kNativeTagBinding = Symbol("native tag binding");
5273
5370
  var kSkipEndTag = Symbol("skip native tag mark");
5274
- var kGetterId = Symbol("node getter id");
5275
5371
  var kTagContentAttr = Symbol("tag could have dynamic content attribute");
5276
5372
  var htmlSelectArgs = /* @__PURE__ */ new WeakMap();
5277
5373
  var native_tag_default = {
@@ -5360,26 +5456,7 @@ var native_tag_default = {
5360
5456
  !!(node.var || hasEventHandlers),
5361
5457
  nodeBinding
5362
5458
  );
5363
- if (node.var) {
5364
- for (const ref of tag.scope.getBinding(node.var.name).referencePaths) {
5365
- const refSection = getOrCreateSection(ref);
5366
- setReferencesScope(ref);
5367
- if (isSameOrChildSection(tagSection, refSection)) {
5368
- addOwnerSerializeReason(refSection, tagSection, true);
5369
- if (!tagExtra[kGetterId] && !isInvokedFunction(ref)) {
5370
- tagExtra[kGetterId] = getRegisterUID(
5371
- tagSection,
5372
- nodeBinding.name
5373
- );
5374
- }
5375
- } else {
5376
- trackHoistedReference(
5377
- ref,
5378
- nodeBinding
5379
- );
5380
- }
5381
- }
5382
- }
5459
+ trackDomVarReferences(tag, nodeBinding);
5383
5460
  addSerializeExpr(
5384
5461
  tagSection,
5385
5462
  push(attrExprExtras, tagExtra),
@@ -5400,17 +5477,7 @@ var native_tag_default = {
5400
5477
  if (tagExtra.tagNameNullable) {
5401
5478
  flushBefore(tag);
5402
5479
  }
5403
- if (tag.node.var) {
5404
- const getterId = tagExtra[kGetterId];
5405
- translateVar(
5406
- tag,
5407
- callRuntime(
5408
- "_el",
5409
- getterId && getScopeIdIdentifier(tagSection),
5410
- getterId && import_compiler30.types.stringLiteral(getterId)
5411
- )
5412
- );
5413
- }
5480
+ translateDomVar(tag, nodeBinding);
5414
5481
  const visitAccessor = nodeBinding && getScopeAccessorLiteral(nodeBinding);
5415
5482
  write`<${tag.node.name}`;
5416
5483
  const usedAttrs = getUsedAttrs(tagName, tag.node);
@@ -5662,59 +5729,6 @@ var native_tag_default = {
5662
5729
  const tagDef = (0, import_babel_utils20.getTagDef)(tag);
5663
5730
  const write = writeTo(tag);
5664
5731
  const tagSection = getSection(tag);
5665
- if (tag.node.var) {
5666
- const varName = tag.node.var.name;
5667
- const varBinding = tag.scope.getBinding(varName);
5668
- const getterId = tagExtra[kGetterId];
5669
- let getterFnIdentifier;
5670
- if (getterId) {
5671
- getterFnIdentifier = generateUidIdentifier(`get_${varName}`);
5672
- (0, import_babel_utils20.getProgram)().node.body.push(
5673
- import_compiler30.types.variableDeclaration("const", [
5674
- import_compiler30.types.variableDeclarator(
5675
- getterFnIdentifier,
5676
- callRuntime(
5677
- "_el",
5678
- import_compiler30.types.stringLiteral(getterId),
5679
- import_compiler30.types.stringLiteral(
5680
- getAccessorPrefix().Getter + getScopeAccessorLiteral(nodeBinding).value
5681
- )
5682
- )
5683
- )
5684
- ])
5685
- );
5686
- }
5687
- for (const reference of varBinding.referencePaths) {
5688
- const referenceSection = getSection(reference);
5689
- if (isSameOrChildSection(tagSection, referenceSection)) {
5690
- if (isInvokedFunction(reference)) {
5691
- reference.parentPath.replaceWith(
5692
- import_compiler30.types.expressionStatement(
5693
- createScopeReadExpression(referenceSection, nodeBinding)
5694
- )
5695
- );
5696
- } else if (getterFnIdentifier) {
5697
- reference.replaceWith(
5698
- import_compiler30.types.callExpression(getterFnIdentifier, [
5699
- getScopeExpression(referenceSection, getSection(tag))
5700
- ])
5701
- );
5702
- } else {
5703
- reference.replaceWith(
5704
- import_compiler30.types.expressionStatement(
5705
- import_compiler30.types.memberExpression(
5706
- getScopeExpression(tagSection, referenceSection),
5707
- import_compiler30.types.stringLiteral(
5708
- getAccessorPrefix().Getter + getScopeAccessorLiteral(nodeBinding).value
5709
- ),
5710
- true
5711
- )
5712
- )
5713
- );
5714
- }
5715
- }
5716
- }
5717
- }
5718
5732
  const visitAccessor = nodeBinding && getScopeAccessorLiteral(nodeBinding);
5719
5733
  if (visitAccessor) {
5720
5734
  visit(tag, 32 /* Get */);
@@ -7779,6 +7793,42 @@ function createBinding(name2, type, section, upstreamAlias, property, excludePro
7779
7793
  getBindings().add(binding);
7780
7794
  return binding;
7781
7795
  }
7796
+ function trackDomVarReferences(tag, binding) {
7797
+ const tagVar = tag.node.var;
7798
+ if (!tagVar) {
7799
+ return;
7800
+ }
7801
+ if (!import_compiler35.types.isIdentifier(tagVar)) {
7802
+ throw tag.get("var").buildCodeFrameError(
7803
+ "Tag variables on native elements cannot be destructured."
7804
+ );
7805
+ }
7806
+ const babelBinding = tag.scope.getBinding(tagVar.name);
7807
+ const section = getOrCreateSection(tag);
7808
+ if (babelBinding.constantViolations.length) {
7809
+ throw babelBinding.constantViolations[0].buildCodeFrameError(
7810
+ "Tag variables on native elements cannot be assigned to."
7811
+ );
7812
+ }
7813
+ let registerId;
7814
+ for (const ref of babelBinding.referencePaths) {
7815
+ const refSection = getOrCreateSection(ref);
7816
+ setReferencesScope(ref);
7817
+ if (isSameOrChildSection(binding.section, refSection)) {
7818
+ (ref.node.extra ??= {}).read = createRead(binding, void 0);
7819
+ if (!isInvokedFunction(ref)) {
7820
+ section.domGetterBindings.set(
7821
+ binding,
7822
+ registerId ??= getRegisterUID(section, binding.name)
7823
+ );
7824
+ }
7825
+ addOwnerSerializeReason(refSection, section, true);
7826
+ } else {
7827
+ trackHoistedReference(ref, binding);
7828
+ }
7829
+ }
7830
+ return binding;
7831
+ }
7782
7832
  function trackVarReferences(tag, type, upstreamAlias) {
7783
7833
  const tagVar = tag.node.var;
7784
7834
  if (tagVar) {
@@ -7898,20 +7948,35 @@ function trackHoistedReference(referencePath, binding) {
7898
7948
  hoistedBinding
7899
7949
  );
7900
7950
  }
7951
+ function isReferenceHoisted(bindingPath, reference) {
7952
+ const tag = bindingPath.isMarkoTag() ? bindingPath : getMarkoRoot(bindingPath)?.parentPath;
7953
+ if (!tag?.isMarkoTag()) {
7954
+ return false;
7955
+ }
7956
+ const body = tag.parentPath;
7957
+ let cur = reference;
7958
+ while (cur) {
7959
+ if (cur.parentPath === body) {
7960
+ return +tag.key > +cur.key;
7961
+ }
7962
+ cur = cur.parentPath;
7963
+ }
7964
+ return true;
7965
+ }
7901
7966
  function trackReferencesForBinding(babelBinding, binding) {
7902
7967
  const { referencePaths, constantViolations } = babelBinding;
7903
- for (const referencePath of referencePaths) {
7904
- const referenceSection = getOrCreateSection(referencePath);
7905
- if (isSameOrChildSection(binding.section, referenceSection)) {
7906
- if (binding.type === 4 /* local */ && referenceSection === binding.section) {
7907
- continue;
7908
- }
7909
- trackReference(referencePath, binding);
7910
- } else {
7911
- trackHoistedReference(referencePath, binding);
7968
+ for (const ref of referencePaths) {
7969
+ const refSection = getOrCreateSection(ref);
7970
+ if (isReferenceHoisted(babelBinding.path, ref)) {
7971
+ trackHoistedReference(ref, binding);
7972
+ } else if (binding.type !== 4 /* local */ || refSection !== binding.section) {
7973
+ trackReference(ref, binding);
7912
7974
  }
7913
7975
  }
7914
7976
  for (const ref of constantViolations) {
7977
+ if (isReferenceHoisted(babelBinding.path, ref)) {
7978
+ throw ref.buildCodeFrameError("Cannot assign to hoisted tag variable.");
7979
+ }
7915
7980
  if (ref.isUpdateExpression()) {
7916
7981
  trackAssignment(ref.get("argument"), binding);
7917
7982
  } else if (ref.isAssignmentExpression()) {
@@ -8347,10 +8412,12 @@ function finalizeReferences() {
8347
8412
  intersectionsBySection
8348
8413
  );
8349
8414
  if (registerReason) {
8350
- forEach(
8351
- fn.referencedBindingsInFunction,
8352
- (binding) => addSerializeReason(binding.section, registerReason, binding)
8353
- );
8415
+ forEach(fn.referencedBindingsInFunction, (binding) => {
8416
+ addSerializeReason(binding.section, registerReason, binding);
8417
+ if (binding.section !== fn.section) {
8418
+ addOwnerSerializeReason(fn.section, binding.section, registerReason);
8419
+ }
8420
+ });
8354
8421
  }
8355
8422
  }
8356
8423
  forEachSectionReverse((section) => {
@@ -8677,10 +8744,23 @@ function getReadReplacement(node) {
8677
8744
  }
8678
8745
  if (binding) {
8679
8746
  if (node.type === "Identifier") {
8680
- if (binding.type === 6 /* hoist */) {
8681
- replacement = node.extra?.[kIsInvoked] ? import_compiler35.types.callExpression(getHoistFunctionIdentifier(binding), [
8682
- getScopeExpression(node.extra.section, binding.section)
8683
- ]) : import_compiler35.types.identifier(binding.name);
8747
+ if (binding.type === 0 /* dom */) {
8748
+ if (binding.section.domGetterBindings.has(binding) && isOutputDOM()) {
8749
+ replacement = import_compiler35.types.callExpression(getBindingGetterIdentifier(binding), [
8750
+ getScopeExpression(node.extra.section, binding.section)
8751
+ ]);
8752
+ }
8753
+ } else if (binding.type === 6 /* hoist */) {
8754
+ if (node.extra?.[kIsInvoked]) {
8755
+ if (isOutputDOM()) {
8756
+ replacement = import_compiler35.types.callExpression(
8757
+ getBindingGetterIdentifier(binding),
8758
+ [getScopeExpression(node.extra.section, binding.section)]
8759
+ );
8760
+ }
8761
+ } else {
8762
+ replacement = import_compiler35.types.identifier(binding.name);
8763
+ }
8684
8764
  } else if (binding.name !== node.name) {
8685
8765
  node.name = binding.name;
8686
8766
  }
@@ -9375,7 +9455,6 @@ function templateElement(value, tail) {
9375
9455
 
9376
9456
  // src/translator/core/html-comment.ts
9377
9457
  var kNodeBinding = Symbol("comment tag binding");
9378
- var kGetterId2 = Symbol("node getter id");
9379
9458
  var html_comment_default = {
9380
9459
  analyze(tag) {
9381
9460
  (0, import_babel_utils33.assertNoArgs)(tag);
@@ -9383,7 +9462,6 @@ var html_comment_default = {
9383
9462
  (0, import_babel_utils33.assertNoAttributes)(tag);
9384
9463
  const tagVar = tag.node.var;
9385
9464
  let needsBinding = false;
9386
- let needsGetter = false;
9387
9465
  if (tagVar) {
9388
9466
  if (!import_compiler43.types.isIdentifier(tagVar)) {
9389
9467
  throw tag.get("var").buildCodeFrameError(
@@ -9391,12 +9469,6 @@ var html_comment_default = {
9391
9469
  );
9392
9470
  }
9393
9471
  needsBinding = true;
9394
- for (const ref of tag.scope.getBinding(tagVar.name).referencePaths) {
9395
- if (!isInvokedFunction(ref)) {
9396
- needsGetter = true;
9397
- break;
9398
- }
9399
- }
9400
9472
  }
9401
9473
  const referenceNodes = [];
9402
9474
  for (const child of tag.get("body").get("body")) {
@@ -9417,9 +9489,7 @@ var html_comment_default = {
9417
9489
  0 /* dom */,
9418
9490
  tagSection
9419
9491
  );
9420
- if (needsGetter) {
9421
- tagExtra[kGetterId2] = getRegisterUID(tagSection, "comment");
9422
- }
9492
+ trackDomVarReferences(tag, nodeBinding);
9423
9493
  addSerializeExpr(tagSection, !!tagVar || tagExtra, nodeBinding);
9424
9494
  }
9425
9495
  tag.skip();
@@ -9428,54 +9498,8 @@ var html_comment_default = {
9428
9498
  enter(tag) {
9429
9499
  const tagExtra = tag.node.extra;
9430
9500
  const nodeBinding = tagExtra[kNodeBinding];
9431
- const hasVar = !!tag.node.var;
9432
- if (hasVar) {
9433
- const getterId = tagExtra[kGetterId2];
9434
- if (isOutputHTML()) {
9435
- translateVar(
9436
- tag,
9437
- callRuntime(
9438
- "_el",
9439
- getterId && getScopeIdIdentifier(getSection(tag)),
9440
- getterId && import_compiler43.types.stringLiteral(getterId)
9441
- )
9442
- );
9443
- } else {
9444
- const varName = tag.node.var.name;
9445
- const references = tag.scope.getBinding(varName).referencePaths;
9446
- let getterFnIdentifier;
9447
- if (getterId) {
9448
- getterFnIdentifier = generateUidIdentifier(`get_${varName}`);
9449
- (0, import_babel_utils33.getProgram)().node.body.push(
9450
- import_compiler43.types.variableDeclaration("const", [
9451
- import_compiler43.types.variableDeclarator(
9452
- getterFnIdentifier,
9453
- callRuntime(
9454
- "_el",
9455
- import_compiler43.types.stringLiteral(getterId),
9456
- getScopeAccessorLiteral(nodeBinding)
9457
- )
9458
- )
9459
- ])
9460
- );
9461
- }
9462
- for (const reference of references) {
9463
- const referenceSection = getSection(reference);
9464
- if (isInvokedFunction(reference)) {
9465
- reference.parentPath.replaceWith(
9466
- import_compiler43.types.expressionStatement(
9467
- createScopeReadExpression(referenceSection, nodeBinding)
9468
- )
9469
- );
9470
- } else if (getterFnIdentifier) {
9471
- reference.replaceWith(
9472
- import_compiler43.types.callExpression(getterFnIdentifier, [
9473
- getScopeExpression(referenceSection, getSection(tag))
9474
- ])
9475
- );
9476
- }
9477
- }
9478
- }
9501
+ if (isOutputHTML()) {
9502
+ translateDomVar(tag, nodeBinding);
9479
9503
  }
9480
9504
  if (nodeBinding) {
9481
9505
  visit(tag, 32 /* Get */);
@@ -9547,7 +9571,6 @@ var html_comment_default = {
9547
9571
  var import_compiler44 = require("@marko/compiler");
9548
9572
  var import_babel_utils34 = require("@marko/compiler/babel-utils");
9549
9573
  var kNodeBinding2 = Symbol("script tag node binding");
9550
- var kGetterId3 = Symbol("node getter id");
9551
9574
  var html_script_default = {
9552
9575
  analyze(tag) {
9553
9576
  (0, import_babel_utils34.assertNoArgs)(tag);
@@ -9629,25 +9652,12 @@ var html_script_default = {
9629
9652
  )
9630
9653
  );
9631
9654
  }
9655
+ trackDomVarReferences(tag, nodeBinding);
9632
9656
  addSerializeExpr(
9633
9657
  tagSection,
9634
9658
  !!(node.var || hasEventHandlers),
9635
9659
  nodeBinding
9636
9660
  );
9637
- if (node.var) {
9638
- for (const ref of tag.scope.getBinding(node.var.name).referencePaths) {
9639
- const refSection = getOrCreateSection(ref);
9640
- setReferencesScope(ref);
9641
- if (isSameOrChildSection(tagSection, refSection)) {
9642
- addOwnerSerializeReason(refSection, tagSection, true);
9643
- if (!tagExtra[kGetterId3] && !isInvokedFunction(ref)) {
9644
- tagExtra[kGetterId3] = getRegisterUID(tagSection, "#script");
9645
- }
9646
- } else {
9647
- trackHoistedReference(ref, nodeBinding);
9648
- }
9649
- }
9650
- }
9651
9661
  addSerializeExpr(tagSection, push(exprExtras, tagExtra), nodeBinding);
9652
9662
  }
9653
9663
  },
@@ -9658,54 +9668,8 @@ var html_script_default = {
9658
9668
  const isHTML = isOutputHTML();
9659
9669
  const write = writeTo(tag);
9660
9670
  const tagSection = getSection(tag);
9661
- const hasVar = !!tag.node.var;
9662
- if (hasVar) {
9663
- const getterId = tagExtra[kGetterId3];
9664
- if (isHTML) {
9665
- translateVar(
9666
- tag,
9667
- callRuntime(
9668
- "_el",
9669
- getterId && getScopeIdIdentifier(tagSection),
9670
- getterId && import_compiler44.types.stringLiteral(getterId)
9671
- )
9672
- );
9673
- } else {
9674
- const varName = tag.node.var.name;
9675
- const references = tag.scope.getBinding(varName).referencePaths;
9676
- let getterFnIdentifier;
9677
- if (getterId) {
9678
- getterFnIdentifier = generateUidIdentifier(`get_${varName}`);
9679
- (0, import_babel_utils34.getProgram)().node.body.push(
9680
- import_compiler44.types.variableDeclaration("const", [
9681
- import_compiler44.types.variableDeclarator(
9682
- getterFnIdentifier,
9683
- callRuntime(
9684
- "_el",
9685
- import_compiler44.types.stringLiteral(getterId),
9686
- getScopeAccessorLiteral(nodeBinding)
9687
- )
9688
- )
9689
- ])
9690
- );
9691
- }
9692
- for (const reference of references) {
9693
- const referenceSection = getSection(reference);
9694
- if (isInvokedFunction(reference)) {
9695
- reference.parentPath.replaceWith(
9696
- import_compiler44.types.expressionStatement(
9697
- createScopeReadExpression(referenceSection, nodeBinding)
9698
- )
9699
- );
9700
- } else if (getterFnIdentifier) {
9701
- reference.replaceWith(
9702
- import_compiler44.types.callExpression(getterFnIdentifier, [
9703
- getScopeExpression(referenceSection, getSection(tag))
9704
- ])
9705
- );
9706
- }
9707
- }
9708
- }
9671
+ if (isHTML) {
9672
+ translateDomVar(tag, nodeBinding);
9709
9673
  }
9710
9674
  const visitAccessor = nodeBinding && getScopeAccessorLiteral(nodeBinding);
9711
9675
  if (visitAccessor) {
@@ -9852,7 +9816,7 @@ var html_script_default = {
9852
9816
  } else {
9853
9817
  const textLiteral = bodyToTextLiteral(tag.node.body);
9854
9818
  if (import_compiler44.types.isStringLiteral(textLiteral)) {
9855
- write`${textLiteral.value}`;
9819
+ write`${textLiteral}`;
9856
9820
  } else {
9857
9821
  addStatement(
9858
9822
  "render",
@@ -9952,7 +9916,6 @@ function getUsedAttrs2(tag) {
9952
9916
  var import_compiler45 = require("@marko/compiler");
9953
9917
  var import_babel_utils35 = require("@marko/compiler/babel-utils");
9954
9918
  var kNodeBinding3 = Symbol("style tag node binding");
9955
- var kGetterId4 = Symbol("node getter id");
9956
9919
  var html_style_default = {
9957
9920
  analyze(tag) {
9958
9921
  (0, import_babel_utils35.assertNoArgs)(tag);
@@ -10034,25 +9997,12 @@ var html_style_default = {
10034
9997
  )
10035
9998
  );
10036
9999
  }
10000
+ trackDomVarReferences(tag, nodeBinding);
10037
10001
  addSerializeExpr(
10038
10002
  tagSection,
10039
10003
  !!(node.var || hasEventHandlers),
10040
10004
  nodeBinding
10041
10005
  );
10042
- if (node.var) {
10043
- for (const ref of tag.scope.getBinding(node.var.name).referencePaths) {
10044
- const refSection = getOrCreateSection(ref);
10045
- setReferencesScope(ref);
10046
- if (isSameOrChildSection(tagSection, refSection)) {
10047
- addOwnerSerializeReason(refSection, tagSection, true);
10048
- if (!tagExtra[kGetterId4] && !isInvokedFunction(ref)) {
10049
- tagExtra[kGetterId4] = getRegisterUID(tagSection, "#style");
10050
- }
10051
- } else {
10052
- trackHoistedReference(ref, nodeBinding);
10053
- }
10054
- }
10055
- }
10056
10006
  addSerializeExpr(tagSection, push(exprExtras, tagExtra), nodeBinding);
10057
10007
  }
10058
10008
  },
@@ -10063,54 +10013,8 @@ var html_style_default = {
10063
10013
  const isHTML = isOutputHTML();
10064
10014
  const write = writeTo(tag);
10065
10015
  const tagSection = getSection(tag);
10066
- const hasVar = !!tag.node.var;
10067
- if (hasVar) {
10068
- const getterId = tagExtra[kGetterId4];
10069
- if (isHTML) {
10070
- translateVar(
10071
- tag,
10072
- callRuntime(
10073
- "_el",
10074
- getterId && getScopeIdIdentifier(tagSection),
10075
- getterId && import_compiler45.types.stringLiteral(getterId)
10076
- )
10077
- );
10078
- } else {
10079
- const varName = tag.node.var.name;
10080
- const references = tag.scope.getBinding(varName).referencePaths;
10081
- let getterFnIdentifier;
10082
- if (getterId) {
10083
- getterFnIdentifier = generateUidIdentifier(`get_${varName}`);
10084
- (0, import_babel_utils35.getProgram)().node.body.push(
10085
- import_compiler45.types.variableDeclaration("const", [
10086
- import_compiler45.types.variableDeclarator(
10087
- getterFnIdentifier,
10088
- callRuntime(
10089
- "_el",
10090
- import_compiler45.types.stringLiteral(getterId),
10091
- getScopeAccessorLiteral(nodeBinding)
10092
- )
10093
- )
10094
- ])
10095
- );
10096
- }
10097
- for (const reference of references) {
10098
- const referenceSection = getSection(reference);
10099
- if (isInvokedFunction(reference)) {
10100
- reference.parentPath.replaceWith(
10101
- import_compiler45.types.expressionStatement(
10102
- createScopeReadExpression(referenceSection, nodeBinding)
10103
- )
10104
- );
10105
- } else if (getterFnIdentifier) {
10106
- reference.replaceWith(
10107
- import_compiler45.types.callExpression(getterFnIdentifier, [
10108
- getScopeExpression(referenceSection, getSection(tag))
10109
- ])
10110
- );
10111
- }
10112
- }
10113
- }
10016
+ if (isHTML) {
10017
+ translateDomVar(tag, nodeBinding);
10114
10018
  }
10115
10019
  const visitAccessor = nodeBinding && getScopeAccessorLiteral(nodeBinding);
10116
10020
  if (visitAccessor) {