marko 6.0.156 → 6.0.157

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.
@@ -1,6 +1,8 @@
1
+ import { type Scope } from "./types";
1
2
  export declare function _el_read_error(): void;
2
3
  export declare function _hoist_read_error(): void;
3
4
  export declare function _assert_hoist(value: unknown): void;
5
+ export declare function _assert_init(scope: Scope, accessor: string): any;
4
6
  export declare function assertExclusiveAttrs(attrs: Record<string, unknown> | undefined, onError?: typeof throwErr): void;
5
7
  export declare function assertValidTagName(tagName: string): void;
6
8
  declare function throwErr(msg: string): void;
package/dist/debug/dom.js CHANGED
@@ -23,6 +23,7 @@ __export(dom_exports, {
23
23
  $signal: () => $signal,
24
24
  $signalReset: () => $signalReset,
25
25
  _assert_hoist: () => _assert_hoist,
26
+ _assert_init: () => _assert_init,
26
27
  _attr: () => _attr,
27
28
  _attr_class: () => _attr_class,
28
29
  _attr_class_item: () => _attr_class_item,
@@ -159,6 +160,21 @@ function _assert_hoist(value) {
159
160
  );
160
161
  }
161
162
  }
163
+ function _assert_init(scope, accessor) {
164
+ if (scope["#Creating" /* Creating */] || !(accessor in scope)) {
165
+ try {
166
+ __UNINITIALIZED__;
167
+ const __UNINITIALIZED__ = 1;
168
+ } catch (err) {
169
+ err.message = err.message.replaceAll("__UNINITIALIZED__", accessor);
170
+ throw err;
171
+ }
172
+ throw new ReferenceError(
173
+ `Cannot access "${accessor}" before initialization.`
174
+ );
175
+ }
176
+ return scope[accessor];
177
+ }
162
178
  function assertExclusiveAttrs(attrs, onError = throwErr) {
163
179
  if (attrs) {
164
180
  let exclusiveAttrs;
@@ -619,11 +635,6 @@ function _closure(...closureSignals) {
619
635
  function _closure_get(valueAccessor, fn, getOwnerScope, resumeId) {
620
636
  if (false) valueAccessor = decodeAccessor(valueAccessor);
621
637
  const closureSignal = ((scope) => {
622
- if (true) {
623
- if (!(valueAccessor in (getOwnerScope ? getOwnerScope(scope) : scope["_" /* Owner */]))) {
624
- throwUninitialized(valueAccessor);
625
- }
626
- }
627
638
  scope[closureSignal.___signalIndexAccessor] = closureSignal.___index;
628
639
  fn(scope);
629
640
  subscribeToScopeSet(
@@ -708,16 +719,6 @@ function _hoist(...path) {
708
719
  function _hoist_resume(id, ...path) {
709
720
  return _resume(id, _hoist(...path));
710
721
  }
711
- function throwUninitialized(name) {
712
- try {
713
- __UNINITIALIZED__;
714
- let __UNINITIALIZED__;
715
- } catch (err) {
716
- err.message = err.message.replaceAll("__UNINITIALIZED__", name);
717
- throw err;
718
- }
719
- throw new ReferenceError(`Cannot access '${name}' before initialization`);
720
- }
721
722
 
722
723
  // src/dom/walker.ts
723
724
  var walker = /* @__PURE__ */ document.createTreeWalker(document);
@@ -44,6 +44,21 @@ function _assert_hoist(value) {
44
44
  );
45
45
  }
46
46
  }
47
+ function _assert_init(scope, accessor) {
48
+ if (scope["#Creating" /* Creating */] || !(accessor in scope)) {
49
+ try {
50
+ __UNINITIALIZED__;
51
+ const __UNINITIALIZED__ = 1;
52
+ } catch (err) {
53
+ err.message = err.message.replaceAll("__UNINITIALIZED__", accessor);
54
+ throw err;
55
+ }
56
+ throw new ReferenceError(
57
+ `Cannot access "${accessor}" before initialization.`
58
+ );
59
+ }
60
+ return scope[accessor];
61
+ }
47
62
  function assertExclusiveAttrs(attrs, onError = throwErr) {
48
63
  if (attrs) {
49
64
  let exclusiveAttrs;
@@ -504,11 +519,6 @@ function _closure(...closureSignals) {
504
519
  function _closure_get(valueAccessor, fn, getOwnerScope, resumeId) {
505
520
  if (false) valueAccessor = decodeAccessor(valueAccessor);
506
521
  const closureSignal = ((scope) => {
507
- if (true) {
508
- if (!(valueAccessor in (getOwnerScope ? getOwnerScope(scope) : scope["_" /* Owner */]))) {
509
- throwUninitialized(valueAccessor);
510
- }
511
- }
512
522
  scope[closureSignal.___signalIndexAccessor] = closureSignal.___index;
513
523
  fn(scope);
514
524
  subscribeToScopeSet(
@@ -593,16 +603,6 @@ function _hoist(...path) {
593
603
  function _hoist_resume(id, ...path) {
594
604
  return _resume(id, _hoist(...path));
595
605
  }
596
- function throwUninitialized(name) {
597
- try {
598
- __UNINITIALIZED__;
599
- let __UNINITIALIZED__;
600
- } catch (err) {
601
- err.message = err.message.replaceAll("__UNINITIALIZED__", name);
602
- throw err;
603
- }
604
- throw new ReferenceError(`Cannot access '${name}' before initialization`);
605
- }
606
606
 
607
607
  // src/dom/walker.ts
608
608
  var walker = /* @__PURE__ */ document.createTreeWalker(document);
@@ -2592,6 +2592,7 @@ export {
2592
2592
  $signal,
2593
2593
  $signalReset,
2594
2594
  _assert_hoist,
2595
+ _assert_init,
2595
2596
  _attr,
2596
2597
  _attr_class,
2597
2598
  _attr_class_item,
package/dist/dom.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { attrTag, attrTags } from "./common/attr-tag";
2
- export { _assert_hoist } from "./common/errors";
2
+ export { _assert_hoist, _assert_init } from "./common/errors";
3
3
  export { forIn, forOf, forTo, forUntil } from "./common/for";
4
4
  export { _call } from "./common/helpers";
5
5
  export { $signal, $signalReset } from "./dom/abort-signal";
package/dist/dom.js CHANGED
@@ -20,6 +20,7 @@ __export(dom_exports, {
20
20
  $signal: () => $signal,
21
21
  $signalReset: () => $signalReset,
22
22
  _assert_hoist: () => _assert_hoist,
23
+ _assert_init: () => _assert_init,
23
24
  _attr: () => _attr,
24
25
  _attr_class: () => _attr_class,
25
26
  _attr_class_item: () => _attr_class_item,
@@ -125,6 +126,9 @@ function* attrTagIterator() {
125
126
  // src/common/errors.ts
126
127
  function _assert_hoist(value) {
127
128
  }
129
+ function _assert_init(scope, accessor) {
130
+ return scope[accessor];
131
+ }
128
132
 
129
133
  // src/common/for.ts
130
134
  function forIn(obj, cb) {
package/dist/dom.mjs CHANGED
@@ -13,6 +13,9 @@ function* attrTagIterator() {
13
13
  // src/common/errors.ts
14
14
  function _assert_hoist(value) {
15
15
  }
16
+ function _assert_init(scope, accessor) {
17
+ return scope[accessor];
18
+ }
16
19
 
17
20
  // src/common/for.ts
18
21
  function forIn(obj, cb) {
@@ -1575,6 +1578,7 @@ export {
1575
1578
  $signal,
1576
1579
  $signalReset,
1577
1580
  _assert_hoist,
1581
+ _assert_init,
1578
1582
  _attr,
1579
1583
  _attr_class,
1580
1584
  _attr_class_item,
@@ -34,7 +34,7 @@ export declare function getScopeById(scopeId: number | undefined): PartialScope
34
34
  export declare function _set_serialize_reason(reason: undefined | 0 | 1): void;
35
35
  export declare function _scope_reason(): 0 | 1 | undefined;
36
36
  export declare function _serialize_if(condition: undefined | 1 | Record<string, 1>, key: string): 1 | undefined;
37
- export declare function _serialize_guard(condition: undefined | 1 | Record<string, 1>, key: string): 1 | 0;
37
+ export declare function _serialize_guard(condition: undefined | 1 | Record<string, 1>, key: string): 0 | 1;
38
38
  export declare function _el_resume(scopeId: number, accessor: Accessor, shouldResume?: 0 | 1): string;
39
39
  export declare function _sep(shouldResume: 0 | 1): "" | "<!>";
40
40
  export declare function _el(scopeId: number, id: string): () => void;
@@ -133,33 +133,33 @@ var AccessorPrefix = /* @__PURE__ */ ((AccessorPrefix4) => {
133
133
  AccessorPrefix4["TagVariableChange"] = "TagVariableChange:";
134
134
  return AccessorPrefix4;
135
135
  })(AccessorPrefix || {});
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;
136
+ var AccessorProp = /* @__PURE__ */ ((AccessorProp6) => {
137
+ AccessorProp6["Global"] = "$global";
138
+ AccessorProp6["Owner"] = "_";
139
+ AccessorProp6["AbortControllers"] = "#AbortControllers";
140
+ AccessorProp6["AbortScopes"] = "#AbortScopes";
141
+ AccessorProp6["AwaitCounter"] = "#AwaitCounter";
142
+ AccessorProp6["BranchAccessor"] = "#BranchAccessor";
143
+ AccessorProp6["BranchScopes"] = "#BranchScopes";
144
+ AccessorProp6["CatchContent"] = "#CatchContent";
145
+ AccessorProp6["ClosestBranch"] = "#ClosestBranch";
146
+ AccessorProp6["ClosestBranchId"] = "#ClosestBranchId";
147
+ AccessorProp6["Creating"] = "#Creating";
148
+ AccessorProp6["Destroyed"] = "#Destroyed";
149
+ AccessorProp6["DetachedAwait"] = "#DetachedAwait";
150
+ AccessorProp6["EndNode"] = "#EndNode";
151
+ AccessorProp6["Id"] = "#Id";
152
+ AccessorProp6["LoopKey"] = "#LoopKey";
153
+ AccessorProp6["ParentBranch"] = "#ParentBranch";
154
+ AccessorProp6["PendingEffects"] = "#PendingEffects";
155
+ AccessorProp6["PendingRenders"] = "#PendingRenders";
156
+ AccessorProp6["PlaceholderBranch"] = "#PlaceholderBranch";
157
+ AccessorProp6["PlaceholderContent"] = "#PlaceholderContent";
158
+ AccessorProp6["Renderer"] = "#Renderer";
159
+ AccessorProp6["StartNode"] = "#StartNode";
160
+ AccessorProp6["TagVariable"] = "#TagVariable";
161
+ AccessorProp6["TagVariableChange"] = "#TagVariableChange";
162
+ return AccessorProp6;
163
163
  })(AccessorProp || {});
164
164
 
165
165
  // src/translator/util/evaluate.ts
@@ -253,6 +253,7 @@ function isNullableExpr(expr) {
253
253
  // src/translator/util/references.ts
254
254
  var import_compiler38 = require("@marko/compiler");
255
255
  var import_babel_utils26 = require("@marko/compiler/babel-utils");
256
+ var import_config = require("@marko/compiler/config");
256
257
 
257
258
  // src/common/helpers.ts
258
259
  function classValue(classValue2) {
@@ -1298,33 +1299,33 @@ var AccessorPrefix2 = /* @__PURE__ */ ((AccessorPrefix4) => {
1298
1299
  AccessorPrefix4["TagVariableChange"] = "M";
1299
1300
  return AccessorPrefix4;
1300
1301
  })(AccessorPrefix2 || {});
1301
- var AccessorProp2 = /* @__PURE__ */ ((AccessorProp5) => {
1302
- AccessorProp5["Global"] = "$";
1303
- AccessorProp5["Owner"] = "_";
1304
- AccessorProp5["AbortControllers"] = "A";
1305
- AccessorProp5["AbortScopes"] = "B";
1306
- AccessorProp5["AwaitCounter"] = "O";
1307
- AccessorProp5["BranchAccessor"] = "C";
1308
- AccessorProp5["BranchScopes"] = "D";
1309
- AccessorProp5["CatchContent"] = "E";
1310
- AccessorProp5["ClosestBranch"] = "F";
1311
- AccessorProp5["ClosestBranchId"] = "G";
1312
- AccessorProp5["Creating"] = "H";
1313
- AccessorProp5["Destroyed"] = "I";
1314
- AccessorProp5["DetachedAwait"] = "V";
1315
- AccessorProp5["EndNode"] = "K";
1316
- AccessorProp5["Id"] = "L";
1317
- AccessorProp5["LoopKey"] = "M";
1318
- AccessorProp5["ParentBranch"] = "N";
1319
- AccessorProp5["PendingEffects"] = "J";
1320
- AccessorProp5["PendingRenders"] = "W";
1321
- AccessorProp5["PlaceholderBranch"] = "P";
1322
- AccessorProp5["PlaceholderContent"] = "Q";
1323
- AccessorProp5["Renderer"] = "R";
1324
- AccessorProp5["StartNode"] = "S";
1325
- AccessorProp5["TagVariable"] = "T";
1326
- AccessorProp5["TagVariableChange"] = "U";
1327
- return AccessorProp5;
1302
+ var AccessorProp2 = /* @__PURE__ */ ((AccessorProp6) => {
1303
+ AccessorProp6["Global"] = "$";
1304
+ AccessorProp6["Owner"] = "_";
1305
+ AccessorProp6["AbortControllers"] = "A";
1306
+ AccessorProp6["AbortScopes"] = "B";
1307
+ AccessorProp6["AwaitCounter"] = "O";
1308
+ AccessorProp6["BranchAccessor"] = "C";
1309
+ AccessorProp6["BranchScopes"] = "D";
1310
+ AccessorProp6["CatchContent"] = "E";
1311
+ AccessorProp6["ClosestBranch"] = "F";
1312
+ AccessorProp6["ClosestBranchId"] = "G";
1313
+ AccessorProp6["Creating"] = "H";
1314
+ AccessorProp6["Destroyed"] = "I";
1315
+ AccessorProp6["DetachedAwait"] = "V";
1316
+ AccessorProp6["EndNode"] = "K";
1317
+ AccessorProp6["Id"] = "L";
1318
+ AccessorProp6["LoopKey"] = "M";
1319
+ AccessorProp6["ParentBranch"] = "N";
1320
+ AccessorProp6["PendingEffects"] = "J";
1321
+ AccessorProp6["PendingRenders"] = "W";
1322
+ AccessorProp6["PlaceholderBranch"] = "P";
1323
+ AccessorProp6["PlaceholderContent"] = "Q";
1324
+ AccessorProp6["Renderer"] = "R";
1325
+ AccessorProp6["StartNode"] = "S";
1326
+ AccessorProp6["TagVariable"] = "T";
1327
+ AccessorProp6["TagVariableChange"] = "U";
1328
+ return AccessorProp6;
1328
1329
  })(AccessorProp2 || {});
1329
1330
 
1330
1331
  // src/translator/util/marko-config.ts
@@ -2169,87 +2170,6 @@ function isStaticRoot(path7) {
2169
2170
  }
2170
2171
  }
2171
2172
 
2172
- // src/translator/util/for-each-identifier.ts
2173
- function forEachIdentifier(node, cb) {
2174
- switch (node.type) {
2175
- case "ObjectPattern":
2176
- for (const prop of node.properties) {
2177
- switch (prop.type) {
2178
- case "ObjectProperty":
2179
- if (prop.value.type === "AssignmentPattern") {
2180
- forEachIdentifier(prop.value.left, cb);
2181
- } else {
2182
- forEachIdentifier(prop.value, cb);
2183
- }
2184
- break;
2185
- case "RestElement":
2186
- forEachIdentifier(prop.argument, cb);
2187
- break;
2188
- }
2189
- }
2190
- break;
2191
- case "ArrayPattern":
2192
- for (const el of node.elements) {
2193
- if (el != null) {
2194
- switch (el.type) {
2195
- case "RestElement":
2196
- forEachIdentifier(el.argument, cb);
2197
- break;
2198
- case "AssignmentPattern":
2199
- forEachIdentifier(el.left, cb);
2200
- break;
2201
- default:
2202
- forEachIdentifier(el, cb);
2203
- break;
2204
- }
2205
- }
2206
- }
2207
- break;
2208
- case "Identifier":
2209
- cb(node);
2210
- break;
2211
- }
2212
- }
2213
- function forEachIdentifierPath(nodePath, cb) {
2214
- if (nodePath.isIdentifier()) {
2215
- cb(nodePath);
2216
- } else if (nodePath.isObjectPattern()) {
2217
- for (const prop of nodePath.get("properties")) {
2218
- if (prop.isObjectProperty()) {
2219
- const value = prop.get("value");
2220
- if (value.isAssignmentPattern()) {
2221
- forEachIdentifierPath(value.get("left"), cb);
2222
- } else {
2223
- forEachIdentifierPath(value, cb);
2224
- }
2225
- } else if (prop.isRestElement()) {
2226
- forEachIdentifierPath(prop.get("argument"), cb);
2227
- }
2228
- }
2229
- } else if (nodePath.isArrayPattern()) {
2230
- for (const el of nodePath.get("elements")) {
2231
- if (el) {
2232
- if (el.isRestElement()) {
2233
- forEachIdentifierPath(el.get("argument"), cb);
2234
- } else if (el.isAssignmentPattern()) {
2235
- forEachIdentifierPath(el.get("left"), cb);
2236
- } else {
2237
- forEachIdentifierPath(el, cb);
2238
- }
2239
- }
2240
- }
2241
- }
2242
- }
2243
-
2244
- // src/translator/util/is-event-or-change-handler.ts
2245
- function isEventOrChangeHandler(prop) {
2246
- return /^on[-A-Z][a-zA-Z0-9_$]|[a-zA-Z_$][a-zA-Z0-9_$]*Change$/.test(prop);
2247
- }
2248
-
2249
- // src/translator/util/known-tag.ts
2250
- var import_compiler37 = require("@marko/compiler");
2251
- var import_babel_utils25 = require("@marko/compiler/babel-utils");
2252
-
2253
2173
  // src/translator/visitors/program/index.ts
2254
2174
  var import_compiler27 = require("@marko/compiler");
2255
2175
  var import_babel_utils17 = require("@marko/compiler/babel-utils");
@@ -2619,8 +2539,8 @@ function getHTMLRuntime() {
2619
2539
  };
2620
2540
  }
2621
2541
  function getRuntimePath(output) {
2622
- const { optimize } = getMarkoOpts();
2623
- return `${runtime_info_default.name}/${optimize ? "" : "debug/"}${output === "html" ? "html" : "dom"}`;
2542
+ const { optimize: optimize2 } = getMarkoOpts();
2543
+ return `${runtime_info_default.name}/${optimize2 ? "" : "debug/"}${output === "html" ? "html" : "dom"}`;
2624
2544
  }
2625
2545
  function filterArguments(args) {
2626
2546
  const filteredArgs = [];
@@ -3305,6 +3225,78 @@ var return_default = {
3305
3225
  ]
3306
3226
  };
3307
3227
 
3228
+ // src/translator/util/for-each-identifier.ts
3229
+ function forEachIdentifier(node, cb) {
3230
+ switch (node.type) {
3231
+ case "ObjectPattern":
3232
+ for (const prop of node.properties) {
3233
+ switch (prop.type) {
3234
+ case "ObjectProperty":
3235
+ if (prop.value.type === "AssignmentPattern") {
3236
+ forEachIdentifier(prop.value.left, cb);
3237
+ } else {
3238
+ forEachIdentifier(prop.value, cb);
3239
+ }
3240
+ break;
3241
+ case "RestElement":
3242
+ forEachIdentifier(prop.argument, cb);
3243
+ break;
3244
+ }
3245
+ }
3246
+ break;
3247
+ case "ArrayPattern":
3248
+ for (const el of node.elements) {
3249
+ if (el != null) {
3250
+ switch (el.type) {
3251
+ case "RestElement":
3252
+ forEachIdentifier(el.argument, cb);
3253
+ break;
3254
+ case "AssignmentPattern":
3255
+ forEachIdentifier(el.left, cb);
3256
+ break;
3257
+ default:
3258
+ forEachIdentifier(el, cb);
3259
+ break;
3260
+ }
3261
+ }
3262
+ }
3263
+ break;
3264
+ case "Identifier":
3265
+ cb(node);
3266
+ break;
3267
+ }
3268
+ }
3269
+ function forEachIdentifierPath(nodePath, cb) {
3270
+ if (nodePath.isIdentifier()) {
3271
+ cb(nodePath);
3272
+ } else if (nodePath.isObjectPattern()) {
3273
+ for (const prop of nodePath.get("properties")) {
3274
+ if (prop.isObjectProperty()) {
3275
+ const value = prop.get("value");
3276
+ if (value.isAssignmentPattern()) {
3277
+ forEachIdentifierPath(value.get("left"), cb);
3278
+ } else {
3279
+ forEachIdentifierPath(value, cb);
3280
+ }
3281
+ } else if (prop.isRestElement()) {
3282
+ forEachIdentifierPath(prop.get("argument"), cb);
3283
+ }
3284
+ }
3285
+ } else if (nodePath.isArrayPattern()) {
3286
+ for (const el of nodePath.get("elements")) {
3287
+ if (el) {
3288
+ if (el.isRestElement()) {
3289
+ forEachIdentifierPath(el.get("argument"), cb);
3290
+ } else if (el.isAssignmentPattern()) {
3291
+ forEachIdentifierPath(el.get("left"), cb);
3292
+ } else {
3293
+ forEachIdentifierPath(el, cb);
3294
+ }
3295
+ }
3296
+ }
3297
+ }
3298
+ }
3299
+
3308
3300
  // src/translator/util/get-defined-binding-expression.ts
3309
3301
  var import_compiler18 = require("@marko/compiler");
3310
3302
  function getDeclaredBindingExpression(binding) {
@@ -3344,7 +3336,7 @@ function createScopeReadExpression(reference, section = reference.section) {
3344
3336
  );
3345
3337
  if (section === reference.section && reference.type !== 0 /* dom */) {
3346
3338
  const exprExtra = expr.extra ??= {};
3347
- exprExtra.read = createRead(reference, void 0, void 0);
3339
+ exprExtra.read = createRead(reference, void 0);
3348
3340
  exprExtra.section = section;
3349
3341
  }
3350
3342
  return expr;
@@ -4997,31 +4989,44 @@ function normalizeTag(tag) {
4997
4989
  }
4998
4990
  for (let i = 0; i < attributes.length; i++) {
4999
4991
  const attr = attributes[i];
5000
- if (import_compiler26.types.isMarkoAttribute(attr) && attr.bound) {
5001
- attr.bound = false;
5002
- attributes.splice(++i, 0, getChangeHandler(tag, attr));
4992
+ if (import_compiler26.types.isMarkoAttribute(attr)) {
4993
+ if (attr.bound) {
4994
+ attributes.splice(++i, 0, getChangeHandler(tag, attr));
4995
+ attr.bound = false;
4996
+ } else if (attr.modifier != null) {
4997
+ attr.name += ":" + attr.modifier;
4998
+ }
4999
+ attr.modifier = null;
5003
5000
  }
5004
5001
  }
5005
5002
  }
5006
5003
  function getChangeHandler(tag, attr) {
5007
5004
  const attrName = attr.name;
5008
5005
  const changeAttrName = attrName + "Change";
5006
+ const modifier = attr.modifier == null ? void 0 : withPreviousLocation(import_compiler26.types.identifier(attr.modifier), attr);
5009
5007
  if (import_compiler26.types.isIdentifier(attr.value)) {
5010
5008
  const binding = tag.scope.getBinding(attr.value.name);
5011
5009
  if (!binding)
5012
5010
  return import_compiler26.types.markoAttribute(
5013
5011
  changeAttrName,
5014
- buildChangeHandlerFunction(attr.value)
5012
+ buildChangeHandlerFunction(attr.value, modifier)
5015
5013
  );
5016
5014
  const existingChangedAttr = BINDING_CHANGE_HANDLER.get(binding.identifier);
5017
5015
  if (!existingChangedAttr) {
5018
5016
  const bindingIdentifierPath = binding.path.getOuterBindingIdentifierPaths()[binding.identifier.name];
5019
- const changeAttrExpr = bindingIdentifierPath ? bindingIdentifierPath.parentPath === binding.path ? buildChangeHandlerFunction(attr.value) : bindingIdentifierPath.parentPath.isObjectProperty() ? getChangeHandlerFromObjectPattern(
5017
+ let changeAttrExpr = bindingIdentifierPath ? bindingIdentifierPath.parentPath === binding.path ? buildChangeHandlerFunction(attr.value, modifier) : bindingIdentifierPath.parentPath.isObjectProperty() ? getChangeHandlerFromObjectPattern(
5020
5018
  bindingIdentifierPath.parentPath
5021
5019
  ) : void 0 : void 0;
5022
5020
  if (!changeAttrExpr) {
5023
5021
  throw tag.hub.buildError(attr.value, "Unable to bind to value.");
5024
5022
  }
5023
+ if (modifier && import_compiler26.types.isIdentifier(changeAttrExpr)) {
5024
+ changeAttrExpr = import_compiler26.types.logicalExpression(
5025
+ "&&",
5026
+ changeAttrExpr,
5027
+ buildChangeHandlerFunction(attr.value, modifier)
5028
+ );
5029
+ }
5025
5030
  const changeHandlerAttr = import_compiler26.types.markoAttribute(
5026
5031
  changeAttrName,
5027
5032
  changeAttrExpr
@@ -5073,10 +5078,26 @@ function getChangeHandler(tag, attr) {
5073
5078
  import_compiler26.types.stringLiteral("Change")
5074
5079
  );
5075
5080
  const computed = memberProp.type !== "Identifier";
5076
- return import_compiler26.types.markoAttribute(
5077
- changeAttrName,
5078
- attr.value.optional ? import_compiler26.types.optionalMemberExpression(memberObj, memberProp, computed, true) : import_compiler26.types.memberExpression(memberObj, memberProp, computed)
5079
- );
5081
+ let changeAttrExpr = attr.value.optional ? import_compiler26.types.optionalMemberExpression(memberObj, memberProp, computed, true) : import_compiler26.types.memberExpression(memberObj, memberProp, computed);
5082
+ if (modifier) {
5083
+ const newValueId = generateUid("next");
5084
+ changeAttrExpr = import_compiler26.types.logicalExpression(
5085
+ "&&",
5086
+ changeAttrExpr,
5087
+ import_compiler26.types.arrowFunctionExpression(
5088
+ [import_compiler26.types.identifier(newValueId)],
5089
+ import_compiler26.types.blockStatement([
5090
+ import_compiler26.types.expressionStatement(
5091
+ import_compiler26.types.callExpression(
5092
+ import_compiler26.types.memberExpression(memberObj, memberProp, computed),
5093
+ [import_compiler26.types.callExpression(modifier, [import_compiler26.types.identifier(newValueId)])]
5094
+ )
5095
+ )
5096
+ ])
5097
+ )
5098
+ );
5099
+ }
5100
+ return import_compiler26.types.markoAttribute(changeAttrName, changeAttrExpr);
5080
5101
  }
5081
5102
  }
5082
5103
  throw tag.hub.buildError(
@@ -5084,8 +5105,12 @@ function getChangeHandler(tag, attr) {
5084
5105
  "Attributes may only be bound to identifiers or member expressions"
5085
5106
  );
5086
5107
  }
5087
- function buildChangeHandlerFunction(id) {
5108
+ function buildChangeHandlerFunction(id, modifier) {
5088
5109
  const newId = "_new_" + id.name;
5110
+ let newValue = withPreviousLocation(import_compiler26.types.identifier(newId), id);
5111
+ if (modifier) {
5112
+ newValue = import_compiler26.types.callExpression(modifier, [newValue]);
5113
+ }
5089
5114
  return import_compiler26.types.arrowFunctionExpression(
5090
5115
  [withPreviousLocation(import_compiler26.types.identifier(newId), id)],
5091
5116
  import_compiler26.types.blockStatement([
@@ -5093,7 +5118,7 @@ function buildChangeHandlerFunction(id) {
5093
5118
  import_compiler26.types.assignmentExpression(
5094
5119
  "=",
5095
5120
  withPreviousLocation(import_compiler26.types.identifier(id.name), id),
5096
- withPreviousLocation(import_compiler26.types.identifier(newId), id)
5121
+ newValue
5097
5122
  )
5098
5123
  )
5099
5124
  ])
@@ -5326,6 +5351,15 @@ function resolveRelativeToEntry(entryFile, file, req) {
5326
5351
  );
5327
5352
  }
5328
5353
 
5354
+ // src/translator/util/is-event-or-change-handler.ts
5355
+ function isEventOrChangeHandler(prop) {
5356
+ return /^on[-A-Z][a-zA-Z0-9_$]|[a-zA-Z_$][a-zA-Z0-9_$]*Change$/.test(prop);
5357
+ }
5358
+
5359
+ // src/translator/util/known-tag.ts
5360
+ var import_compiler37 = require("@marko/compiler");
5361
+ var import_babel_utils25 = require("@marko/compiler/babel-utils");
5362
+
5329
5363
  // src/translator/util/nested-attribute-tags.ts
5330
5364
  var import_compiler28 = require("@marko/compiler");
5331
5365
  var import_babel_utils18 = require("@marko/compiler/babel-utils");
@@ -8701,9 +8735,30 @@ function trackParamsReferences(body, type) {
8701
8735
  return paramsBinding;
8702
8736
  }
8703
8737
  }
8738
+ function getMarkoRootAsTag(path7) {
8739
+ const tag = path7.isMarkoTag() ? path7 : getMarkoRoot(path7)?.parentPath;
8740
+ if (tag?.isMarkoTag()) {
8741
+ return tag;
8742
+ }
8743
+ }
8744
+ function isReferenceInOwnBody(bindingPath, reference) {
8745
+ const tag = getMarkoRootAsTag(bindingPath);
8746
+ if (!tag) {
8747
+ return false;
8748
+ }
8749
+ const body = tag.get("body");
8750
+ let cur = reference;
8751
+ while (cur) {
8752
+ if (cur === body) {
8753
+ return true;
8754
+ }
8755
+ cur = cur.parentPath;
8756
+ }
8757
+ return false;
8758
+ }
8704
8759
  function isReferenceHoisted(bindingPath, reference) {
8705
- const tag = bindingPath.isMarkoTag() ? bindingPath : getMarkoRoot(bindingPath)?.parentPath;
8706
- if (!tag?.isMarkoTag()) {
8760
+ const tag = getMarkoRootAsTag(bindingPath);
8761
+ if (!tag) {
8707
8762
  return false;
8708
8763
  }
8709
8764
  const body = tag.parentPath;
@@ -9456,7 +9511,7 @@ var [getFunctionReadsByExpression] = createProgramState(
9456
9511
  );
9457
9512
  function addRead(exprExtra, extra, binding, section, getter) {
9458
9513
  const readsByExpression = getReadsByExpression();
9459
- const read = { binding, extra, getter };
9514
+ const read = { binding, extra, getter, ownVar: false };
9460
9515
  binding.reads.add(exprExtra);
9461
9516
  exprExtra.section = section;
9462
9517
  readsByExpression.set(
@@ -9501,6 +9556,10 @@ function addReadToExpression(root, binding, getter) {
9501
9556
  section,
9502
9557
  getter
9503
9558
  );
9559
+ if (!getter && binding.type === 5 /* derived */) {
9560
+ const babelBinding = root.scope.getBinding(binding.name);
9561
+ read.ownVar = !!babelBinding && babelBinding.kind !== "param" && isReferenceInOwnBody(babelBinding.path, root);
9562
+ }
9504
9563
  if (root.parent.type === "MarkoSpreadAttribute") {
9505
9564
  exprExtra.spreadFrom = binding;
9506
9565
  }
@@ -9636,6 +9695,12 @@ function getReadReplacement(node, signal) {
9636
9695
  [getScopeExpression(extra.section, readBinding.section)]
9637
9696
  );
9638
9697
  }
9698
+ } else if (!import_config.optimize && read.ownVar) {
9699
+ replacement = callRuntime(
9700
+ "_assert_init",
9701
+ extra.section ? getScopeExpression(extra.section, readBinding.section) : scopeIdentifier,
9702
+ getScopeAccessorLiteral(readBinding)
9703
+ );
9639
9704
  } else {
9640
9705
  replacement = createScopeReadExpression(readBinding, extra.section);
9641
9706
  }
@@ -9847,7 +9912,7 @@ function resolveReferencedBindings(expr, reads, intersectionsBySection) {
9847
9912
  const { extra, getter } = read;
9848
9913
  if (getter) {
9849
9914
  extra.section = expr.section;
9850
- extra.read = createRead(binding, void 0, getter);
9915
+ extra.read = createGetterRead(binding, void 0, getter);
9851
9916
  addBindingGetter(binding, getter);
9852
9917
  if (getter.hoisted) {
9853
9918
  binding.hoists = sectionUtil.add(binding.hoists, getter.hoisted);
@@ -9870,20 +9935,23 @@ function resolveReferencedBindings(expr, reads, intersectionsBySection) {
9870
9935
  allBindings = bindingUtil.add(allBindings, binding);
9871
9936
  }
9872
9937
  } else if (reads) {
9873
- const { binding, extra, getter } = reads;
9938
+ const { binding, extra, getter, ownVar } = reads;
9874
9939
  if (getter) {
9940
+ extra.read = createGetterRead(binding, void 0, getter);
9875
9941
  addBindingGetter(binding, getter);
9876
9942
  if (getter.hoisted) {
9877
9943
  binding.hoists = sectionUtil.add(binding.hoists, getter.hoisted);
9878
9944
  hoistedBindings = bindingUtil.add(hoistedBindings, binding);
9879
9945
  }
9880
- } else if (binding.type === 6 /* constant */) {
9881
- constantBindings = binding;
9882
- } else if (binding.type !== 0 /* dom */) {
9883
- referencedBindings = binding;
9946
+ } else {
9947
+ extra.read = createRead(binding, void 0, ownVar);
9948
+ if (binding.type === 6 /* constant */) {
9949
+ constantBindings = binding;
9950
+ } else if (binding.type !== 0 /* dom */) {
9951
+ referencedBindings = binding;
9952
+ }
9884
9953
  }
9885
9954
  extra.section = expr.section;
9886
- extra.read = createRead(binding, void 0, getter);
9887
9955
  allBindings = binding;
9888
9956
  }
9889
9957
  if (Array.isArray(referencedBindings)) {
@@ -9930,7 +9998,7 @@ function resolveReferencedBindings(expr, reads, intersectionsBySection) {
9930
9998
  function resolveExpressionReference(rootBindings, readBinding) {
9931
9999
  const upstreamRoot = readBinding.upstreamAlias && findClosestReference(readBinding.upstreamAlias, rootBindings);
9932
10000
  if (!upstreamRoot) {
9933
- return createRead(readBinding, void 0, void 0);
10001
+ return createRead(readBinding, void 0);
9934
10002
  }
9935
10003
  let curBinding = readBinding;
9936
10004
  let props;
@@ -9943,15 +10011,18 @@ function resolveExpressionReference(rootBindings, readBinding) {
9943
10011
  if (Array.isArray(props)) {
9944
10012
  props.reverse();
9945
10013
  }
9946
- return createRead(upstreamRoot, props, void 0);
10014
+ return createRead(upstreamRoot, props);
9947
10015
  }
9948
10016
  function isSupersetSources(a, b) {
9949
10017
  if (!b.sources) return true;
9950
10018
  if (!a.sources) return false;
9951
10019
  return bindingUtil.isSuperset(a.sources.state, b.sources.state) && bindingUtil.isSuperset(a.sources.param, b.sources.param);
9952
10020
  }
9953
- function createRead(binding, props, getter) {
9954
- return { binding, props, getter };
10021
+ function createRead(binding, props, ownVar = false) {
10022
+ return { binding, props, ownVar, getter: void 0 };
10023
+ }
10024
+ function createGetterRead(binding, props, getter) {
10025
+ return { binding, props, ownVar: false, getter };
9955
10026
  }
9956
10027
  function getMemberExpressionPropString(expr) {
9957
10028
  switch (expr.property.type) {
@@ -12976,15 +13047,6 @@ var tag_default = {
12976
13047
  `Unsupported arguments on the \`${attr.node.name}\` attribute.`
12977
13048
  );
12978
13049
  }
12979
- if (attr.node.modifier) {
12980
- if ((0, import_babel_utils51.isNativeTag)(attr.parentPath)) {
12981
- attr.node.name += `:${attr.node.modifier}`;
12982
- } else {
12983
- throw attr.buildCodeFrameError(
12984
- `Unsupported modifier \`${attr.node.modifier}\`.`
12985
- );
12986
- }
12987
- }
12988
13050
  }
12989
13051
  }
12990
13052
  switch (analyzeTagNameType(tag)) {
@@ -13215,9 +13277,6 @@ function scanTag(state, tag) {
13215
13277
  attr.get("arguments")[0]
13216
13278
  );
13217
13279
  break;
13218
- } else if (attr.node.modifier) {
13219
- addFeature(state, "class" /* Class */, "Attribute modifier", attr);
13220
- break;
13221
13280
  } else if (attr.node.bound) {
13222
13281
  addFeature(state, "tags" /* Tags */, "Bound attribute", attr);
13223
13282
  break;
@@ -13289,10 +13348,10 @@ function createInteropTranslator(translate5) {
13289
13348
  import_compiler65.taglib.resolveOptionalTaglibs(translate5.optionalTaglibs).concat(translate5.taglibs),
13290
13349
  taglibs
13291
13350
  ),
13292
- getRuntimeEntryFiles(output, optimize) {
13351
+ getRuntimeEntryFiles(output, optimize2) {
13293
13352
  return [
13294
- ...translate5.getRuntimeEntryFiles(output, optimize),
13295
- ...getRuntimeEntryFiles(output, optimize)
13353
+ ...translate5.getRuntimeEntryFiles(output, optimize2),
13354
+ ...getRuntimeEntryFiles(output, optimize2)
13296
13355
  ];
13297
13356
  }
13298
13357
  };
@@ -13572,9 +13631,9 @@ var taglibs = [
13572
13631
  }
13573
13632
  ]
13574
13633
  ];
13575
- function getRuntimeEntryFiles(output, optimize) {
13634
+ function getRuntimeEntryFiles(output, optimize2) {
13576
13635
  return [
13577
- `${runtime_info_default.name}${optimize ? "" : "/debug"}/${output === "html" ? "html" : "dom"}`
13636
+ `${runtime_info_default.name}${optimize2 ? "" : "/debug"}/${output === "html" ? "html" : "dom"}`
13578
13637
  ];
13579
13638
  }
13580
13639
  // Annotate the CommonJS export names for ESM import in node:
@@ -63,11 +63,13 @@ export interface Getter {
63
63
  interface Read {
64
64
  binding: Binding;
65
65
  extra: t.NodeExtra;
66
+ ownVar: boolean;
66
67
  getter: Getter | undefined;
67
68
  }
68
69
  interface ExtraRead {
69
70
  binding: Binding;
70
71
  props: Opt<string>;
72
+ ownVar: boolean;
71
73
  getter: Getter | undefined;
72
74
  }
73
75
  declare module "@marko/compiler/dist/types" {
@@ -107,6 +109,7 @@ export declare function getOrCreatePropertyAlias(binding: Binding, property: str
107
109
  export declare function trackDomVarReferences(tag: t.NodePath<t.MarkoTag>, binding: Binding): Binding | undefined;
108
110
  export declare function trackVarReferences(tag: t.NodePath<t.MarkoTag>, type: BindingType, upstreamAlias?: Binding["upstreamAlias"]): Binding | undefined;
109
111
  export declare function trackParamsReferences(body: t.NodePath<t.MarkoTagBody | t.Program>, type: BindingType): Binding | undefined;
112
+ export declare function isReferenceInOwnBody(bindingPath: t.NodePath, reference: t.NodePath): boolean;
110
113
  export declare function isReferenceHoisted(bindingPath: t.NodePath, reference: t.NodePath): boolean;
111
114
  export declare function setReferencesScope(path: t.NodePath<any>): void;
112
115
  export declare function mergeReferences<T extends t.Node>(section: Section, target: T, nodes: (t.Node | undefined)[]): NonNullable<T["extra"]> & ReferencedExtra;
@@ -139,7 +142,8 @@ export declare function getSectionInstancesAccessorLiteral(section: Section): t.
139
142
  export declare function getReadReplacement(node: t.Identifier | t.MemberExpression | t.OptionalMemberExpression, signal?: Signal): t.Expression | undefined;
140
143
  export declare function hasNonConstantPropertyAlias(ref: Binding): boolean;
141
144
  export declare function pruneBinding(binding: Binding): boolean;
142
- export declare function createRead(binding: Binding, props: Opt<string>, getter: Getter | undefined): ExtraRead;
145
+ export declare function createRead(binding: Binding, props: Opt<string>, ownVar?: boolean): ExtraRead;
146
+ export declare function createGetterRead(binding: Binding, props: Opt<string>, getter: Getter): ExtraRead;
143
147
  export declare function getObjectPropertyKeyString(expr: t.ObjectProperty | t.ObjectMethod): string | undefined;
144
148
  export interface ReferencedExtra extends t.NodeExtra {
145
149
  section: Section;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.156",
3
+ "version": "6.0.157",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",
@@ -49,7 +49,7 @@
49
49
  "build": "node -r ~ts ./scripts/bundle.ts"
50
50
  },
51
51
  "dependencies": {
52
- "@marko/compiler": "^5.39.60",
52
+ "@marko/compiler": "^5.39.61",
53
53
  "csstype": "^3.2.3",
54
54
  "fastest-levenshtein": "^1.0.16",
55
55
  "magic-string": "^0.30.21"