@marko/runtime-tags 0.3.42 → 0.3.43

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.
@@ -35,7 +35,6 @@ __export(html_exports, {
35
35
  controllable_textarea_value: () => controllable_textarea_value,
36
36
  createRenderer: () => createRenderer,
37
37
  createTemplate: () => createTemplate,
38
- debug: () => debug,
39
38
  dynamicTagArgs: () => dynamicTagArgs,
40
39
  dynamicTagInput: () => dynamicTagInput,
41
40
  ensureScopeWithId: () => ensureScopeWithId,
@@ -584,15 +583,12 @@ var Reference = class {
584
583
  assigns = "";
585
584
  };
586
585
  var DEBUG = /* @__PURE__ */ new WeakMap();
587
- function debug(obj, file, loc, vars) {
588
- if (true) {
589
- DEBUG.set(obj, {
590
- file,
591
- loc,
592
- vars
593
- });
594
- }
595
- return obj;
586
+ function setDebugInfo(obj, file, loc, vars) {
587
+ DEBUG.set(obj, {
588
+ file,
589
+ loc,
590
+ vars
591
+ });
596
592
  }
597
593
  var Serializer = class {
598
594
  #state = new State();
@@ -1319,21 +1315,21 @@ function throwUnserializable(state, cause, ref = null, accessor = "") {
1319
1315
  let message = "Unable to serialize";
1320
1316
  let access = "";
1321
1317
  while (ref?.accessor) {
1322
- const debug2 = ref.parent?.debug;
1323
- if (debug2) {
1324
- const varLoc = debug2.vars?.[ref.accessor];
1318
+ const debug = ref.parent?.debug;
1319
+ if (debug) {
1320
+ const varLoc = debug.vars?.[ref.accessor];
1321
+ let debugAccess = ref.accessor;
1322
+ let debugLoc = debug.loc;
1325
1323
  if (varLoc) {
1326
1324
  if (Array.isArray(varLoc)) {
1327
- message += ` "${varLoc[0]}" in ${debug2.file}:${varLoc[1]}`;
1325
+ debugAccess = varLoc[0];
1326
+ if (varLoc[1]) debugLoc = varLoc[1];
1328
1327
  } else {
1329
- message += ` "${ref.accessor}" in ${debug2.file}:${varLoc}`;
1330
- }
1331
- } else {
1332
- message += ` ${JSON.stringify(ref.accessor)} in ${debug2.file}`;
1333
- if (debug2.loc) {
1334
- message += `:${debug2.loc}`;
1328
+ debugLoc = varLoc;
1335
1329
  }
1336
1330
  }
1331
+ message += ` ${JSON.stringify(debugAccess)} in ${debug.file}`;
1332
+ if (debugLoc) message += `:${debugLoc}`;
1337
1333
  break;
1338
1334
  }
1339
1335
  access = toAccess(ref.accessor) + access;
@@ -1729,7 +1725,7 @@ function resumeSingleNodeConditional(cb, scopeId, accessor, onlyChild) {
1729
1725
  )
1730
1726
  );
1731
1727
  }
1732
- function writeScope(scopeId, partialScope) {
1728
+ var writeScope = (scopeId, partialScope) => {
1733
1729
  const { state } = $chunk.boundary;
1734
1730
  const { scopes } = state;
1735
1731
  let scope = scopes.get(scopeId);
@@ -1753,6 +1749,15 @@ function writeScope(scopeId, partialScope) {
1753
1749
  };
1754
1750
  }
1755
1751
  return scope;
1752
+ };
1753
+ if (true) {
1754
+ writeScope = /* @__PURE__ */ ((writeScope2) => (scopeId, partialScope, file, loc, vars) => {
1755
+ const scope = writeScope2(scopeId, partialScope);
1756
+ if (file && loc !== void 0) {
1757
+ setDebugInfo(scope, file, loc, vars);
1758
+ }
1759
+ return scope;
1760
+ })(writeScope);
1756
1761
  }
1757
1762
  function writeExistingScope(scope) {
1758
1763
  return writeScope(scope[K_SCOPE_ID], scope);
@@ -2967,7 +2972,6 @@ function NOOP2() {
2967
2972
  controllable_textarea_value,
2968
2973
  createRenderer,
2969
2974
  createTemplate,
2970
- debug,
2971
2975
  dynamicTagArgs,
2972
2976
  dynamicTagInput,
2973
2977
  ensureScopeWithId,
@@ -502,15 +502,12 @@ var Reference = class {
502
502
  assigns = "";
503
503
  };
504
504
  var DEBUG = /* @__PURE__ */ new WeakMap();
505
- function debug(obj, file, loc, vars) {
506
- if (true) {
507
- DEBUG.set(obj, {
508
- file,
509
- loc,
510
- vars
511
- });
512
- }
513
- return obj;
505
+ function setDebugInfo(obj, file, loc, vars) {
506
+ DEBUG.set(obj, {
507
+ file,
508
+ loc,
509
+ vars
510
+ });
514
511
  }
515
512
  var Serializer = class {
516
513
  #state = new State();
@@ -1237,21 +1234,21 @@ function throwUnserializable(state, cause, ref = null, accessor = "") {
1237
1234
  let message = "Unable to serialize";
1238
1235
  let access = "";
1239
1236
  while (ref?.accessor) {
1240
- const debug2 = ref.parent?.debug;
1241
- if (debug2) {
1242
- const varLoc = debug2.vars?.[ref.accessor];
1237
+ const debug = ref.parent?.debug;
1238
+ if (debug) {
1239
+ const varLoc = debug.vars?.[ref.accessor];
1240
+ let debugAccess = ref.accessor;
1241
+ let debugLoc = debug.loc;
1243
1242
  if (varLoc) {
1244
1243
  if (Array.isArray(varLoc)) {
1245
- message += ` "${varLoc[0]}" in ${debug2.file}:${varLoc[1]}`;
1244
+ debugAccess = varLoc[0];
1245
+ if (varLoc[1]) debugLoc = varLoc[1];
1246
1246
  } else {
1247
- message += ` "${ref.accessor}" in ${debug2.file}:${varLoc}`;
1248
- }
1249
- } else {
1250
- message += ` ${JSON.stringify(ref.accessor)} in ${debug2.file}`;
1251
- if (debug2.loc) {
1252
- message += `:${debug2.loc}`;
1247
+ debugLoc = varLoc;
1253
1248
  }
1254
1249
  }
1250
+ message += ` ${JSON.stringify(debugAccess)} in ${debug.file}`;
1251
+ if (debugLoc) message += `:${debugLoc}`;
1255
1252
  break;
1256
1253
  }
1257
1254
  access = toAccess(ref.accessor) + access;
@@ -1647,7 +1644,7 @@ function resumeSingleNodeConditional(cb, scopeId, accessor, onlyChild) {
1647
1644
  )
1648
1645
  );
1649
1646
  }
1650
- function writeScope(scopeId, partialScope) {
1647
+ var writeScope = (scopeId, partialScope) => {
1651
1648
  const { state } = $chunk.boundary;
1652
1649
  const { scopes } = state;
1653
1650
  let scope = scopes.get(scopeId);
@@ -1671,6 +1668,15 @@ function writeScope(scopeId, partialScope) {
1671
1668
  };
1672
1669
  }
1673
1670
  return scope;
1671
+ };
1672
+ if (true) {
1673
+ writeScope = /* @__PURE__ */ ((writeScope2) => (scopeId, partialScope, file, loc, vars) => {
1674
+ const scope = writeScope2(scopeId, partialScope);
1675
+ if (file && loc !== void 0) {
1676
+ setDebugInfo(scope, file, loc, vars);
1677
+ }
1678
+ return scope;
1679
+ })(writeScope);
1674
1680
  }
1675
1681
  function writeExistingScope(scope) {
1676
1682
  return writeScope(scope[K_SCOPE_ID], scope);
@@ -2884,7 +2890,6 @@ export {
2884
2890
  controllable_textarea_value,
2885
2891
  createRenderer,
2886
2892
  createTemplate,
2887
- debug,
2888
2893
  dynamicTagArgs,
2889
2894
  dynamicTagInput,
2890
2895
  ensureScopeWithId,
@@ -1,5 +1,5 @@
1
1
  import type { Boundary } from "./writer";
2
- export declare function debug(obj: WeakKey, file: string, loc: string | 0, vars?: Record<string, string>): WeakKey;
2
+ export declare function setDebugInfo(obj: WeakKey, file: string, loc: string | 0, vars?: Record<string, string>): void;
3
3
  export declare class Serializer {
4
4
  #private;
5
5
  get flushed(): boolean;
@@ -34,7 +34,8 @@ export declare function resumeForTo(to: number, from: number | Falsy, step: numb
34
34
  export declare function resumeSingleNodeForTo(to: number, from: number | Falsy, step: number | Falsy, cb: (index: number) => void, scopeId: number, accessor: Accessor, onlyChild?: 1): void;
35
35
  export declare function resumeConditional(cb: () => void | number, scopeId: number, accessor: Accessor): void;
36
36
  export declare function resumeSingleNodeConditional(cb: () => void | number, scopeId: number, accessor: Accessor, onlyChild?: 1): void;
37
- export declare function writeScope(scopeId: number, partialScope: PartialScope): ScopeInternals;
37
+ declare let writeScope: (scopeId: number, partialScope: PartialScope) => ScopeInternals;
38
+ export { writeScope };
38
39
  export declare function writeExistingScope(scope: ScopeInternals): ScopeInternals;
39
40
  export declare function ensureScopeWithId(scopeId: number): PartialScope;
40
41
  export declare function $global(): $Global & {
@@ -119,4 +120,3 @@ export declare function writeTrailers(html: string): void;
119
120
  type QueueCallback = (ticked: true) => void;
120
121
  export declare function queueTick(cb: QueueCallback): void;
121
122
  export declare function offTick(cb: QueueCallback): void;
122
- export {};
package/dist/html.d.ts CHANGED
@@ -5,6 +5,5 @@ export { compat } from "./html/compat";
5
5
  export { escapeScript, escapeStyle, escapeXML, toString } from "./html/content";
6
6
  export { createRenderer, dynamicTagArgs, dynamicTagInput, } from "./html/dynamic-tag";
7
7
  export { forIn, forInBy, forOf, forOfBy, forTo, forToBy } from "./html/for";
8
- export { debug } from "./html/serializer";
9
8
  export { createTemplate } from "./html/template";
10
9
  export { $global, ensureScopeWithId, fork, getScopeById, markResumeNode, nextScopeId, nextTagId, nodeRef, peekNextScope, register, resumeClosestBranch, resumeConditional, resumeForIn, resumeForOf, resumeForTo, resumeSingleNodeConditional, resumeSingleNodeForIn, resumeSingleNodeForOf, resumeSingleNodeForTo, setTagVar, tryContent, write, writeEffect, writeExistingScope, writeScope, writeTrailers, } from "./html/writer";
package/dist/html.js CHANGED
@@ -32,7 +32,6 @@ __export(html_exports, {
32
32
  controllable_textarea_value: () => controllable_textarea_value,
33
33
  createRenderer: () => createRenderer,
34
34
  createTemplate: () => createTemplate,
35
- debug: () => debug,
36
35
  dynamicTagArgs: () => dynamicTagArgs,
37
36
  dynamicTagInput: () => dynamicTagInput,
38
37
  ensureScopeWithId: () => ensureScopeWithId,
@@ -437,9 +436,6 @@ var { hasOwnProperty } = {}, Generator = function* () {
437
436
  init = "";
438
437
  assigns = "";
439
438
  };
440
- function debug(obj, file, loc, vars) {
441
- return obj;
442
- }
443
439
  var Serializer = class {
444
440
  #state = new State();
445
441
  get flushed() {
@@ -1164,13 +1160,13 @@ function resumeSingleNodeConditional(cb, scopeId, accessor, onlyChild) {
1164
1160
  )
1165
1161
  );
1166
1162
  }
1167
- function writeScope(scopeId, partialScope) {
1163
+ var writeScope = (scopeId, partialScope) => {
1168
1164
  let { state } = $chunk.boundary, { scopes } = state, scope = scopes.get(scopeId);
1169
1165
  return state.needsMainRuntime = !0, scope ? Object.assign(scope, partialScope) : (scope = partialScope, scope[K_SCOPE_ID] = scopeId, state.scopes.set(scopeId, scope)), state.writeScopes ? state.writeScopes[scopeId] = scope : state.hasGlobals ? state.writeScopes = { [scopeId]: scope } : (state.hasGlobals = !0, state.writeScopes = {
1170
1166
  $: getFilteredGlobals(state.$global),
1171
1167
  [scopeId]: scope
1172
1168
  }), scope;
1173
- }
1169
+ };
1174
1170
  function writeExistingScope(scope) {
1175
1171
  return writeScope(scope[K_SCOPE_ID], scope);
1176
1172
  }
@@ -1958,7 +1954,6 @@ function NOOP2() {
1958
1954
  controllable_textarea_value,
1959
1955
  createRenderer,
1960
1956
  createTemplate,
1961
- debug,
1962
1957
  dynamicTagArgs,
1963
1958
  dynamicTagInput,
1964
1959
  ensureScopeWithId,
package/dist/html.mjs CHANGED
@@ -358,9 +358,6 @@ var { hasOwnProperty } = {}, Generator = function* () {
358
358
  init = "";
359
359
  assigns = "";
360
360
  };
361
- function debug(obj, file, loc, vars) {
362
- return obj;
363
- }
364
361
  var Serializer = class {
365
362
  #state = new State();
366
363
  get flushed() {
@@ -1085,13 +1082,13 @@ function resumeSingleNodeConditional(cb, scopeId, accessor, onlyChild) {
1085
1082
  )
1086
1083
  );
1087
1084
  }
1088
- function writeScope(scopeId, partialScope) {
1085
+ var writeScope = (scopeId, partialScope) => {
1089
1086
  let { state } = $chunk.boundary, { scopes } = state, scope = scopes.get(scopeId);
1090
1087
  return state.needsMainRuntime = !0, scope ? Object.assign(scope, partialScope) : (scope = partialScope, scope[K_SCOPE_ID] = scopeId, state.scopes.set(scopeId, scope)), state.writeScopes ? state.writeScopes[scopeId] = scope : state.hasGlobals ? state.writeScopes = { [scopeId]: scope } : (state.hasGlobals = !0, state.writeScopes = {
1091
1088
  $: getFilteredGlobals(state.$global),
1092
1089
  [scopeId]: scope
1093
1090
  }), scope;
1094
- }
1091
+ };
1095
1092
  function writeExistingScope(scope) {
1096
1093
  return writeScope(scope[K_SCOPE_ID], scope);
1097
1094
  }
@@ -1878,7 +1875,6 @@ export {
1878
1875
  controllable_textarea_value,
1879
1876
  createRenderer,
1880
1877
  createTemplate,
1881
- debug,
1882
1878
  dynamicTagArgs,
1883
1879
  dynamicTagInput,
1884
1880
  ensureScopeWithId,
@@ -550,6 +550,15 @@ function toAccess(accessor) {
550
550
  var K_SCOPE_ID = Symbol("Scope ID");
551
551
  var kPendingContexts = Symbol("Pending Contexts");
552
552
  var branchIdKey = Symbol();
553
+ if (false) {
554
+ writeScope = /* @__PURE__ */ ((writeScope2) => (scopeId, partialScope, file, loc, vars) => {
555
+ const scope = writeScope2(scopeId, partialScope);
556
+ if (file && loc !== void 0) {
557
+ setDebugInfo(scope, file, loc, vars);
558
+ }
559
+ return scope;
560
+ })(writeScope);
561
+ }
553
562
  var tick = globalThis.setImmediate || globalThis.setTimeout || globalThis.queueMicrotask || ((cb) => Promise.resolve().then(cb));
554
563
 
555
564
  // src/html/attrs.ts
@@ -606,8 +615,11 @@ var K_TAGS_API_STATE = Symbol();
606
615
 
607
616
  // src/translator/util/to-property-name.ts
608
617
  var import_compiler3 = require("@marko/compiler");
618
+ function isValidPropertyIdentifier(name2) {
619
+ return /^[a-z_$][a-z0-9_$]*$/i.test(name2);
620
+ }
609
621
  function toPropertyName(name2) {
610
- if (/^[a-z_$][a-z0-9_$]*$/i.test(name2)) {
622
+ if (isValidPropertyIdentifier(name2)) {
611
623
  return import_compiler3.types.identifier(name2);
612
624
  } else if (/^(?:0|[1-9][0-9]*)$/.test(name2)) {
613
625
  return import_compiler3.types.numericLiteral(parseInt(name2, 10));
@@ -1719,8 +1731,9 @@ var return_default = {
1719
1731
  const attrs2 = getKnownAttrValues(tag.node);
1720
1732
  flushBefore(tag);
1721
1733
  if (attrs2.valueChange) {
1722
- getSerializedScopeProperties(section).set(
1723
- import_compiler11.types.stringLiteral("@" /* TagVariableChange */),
1734
+ setSerializedProperty(
1735
+ section,
1736
+ "@" /* TagVariableChange */,
1724
1737
  attrs2.valueChange
1725
1738
  );
1726
1739
  }
@@ -1843,10 +1856,10 @@ function createScopeReadPattern(section, referencedBindings) {
1843
1856
  const rootPattern = import_compiler13.types.objectPattern([]);
1844
1857
  let nestedPatterns;
1845
1858
  forEach(referencedBindings, (ref) => {
1846
- if (ref.name.includes("#")) return;
1847
- const propertyKey = getScopeAccessorLiteral(ref);
1848
- const propertyValue = import_compiler13.types.identifier(ref.name);
1849
- const isShorthand = propertyKey.value === propertyValue.name;
1859
+ const propertyValue = ref.name;
1860
+ if (!isValidPropertyIdentifier(propertyValue)) return;
1861
+ const propertyKey = getScopeAccessor(ref);
1862
+ const isShorthand = propertyKey === propertyValue;
1850
1863
  let pattern = rootPattern;
1851
1864
  if (ref.section !== section) {
1852
1865
  if (!nestedPatterns) nestedPatterns = [rootPattern];
@@ -1865,8 +1878,8 @@ function createScopeReadPattern(section, referencedBindings) {
1865
1878
  }
1866
1879
  pattern.properties.push(
1867
1880
  import_compiler13.types.objectProperty(
1868
- isShorthand ? propertyValue : propertyKey,
1869
- propertyValue,
1881
+ toPropertyName(propertyKey),
1882
+ import_compiler13.types.identifier(propertyValue),
1870
1883
  false,
1871
1884
  isShorthand
1872
1885
  )
@@ -1886,10 +1899,11 @@ function getScopeExpression(section, targetSection) {
1886
1899
  return scope;
1887
1900
  }
1888
1901
  function createScopeReadExpression(section, reference) {
1902
+ const propName = toPropertyName(getScopeAccessor(reference));
1889
1903
  return import_compiler13.types.memberExpression(
1890
1904
  getScopeExpression(section, reference.section),
1891
- getScopeAccessorLiteral(reference),
1892
- true
1905
+ propName,
1906
+ propName.type !== "Identifier"
1893
1907
  );
1894
1908
  }
1895
1909
 
@@ -1996,6 +2010,9 @@ function setForceResumeScope(section) {
1996
2010
  _setForceResumeScope(section, true);
1997
2011
  }
1998
2012
  var [getSerializedScopeProperties] = createSectionState("serializedScopeProperties", () => /* @__PURE__ */ new Map());
2013
+ function setSerializedProperty(section, key, value) {
2014
+ getSerializedScopeProperties(section).set(key, value);
2015
+ }
1999
2016
  var [getHTMLSectionStatements] = createSectionState(
2000
2017
  "htmlScopeStatements",
2001
2018
  () => []
@@ -2562,26 +2579,34 @@ function writeHTMLResumeStatements(path5) {
2562
2579
  forEach(section.assignments, (assignment) => {
2563
2580
  let currentSection = section;
2564
2581
  while (currentSection !== assignment.section) {
2565
- getSerializedScopeProperties(currentSection).set(
2566
- import_compiler17.types.stringLiteral("_"),
2567
- callRuntime(
2568
- "ensureScopeWithId",
2569
- getScopeIdIdentifier(currentSection = currentSection.parent)
2570
- )
2571
- );
2582
+ const currentSerialized = getSerializedScopeProperties(currentSection);
2583
+ currentSection = currentSection.parent;
2584
+ if (!currentSerialized.has("_")) {
2585
+ currentSerialized.set(
2586
+ "_",
2587
+ callRuntime(
2588
+ "ensureScopeWithId",
2589
+ getScopeIdIdentifier(currentSection)
2590
+ )
2591
+ );
2592
+ }
2572
2593
  }
2573
2594
  });
2574
2595
  forEach(section.closures, (closure) => {
2575
2596
  if (isStatefulReferences(closure)) {
2576
2597
  let currentSection = section;
2577
2598
  while (currentSection !== closure.section) {
2578
- getSerializedScopeProperties(currentSection).set(
2579
- import_compiler17.types.stringLiteral("_"),
2580
- callRuntime(
2581
- "ensureScopeWithId",
2582
- getScopeIdIdentifier(currentSection = currentSection.parent)
2583
- )
2584
- );
2599
+ const currentSerialized = getSerializedScopeProperties(currentSection);
2600
+ currentSection = currentSection.parent;
2601
+ if (!currentSerialized.has("_")) {
2602
+ currentSerialized.set(
2603
+ "_",
2604
+ callRuntime(
2605
+ "ensureScopeWithId",
2606
+ getScopeIdIdentifier(currentSection)
2607
+ )
2608
+ );
2609
+ }
2585
2610
  }
2586
2611
  setForceResumeScope(closure.section);
2587
2612
  const isImmediateOwner = section.parent?.id === closure.section.id;
@@ -2617,69 +2642,63 @@ function writeHTMLResumeStatements(path5) {
2617
2642
  );
2618
2643
  }
2619
2644
  }
2620
- const accessors = /* @__PURE__ */ new Set();
2621
- const additionalProperties = getSerializedScopeProperties(section);
2645
+ const serializedLookup = getSerializedScopeProperties(section);
2622
2646
  const serializedProperties = [];
2623
2647
  forEach(section.bindings, (binding) => {
2624
2648
  if (binding.serialize && binding.type !== 0 /* dom */) {
2625
- const accessor = getScopeAccessorLiteral(binding);
2649
+ const accessor = getScopeAccessor(binding);
2650
+ serializedLookup.delete(accessor);
2626
2651
  serializedProperties.push(
2627
- import_compiler17.types.objectProperty(accessor, getDeclaredBindingExpression(binding))
2652
+ toObjectProperty(accessor, getDeclaredBindingExpression(binding))
2628
2653
  );
2629
- accessors.add(accessor.value);
2630
2654
  }
2631
2655
  });
2632
- for (const [key, value] of additionalProperties) {
2633
- if (!accessors.has(key.value)) {
2634
- serializedProperties.push(
2635
- import_compiler17.types.objectProperty(key, value, !import_compiler17.types.isLiteral(key))
2636
- );
2637
- accessors.add(key.value);
2638
- }
2656
+ for (const [key, value] of serializedLookup) {
2657
+ serializedProperties.push(toObjectProperty(key, value));
2639
2658
  }
2640
2659
  if (serializedProperties.length || forceResumeScope(section)) {
2641
- let writeScope2 = callRuntime(
2642
- "writeScope",
2660
+ const writeScopeArgs = [
2643
2661
  scopeIdIdentifier,
2644
2662
  import_compiler17.types.objectExpression(serializedProperties)
2645
- );
2663
+ ];
2646
2664
  if (!isOptimize()) {
2647
2665
  let debugVars;
2648
2666
  forEach(section.bindings, (binding) => {
2667
+ if (!binding.serialize || binding.type === 0 /* dom */) return;
2649
2668
  let root = binding;
2650
2669
  let access = "";
2651
- while (!root.loc && root.upstreamAlias) {
2670
+ while (!(root.loc || root.declared) && root.upstreamAlias) {
2652
2671
  if (root.property !== void 0) {
2653
2672
  access = toAccess(root.property) + access;
2654
2673
  }
2655
2674
  root = root.upstreamAlias;
2656
2675
  }
2657
- if (root.loc) {
2658
- const locStr = import_compiler17.types.stringLiteral(
2659
- `${root.loc.start.line}:${root.loc.start.column + 1}`
2660
- );
2661
- (debugVars ||= []).push(
2662
- import_compiler17.types.objectProperty(
2663
- getScopeAccessorLiteral(binding),
2664
- root !== binding ? import_compiler17.types.arrayExpression([
2665
- import_compiler17.types.stringLiteral(root.name + access),
2666
- locStr
2667
- ]) : locStr
2668
- )
2669
- );
2670
- }
2676
+ const locExpr = root.loc && import_compiler17.types.stringLiteral(
2677
+ `${root.loc.start.line}:${root.loc.start.column + 1}`
2678
+ );
2679
+ (debugVars ||= []).push(
2680
+ toObjectProperty(
2681
+ getScopeAccessor(binding),
2682
+ root !== binding ? import_compiler17.types.arrayExpression(
2683
+ locExpr ? [import_compiler17.types.stringLiteral(root.name + access), locExpr] : [import_compiler17.types.stringLiteral(root.name + access)]
2684
+ ) : locExpr || import_compiler17.types.numericLiteral(0)
2685
+ )
2686
+ );
2671
2687
  });
2672
- writeScope2 = callRuntime(
2673
- "debug",
2674
- writeScope2,
2688
+ writeScopeArgs.push(
2675
2689
  import_compiler17.types.stringLiteral(path5.hub.file.opts.filenameRelative),
2676
2690
  section.loc && section.loc.start.line != null ? import_compiler17.types.stringLiteral(
2677
2691
  `${section.loc.start.line}:${section.loc.start.column + 1}`
2678
- ) : import_compiler17.types.numericLiteral(0),
2679
- debugVars && import_compiler17.types.objectExpression(debugVars)
2692
+ ) : import_compiler17.types.numericLiteral(0)
2680
2693
  );
2694
+ if (debugVars) {
2695
+ writeScopeArgs.push(import_compiler17.types.objectExpression(debugVars));
2696
+ }
2681
2697
  }
2682
- path5.pushContainer("body", import_compiler17.types.expressionStatement(writeScope2));
2698
+ path5.pushContainer(
2699
+ "body",
2700
+ import_compiler17.types.expressionStatement(callRuntime("writeScope", ...writeScopeArgs))
2701
+ );
2683
2702
  }
2684
2703
  const resumeClosestBranch2 = !section.isBranch && (section.hasAbortSignal || !!section.closures || !!find(section.bindings, (binding) => binding.type === 1 /* let */));
2685
2704
  if (resumeClosestBranch2) {
@@ -3819,6 +3838,12 @@ function getScopeAccessorLiteral(binding) {
3819
3838
  binding.name + (binding.type === 0 /* dom */ ? `/${binding.id}` : "")
3820
3839
  );
3821
3840
  }
3841
+ function getScopeAccessor(binding) {
3842
+ if (isOptimize()) {
3843
+ return binding.id + "";
3844
+ }
3845
+ return binding.name + (binding.type === 0 /* dom */ ? `/${binding.id}` : "");
3846
+ }
3822
3847
  function getReadReplacement(node) {
3823
3848
  const { extra } = node;
3824
3849
  if (!extra) return;
@@ -4580,8 +4605,9 @@ var native_tag_default = {
4580
4605
  for (const reference of references) {
4581
4606
  let currentSection = getSection(reference);
4582
4607
  while (currentSection !== section && currentSection.parent) {
4583
- getSerializedScopeProperties(currentSection).set(
4584
- import_compiler28.types.stringLiteral("_"),
4608
+ setSerializedProperty(
4609
+ currentSection,
4610
+ "_",
4585
4611
  callRuntime(
4586
4612
  "ensureScopeWithId",
4587
4613
  getScopeIdIdentifier(
@@ -5210,10 +5236,9 @@ var for_default = {
5210
5236
  )
5211
5237
  );
5212
5238
  }
5213
- getSerializedScopeProperties(tagSection).set(
5214
- import_compiler30.types.stringLiteral(
5215
- getScopeAccessorLiteral(nodeRef2).value + "(" /* LoopScopeMap */
5216
- ),
5239
+ setSerializedProperty(
5240
+ tagSection,
5241
+ getScopeAccessor(nodeRef2) + "(" /* LoopScopeMap */,
5217
5242
  import_compiler30.types.conditionalExpression(
5218
5243
  import_compiler30.types.memberExpression(forScopesIdentifier, import_compiler30.types.identifier("size")),
5219
5244
  forScopesIdentifier,
@@ -6210,8 +6235,9 @@ var html_script_default = {
6210
6235
  for (const reference of references) {
6211
6236
  let currentSection = getSection(reference);
6212
6237
  while (currentSection !== section && currentSection.parent) {
6213
- getSerializedScopeProperties(currentSection).set(
6214
- import_compiler35.types.stringLiteral("_"),
6238
+ setSerializedProperty(
6239
+ currentSection,
6240
+ "_",
6215
6241
  callRuntime(
6216
6242
  "ensureScopeWithId",
6217
6243
  getScopeIdIdentifier(currentSection = currentSection.parent)
@@ -6605,8 +6631,9 @@ var html_style_default = {
6605
6631
  for (const reference of references) {
6606
6632
  let currentSection = getSection(reference);
6607
6633
  while (currentSection !== section && currentSection.parent) {
6608
- getSerializedScopeProperties(currentSection).set(
6609
- import_compiler36.types.stringLiteral("_"),
6634
+ setSerializedProperty(
6635
+ currentSection,
6636
+ "_",
6610
6637
  callRuntime(
6611
6638
  "ensureScopeWithId",
6612
6639
  getScopeIdIdentifier(currentSection = currentSection.parent)
@@ -7080,10 +7107,9 @@ var IfTag = {
7080
7107
  nextTag.insertBefore(statement);
7081
7108
  } else {
7082
7109
  if (isStateful) {
7083
- getSerializedScopeProperties(section).set(
7084
- import_compiler39.types.stringLiteral(
7085
- getScopeAccessorLiteral(nodeRef2).value + "(" /* ConditionalRenderer */
7086
- ),
7110
+ setSerializedProperty(
7111
+ section,
7112
+ getScopeAccessor(nodeRef2) + "(" /* ConditionalRenderer */,
7087
7113
  ifBranchIdentifier
7088
7114
  );
7089
7115
  const cbNode = import_compiler39.types.arrowFunctionExpression(
@@ -7115,10 +7141,9 @@ var IfTag = {
7115
7141
  ].filter(Boolean)
7116
7142
  )
7117
7143
  );
7118
- getSerializedScopeProperties(section).set(
7119
- import_compiler39.types.stringLiteral(
7120
- getScopeAccessorLiteral(nodeRef2).value + "!" /* ConditionalScope */
7121
- ),
7144
+ setSerializedProperty(
7145
+ section,
7146
+ getScopeAccessor(nodeRef2) + "!" /* ConditionalScope */,
7122
7147
  callRuntime("getScopeById", ifScopeIdIdentifier)
7123
7148
  );
7124
7149
  }
@@ -7409,10 +7434,9 @@ var let_default = {
7409
7434
  } else {
7410
7435
  translateVar(tag, valueAttr.value);
7411
7436
  if (valueChangeAttr) {
7412
- getSerializedScopeProperties(section).set(
7413
- import_compiler40.types.stringLiteral(
7414
- getScopeAccessorLiteral(binding).value + "@" /* TagVariableChange */
7415
- ),
7437
+ setSerializedProperty(
7438
+ section,
7439
+ getScopeAccessor(binding) + "@" /* TagVariableChange */,
7416
7440
  valueChangeAttr.value
7417
7441
  );
7418
7442
  }
@@ -8497,8 +8521,9 @@ function translateHTML(tag) {
8497
8521
  import_compiler52.types.variableDeclarator(peekScopeId, callRuntime("peekNextScope"))
8498
8522
  ])
8499
8523
  );
8500
- getSerializedScopeProperties(section).set(
8501
- getScopeAccessorLiteral(childScopeBinding),
8524
+ setSerializedProperty(
8525
+ section,
8526
+ getScopeAccessor(childScopeBinding),
8502
8527
  callRuntime("writeExistingScope", peekScopeId)
8503
8528
  );
8504
8529
  if (tagVar) {
@@ -9099,10 +9124,11 @@ var dynamic_tag_default = {
9099
9124
  },
9100
9125
  exit(tag) {
9101
9126
  const { node } = tag;
9102
- const extra = node.extra;
9103
- const nodeRef2 = extra[kDOMBinding];
9127
+ const tagExtra = node.extra;
9128
+ const nodeRef2 = tagExtra[kDOMBinding];
9104
9129
  const section = getSection(tag);
9105
- const isClassAPI = extra.featureType === "class";
9130
+ const isClassAPI = tagExtra.featureType === "class";
9131
+ const tagNameReferences = node.name.extra?.referencedBindings;
9106
9132
  let tagExpression = node.name;
9107
9133
  if (import_compiler53.types.isStringLiteral(tagExpression)) {
9108
9134
  tagExpression = (0, import_babel_utils42.importDefault)(
@@ -9217,16 +9243,14 @@ var dynamic_tag_default = {
9217
9243
  } else {
9218
9244
  statements.push(import_compiler53.types.expressionStatement(dynamicTagExpr));
9219
9245
  }
9220
- getSerializedScopeProperties(section).set(
9221
- import_compiler53.types.stringLiteral(
9222
- getScopeAccessorLiteral(nodeRef2).value + "!" /* ConditionalScope */
9223
- ),
9246
+ setSerializedProperty(
9247
+ section,
9248
+ getScopeAccessor(nodeRef2) + "!" /* ConditionalScope */,
9224
9249
  callRuntime("writeExistingScope", dynamicScopeIdentifier)
9225
9250
  );
9226
- getSerializedScopeProperties(section).set(
9227
- import_compiler53.types.stringLiteral(
9228
- getScopeAccessorLiteral(nodeRef2).value + "(" /* ConditionalRenderer */
9229
- ),
9251
+ setSerializedProperty(
9252
+ section,
9253
+ getScopeAccessor(nodeRef2) + "(" /* ConditionalRenderer */,
9230
9254
  callRuntime(
9231
9255
  "normalizeDynamicRenderer",
9232
9256
  import_compiler53.types.isIdentifier(tagExpression) ? import_compiler53.types.identifier(tagExpression.name) : tagExpression
@@ -9250,7 +9274,7 @@ var dynamic_tag_default = {
9250
9274
  signal.hasDownstreamIntersections = () => true;
9251
9275
  addValue(
9252
9276
  section2,
9253
- node.name.extra?.referencedBindings,
9277
+ tagNameReferences,
9254
9278
  signal,
9255
9279
  bodySection ? import_compiler53.types.logicalExpression(
9256
9280
  "||",
@@ -9262,7 +9286,7 @@ var dynamic_tag_default = {
9262
9286
  );
9263
9287
  if (tag.node.var) {
9264
9288
  const childScopeLiteral = import_compiler53.types.stringLiteral(
9265
- getScopeAccessorLiteral(extra[kDOMBinding]).value + "!" /* ConditionalScope */
9289
+ getScopeAccessor(nodeRef2) + "!" /* ConditionalScope */
9266
9290
  );
9267
9291
  const source = initValue(
9268
9292
  // TODO: support destructuring
@@ -9307,7 +9331,7 @@ var dynamic_tag_default = {
9307
9331
  let added = false;
9308
9332
  addValue(
9309
9333
  section2,
9310
- node.extra?.referencedBindings,
9334
+ tagExtra.referencedBindings,
9311
9335
  {
9312
9336
  get identifier() {
9313
9337
  if (!added) {
@@ -67,6 +67,7 @@ export declare function dropReferences(node: t.Node | t.Node[]): void;
67
67
  export declare function getCanonicalBinding(binding?: Binding): Binding | undefined;
68
68
  export declare function getAllTagReferenceNodes(tag: t.MarkoTag, referenceNodes?: t.Node[]): t.Node[];
69
69
  export declare function getScopeAccessorLiteral(binding: Binding): t.StringLiteral | t.NumericLiteral;
70
+ export declare function getScopeAccessor(binding: Binding): string;
70
71
  export declare function getReadReplacement(node: t.Identifier | t.MemberExpression): t.Node | undefined;
71
72
  export interface ReferencedExtra extends t.NodeExtra {
72
73
  section: Section;
@@ -35,7 +35,7 @@ export type Signal = {
35
35
  type closureSignalBuilder = (signal: Signal, render: t.Expression, intersection?: t.Expression) => t.Expression;
36
36
  export declare function setClosureSignalBuilder(tag: t.NodePath<t.MarkoTag>, builder: closureSignalBuilder): void;
37
37
  export declare function setForceResumeScope(section: Section): void;
38
- export declare const getSerializedScopeProperties: (section: Section) => Map<t.StringLiteral | t.NumericLiteral, t.Expression>;
38
+ export declare function setSerializedProperty(section: Section, key: string, value: t.Expression): void;
39
39
  export declare const getHTMLSectionStatements: (section: Section) => t.Statement[];
40
40
  export declare function getSignal(section: Section, referencedBindings: ReferencedBindings, name?: string): Signal;
41
41
  export declare function initValue(binding: Binding, runtimeHelper?: "value" | "state"): Signal;
@@ -1,4 +1,5 @@
1
1
  import { types as t } from "@marko/compiler";
2
+ export declare function isValidPropertyIdentifier(name: string): boolean;
2
3
  export declare function toPropertyName(name: string): t.Identifier | t.StringLiteral | t.NumericLiteral;
3
4
  export declare function toObjectProperty(name: string, value: t.Expression): t.ObjectProperty;
4
5
  export declare function toMemberExpression(object: t.Expression, key: string): t.MemberExpression;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marko/runtime-tags",
3
- "version": "0.3.42",
3
+ "version": "0.3.43",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",