marko 6.0.126 → 6.0.128

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.
@@ -133,33 +133,33 @@ var AccessorPrefix = /* @__PURE__ */ ((AccessorPrefix4) => {
133
133
  AccessorPrefix4["TagVariableChange"] = "TagVariableChange:";
134
134
  return AccessorPrefix4;
135
135
  })(AccessorPrefix || {});
136
- var AccessorProp = /* @__PURE__ */ ((AccessorProp4) => {
137
- AccessorProp4["Global"] = "$global";
138
- AccessorProp4["Owner"] = "_";
139
- AccessorProp4["AbortControllers"] = "#AbortControllers";
140
- AccessorProp4["AbortScopes"] = "#AbortScopes";
141
- AccessorProp4["AwaitCounter"] = "#AwaitCounter";
142
- AccessorProp4["BranchAccessor"] = "#BranchAccessor";
143
- AccessorProp4["BranchScopes"] = "#BranchScopes";
144
- AccessorProp4["CatchContent"] = "#CatchContent";
145
- AccessorProp4["ClosestBranch"] = "#ClosestBranch";
146
- AccessorProp4["ClosestBranchId"] = "#ClosestBranchId";
147
- AccessorProp4["Creating"] = "#Creating";
148
- AccessorProp4["Destroyed"] = "#Destroyed";
149
- AccessorProp4["DetachedAwait"] = "#DetachedAwait";
150
- AccessorProp4["EndNode"] = "#EndNode";
151
- AccessorProp4["Id"] = "#Id";
152
- AccessorProp4["LoopKey"] = "#LoopKey";
153
- AccessorProp4["ParentBranch"] = "#ParentBranch";
154
- AccessorProp4["PendingEffects"] = "#PendingEffects";
155
- AccessorProp4["PendingRenders"] = "#PendingRenders";
156
- AccessorProp4["PlaceholderBranch"] = "#PlaceholderBranch";
157
- AccessorProp4["PlaceholderContent"] = "#PlaceholderContent";
158
- AccessorProp4["Renderer"] = "#Renderer";
159
- AccessorProp4["StartNode"] = "#StartNode";
160
- AccessorProp4["TagVariable"] = "#TagVariable";
161
- AccessorProp4["TagVariableChange"] = "#TagVariableChange";
162
- return AccessorProp4;
136
+ var AccessorProp = /* @__PURE__ */ ((AccessorProp5) => {
137
+ AccessorProp5["Global"] = "$global";
138
+ AccessorProp5["Owner"] = "_";
139
+ AccessorProp5["AbortControllers"] = "#AbortControllers";
140
+ AccessorProp5["AbortScopes"] = "#AbortScopes";
141
+ AccessorProp5["AwaitCounter"] = "#AwaitCounter";
142
+ AccessorProp5["BranchAccessor"] = "#BranchAccessor";
143
+ AccessorProp5["BranchScopes"] = "#BranchScopes";
144
+ AccessorProp5["CatchContent"] = "#CatchContent";
145
+ AccessorProp5["ClosestBranch"] = "#ClosestBranch";
146
+ AccessorProp5["ClosestBranchId"] = "#ClosestBranchId";
147
+ AccessorProp5["Creating"] = "#Creating";
148
+ AccessorProp5["Destroyed"] = "#Destroyed";
149
+ AccessorProp5["DetachedAwait"] = "#DetachedAwait";
150
+ AccessorProp5["EndNode"] = "#EndNode";
151
+ AccessorProp5["Id"] = "#Id";
152
+ AccessorProp5["LoopKey"] = "#LoopKey";
153
+ AccessorProp5["ParentBranch"] = "#ParentBranch";
154
+ AccessorProp5["PendingEffects"] = "#PendingEffects";
155
+ AccessorProp5["PendingRenders"] = "#PendingRenders";
156
+ AccessorProp5["PlaceholderBranch"] = "#PlaceholderBranch";
157
+ AccessorProp5["PlaceholderContent"] = "#PlaceholderContent";
158
+ AccessorProp5["Renderer"] = "#Renderer";
159
+ AccessorProp5["StartNode"] = "#StartNode";
160
+ AccessorProp5["TagVariable"] = "#TagVariable";
161
+ AccessorProp5["TagVariableChange"] = "#TagVariableChange";
162
+ return AccessorProp5;
163
163
  })(AccessorProp || {});
164
164
 
165
165
  // src/translator/util/evaluate.ts
@@ -587,19 +587,19 @@ function isTranslate() {
587
587
  // src/translator/util/traverse.ts
588
588
  var import_compiler2 = require("@marko/compiler");
589
589
  var skip = Symbol("skip");
590
- function traverseReplace(container, key, enter3) {
590
+ function traverseReplace(container, key, enter3, state) {
591
591
  const node = container[key];
592
592
  if (node) {
593
593
  if (Array.isArray(node)) {
594
594
  for (let i = node.length; i--; ) {
595
- traverseReplace(node, i, enter3);
595
+ traverseReplace(node, i, enter3, state);
596
596
  }
597
597
  } else {
598
598
  const keys = import_compiler2.types.VISITOR_KEYS[node.type];
599
599
  for (let i = keys.length; i--; ) {
600
- traverseReplace(node, keys[i], enter3);
600
+ traverseReplace(node, keys[i], enter3, state);
601
601
  }
602
- const replacement = enter3(node, container, key);
602
+ const replacement = enter3(node, state);
603
603
  if (replacement) container[key] = replacement;
604
604
  }
605
605
  }
@@ -952,12 +952,12 @@ var Sorted = class {
952
952
  this.compare = compare;
953
953
  }
954
954
  add(data, item) {
955
- return data ? Array.isArray(data) ? addSorted(this.compare, data, item) : joinRepeatable(this.compare, data, item) : item;
955
+ return data !== void 0 ? Array.isArray(data) ? addSorted(this.compare, data, item) : joinRepeatable(this.compare, data, item) : item;
956
956
  }
957
957
  union(a, b) {
958
- if (a) {
958
+ if (a !== void 0) {
959
959
  if (Array.isArray(a)) {
960
- if (b) {
960
+ if (b !== void 0) {
961
961
  if (Array.isArray(b)) {
962
962
  return unionSortedRepeatable(this.compare, a, b);
963
963
  } else {
@@ -966,7 +966,7 @@ var Sorted = class {
966
966
  }
967
967
  return a;
968
968
  }
969
- if (b) {
969
+ if (b !== void 0) {
970
970
  if (Array.isArray(b)) {
971
971
  return addSorted(this.compare, b, a);
972
972
  }
@@ -977,7 +977,7 @@ var Sorted = class {
977
977
  return b;
978
978
  }
979
979
  find(data, item) {
980
- if (data) {
980
+ if (data !== void 0) {
981
981
  if (Array.isArray(data)) {
982
982
  return findSorted(this.compare, data, item);
983
983
  } else if (this.compare(data, item) === 0) {
@@ -989,7 +989,7 @@ var Sorted = class {
989
989
  return this.findIndex(data, item) !== -1;
990
990
  }
991
991
  findIndex(data, item) {
992
- if (data) {
992
+ if (data !== void 0) {
993
993
  if (Array.isArray(data)) {
994
994
  return findIndexSorted(this.compare, data, item);
995
995
  } else if (this.compare(data, item) === 0) {
@@ -1000,7 +1000,7 @@ var Sorted = class {
1000
1000
  }
1001
1001
  groupBy(data, cb) {
1002
1002
  const group = /* @__PURE__ */ new Map();
1003
- if (data) {
1003
+ if (data !== void 0) {
1004
1004
  if (Array.isArray(data)) {
1005
1005
  for (const item of data) {
1006
1006
  const key = cb(item);
@@ -1013,7 +1013,7 @@ var Sorted = class {
1013
1013
  return group;
1014
1014
  }
1015
1015
  isSuperset(superset, subset) {
1016
- if (!subset) {
1016
+ if (subset === void 0) {
1017
1017
  return true;
1018
1018
  }
1019
1019
  if (!Array.isArray(subset)) {
@@ -1035,7 +1035,7 @@ var Sorted = class {
1035
1035
  }
1036
1036
  };
1037
1037
  function push(data, item) {
1038
- if (data) {
1038
+ if (data !== void 0) {
1039
1039
  if (Array.isArray(data)) {
1040
1040
  data.push(item);
1041
1041
  return data;
@@ -1045,8 +1045,8 @@ function push(data, item) {
1045
1045
  return item;
1046
1046
  }
1047
1047
  function concat(a, b) {
1048
- if (a) {
1049
- if (b) {
1048
+ if (a !== void 0) {
1049
+ if (b !== void 0) {
1050
1050
  if (Array.isArray(a)) {
1051
1051
  return a.concat(b);
1052
1052
  } else if (Array.isArray(b)) {
@@ -1060,7 +1060,7 @@ function concat(a, b) {
1060
1060
  return b;
1061
1061
  }
1062
1062
  function filter(data, cb) {
1063
- if (data) {
1063
+ if (data !== void 0) {
1064
1064
  if (Array.isArray(data)) {
1065
1065
  const len = data.length;
1066
1066
  let result;
@@ -1091,10 +1091,9 @@ function filter(data, cb) {
1091
1091
  return data;
1092
1092
  }
1093
1093
  }
1094
- return void 0;
1095
1094
  }
1096
1095
  function forEach(data, cb) {
1097
- if (data) {
1096
+ if (data !== void 0) {
1098
1097
  if (Array.isArray(data)) {
1099
1098
  let i = 0;
1100
1099
  for (const item of data) {
@@ -1119,8 +1118,11 @@ function fromIter(data) {
1119
1118
  }
1120
1119
  return many || one;
1121
1120
  }
1121
+ function includes(data, item) {
1122
+ return data !== void 0 ? Array.isArray(data) ? data.includes(item) : data === item : false;
1123
+ }
1122
1124
  function find(data, cb) {
1123
- if (data) {
1125
+ if (data !== void 0) {
1124
1126
  if (Array.isArray(data)) {
1125
1127
  return data.find(cb);
1126
1128
  }
@@ -1130,13 +1132,13 @@ function find(data, cb) {
1130
1132
  }
1131
1133
  }
1132
1134
  function some(data, cb) {
1133
- return data ? Array.isArray(data) ? data.some(cb) : !!cb(data, 0) : false;
1135
+ return data !== void 0 ? Array.isArray(data) ? data.some(cb) : !!cb(data, 0) : false;
1134
1136
  }
1135
1137
  function toArray(data, cb) {
1136
- return data ? Array.isArray(data) ? data.map(cb) : [cb(data, 0)] : [];
1138
+ return data !== void 0 ? Array.isArray(data) ? data.map(cb) : [cb(data, 0)] : [];
1137
1139
  }
1138
1140
  function mapToString(data, sep, cb) {
1139
- if (data) {
1141
+ if (data !== void 0) {
1140
1142
  if (Array.isArray(data)) {
1141
1143
  let str = "";
1142
1144
  let curSep = "";
@@ -1151,22 +1153,22 @@ function mapToString(data, sep, cb) {
1151
1153
  return "";
1152
1154
  }
1153
1155
  function filterMap(data, cb) {
1154
- if (data) {
1156
+ if (data !== void 0) {
1155
1157
  if (Array.isArray(data)) {
1156
1158
  const len = data.length;
1157
1159
  let result;
1158
1160
  let i = 0;
1159
1161
  while (i < len) {
1160
1162
  let item = cb(data[i++]);
1161
- if (item) {
1163
+ if (item !== void 0) {
1162
1164
  result = item;
1163
1165
  while (i < len) {
1164
1166
  item = cb(data[i++]);
1165
- if (item) {
1167
+ if (item !== void 0) {
1166
1168
  result = [result, item];
1167
1169
  while (i < len) {
1168
1170
  item = cb(data[i++]);
1169
- if (item) {
1171
+ if (item !== void 0) {
1170
1172
  result.push(item);
1171
1173
  }
1172
1174
  }
@@ -1177,9 +1179,8 @@ function filterMap(data, cb) {
1177
1179
  }
1178
1180
  }
1179
1181
  return result;
1180
- } else {
1181
- return cb(data);
1182
1182
  }
1183
+ return cb(data);
1183
1184
  }
1184
1185
  }
1185
1186
  function findSorted(compare, data, item) {
@@ -1288,33 +1289,33 @@ var AccessorPrefix2 = /* @__PURE__ */ ((AccessorPrefix4) => {
1288
1289
  AccessorPrefix4["TagVariableChange"] = "M";
1289
1290
  return AccessorPrefix4;
1290
1291
  })(AccessorPrefix2 || {});
1291
- var AccessorProp2 = /* @__PURE__ */ ((AccessorProp4) => {
1292
- AccessorProp4["Global"] = "$";
1293
- AccessorProp4["Owner"] = "_";
1294
- AccessorProp4["AbortControllers"] = "A";
1295
- AccessorProp4["AbortScopes"] = "B";
1296
- AccessorProp4["AwaitCounter"] = "O";
1297
- AccessorProp4["BranchAccessor"] = "C";
1298
- AccessorProp4["BranchScopes"] = "D";
1299
- AccessorProp4["CatchContent"] = "E";
1300
- AccessorProp4["ClosestBranch"] = "F";
1301
- AccessorProp4["ClosestBranchId"] = "G";
1302
- AccessorProp4["Creating"] = "H";
1303
- AccessorProp4["Destroyed"] = "I";
1304
- AccessorProp4["DetachedAwait"] = "V";
1305
- AccessorProp4["EndNode"] = "K";
1306
- AccessorProp4["Id"] = "L";
1307
- AccessorProp4["LoopKey"] = "M";
1308
- AccessorProp4["ParentBranch"] = "N";
1309
- AccessorProp4["PendingEffects"] = "J";
1310
- AccessorProp4["PendingRenders"] = "W";
1311
- AccessorProp4["PlaceholderBranch"] = "P";
1312
- AccessorProp4["PlaceholderContent"] = "Q";
1313
- AccessorProp4["Renderer"] = "R";
1314
- AccessorProp4["StartNode"] = "S";
1315
- AccessorProp4["TagVariable"] = "T";
1316
- AccessorProp4["TagVariableChange"] = "U";
1317
- return AccessorProp4;
1292
+ var AccessorProp2 = /* @__PURE__ */ ((AccessorProp5) => {
1293
+ AccessorProp5["Global"] = "$";
1294
+ AccessorProp5["Owner"] = "_";
1295
+ AccessorProp5["AbortControllers"] = "A";
1296
+ AccessorProp5["AbortScopes"] = "B";
1297
+ AccessorProp5["AwaitCounter"] = "O";
1298
+ AccessorProp5["BranchAccessor"] = "C";
1299
+ AccessorProp5["BranchScopes"] = "D";
1300
+ AccessorProp5["CatchContent"] = "E";
1301
+ AccessorProp5["ClosestBranch"] = "F";
1302
+ AccessorProp5["ClosestBranchId"] = "G";
1303
+ AccessorProp5["Creating"] = "H";
1304
+ AccessorProp5["Destroyed"] = "I";
1305
+ AccessorProp5["DetachedAwait"] = "V";
1306
+ AccessorProp5["EndNode"] = "K";
1307
+ AccessorProp5["Id"] = "L";
1308
+ AccessorProp5["LoopKey"] = "M";
1309
+ AccessorProp5["ParentBranch"] = "N";
1310
+ AccessorProp5["PendingEffects"] = "J";
1311
+ AccessorProp5["PendingRenders"] = "W";
1312
+ AccessorProp5["PlaceholderBranch"] = "P";
1313
+ AccessorProp5["PlaceholderContent"] = "Q";
1314
+ AccessorProp5["Renderer"] = "R";
1315
+ AccessorProp5["StartNode"] = "S";
1316
+ AccessorProp5["TagVariable"] = "T";
1317
+ AccessorProp5["TagVariableChange"] = "U";
1318
+ return AccessorProp5;
1318
1319
  })(AccessorProp2 || {});
1319
1320
 
1320
1321
  // src/translator/util/marko-config.ts
@@ -2290,6 +2291,13 @@ function hasSupersetExcludeProperties(binding, excludeProperties) {
2290
2291
  }
2291
2292
  return true;
2292
2293
  }
2294
+ function getBindingPropTreeProp(propTree, name2) {
2295
+ return propTree.props?.[name2] || propTree.rest?.props?.[name2];
2296
+ }
2297
+ function getAllBindingPropTreePropKeys(propTree) {
2298
+ const keys = propTree.props ? Object.keys(propTree.props) : [];
2299
+ return propTree.rest?.props ? keys.concat(Object.keys(propTree.rest.props)) : keys;
2300
+ }
2293
2301
 
2294
2302
  // src/translator/util/entry-builder.ts
2295
2303
  var import_compiler9 = require("@marko/compiler");
@@ -2438,6 +2446,7 @@ function _escape_style(val) {
2438
2446
 
2439
2447
  // src/html/writer.ts
2440
2448
  var K_SCOPE_ID = Symbol("Scope ID");
2449
+ var K_SCOPE_REFERENCED = Symbol("Scope Referenced");
2441
2450
  var kPendingContexts = Symbol("Pending Contexts");
2442
2451
  var kBranchId = Symbol("Branch Id");
2443
2452
  var kIsAsync = Symbol("Is Async");
@@ -3283,11 +3292,16 @@ function getScopeExpression(section, targetSection) {
3283
3292
  }
3284
3293
  function createScopeReadExpression(reference, section) {
3285
3294
  const propName = toPropertyName(getScopeAccessor(reference));
3286
- return import_compiler19.types.memberExpression(
3287
- section && reference.type !== 4 /* local */ ? getScopeExpression(section, reference.section) : scopeIdentifier,
3295
+ const scope = section && reference.type !== 4 /* local */ ? getScopeExpression(section, reference.section) : scopeIdentifier;
3296
+ const expr = import_compiler19.types.memberExpression(
3297
+ scope,
3288
3298
  propName,
3289
3299
  propName.type !== "Identifier"
3290
3300
  );
3301
+ if (scope === scopeIdentifier) {
3302
+ (expr.extra ??= {}).read = createRead(reference, void 0);
3303
+ }
3304
+ return expr;
3291
3305
  }
3292
3306
 
3293
3307
  // src/translator/util/simplify-fn.ts
@@ -3396,6 +3410,9 @@ function getBindingGetterIdentifier(binding) {
3396
3410
  return identifier;
3397
3411
  }
3398
3412
  function getSignal(section, referencedBindings, name2 = generateSignalName(referencedBindings)) {
3413
+ if (!Array.isArray(referencedBindings) && referencedBindings?.type === 7 /* constant */) {
3414
+ return getSignal(section, void 0);
3415
+ }
3399
3416
  const signals = getSignals(section);
3400
3417
  let signal = signals.get(referencedBindings);
3401
3418
  if (!signal) {
@@ -3474,7 +3491,7 @@ function initValue(binding, isLet = false) {
3474
3491
  signal.build = () => {
3475
3492
  const fn = getSignalFn(signal);
3476
3493
  const isDirectAlias = binding.upstreamAlias && binding.property === void 0 && binding.excludeProperties === void 0;
3477
- if (isDirectAlias || !signalHasStatements(signal)) {
3494
+ if (isDirectAlias || !signal.hasSideEffect || !signalHasStatements(signal)) {
3478
3495
  return fn;
3479
3496
  }
3480
3497
  return callRuntime(
@@ -3484,10 +3501,14 @@ function initValue(binding, isLet = false) {
3484
3501
  );
3485
3502
  };
3486
3503
  for (const alias of binding.aliases) {
3487
- initValue(alias);
3504
+ if (alias.type !== 7 /* constant */) {
3505
+ initValue(alias);
3506
+ }
3488
3507
  }
3489
3508
  for (const alias of binding.propertyAliases.values()) {
3490
- initValue(alias);
3509
+ if (alias.type !== 7 /* constant */) {
3510
+ initValue(alias);
3511
+ }
3491
3512
  }
3492
3513
  return signal;
3493
3514
  }
@@ -3497,7 +3518,7 @@ function signalHasStatements(signal) {
3497
3518
  }
3498
3519
  const binding = signal.referencedBindings;
3499
3520
  if (binding) {
3500
- if (!Array.isArray(binding) && (binding.closureSections || binding.type === 0 /* dom */ || binding.section === signal.section && (binding.hoists.size || binding.aliases.size || binding.propertyAliases.size))) {
3521
+ if (!Array.isArray(binding) && (binding.closureSections || binding.type === 0 /* dom */ || binding.section === signal.section && (binding.hoists.size || binding.aliases.size || hasNonConstantPropertyAlias(binding)))) {
3501
3522
  return true;
3502
3523
  }
3503
3524
  } else if (signal.section.referencedClosures) {
@@ -3561,20 +3582,22 @@ function getSignalFn(signal) {
3561
3582
  }
3562
3583
  }
3563
3584
  for (const [key, alias] of binding.propertyAliases) {
3564
- const aliasSignal = getSignal(alias.section, alias);
3565
- signal.render.push(
3566
- import_compiler22.types.expressionStatement(
3567
- import_compiler22.types.callExpression(aliasSignal.identifier, [
3568
- scopeIdentifier,
3569
- toMemberExpression(
3570
- createScopeReadExpression(binding),
3571
- key,
3572
- binding.nullable
3573
- ),
3574
- ...getTranslatedExtraArgs(aliasSignal)
3575
- ])
3576
- )
3577
- );
3585
+ if (alias.type !== 7 /* constant */) {
3586
+ const aliasSignal = getSignal(alias.section, alias);
3587
+ signal.render.push(
3588
+ import_compiler22.types.expressionStatement(
3589
+ import_compiler22.types.callExpression(aliasSignal.identifier, [
3590
+ scopeIdentifier,
3591
+ toMemberExpression(
3592
+ createScopeReadExpression(binding),
3593
+ key,
3594
+ binding.nullable
3595
+ ),
3596
+ ...getTranslatedExtraArgs(aliasSignal)
3597
+ ])
3598
+ )
3599
+ );
3600
+ }
3578
3601
  }
3579
3602
  if (assertsHoists) {
3580
3603
  signal.render.push(
@@ -3655,20 +3678,27 @@ function getSignalFn(signal) {
3655
3678
  }
3656
3679
  if (signal.effect.length) {
3657
3680
  const effectIdentifier = import_compiler22.types.identifier(`${signal.identifier.name}__script`);
3681
+ signal.hasSideEffect = true;
3658
3682
  signal.render.push(
3659
3683
  import_compiler22.types.expressionStatement(
3660
3684
  import_compiler22.types.callExpression(effectIdentifier, [scopeIdentifier])
3661
3685
  )
3662
3686
  );
3663
3687
  }
3688
+ if (!signal.hasSideEffect) {
3689
+ return import_compiler22.types.arrowFunctionExpression(
3690
+ isValue ? [scopeIdentifier, getSignalValueIdentifier(signal)] : [scopeIdentifier],
3691
+ toFirstExpressionOrBlock(signal.render)
3692
+ );
3693
+ }
3664
3694
  if (signal.render.length === 1) {
3665
3695
  const render = signal.render[0];
3666
3696
  if (render.type === "ExpressionStatement") {
3667
3697
  const { expression } = render;
3668
3698
  if (expression.type === "CallExpression") {
3669
3699
  const args = expression.arguments;
3670
- if (args.length === 1 && args[0].type === "Identifier" && args[0].name === scopeIdentifier.name) {
3671
- if (expression.callee.type === "MemberExpression" && expression.callee.property.type === "Identifier" && expression.callee.property.name === "_") {
3700
+ if (args.length === 1 && args[0] === scopeIdentifier) {
3701
+ if (expression.callee.type === "MemberExpression" && expression.callee.property.type === "Identifier" && expression.callee.property.name === getAccessorProp().Owner) {
3672
3702
  return expression.callee.object;
3673
3703
  }
3674
3704
  return expression.callee;
@@ -3693,15 +3723,23 @@ function getTranslatedExtraArgs(signal) {
3693
3723
  }
3694
3724
  return emptyExtraArgs;
3695
3725
  }
3726
+ function getSignalValueIdentifier(signal) {
3727
+ const canonicalBinding = getCanonicalBinding(
3728
+ signal.referencedBindings
3729
+ );
3730
+ return import_compiler22.types.identifier(canonicalBinding.name);
3731
+ }
3696
3732
  function subscribe(references, subscriber) {
3697
3733
  if (references) {
3698
3734
  forEach(references, (binding) => {
3699
- const source = binding.property === void 0 && binding.excludeProperties === void 0 && binding.upstreamAlias || binding;
3700
- const providerSignal = getSignal(subscriber.section, source);
3701
- providerSignal.intersection = push(
3702
- providerSignal.intersection,
3703
- subscriber
3704
- );
3735
+ if (binding.type !== 7 /* constant */) {
3736
+ const source = binding.property === void 0 && binding.excludeProperties === void 0 && binding.upstreamAlias || binding;
3737
+ const providerSignal = getSignal(subscriber.section, source);
3738
+ providerSignal.intersection = push(
3739
+ providerSignal.intersection,
3740
+ subscriber
3741
+ );
3742
+ }
3705
3743
  });
3706
3744
  }
3707
3745
  }
@@ -3755,7 +3793,7 @@ function replaceNullishAndEmptyFunctionsWith0(args) {
3755
3793
  args.length = finalLen || 0;
3756
3794
  return args;
3757
3795
  }
3758
- function addStatement(type, targetSection, referencedBindings, statement, usedReferences) {
3796
+ function addStatement(type, targetSection, referencedBindings, statement, usedReferences, isPure) {
3759
3797
  const signal = getSignal(targetSection, referencedBindings);
3760
3798
  const statements = signal[type] ??= [];
3761
3799
  const add = type === "effect" ? addEffectReferences : addRenderReferences;
@@ -3773,6 +3811,9 @@ function addStatement(type, targetSection, referencedBindings, statement, usedRe
3773
3811
  add(signal, referencedBindings);
3774
3812
  }
3775
3813
  }
3814
+ if (!isPure || type === "effect") {
3815
+ signal.hasSideEffect = true;
3816
+ }
3776
3817
  }
3777
3818
  function addEffectReferences(signal, referencedBindings) {
3778
3819
  signal.effectReferencedBindings = bindingUtil.union(
@@ -3793,6 +3834,9 @@ function addValue(targetSection, referencedBindings, signal, value) {
3793
3834
  signal,
3794
3835
  value
3795
3836
  });
3837
+ if (value.extra?.referencedBindingsInFunction) {
3838
+ parentSignal.hasSideEffect = true;
3839
+ }
3796
3840
  }
3797
3841
  function getResumeRegisterId(section, referencedBindings, type) {
3798
3842
  const {
@@ -3853,7 +3897,12 @@ function writeSignals(section) {
3853
3897
  traverseReplace(value, "value", replaceRenderNode);
3854
3898
  }
3855
3899
  forEach(signal.intersection, writeSignal);
3856
- traverseReplace(signal, "render", replaceRenderNode);
3900
+ if (!signal.hasSideEffect) {
3901
+ const binding = signal.referencedBindings;
3902
+ if (binding && (signal.intersection || Array.isArray(binding) || binding.type === 1 /* let */ || binding.closureSections || binding.hoists.size || binding.section !== signal.section)) {
3903
+ signal.hasSideEffect = true;
3904
+ }
3905
+ }
3857
3906
  let effectDeclarator;
3858
3907
  if (signal.effect.length) {
3859
3908
  traverseReplace(signal, "effect", replaceEffectNode);
@@ -3902,6 +3951,7 @@ function writeSignals(section) {
3902
3951
  signalDeclaration = import_compiler22.types.exportNamedDeclaration(signalDeclaration);
3903
3952
  }
3904
3953
  }
3954
+ traverseReplace(signal, "render", replaceRenderNode, signal);
3905
3955
  const signalStatements = signal.prependStatements || [];
3906
3956
  if (effectDeclarator) {
3907
3957
  signalStatements.push(import_compiler22.types.variableDeclaration("const", [effectDeclarator]));
@@ -4227,18 +4277,18 @@ function writeHTMLResumeStatements(path7) {
4227
4277
  function getSetup(section) {
4228
4278
  return section.hoistedTo ? getSignal(section, void 0).identifier : getSignals(section).get(void 0)?.identifier;
4229
4279
  }
4230
- function replaceRenderNode(node) {
4231
- return replaceAssignedNode(node) || replaceBindingReadNode(node) || replaceRegisteredFunctionNode(node);
4280
+ function replaceRenderNode(node, signal) {
4281
+ return replaceAssignedNode(node) || replaceBindingReadNode(node, signal) || replaceRegisteredFunctionNode(node);
4232
4282
  }
4233
4283
  function replaceEffectNode(node) {
4234
4284
  return replaceAssignedNode(node) || replaceBindingReadNode(node);
4235
4285
  }
4236
- function replaceBindingReadNode(node) {
4286
+ function replaceBindingReadNode(node, signal) {
4237
4287
  switch (node.type) {
4238
4288
  case "Identifier":
4239
4289
  case "MemberExpression":
4240
4290
  case "OptionalMemberExpression": {
4241
- return getReadReplacement(node);
4291
+ return getReadReplacement(node, signal);
4242
4292
  }
4243
4293
  case "CallExpression": {
4244
4294
  const { extra } = node.callee;
@@ -4453,22 +4503,24 @@ var dom_default = {
4453
4503
  forEachSectionReverse((childSection) => {
4454
4504
  if (childSection !== section) {
4455
4505
  forEach(childSection.referencedClosures, (closure) => {
4456
- const closureSignal = getSignal(childSection, closure);
4457
- if (signalHasStatements(closureSignal)) {
4458
- addStatement(
4459
- "render",
4460
- childSection,
4461
- void 0,
4462
- import_compiler23.types.expressionStatement(
4463
- import_compiler23.types.callExpression(
4464
- isDynamicClosure(childSection, closure) ? closureSignal.identifier : import_compiler23.types.memberExpression(
4465
- closureSignal.identifier,
4466
- import_compiler23.types.identifier("_")
4467
- ),
4468
- [scopeIdentifier]
4506
+ if (closure.type !== 7 /* constant */) {
4507
+ const closureSignal = getSignal(childSection, closure);
4508
+ if (signalHasStatements(closureSignal)) {
4509
+ addStatement(
4510
+ "render",
4511
+ childSection,
4512
+ void 0,
4513
+ import_compiler23.types.expressionStatement(
4514
+ import_compiler23.types.callExpression(
4515
+ isDynamicClosure(childSection, closure) ? closureSignal.identifier : import_compiler23.types.memberExpression(
4516
+ closureSignal.identifier,
4517
+ import_compiler23.types.identifier("_")
4518
+ ),
4519
+ [scopeIdentifier]
4520
+ )
4469
4521
  )
4470
- )
4471
- );
4522
+ );
4523
+ }
4472
4524
  }
4473
4525
  });
4474
4526
  const tagParamsSignal = childSection.params && initValue(childSection.params);
@@ -4723,8 +4775,8 @@ var html_default = {
4723
4775
  }
4724
4776
  }
4725
4777
  };
4726
- function replaceNode(node, container) {
4727
- return replaceBindingReadNode2(node) || replaceRegisteredFunctionNode2(node, container);
4778
+ function replaceNode(node) {
4779
+ return replaceBindingReadNode2(node) || replaceRegisteredFunctionNode2(node);
4728
4780
  }
4729
4781
  function replaceBindingReadNode2(node) {
4730
4782
  switch (node.type) {
@@ -4756,7 +4808,7 @@ function replaceBindingReadNode2(node) {
4756
4808
  }
4757
4809
  }
4758
4810
  }
4759
- function replaceRegisteredFunctionNode2(node, container) {
4811
+ function replaceRegisteredFunctionNode2(node) {
4760
4812
  switch (node.type) {
4761
4813
  case "ClassMethod": {
4762
4814
  const replacement = getRegisteredFnExpression2(node);
@@ -4770,25 +4822,6 @@ function replaceRegisteredFunctionNode2(node, container) {
4770
4822
  const replacement = getRegisteredFnExpression2(node);
4771
4823
  return replacement && import_compiler24.types.objectProperty(node.key, replacement);
4772
4824
  }
4773
- case "FunctionDeclaration": {
4774
- const { extra } = node;
4775
- if (isRegisteredFnExtra(extra)) {
4776
- let registeredFnDeclarations = registeredFnDeclarationsByBody.get(
4777
- container
4778
- );
4779
- if (!registeredFnDeclarations) {
4780
- registeredFnDeclarationsByBody.set(
4781
- container,
4782
- registeredFnDeclarations = []
4783
- );
4784
- }
4785
- registeredFnDeclarations.push({
4786
- id: node.id.name,
4787
- registerId: extra.registerId
4788
- });
4789
- }
4790
- break;
4791
- }
4792
4825
  case "ArrowFunctionExpression":
4793
4826
  case "FunctionExpression": {
4794
4827
  return getRegisteredFnExpression2(node);
@@ -4799,14 +4832,18 @@ function replaceRegisteredFunctionNode2(node, container) {
4799
4832
  break;
4800
4833
  }
4801
4834
  }
4802
- var registeredFnDeclarationsByBody = /* @__PURE__ */ new WeakMap();
4803
4835
  function addRegisteredDeclarations(body) {
4804
- const registeredFnDeclarations = registeredFnDeclarationsByBody.get(body);
4805
- if (registeredFnDeclarations) {
4806
- for (const { id, registerId } of registeredFnDeclarations) {
4836
+ const len = body.length;
4837
+ for (let i = 0; i < len; i++) {
4838
+ const child = body[i];
4839
+ if (child.type === "FunctionDeclaration" && isRegisteredFnExtra(child.extra)) {
4807
4840
  body.push(
4808
4841
  import_compiler24.types.expressionStatement(
4809
- callRuntime("_resume", import_compiler24.types.identifier(id), import_compiler24.types.stringLiteral(registerId))
4842
+ callRuntime(
4843
+ "_resume",
4844
+ import_compiler24.types.identifier(child.id.name),
4845
+ import_compiler24.types.stringLiteral(child.extra.registerId)
4846
+ )
4810
4847
  )
4811
4848
  );
4812
4849
  }
@@ -5127,7 +5164,6 @@ function buildUndefined() {
5127
5164
  }
5128
5165
 
5129
5166
  // src/translator/visitors/program/index.ts
5130
- var cleanIdentifier;
5131
5167
  var scopeIdentifier;
5132
5168
  function isScopeIdentifier(node) {
5133
5169
  return node === scopeIdentifier;
@@ -5181,7 +5217,6 @@ var program_default = {
5181
5217
  translate: {
5182
5218
  enter(program) {
5183
5219
  scopeIdentifier = isOutputDOM() ? generateUidIdentifier("scope") : null;
5184
- cleanIdentifier = isOutputDOM() ? generateUidIdentifier("clean") : null;
5185
5220
  if (getMarkoOpts().output === "hydrate") {
5186
5221
  const entryFile = program.hub.file;
5187
5222
  const visitedFiles = /* @__PURE__ */ new Set([
@@ -5989,7 +6024,9 @@ var native_tag_default = {
5989
6024
  scopeIdentifier,
5990
6025
  getScopeAccessorLiteral(nodeBinding)
5991
6026
  )
5992
- )
6027
+ ),
6028
+ void 0,
6029
+ true
5993
6030
  );
5994
6031
  }
5995
6032
  if (staticControllable) {
@@ -6075,7 +6112,14 @@ var native_tag_default = {
6075
6112
  }
6076
6113
  }
6077
6114
  if (stmt) {
6078
- addStatement("render", tagSection, valueReferences, stmt);
6115
+ addStatement(
6116
+ "render",
6117
+ tagSection,
6118
+ valueReferences,
6119
+ stmt,
6120
+ void 0,
6121
+ !!meta.dynamicItems
6122
+ );
6079
6123
  }
6080
6124
  }
6081
6125
  break;
@@ -6109,7 +6153,9 @@ var native_tag_default = {
6109
6153
  import_compiler33.types.stringLiteral(name2),
6110
6154
  value
6111
6155
  )
6112
- )
6156
+ ),
6157
+ void 0,
6158
+ true
6113
6159
  );
6114
6160
  }
6115
6161
  break;
@@ -6169,7 +6215,9 @@ var native_tag_default = {
6169
6215
  visitAccessor,
6170
6216
  staticContentAttr.value
6171
6217
  )
6172
- )
6218
+ ),
6219
+ void 0,
6220
+ true
6173
6221
  );
6174
6222
  }
6175
6223
  if (isOpenOnly) {
@@ -6209,7 +6257,9 @@ var native_tag_default = {
6209
6257
  createScopeReadExpression(nodeBinding),
6210
6258
  textLiteral
6211
6259
  )
6212
- )
6260
+ ),
6261
+ void 0,
6262
+ true
6213
6263
  );
6214
6264
  }
6215
6265
  } else {
@@ -6537,7 +6587,8 @@ var for_default = {
6537
6587
  (0, import_babel_utils23.assertNoVar)(tag);
6538
6588
  (0, import_babel_utils23.assertNoArgs)(tag);
6539
6589
  assertNoSpreadAttrs(tag);
6540
- switch (getForType(tag.node)) {
6590
+ const forType = getForType(tag.node);
6591
+ switch (forType) {
6541
6592
  case "of":
6542
6593
  allowAttrs = ["of"];
6543
6594
  break;
@@ -6574,6 +6625,13 @@ var for_default = {
6574
6625
  addSerializeExpr(tagSection, tagExtra, kStatefulReason);
6575
6626
  if (paramsBinding) {
6576
6627
  setBindingDownstream(paramsBinding, tagExtra);
6628
+ const keyBinding = paramsBinding.propertyAliases.get(
6629
+ forType === "of" ? "1" : "0"
6630
+ );
6631
+ if (keyBinding) {
6632
+ keyBinding.type = 7 /* constant */;
6633
+ keyBinding.scopeAccessor = getAccessorProp().LoopKey;
6634
+ }
6577
6635
  }
6578
6636
  bodySection.sectionAccessor = {
6579
6637
  binding: nodeBinding,
@@ -7612,11 +7670,9 @@ function analyzeAttrs(rootTagExtra, section, tag, propTree, rootAttrExprs) {
7612
7670
  }
7613
7671
  bindings = bindingUtil.add(bindings, templateExportAttr.binding);
7614
7672
  }
7615
- if (bindings) {
7616
- forEach(bindings, (binding) => {
7617
- setBindingDownstream(binding, groupExtra);
7618
- });
7619
- }
7673
+ forEach(bindings, (binding) => {
7674
+ setBindingDownstream(binding, groupExtra);
7675
+ });
7620
7676
  for (const name2 of group) {
7621
7677
  known[attrTagLookup[name2].name] = groupKnownValue;
7622
7678
  }
@@ -7629,65 +7685,97 @@ function analyzeAttrs(rootTagExtra, section, tag, propTree, rootAttrExprs) {
7629
7685
  known.content = { value: void 0 };
7630
7686
  }
7631
7687
  }
7632
- const { attributes } = tag.node;
7688
+ let knownSpreadBinding;
7633
7689
  let spreadReferenceNodes;
7690
+ const { attributes } = tag.node;
7634
7691
  for (let i = attributes.length; i--; ) {
7635
7692
  const attr = attributes[i];
7636
7693
  if (import_compiler37.types.isMarkoAttribute(attr)) {
7637
- const templateExportAttr = propTree.props[attr.name];
7694
+ const templateExportAttr = getBindingPropTreeProp(propTree, attr.name);
7638
7695
  if (!templateExportAttr || seen.has(attr.name)) {
7639
7696
  unknownReferences.push(attr.value);
7640
7697
  continue;
7641
7698
  }
7699
+ const attrExtra = attr.value.extra ??= {};
7642
7700
  seen.add(attr.name);
7643
- setBindingDownstream(
7644
- templateExportAttr.binding,
7645
- attr.value.extra ??= {}
7646
- );
7701
+ setBindingDownstream(templateExportAttr.binding, attrExtra);
7702
+ if (knownSpreadBinding && !includes(knownSpreadBinding.excludeProperties, attr.name)) {
7703
+ const propBinding = getOrCreatePropertyAlias(
7704
+ knownSpreadBinding,
7705
+ attr.name
7706
+ );
7707
+ addRead(attrExtra, void 0, propBinding, section);
7708
+ }
7647
7709
  }
7648
7710
  if (spreadReferenceNodes) {
7649
7711
  spreadReferenceNodes.push(attr.value);
7650
7712
  } else if (import_compiler37.types.isMarkoSpreadAttribute(attr)) {
7651
- spreadReferenceNodes = [attr.value];
7713
+ knownSpreadBinding = getSingleKnownSpreadBinding(attributes);
7714
+ if (knownSpreadBinding) {
7715
+ dropRead(attr.value.extra);
7716
+ } else {
7717
+ spreadReferenceNodes = [attr.value];
7718
+ }
7652
7719
  } else {
7653
7720
  const attrValueExtra = attr.value.extra ??= {};
7654
7721
  known[attr.name] = { value: attrValueExtra };
7655
7722
  rootAttrExprs.add(attrValueExtra);
7656
7723
  }
7657
7724
  }
7658
- if (spreadReferenceNodes) {
7659
- const extra = inputExpr.value = mergeReferences(
7660
- section,
7661
- tag.node,
7662
- spreadReferenceNodes
7663
- );
7664
- let spreadBinding = propTree.binding;
7665
- if (seen.size) {
7666
- spreadBinding = createBinding(
7725
+ if (knownSpreadBinding) {
7726
+ for (const prop of getAllBindingPropTreePropKeys(propTree)) {
7727
+ if (!seen.has(prop)) {
7728
+ const propBinding = getOrCreatePropertyAlias(knownSpreadBinding, prop);
7729
+ const propExtra = { section };
7730
+ known[prop] = { value: propExtra };
7731
+ rootAttrExprs.add(propExtra);
7732
+ addRead(propExtra, propExtra, propBinding, section);
7733
+ setBindingDownstream(propBinding, propExtra);
7734
+ }
7735
+ }
7736
+ } else if (spreadReferenceNodes) {
7737
+ setBindingDownstream(
7738
+ seen.size ? createBinding(
7667
7739
  generateUid(`${getTagName(tag)}_attrs`),
7668
- spreadBinding.type,
7669
- spreadBinding.section,
7670
- spreadBinding,
7740
+ propTree.binding.type,
7741
+ propTree.binding.section,
7742
+ propTree.binding,
7671
7743
  void 0,
7672
7744
  fromIter(seen),
7673
7745
  spreadReferenceNodes[0].loc,
7674
7746
  true
7675
- );
7676
- }
7677
- setBindingDownstream(spreadBinding, extra);
7747
+ ) : propTree.binding,
7748
+ inputExpr.value = mergeReferences(
7749
+ section,
7750
+ tag.node,
7751
+ spreadReferenceNodes
7752
+ )
7753
+ );
7678
7754
  }
7679
7755
  if (propTree.rest) {
7680
- const extra = inputExpr.value = mergeReferences(
7681
- section,
7682
- tag.node,
7683
- unknownReferences.flat()
7756
+ setBindingDownstream(
7757
+ propTree.binding,
7758
+ inputExpr.value = mergeReferences(
7759
+ section,
7760
+ tag.node,
7761
+ unknownReferences.flat()
7762
+ )
7684
7763
  );
7685
- setBindingDownstream(propTree.binding, extra);
7686
7764
  } else {
7687
7765
  unknownReferences.forEach(dropReferences);
7688
7766
  }
7689
7767
  return inputExpr;
7690
7768
  }
7769
+ function getSingleKnownSpreadBinding(attributes) {
7770
+ let binding;
7771
+ for (let i = attributes.length; i--; ) {
7772
+ const attr = attributes[i];
7773
+ if (attr.type === "MarkoSpreadAttribute" ? binding || !(binding = attr.value.extra?.spreadFrom) : binding && !includes(binding.excludeProperties, attr.name)) {
7774
+ return;
7775
+ }
7776
+ }
7777
+ return binding;
7778
+ }
7691
7779
  function writeParamsToSignals(tag, propTree, importAlias, info) {
7692
7780
  if (!propTree.props || tag.node.arguments?.some((node) => import_compiler37.types.isSpreadElement(node))) {
7693
7781
  const referencedBindings = tag.node.extra?.referencedBindings;
@@ -7745,7 +7833,9 @@ function writeParamsToSignals(tag, propTree, importAlias, info) {
7745
7833
  ),
7746
7834
  arg
7747
7835
  ])
7748
- )
7836
+ ),
7837
+ void 0,
7838
+ true
7749
7839
  );
7750
7840
  }
7751
7841
  i++;
@@ -7871,20 +7961,20 @@ function writeAttrsToSignals(tag, propTree, importAlias, info) {
7871
7961
  scopeIdentifier
7872
7962
  ])
7873
7963
  ])
7874
- )
7964
+ ),
7965
+ void 0,
7966
+ true
7875
7967
  );
7876
7968
  }
7877
7969
  }
7878
- const { attributes } = tag.node;
7879
- const staticAttrs = [];
7970
+ let knownSpreadBinding;
7880
7971
  let spreadProps;
7972
+ const staticAttrs = [];
7973
+ const { attributes } = tag.node;
7881
7974
  for (let i = attributes.length; i--; ) {
7882
7975
  const attr = attributes[i];
7883
7976
  if (import_compiler37.types.isMarkoAttribute(attr)) {
7884
- const childAttrExports = propTree.props[attr.name];
7885
- if (!childAttrExports || seen.has(attr.name)) continue;
7886
- if (spreadProps) {
7887
- spreadProps.push(toObjectProperty(attr.name, attr.value));
7977
+ if (!getBindingPropTreeProp(propTree, attr.name) || seen.has(attr.name) || spreadProps?.push(toObjectProperty(attr.name, attr.value))) {
7888
7978
  continue;
7889
7979
  }
7890
7980
  seen.add(attr.name);
@@ -7892,11 +7982,14 @@ function writeAttrsToSignals(tag, propTree, importAlias, info) {
7892
7982
  } else if (spreadProps) {
7893
7983
  spreadProps.push(import_compiler37.types.spreadElement(attr.value));
7894
7984
  } else {
7895
- spreadProps = [import_compiler37.types.spreadElement(attr.value)];
7985
+ knownSpreadBinding = getSingleKnownSpreadBinding(attributes);
7986
+ if (!knownSpreadBinding) {
7987
+ spreadProps = [import_compiler37.types.spreadElement(attr.value)];
7988
+ }
7896
7989
  }
7897
7990
  }
7898
7991
  for (const attr of staticAttrs.reverse()) {
7899
- const childAttrExports = propTree.props[attr.name];
7992
+ const childAttrExports = getBindingPropTreeProp(propTree, attr.name);
7900
7993
  const attrExportIdentifier = info.getBindingIdentifier(
7901
7994
  childAttrExports.binding,
7902
7995
  `${importAlias}_${attr.name}`
@@ -7908,65 +8001,95 @@ function writeAttrsToSignals(tag, propTree, importAlias, info) {
7908
8001
  import_compiler37.types.expressionStatement(
7909
8002
  import_compiler37.types.callExpression(attrExportIdentifier, [
7910
8003
  createScopeReadExpression(info.childScopeBinding, info.tagSection),
8004
+ // TODO: use spreadBinding property alias after we optimize `in`
7911
8005
  attr.value
7912
8006
  ])
7913
- )
8007
+ ),
8008
+ void 0,
8009
+ true
7914
8010
  );
7915
8011
  }
7916
- const missing = new Set(Object.keys(propTree.props));
8012
+ const missing = new Set(getAllBindingPropTreePropKeys(propTree));
7917
8013
  for (const name2 of seen) missing.delete(name2);
7918
8014
  if (missing.size) {
7919
- const referencedBindings = tag.node.extra?.referencedBindings;
7920
- if (spreadProps) {
7921
- const spreadExpr = propsToExpression(
7922
- propTree.rest ? (translatedAttrs = translateAttrs(tag, propTree, seen)).properties : spreadProps.reverse()
7923
- );
7924
- if (isSimpleReference(spreadExpr)) {
7925
- spreadId = spreadExpr;
7926
- } else {
7927
- spreadId = generateUidIdentifier(`${importAlias}_spread`);
7928
- if (translatedAttrs) {
7929
- translatedAttrs.properties = [import_compiler37.types.spreadElement(spreadId)];
7930
- }
7931
- addStatement("render", info.tagSection, referencedBindings, [
7932
- import_compiler37.types.variableDeclaration("const", [
7933
- import_compiler37.types.variableDeclarator(spreadId, spreadExpr)
7934
- ])
7935
- ]);
7936
- }
7937
- }
7938
- for (const name2 of missing) {
7939
- const childAttrExports = propTree.props[name2];
7940
- const attrExportIdentifier = info.getBindingIdentifier(
7941
- childAttrExports.binding,
7942
- `${importAlias}_${name2}`
7943
- );
7944
- addStatement(
7945
- "render",
7946
- info.tagSection,
7947
- referencedBindings,
7948
- import_compiler37.types.expressionStatement(
7949
- import_compiler37.types.callExpression(
7950
- attrExportIdentifier,
7951
- spreadId ? [
8015
+ if (knownSpreadBinding) {
8016
+ for (const prop of missing) {
8017
+ const childAttrExports = getBindingPropTreeProp(propTree, prop);
8018
+ const attrExportIdentifier = info.getBindingIdentifier(
8019
+ childAttrExports.binding,
8020
+ `${importAlias}_${prop}`
8021
+ );
8022
+ const propBinding = knownSpreadBinding.propertyAliases.get(prop);
8023
+ addStatement(
8024
+ "render",
8025
+ info.tagSection,
8026
+ propBinding,
8027
+ import_compiler37.types.expressionStatement(
8028
+ import_compiler37.types.callExpression(attrExportIdentifier, [
7952
8029
  createScopeReadExpression(
7953
8030
  info.childScopeBinding,
7954
8031
  info.tagSection
7955
8032
  ),
7956
- toMemberExpression(import_compiler37.types.cloneNode(spreadId, true), name2)
7957
- ] : [
7958
- createScopeReadExpression(
7959
- info.childScopeBinding,
7960
- info.tagSection
7961
- )
7962
- ]
8033
+ createScopeReadExpression(propBinding, info.tagSection)
8034
+ ])
8035
+ ),
8036
+ void 0,
8037
+ true
8038
+ );
8039
+ }
8040
+ } else {
8041
+ const referencedBindings = tag.node.extra?.referencedBindings;
8042
+ if (spreadProps) {
8043
+ const spreadExpr = propsToExpression(
8044
+ propTree.rest ? (translatedAttrs = translateAttrs(tag, propTree, seen)).properties : spreadProps.reverse()
8045
+ );
8046
+ if (isSimpleReference(spreadExpr)) {
8047
+ spreadId = spreadExpr;
8048
+ } else {
8049
+ spreadId = generateUidIdentifier(`${importAlias}_spread`);
8050
+ if (translatedAttrs) {
8051
+ translatedAttrs.properties = [import_compiler37.types.spreadElement(spreadId)];
8052
+ }
8053
+ addStatement("render", info.tagSection, referencedBindings, [
8054
+ import_compiler37.types.variableDeclaration("const", [
8055
+ import_compiler37.types.variableDeclarator(spreadId, spreadExpr)
8056
+ ])
8057
+ ]);
8058
+ }
8059
+ }
8060
+ for (const name2 of missing) {
8061
+ const childAttrExports = getBindingPropTreeProp(propTree, name2);
8062
+ const attrExportIdentifier = info.getBindingIdentifier(
8063
+ childAttrExports.binding,
8064
+ `${importAlias}_${name2}`
8065
+ );
8066
+ addStatement(
8067
+ "render",
8068
+ info.tagSection,
8069
+ spreadProps && referencedBindings,
8070
+ import_compiler37.types.expressionStatement(
8071
+ import_compiler37.types.callExpression(
8072
+ attrExportIdentifier,
8073
+ spreadId ? [
8074
+ createScopeReadExpression(
8075
+ info.childScopeBinding,
8076
+ info.tagSection
8077
+ ),
8078
+ toMemberExpression(import_compiler37.types.cloneNode(spreadId, true), name2)
8079
+ ] : [
8080
+ createScopeReadExpression(
8081
+ info.childScopeBinding,
8082
+ info.tagSection
8083
+ )
8084
+ ]
8085
+ )
7963
8086
  )
7964
- )
7965
- );
8087
+ );
8088
+ }
7966
8089
  }
7967
8090
  }
7968
8091
  }
7969
- if (!propTree.props || propTree.rest) {
8092
+ if (!propTree.props || propTree.rest && !propTree.rest.props) {
7970
8093
  if (!translatedAttrs) {
7971
8094
  if (propTree.rest) {
7972
8095
  seen ||= /* @__PURE__ */ new Set();
@@ -8127,6 +8250,7 @@ function createBinding(name2, type, section, upstreamAlias, property, excludePro
8127
8250
  upstreamAlias,
8128
8251
  downstreamExpressions: /* @__PURE__ */ new Set(),
8129
8252
  scopeOffset: void 0,
8253
+ scopeAccessor: void 0,
8130
8254
  export: void 0,
8131
8255
  nullable: excludeProperties === void 0
8132
8256
  };
@@ -8147,6 +8271,15 @@ function createBinding(name2, type, section, upstreamAlias, property, excludePro
8147
8271
  getBindings().add(binding);
8148
8272
  return binding;
8149
8273
  }
8274
+ function getOrCreatePropertyAlias(binding, property) {
8275
+ return binding.propertyAliases.get(property) || createBinding(
8276
+ `${binding.name}_${property.replace(/[^a-zA-Z0-9_$]/g, "_")}`,
8277
+ binding.type,
8278
+ binding.section,
8279
+ binding,
8280
+ property
8281
+ );
8282
+ }
8150
8283
  function trackDomVarReferences(tag, binding) {
8151
8284
  const tagVar = tag.node.var;
8152
8285
  if (!tagVar) {
@@ -8517,7 +8650,6 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
8517
8650
  function trackReference(referencePath, binding) {
8518
8651
  let root = referencePath;
8519
8652
  let reference = binding;
8520
- let propPath = binding.name;
8521
8653
  while (true) {
8522
8654
  const { parent } = root;
8523
8655
  if (!import_compiler38.types.isMemberExpression(parent) && !import_compiler38.types.isOptionalMemberExpression(parent))
@@ -8527,23 +8659,11 @@ function trackReference(referencePath, binding) {
8527
8659
  if (reference.upstreamAlias && reference.excludeProperties !== void 0 && !propsUtil.has(reference.excludeProperties, prop)) {
8528
8660
  reference = reference.upstreamAlias;
8529
8661
  }
8530
- if (reference.propertyAliases.has(prop)) {
8531
- root = root.parentPath;
8532
- reference = reference.propertyAliases.get(prop);
8533
- propPath = reference.name;
8534
- continue;
8535
- }
8536
8662
  if (isInvokedFunction(root.parentPath) && !isEventOrChangeHandler(prop)) {
8537
8663
  break;
8538
8664
  }
8539
8665
  root = root.parentPath;
8540
- reference = createBinding(
8541
- propPath += `_${prop.replace(/[^a-zA-Z0-9_$]/g, "_")}`,
8542
- reference.type,
8543
- reference.section,
8544
- reference,
8545
- prop
8546
- );
8666
+ reference = getOrCreatePropertyAlias(reference, prop);
8547
8667
  }
8548
8668
  addReadToExpression(root, reference);
8549
8669
  }
@@ -8618,7 +8738,8 @@ function finalizeReferences() {
8618
8738
  const intersectionsBySection = /* @__PURE__ */ new Map();
8619
8739
  for (const [expr, reads] of readsByExpression) {
8620
8740
  if (isReferencedExtra(expr)) {
8621
- const referencedBindings = expr.referencedBindings = resolveReferencedBindings(expr, reads, intersectionsBySection);
8741
+ const { referencedBindings, constantBindings } = resolveReferencedBindings(expr, reads, intersectionsBySection);
8742
+ expr.referencedBindings = referencedBindings;
8622
8743
  if (referencedBindings) {
8623
8744
  forEach(referencedBindings, (binding) => {
8624
8745
  binding.downstreamExpressions.add(expr);
@@ -8637,6 +8758,11 @@ function finalizeReferences() {
8637
8758
  }
8638
8759
  }
8639
8760
  }
8761
+ if (constantBindings) {
8762
+ forEach(constantBindings, (binding) => {
8763
+ binding.downstreamExpressions.add(expr);
8764
+ });
8765
+ }
8640
8766
  }
8641
8767
  }
8642
8768
  for (const binding of bindings) {
@@ -9028,18 +9154,32 @@ var [getReadsByExpression] = createProgramState(
9028
9154
  var [getFunctionReadsByExpression] = createProgramState(
9029
9155
  () => /* @__PURE__ */ new Map()
9030
9156
  );
9031
- function addReadToExpression(root, binding) {
9032
- const { node } = root;
9033
- const fnRoot = getFnRoot(root);
9034
- const exprRoot = getExprRoot(fnRoot || root);
9035
- const exprExtra = exprRoot.node.extra ??= {};
9157
+ function addRead(exprExtra, readExtra, binding, section) {
9036
9158
  const readsByExpression = getReadsByExpression();
9037
- const section = exprExtra.section = getOrCreateSection(exprRoot);
9038
- const read = { binding, node };
9159
+ const read = {
9160
+ binding,
9161
+ extra: readExtra
9162
+ };
9163
+ exprExtra.section = section;
9039
9164
  readsByExpression.set(
9040
9165
  exprExtra,
9041
9166
  push(readsByExpression.get(exprExtra), read)
9042
9167
  );
9168
+ return read;
9169
+ }
9170
+ function dropRead(exprExtra) {
9171
+ getReadsByExpression().delete(exprExtra);
9172
+ }
9173
+ function addReadToExpression(root, binding) {
9174
+ const { node } = root;
9175
+ const fnRoot = getFnRoot(root);
9176
+ const exprRoot = getExprRoot(fnRoot || root);
9177
+ const exprExtra = exprRoot.node.extra ??= {};
9178
+ const section = getOrCreateSection(exprRoot);
9179
+ const read = addRead(exprExtra, node.extra ??= {}, binding, section);
9180
+ if (root.parent.type === "MarkoSpreadAttribute") {
9181
+ exprExtra.spreadFrom = binding;
9182
+ }
9043
9183
  if (fnRoot) {
9044
9184
  const fnReadsByExpr = getFunctionReadsByExpression();
9045
9185
  let exprFnReads = fnReadsByExpr.get(exprExtra);
@@ -9092,21 +9232,29 @@ function getAllTagReferenceNodes(tag, referenceNodes = []) {
9092
9232
  }
9093
9233
  function getScopeAccessorLiteral(binding, encoded, includeId) {
9094
9234
  const canonicalBinding = getCanonicalBinding(binding);
9095
- if (isOptimize()) {
9235
+ if (canonicalBinding.type === 7 /* constant */) {
9236
+ return import_compiler38.types.stringLiteral(
9237
+ canonicalBinding.scopeAccessor ?? canonicalBinding.name
9238
+ );
9239
+ } else if (isOptimize()) {
9096
9240
  return encoded ? import_compiler38.types.numericLiteral(canonicalBinding.id) : import_compiler38.types.stringLiteral(decodeAccessor(canonicalBinding.id));
9097
9241
  } else if (includeId || canonicalBinding.type === 0 /* dom */) {
9098
9242
  return import_compiler38.types.stringLiteral(`${canonicalBinding.name}/${canonicalBinding.id}`);
9099
9243
  }
9100
- return import_compiler38.types.stringLiteral(canonicalBinding.name);
9244
+ return import_compiler38.types.stringLiteral(
9245
+ canonicalBinding.scopeAccessor ?? canonicalBinding.name
9246
+ );
9101
9247
  }
9102
9248
  function getScopeAccessor(binding, encoded, includeId) {
9103
9249
  const canonicalBinding = getCanonicalBinding(binding);
9104
- if (isOptimize()) {
9250
+ if (canonicalBinding.type === 7 /* constant */) {
9251
+ return canonicalBinding.scopeAccessor ?? canonicalBinding.name;
9252
+ } else if (isOptimize()) {
9105
9253
  return encoded ? canonicalBinding.id + "" : decodeAccessor(canonicalBinding.id);
9106
9254
  } else if (includeId || canonicalBinding.type === 0 /* dom */) {
9107
9255
  return `${canonicalBinding.name}/${canonicalBinding.id}`;
9108
9256
  }
9109
- return canonicalBinding.name;
9257
+ return canonicalBinding.scopeAccessor ?? canonicalBinding.name;
9110
9258
  }
9111
9259
  function getDebugScopeAccess(binding) {
9112
9260
  let root = binding;
@@ -9147,7 +9295,7 @@ function getSectionInstancesAccessorLiteral(section) {
9147
9295
  const accessor = getSectionInstancesAccessor(section);
9148
9296
  return accessor ? typeof accessor === "number" ? import_compiler38.types.numericLiteral(accessor) : import_compiler38.types.stringLiteral(accessor) : void 0;
9149
9297
  }
9150
- function getReadReplacement(node) {
9298
+ function getReadReplacement(node, signal) {
9151
9299
  const { extra } = node;
9152
9300
  if (!extra || extra.assignment) return;
9153
9301
  const { read, binding } = extra;
@@ -9156,7 +9304,9 @@ function getReadReplacement(node) {
9156
9304
  let replacement;
9157
9305
  if (read.props === void 0) {
9158
9306
  if (isOutputDOM()) {
9159
- if (readBinding.type === 0 /* dom */) {
9307
+ if (signal?.referencedBindings === readBinding && !signal.hasSideEffect) {
9308
+ replacement = getSignalValueIdentifier(signal);
9309
+ } else if (readBinding.type === 0 /* dom */) {
9160
9310
  if (!extra[kIsInvoked] && readBinding.section.domGetterBindings.has(readBinding)) {
9161
9311
  replacement = import_compiler38.types.callExpression(
9162
9312
  getBindingGetterIdentifier(readBinding),
@@ -9181,9 +9331,17 @@ function getReadReplacement(node) {
9181
9331
  } else {
9182
9332
  const props = read.props ? Array.isArray(read.props) ? read.props.slice() : [read.props] : [];
9183
9333
  let curNode = node;
9184
- let curBinding = read.binding;
9334
+ let curBinding = readBinding;
9185
9335
  let replaceMember;
9186
- replacement = isOutputDOM() ? createScopeReadExpression(read.binding, extra.section) : import_compiler38.types.identifier(read.binding.name);
9336
+ if (isOutputDOM()) {
9337
+ if (signal?.referencedBindings === readBinding && !signal.hasSideEffect) {
9338
+ replacement = getSignalValueIdentifier(signal);
9339
+ } else {
9340
+ replacement = createScopeReadExpression(readBinding, extra.section);
9341
+ }
9342
+ } else {
9343
+ replacement = import_compiler38.types.identifier(readBinding.name);
9344
+ }
9187
9345
  while (props.length && (curNode.type === "MemberExpression" || curNode.type === "OptionalMemberExpression")) {
9188
9346
  const prop = props.pop();
9189
9347
  const memberProp = getMemberExpressionPropString(curNode);
@@ -9202,7 +9360,7 @@ function getReadReplacement(node) {
9202
9360
  );
9203
9361
  }
9204
9362
  if (replaceMember) {
9205
- if (read.binding.nullable && replaceMember.object.type !== replacement.type) {
9363
+ if (readBinding.nullable && replaceMember.object.type !== replacement.type) {
9206
9364
  replaceMember.type = "OptionalMemberExpression";
9207
9365
  replaceMember.optional = true;
9208
9366
  }
@@ -9218,6 +9376,14 @@ function getReadReplacement(node) {
9218
9376
  node.name = binding.name;
9219
9377
  }
9220
9378
  }
9379
+ function hasNonConstantPropertyAlias(ref) {
9380
+ for (const alias of ref.propertyAliases.values()) {
9381
+ if (alias.type !== 7 /* constant */) {
9382
+ return true;
9383
+ }
9384
+ }
9385
+ return false;
9386
+ }
9221
9387
  function pruneBinding(bindings, binding) {
9222
9388
  let shouldPrune = !binding.downstreamExpressions.size;
9223
9389
  if (binding.hoists.size) {
@@ -9226,14 +9392,14 @@ function pruneBinding(bindings, binding) {
9226
9392
  for (const alias of binding.aliases) {
9227
9393
  if (pruneBinding(bindings, alias)) {
9228
9394
  binding.aliases.delete(alias);
9229
- } else {
9395
+ } else if (alias.type !== 7 /* constant */) {
9230
9396
  shouldPrune = false;
9231
9397
  }
9232
9398
  }
9233
9399
  for (const [key, alias] of binding.propertyAliases) {
9234
9400
  if (pruneBinding(bindings, alias)) {
9235
9401
  binding.propertyAliases.delete(key);
9236
- } else {
9402
+ } else if (alias.type !== 7 /* constant */) {
9237
9403
  shouldPrune = false;
9238
9404
  }
9239
9405
  }
@@ -9300,12 +9466,13 @@ function getRootBindings(reads) {
9300
9466
  }
9301
9467
  function resolveReferencedBindings(expr, reads, intersectionsBySection) {
9302
9468
  let referencedBindings;
9469
+ let constantBindings;
9303
9470
  if (Array.isArray(reads)) {
9304
9471
  const rootBindings = getRootBindings(reads);
9305
9472
  for (const read of reads) {
9306
9473
  let { binding } = read;
9307
- if (read.node) {
9308
- const readExtra = read.node.extra ??= {};
9474
+ const readExtra = read.extra;
9475
+ if (readExtra) {
9309
9476
  if (readExtra.assignmentTo !== binding) {
9310
9477
  readExtra.section = expr.section;
9311
9478
  ({ binding } = readExtra.read ??= resolveExpressionReference(
@@ -9314,15 +9481,22 @@ function resolveReferencedBindings(expr, reads, intersectionsBySection) {
9314
9481
  ));
9315
9482
  }
9316
9483
  }
9317
- referencedBindings = bindingUtil.add(referencedBindings, binding);
9484
+ if (binding.type === 7 /* constant */) {
9485
+ constantBindings = bindingUtil.add(constantBindings, binding);
9486
+ } else {
9487
+ referencedBindings = bindingUtil.add(referencedBindings, binding);
9488
+ }
9318
9489
  }
9319
9490
  } else if (reads) {
9320
- if (reads.node) {
9321
- const readExtra = reads.node.extra ??= {};
9322
- readExtra.section = expr.section;
9323
- readExtra.read = createRead(reads.binding, void 0);
9491
+ if (reads.extra) {
9492
+ reads.extra.section = expr.section;
9493
+ reads.extra.read = createRead(reads.binding, void 0);
9494
+ }
9495
+ if (reads.binding.type === 7 /* constant */) {
9496
+ constantBindings = reads.binding;
9497
+ } else {
9498
+ referencedBindings = reads.binding;
9324
9499
  }
9325
- referencedBindings = reads.binding;
9326
9500
  }
9327
9501
  if (Array.isArray(referencedBindings)) {
9328
9502
  const intersections = intersectionsBySection.get(expr.section) || [];
@@ -9340,7 +9514,28 @@ function resolveReferencedBindings(expr, reads, intersectionsBySection) {
9340
9514
  );
9341
9515
  }
9342
9516
  }
9343
- return referencedBindings;
9517
+ if (referencedBindings && constantBindings) {
9518
+ const intersections = intersectionsBySection.get(expr.section) || [];
9519
+ const combined = concat(
9520
+ referencedBindings,
9521
+ constantBindings
9522
+ );
9523
+ const intersection = findSorted(
9524
+ compareIntersections,
9525
+ intersections,
9526
+ combined
9527
+ );
9528
+ if (!intersection) {
9529
+ intersectionsBySection.set(
9530
+ expr.section,
9531
+ addSorted(compareIntersections, intersections, combined)
9532
+ );
9533
+ }
9534
+ }
9535
+ return {
9536
+ referencedBindings,
9537
+ constantBindings
9538
+ };
9344
9539
  }
9345
9540
  function resolveExpressionReference(rootBindings, readBinding) {
9346
9541
  const upstreamRoot = readBinding.upstreamAlias && findClosestReference(readBinding.upstreamAlias, rootBindings);
@@ -11470,7 +11665,9 @@ var placeholder_default = {
11470
11665
  value,
11471
11666
  getScopeAccessorLiteral(nodeBinding)
11472
11667
  )
11473
- )
11668
+ ),
11669
+ void 0,
11670
+ true
11474
11671
  );
11475
11672
  }
11476
11673
  }