marko 6.0.0-next.3.26 → 6.0.0-next.3.28

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.
package/dist/html.js CHANGED
@@ -32,6 +32,7 @@ __export(html_exports, {
32
32
  controllable_textarea_value: () => controllable_textarea_value,
33
33
  createRenderer: () => createRenderer,
34
34
  createTemplate: () => createTemplate,
35
+ debug: () => debug,
35
36
  dynamicTagArgs: () => dynamicTagArgs,
36
37
  dynamicTagInput: () => dynamicTagInput,
37
38
  ensureScopeWithId: () => ensureScopeWithId,
@@ -435,7 +436,11 @@ var { hasOwnProperty } = {}, Generator = function* () {
435
436
  }
436
437
  init = "";
437
438
  assigns = "";
438
- }, Serializer = class {
439
+ };
440
+ function debug(obj, file, loc, vars) {
441
+ return obj;
442
+ }
443
+ var Serializer = class {
439
444
  #state = new State();
440
445
  get flushed() {
441
446
  return this.#state.flushed;
@@ -562,7 +567,7 @@ function writeSymbol(state, val, parent, accessor) {
562
567
  function writeUnknownSymbol(state) {
563
568
  return state.buf.push("Symbol()"), !0;
564
569
  }
565
- function writeNever() {
570
+ function writeNever(state, val, ref) {
566
571
  return !1;
567
572
  }
568
573
  function writeNull(state) {
@@ -1618,7 +1623,7 @@ function escapeAttrValue(str) {
1618
1623
  }
1619
1624
 
1620
1625
  // src/common/compat-meta.ts
1621
- var prefix = "$C_", RENDERER_REGISTER_ID = prefix + "r", SET_SCOPE_REGISTER_ID = prefix + "s";
1626
+ var prefix = "$C_", RENDERER_REGISTER_ID = prefix + "r", SET_SCOPE_REGISTER_ID = prefix + "s", RENDER_BODY_ID = prefix + "b";
1622
1627
 
1623
1628
  // src/common/meta.ts
1624
1629
  var DEFAULT_RUNTIME_ID = "M", DEFAULT_RENDER_ID = "_";
@@ -1745,8 +1750,10 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
1745
1750
  let asyncOut = classAPIOut.beginAsync();
1746
1751
  (boundary.onNext = () => {
1747
1752
  boundary.done && (boundary.signal.aborted ? asyncOut.error(boundary.signal.reason) : queueMicrotask(() => {
1748
- let { scripts, html } = head = prepareChunk(head);
1749
- asyncOut.script(scripts), asyncOut.write(html), asyncOut.end(), head.html = head.scripts = "";
1753
+ if (head = prepareChunk(head), boundary.done) {
1754
+ let { scripts, html } = head;
1755
+ asyncOut.script(scripts), asyncOut.write(html), asyncOut.end(), head.html = head.scripts = "";
1756
+ }
1750
1757
  }));
1751
1758
  })();
1752
1759
  },
@@ -1757,6 +1764,9 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
1757
1764
  register(id, () => {
1758
1765
  })
1759
1766
  );
1767
+ },
1768
+ registerRenderBody(fn) {
1769
+ register(RENDER_BODY_ID, fn);
1760
1770
  }
1761
1771
  };
1762
1772
 
@@ -1805,16 +1815,17 @@ var ServerRenderResult = class {
1805
1815
  aborted = !0, reason = err, reject && reject(err);
1806
1816
  },
1807
1817
  () => {
1808
- done = !0, resolve && resolve({ value, done: !value });
1818
+ done = !0, resolve && (resolve({ value, done: !value }), value = "");
1809
1819
  }
1810
1820
  );
1811
1821
  return {
1812
1822
  next() {
1823
+ if (aborted)
1824
+ return Promise.reject(reason);
1813
1825
  if (value) {
1814
1826
  let result = { value, done: !1 };
1815
1827
  return value = "", Promise.resolve(result);
1816
- }
1817
- return done ? Promise.resolve({ value: "", done }) : aborted ? Promise.reject(reason) : new Promise(exec);
1828
+ } else return done ? Promise.resolve({ value: "", done }) : new Promise(exec);
1818
1829
  },
1819
1830
  throw(error) {
1820
1831
  return done || aborted || boundary?.abort(error), Promise.resolve({
@@ -1881,7 +1892,7 @@ var ServerRenderResult = class {
1881
1892
  return reject(new Error("Cannot read from a consumed render result"));
1882
1893
  let { boundary } = head;
1883
1894
  (boundary.onNext = () => {
1884
- boundary.done && (boundary.signal.aborted ? reject(boundary.signal.reason) : (head = prepareChunk(head), boundary.done && resolve(flushChunk(head, !0))));
1895
+ boundary.signal.aborted ? (boundary.onNext = NOOP2, reject(boundary.signal.reason)) : boundary.done && (head = prepareChunk(head), boundary.done && resolve(flushChunk(head, !0)));
1885
1896
  })();
1886
1897
  });
1887
1898
  }
@@ -1892,14 +1903,9 @@ var ServerRenderResult = class {
1892
1903
  return;
1893
1904
  }
1894
1905
  let { boundary } = head, onNext = boundary.onNext = (write2) => {
1895
- if (write2 || boundary.done) {
1896
- if (boundary.signal.aborted) {
1897
- tick2 || offTick(onNext), onAbort(boundary.signal.reason);
1898
- return;
1899
- }
1900
- head = prepareChunk(head);
1901
- }
1902
- if (write2 || boundary.done) {
1906
+ if (boundary.signal.aborted)
1907
+ tick2 || offTick(onNext), boundary.onNext = NOOP2, onAbort(boundary.signal.reason);
1908
+ else if ((write2 || boundary.done) && (head = prepareChunk(head)), write2 || boundary.done) {
1903
1909
  let html = flushChunk(head, boundary.done);
1904
1910
  html && onWrite(html), boundary.done ? (tick2 || offTick(onNext), onClose()) : tick2 = !0;
1905
1911
  } else tick2 && (tick2 = !1, queueTick(onNext));
@@ -1913,6 +1919,8 @@ var ServerRenderResult = class {
1913
1919
  return this.#head = null, flushChunk(prepareChunk(head), !0);
1914
1920
  }
1915
1921
  };
1922
+ function NOOP2() {
1923
+ }
1916
1924
  // Annotate the CommonJS export names for ESM import in node:
1917
1925
  0 && (module.exports = {
1918
1926
  $global,
@@ -1930,6 +1938,7 @@ var ServerRenderResult = class {
1930
1938
  controllable_textarea_value,
1931
1939
  createRenderer,
1932
1940
  createTemplate,
1941
+ debug,
1933
1942
  dynamicTagArgs,
1934
1943
  dynamicTagInput,
1935
1944
  ensureScopeWithId,
package/dist/html.mjs CHANGED
@@ -358,7 +358,11 @@ var { hasOwnProperty } = {}, Generator = function* () {
358
358
  }
359
359
  init = "";
360
360
  assigns = "";
361
- }, Serializer = class {
361
+ };
362
+ function debug(obj, file, loc, vars) {
363
+ return obj;
364
+ }
365
+ var Serializer = class {
362
366
  #state = new State();
363
367
  get flushed() {
364
368
  return this.#state.flushed;
@@ -485,7 +489,7 @@ function writeSymbol(state, val, parent, accessor) {
485
489
  function writeUnknownSymbol(state) {
486
490
  return state.buf.push("Symbol()"), !0;
487
491
  }
488
- function writeNever() {
492
+ function writeNever(state, val, ref) {
489
493
  return !1;
490
494
  }
491
495
  function writeNull(state) {
@@ -1541,7 +1545,7 @@ function escapeAttrValue(str) {
1541
1545
  }
1542
1546
 
1543
1547
  // src/common/compat-meta.ts
1544
- var prefix = "$C_", RENDERER_REGISTER_ID = prefix + "r", SET_SCOPE_REGISTER_ID = prefix + "s";
1548
+ var prefix = "$C_", RENDERER_REGISTER_ID = prefix + "r", SET_SCOPE_REGISTER_ID = prefix + "s", RENDER_BODY_ID = prefix + "b";
1545
1549
 
1546
1550
  // src/common/meta.ts
1547
1551
  var DEFAULT_RUNTIME_ID = "M", DEFAULT_RENDER_ID = "_";
@@ -1668,8 +1672,10 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
1668
1672
  let asyncOut = classAPIOut.beginAsync();
1669
1673
  (boundary.onNext = () => {
1670
1674
  boundary.done && (boundary.signal.aborted ? asyncOut.error(boundary.signal.reason) : queueMicrotask(() => {
1671
- let { scripts, html } = head = prepareChunk(head);
1672
- asyncOut.script(scripts), asyncOut.write(html), asyncOut.end(), head.html = head.scripts = "";
1675
+ if (head = prepareChunk(head), boundary.done) {
1676
+ let { scripts, html } = head;
1677
+ asyncOut.script(scripts), asyncOut.write(html), asyncOut.end(), head.html = head.scripts = "";
1678
+ }
1673
1679
  }));
1674
1680
  })();
1675
1681
  },
@@ -1680,6 +1686,9 @@ var K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap()
1680
1686
  register(id, () => {
1681
1687
  })
1682
1688
  );
1689
+ },
1690
+ registerRenderBody(fn) {
1691
+ register(RENDER_BODY_ID, fn);
1683
1692
  }
1684
1693
  };
1685
1694
 
@@ -1728,16 +1737,17 @@ var ServerRenderResult = class {
1728
1737
  aborted = !0, reason = err, reject && reject(err);
1729
1738
  },
1730
1739
  () => {
1731
- done = !0, resolve && resolve({ value, done: !value });
1740
+ done = !0, resolve && (resolve({ value, done: !value }), value = "");
1732
1741
  }
1733
1742
  );
1734
1743
  return {
1735
1744
  next() {
1745
+ if (aborted)
1746
+ return Promise.reject(reason);
1736
1747
  if (value) {
1737
1748
  let result = { value, done: !1 };
1738
1749
  return value = "", Promise.resolve(result);
1739
- }
1740
- return done ? Promise.resolve({ value: "", done }) : aborted ? Promise.reject(reason) : new Promise(exec);
1750
+ } else return done ? Promise.resolve({ value: "", done }) : new Promise(exec);
1741
1751
  },
1742
1752
  throw(error) {
1743
1753
  return done || aborted || boundary?.abort(error), Promise.resolve({
@@ -1804,7 +1814,7 @@ var ServerRenderResult = class {
1804
1814
  return reject(new Error("Cannot read from a consumed render result"));
1805
1815
  let { boundary } = head;
1806
1816
  (boundary.onNext = () => {
1807
- boundary.done && (boundary.signal.aborted ? reject(boundary.signal.reason) : (head = prepareChunk(head), boundary.done && resolve(flushChunk(head, !0))));
1817
+ boundary.signal.aborted ? (boundary.onNext = NOOP2, reject(boundary.signal.reason)) : boundary.done && (head = prepareChunk(head), boundary.done && resolve(flushChunk(head, !0)));
1808
1818
  })();
1809
1819
  });
1810
1820
  }
@@ -1815,14 +1825,9 @@ var ServerRenderResult = class {
1815
1825
  return;
1816
1826
  }
1817
1827
  let { boundary } = head, onNext = boundary.onNext = (write2) => {
1818
- if (write2 || boundary.done) {
1819
- if (boundary.signal.aborted) {
1820
- tick2 || offTick(onNext), onAbort(boundary.signal.reason);
1821
- return;
1822
- }
1823
- head = prepareChunk(head);
1824
- }
1825
- if (write2 || boundary.done) {
1828
+ if (boundary.signal.aborted)
1829
+ tick2 || offTick(onNext), boundary.onNext = NOOP2, onAbort(boundary.signal.reason);
1830
+ else if ((write2 || boundary.done) && (head = prepareChunk(head)), write2 || boundary.done) {
1826
1831
  let html = flushChunk(head, boundary.done);
1827
1832
  html && onWrite(html), boundary.done ? (tick2 || offTick(onNext), onClose()) : tick2 = !0;
1828
1833
  } else tick2 && (tick2 = !1, queueTick(onNext));
@@ -1836,6 +1841,8 @@ var ServerRenderResult = class {
1836
1841
  return this.#head = null, flushChunk(prepareChunk(head), !0);
1837
1842
  }
1838
1843
  };
1844
+ function NOOP2() {
1845
+ }
1839
1846
  export {
1840
1847
  $global,
1841
1848
  attr,
@@ -1852,6 +1859,7 @@ export {
1852
1859
  controllable_textarea_value,
1853
1860
  createRenderer,
1854
1861
  createTemplate,
1862
+ debug,
1855
1863
  dynamicTagArgs,
1856
1864
  dynamicTagInput,
1857
1865
  ensureScopeWithId,
@@ -542,6 +542,10 @@ var KNOWN_OBJECTS = /* @__PURE__ */ new Map([
542
542
  [Math, "Math"],
543
543
  [Reflect, "Reflect"]
544
544
  ]);
545
+ function toAccess(accessor) {
546
+ const start = accessor[0];
547
+ return start === '"' || start >= "0" && start <= "9" ? "[" + accessor + "]" : "." + accessor;
548
+ }
545
549
 
546
550
  // src/html/writer.ts
547
551
  var K_SCOPE_ID = Symbol("Scope ID");
@@ -596,6 +600,7 @@ function escapeAttrValue(str) {
596
600
  var prefix = false ? "$compat_" : "$C_";
597
601
  var RENDERER_REGISTER_ID = prefix + (false ? "renderer" : "r");
598
602
  var SET_SCOPE_REGISTER_ID = prefix + (false ? "setScope" : "s");
603
+ var RENDER_BODY_ID = prefix + (false ? "renderBody" : "b");
599
604
 
600
605
  // src/html/compat.ts
601
606
  var K_TAGS_API_STATE = Symbol();
@@ -1091,6 +1096,7 @@ function startSection(path5) {
1091
1096
  section = extra.section = {
1092
1097
  id: sections.length,
1093
1098
  name: sectionName,
1099
+ loc: sectionNamePath?.node.loc || void 0,
1094
1100
  depth: parentSection ? parentSection.depth + 1 : 0,
1095
1101
  parent: parentSection,
1096
1102
  params: void 0,
@@ -2581,16 +2587,48 @@ function writeHTMLResumeStatements(path5, tagVarIdentifier) {
2581
2587
  }
2582
2588
  }
2583
2589
  if (serializedProperties.length || forceResumeScope(section)) {
2584
- path5.pushContainer(
2585
- "body",
2586
- import_compiler17.types.expressionStatement(
2587
- callRuntime(
2588
- "writeScope",
2589
- scopeIdIdentifier,
2590
- import_compiler17.types.objectExpression(serializedProperties)
2591
- )
2592
- )
2590
+ let writeScope2 = callRuntime(
2591
+ "writeScope",
2592
+ scopeIdIdentifier,
2593
+ import_compiler17.types.objectExpression(serializedProperties)
2593
2594
  );
2595
+ if (!isOptimize()) {
2596
+ let debugVars;
2597
+ forEach(section.bindings, (binding) => {
2598
+ let root = binding;
2599
+ let access = "";
2600
+ while (!root.loc && root.upstreamAlias) {
2601
+ if (root.property !== void 0) {
2602
+ access = toAccess(root.property) + access;
2603
+ }
2604
+ root = root.upstreamAlias;
2605
+ }
2606
+ if (root.loc) {
2607
+ const locStr = import_compiler17.types.stringLiteral(
2608
+ `${root.loc.start.line}:${root.loc.start.column + 1}`
2609
+ );
2610
+ (debugVars ||= []).push(
2611
+ import_compiler17.types.objectProperty(
2612
+ getScopeAccessorLiteral(binding),
2613
+ root !== binding ? import_compiler17.types.arrayExpression([
2614
+ import_compiler17.types.stringLiteral(root.name + access),
2615
+ locStr
2616
+ ]) : locStr
2617
+ )
2618
+ );
2619
+ }
2620
+ });
2621
+ writeScope2 = callRuntime(
2622
+ "debug",
2623
+ writeScope2,
2624
+ import_compiler17.types.stringLiteral(path5.hub.file.opts.filenameRelative),
2625
+ section.loc && section.loc.start.line != null ? import_compiler17.types.stringLiteral(
2626
+ `${section.loc.start.line}:${section.loc.start.column + 1}`
2627
+ ) : import_compiler17.types.numericLiteral(0),
2628
+ debugVars && import_compiler17.types.objectExpression(debugVars)
2629
+ );
2630
+ }
2631
+ path5.pushContainer("body", import_compiler17.types.expressionStatement(writeScope2));
2594
2632
  }
2595
2633
  const resumeClosestBranch2 = !section.isBranch && (section.hasAbortSignal || !!section.closures || !!find(section.bindings, (binding) => binding.type === 1 /* let */));
2596
2634
  if (resumeClosestBranch2) {
@@ -3204,12 +3242,13 @@ function withPreviousLocation(newNode, originalNode) {
3204
3242
  // src/translator/util/references.ts
3205
3243
  var [getBindings] = createProgramState(() => /* @__PURE__ */ new Set());
3206
3244
  var [getNextBindingId, setNextBindingId] = createProgramState(() => 0);
3207
- function createBinding(name2, type, section, upstreamAlias, upstreamExpression, property, declared = false) {
3245
+ function createBinding(name2, type, section, upstreamAlias, upstreamExpression, property, loc = null, declared = false) {
3208
3246
  const id = getNextBindingId();
3209
3247
  const binding = {
3210
3248
  id,
3211
3249
  name: name2,
3212
3250
  type,
3251
+ loc,
3213
3252
  section,
3214
3253
  property,
3215
3254
  declared,
@@ -3333,6 +3372,7 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
3333
3372
  upstreamAlias,
3334
3373
  upstreamExpression,
3335
3374
  property,
3375
+ lVal.loc,
3336
3376
  true
3337
3377
  );
3338
3378
  trackReferencesForBinding(scope.getBinding(lVal.name));
@@ -3344,7 +3384,8 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
3344
3384
  section,
3345
3385
  upstreamAlias,
3346
3386
  void 0,
3347
- property
3387
+ property,
3388
+ lVal.loc
3348
3389
  ));
3349
3390
  for (const prop of lVal.properties) {
3350
3391
  if (prop.type === "RestElement") {
@@ -3386,7 +3427,8 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
3386
3427
  section,
3387
3428
  upstreamAlias,
3388
3429
  void 0,
3389
- property
3430
+ property,
3431
+ lVal.loc
3390
3432
  ));
3391
3433
  let i = -1;
3392
3434
  for (const element of lVal.elements) {
@@ -7930,7 +7972,7 @@ var function_default = {
7930
7972
  const extra = node.extra ??= {};
7931
7973
  const name2 = extra.name = fn.node.id?.name || (isMarkoAttribute(markoRoot) ? markoRoot.node.default ? import_compiler47.types.toIdentifier(
7932
7974
  markoRoot.parentPath.has("var") ? markoRoot.parentPath.get("var") : markoRoot.parentPath.get("name")
7933
- ) : markoRoot.node.name : import_compiler47.types.isVariableDeclarator(fn.parent) && import_compiler47.types.isIdentifier(fn.parent.id) ? fn.parent.id.name : "anonymous");
7975
+ ) : markoRoot.node.name : import_compiler47.types.isVariableDeclarator(fn.parent) && import_compiler47.types.isIdentifier(fn.parent.id) ? fn.parent.id.name : import_compiler47.types.isObjectMethod(node) && import_compiler47.types.isIdentifier(node.key) ? node.key.name : "anonymous");
7934
7976
  if (isMarkoAttribute(markoRoot) && ((0, import_babel_utils37.isNativeTag)(markoRoot.parentPath) && /^on[A-Z-]/.test(markoRoot.node.name) || isCoreTagName(markoRoot.parentPath, "script") || isCoreTagName(markoRoot.parentPath, "lifecycle") || isCoreTagName(markoRoot.parentPath, "for"))) {
7935
7977
  return;
7936
7978
  }
@@ -7965,6 +8007,7 @@ function isFunction(fn, isStatic2) {
7965
8007
  return isStatic2 && !fn.node.declare;
7966
8008
  case "FunctionExpression":
7967
8009
  case "ArrowFunctionExpression":
8010
+ case "ObjectMethod":
7968
8011
  return true;
7969
8012
  default:
7970
8013
  return false;
@@ -15,6 +15,7 @@ export type Binding = {
15
15
  id: number;
16
16
  name: string;
17
17
  type: BindingType;
18
+ loc: t.SourceLocation | null;
18
19
  section: Section;
19
20
  serialize: boolean | Set<Binding>;
20
21
  aliases: Set<Binding>;
@@ -53,7 +54,7 @@ declare module "@marko/compiler/dist/types" {
53
54
  interface FunctionExpressionExtra extends FunctionExtra {
54
55
  }
55
56
  }
56
- export declare function createBinding(name: string, type: Binding["type"], section: Section, upstreamAlias?: Binding["upstreamAlias"], upstreamExpression?: Binding["upstreamExpression"], property?: string, declared?: boolean): Binding;
57
+ export declare function createBinding(name: string, type: Binding["type"], section: Section, upstreamAlias?: Binding["upstreamAlias"], upstreamExpression?: Binding["upstreamExpression"], property?: string, loc?: t.SourceLocation | null, declared?: boolean): Binding;
57
58
  export declare function trackVarReferences(tag: t.NodePath<t.MarkoTag>, type: BindingType, upstreamAlias?: Binding["upstreamAlias"], upstreamExpression?: Binding["upstreamExpression"]): void;
58
59
  export declare function trackParamsReferences(body: t.NodePath<t.MarkoTagBody | t.Program>, type: BindingType, upstreamAlias?: Binding["upstreamAlias"], upstreamExpression?: Binding["upstreamExpression"]): void;
59
60
  export declare function setReferencesScope(path: t.NodePath<any>): void;
@@ -10,6 +10,7 @@ export declare enum ContentType {
10
10
  export interface Section {
11
11
  id: number;
12
12
  name: string;
13
+ loc: t.SourceLocation | undefined;
13
14
  depth: number;
14
15
  parent: Section | undefined;
15
16
  params: undefined | Binding;
package/index.d.ts CHANGED
@@ -82,7 +82,7 @@ declare global {
82
82
  /** Render and attach the template to a DOM node. */
83
83
  abstract mount(
84
84
  input: Marko.TemplateInput<Input>,
85
- reference: ParentNode & Node,
85
+ reference: Node,
86
86
  position?: "afterbegin" | "afterend" | "beforebegin" | "beforeend",
87
87
  ): {
88
88
  update(input: Marko.TemplateInput<Input>): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.0-next.3.26",
3
+ "version": "6.0.0-next.3.28",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",
@@ -48,7 +48,7 @@
48
48
  "build": "node -r ~ts ./scripts/bundle.ts"
49
49
  },
50
50
  "dependencies": {
51
- "@marko/compiler": "^5.39.11",
51
+ "@marko/compiler": "^5.39.12",
52
52
  "csstype": "^3.1.3",
53
53
  "magic-string": "^0.30.17"
54
54
  },