@marko/runtime-tags 6.0.140 → 6.0.141

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/debug/dom.js CHANGED
@@ -604,6 +604,11 @@ function _closure(...closureSignals) {
604
604
  function _closure_get(valueAccessor, fn, getOwnerScope, resumeId) {
605
605
  if (false) valueAccessor = decodeAccessor(valueAccessor);
606
606
  const closureSignal = ((scope) => {
607
+ if (true) {
608
+ if (!(valueAccessor in (getOwnerScope ? getOwnerScope(scope) : scope["_" /* Owner */]))) {
609
+ throwUninitialized(valueAccessor);
610
+ }
611
+ }
607
612
  scope[closureSignal.___signalIndexAccessor] = closureSignal.___index;
608
613
  fn(scope);
609
614
  subscribeToScopeSet(
@@ -688,6 +693,16 @@ function _hoist(...path) {
688
693
  function _hoist_resume(id, ...path) {
689
694
  return _resume(id, _hoist(...path));
690
695
  }
696
+ function throwUninitialized(name) {
697
+ try {
698
+ __UNINITIALIZED__;
699
+ let __UNINITIALIZED__;
700
+ } catch (err) {
701
+ err.message = err.message.replaceAll("__UNINITIALIZED__", name);
702
+ throw err;
703
+ }
704
+ throw new ReferenceError(`Cannot access '${name}' before initialization`);
705
+ }
691
706
 
692
707
  // src/dom/walker.ts
693
708
  var walker = /* @__PURE__ */ document.createTreeWalker(document);
@@ -1421,8 +1436,9 @@ function _attrs_partial(scope, nodeAccessor, nextAttrs, skip) {
1421
1436
  el.removeAttribute(name);
1422
1437
  }
1423
1438
  }
1424
- for (const key in nextAttrs) {
1425
- if (!skip[key]) partial[key] = nextAttrs[key];
1439
+ for (const name in nextAttrs) {
1440
+ const key = isEventHandler(name) ? `on-${getEventHandlerName(name)}` : name;
1441
+ if (!skip[key]) partial[key] = nextAttrs[name];
1426
1442
  }
1427
1443
  if (true) {
1428
1444
  assertExclusiveAttrs({ ...nextAttrs, ...skip });
@@ -497,6 +497,11 @@ function _closure(...closureSignals) {
497
497
  function _closure_get(valueAccessor, fn, getOwnerScope, resumeId) {
498
498
  if (false) valueAccessor = decodeAccessor(valueAccessor);
499
499
  const closureSignal = ((scope) => {
500
+ if (true) {
501
+ if (!(valueAccessor in (getOwnerScope ? getOwnerScope(scope) : scope["_" /* Owner */]))) {
502
+ throwUninitialized(valueAccessor);
503
+ }
504
+ }
500
505
  scope[closureSignal.___signalIndexAccessor] = closureSignal.___index;
501
506
  fn(scope);
502
507
  subscribeToScopeSet(
@@ -581,6 +586,16 @@ function _hoist(...path) {
581
586
  function _hoist_resume(id, ...path) {
582
587
  return _resume(id, _hoist(...path));
583
588
  }
589
+ function throwUninitialized(name) {
590
+ try {
591
+ __UNINITIALIZED__;
592
+ let __UNINITIALIZED__;
593
+ } catch (err) {
594
+ err.message = err.message.replaceAll("__UNINITIALIZED__", name);
595
+ throw err;
596
+ }
597
+ throw new ReferenceError(`Cannot access '${name}' before initialization`);
598
+ }
584
599
 
585
600
  // src/dom/walker.ts
586
601
  var walker = /* @__PURE__ */ document.createTreeWalker(document);
@@ -1314,8 +1329,9 @@ function _attrs_partial(scope, nodeAccessor, nextAttrs, skip) {
1314
1329
  el.removeAttribute(name);
1315
1330
  }
1316
1331
  }
1317
- for (const key in nextAttrs) {
1318
- if (!skip[key]) partial[key] = nextAttrs[key];
1332
+ for (const name in nextAttrs) {
1333
+ const key = isEventHandler(name) ? `on-${getEventHandlerName(name)}` : name;
1334
+ if (!skip[key]) partial[key] = nextAttrs[name];
1319
1335
  }
1320
1336
  if (true) {
1321
1337
  assertExclusiveAttrs({ ...nextAttrs, ...skip });
@@ -3060,8 +3060,9 @@ function _attrs_content(data, nodeAccessor, scopeId, tagName, serializeReason) {
3060
3060
  }
3061
3061
  function _attrs_partial(data, skip, nodeAccessor, scopeId, tagName) {
3062
3062
  const partial = {};
3063
- for (const key in data) {
3064
- if (!skip[key]) partial[key] = data[key];
3063
+ for (const name in data) {
3064
+ const key = isEventHandler(name) ? `on-${getEventHandlerName(name)}` : name;
3065
+ if (!skip[key]) partial[key] = data[name];
3065
3066
  }
3066
3067
  return _attrs(partial, nodeAccessor, scopeId, tagName);
3067
3068
  }
@@ -2967,8 +2967,9 @@ function _attrs_content(data, nodeAccessor, scopeId, tagName, serializeReason) {
2967
2967
  }
2968
2968
  function _attrs_partial(data, skip, nodeAccessor, scopeId, tagName) {
2969
2969
  const partial = {};
2970
- for (const key in data) {
2971
- if (!skip[key]) partial[key] = data[key];
2970
+ for (const name in data) {
2971
+ const key = isEventHandler(name) ? `on-${getEventHandlerName(name)}` : name;
2972
+ if (!skip[key]) partial[key] = data[name];
2972
2973
  }
2973
2974
  return _attrs(partial, nodeAccessor, scopeId, tagName);
2974
2975
  }
package/dist/dom.js CHANGED
@@ -886,8 +886,10 @@ function _attrs_partial(scope, nodeAccessor, nextAttrs, skip) {
886
886
  let { name } = el.attributes.item(i);
887
887
  !skip[name] && !(nextAttrs && name in nextAttrs) && el.removeAttribute(name);
888
888
  }
889
- for (let key in nextAttrs)
890
- skip[key] || (partial[key] = nextAttrs[key]);
889
+ for (let name in nextAttrs) {
890
+ let key = isEventHandler(name) ? `on-${getEventHandlerName(name)}` : name;
891
+ skip[key] || (partial[key] = nextAttrs[name]);
892
+ }
891
893
  attrsInternal(scope, nodeAccessor, partial);
892
894
  }
893
895
  function _attrs_partial_content(scope, nodeAccessor, nextAttrs, skip) {
package/dist/dom.mjs CHANGED
@@ -782,8 +782,10 @@ function _attrs_partial(scope, nodeAccessor, nextAttrs, skip) {
782
782
  let { name } = el.attributes.item(i);
783
783
  !skip[name] && !(nextAttrs && name in nextAttrs) && el.removeAttribute(name);
784
784
  }
785
- for (let key in nextAttrs)
786
- skip[key] || (partial[key] = nextAttrs[key]);
785
+ for (let name in nextAttrs) {
786
+ let key = isEventHandler(name) ? `on-${getEventHandlerName(name)}` : name;
787
+ skip[key] || (partial[key] = nextAttrs[name]);
788
+ }
787
789
  attrsInternal(scope, nodeAccessor, partial);
788
790
  }
789
791
  function _attrs_partial_content(scope, nodeAccessor, nextAttrs, skip) {
package/dist/html.js CHANGED
@@ -1910,8 +1910,10 @@ function _attrs_content(data, nodeAccessor, scopeId, tagName, serializeReason) {
1910
1910
  }
1911
1911
  function _attrs_partial(data, skip, nodeAccessor, scopeId, tagName) {
1912
1912
  let partial = {};
1913
- for (let key in data)
1914
- skip[key] || (partial[key] = data[key]);
1913
+ for (let name in data) {
1914
+ let key = isEventHandler(name) ? `on-${getEventHandlerName(name)}` : name;
1915
+ skip[key] || (partial[key] = data[name]);
1916
+ }
1915
1917
  return _attrs(partial, nodeAccessor, scopeId, tagName);
1916
1918
  }
1917
1919
  function _attrs_partial_content(data, skip, nodeAccessor, scopeId, tagName, serializeReason) {
package/dist/html.mjs CHANGED
@@ -1820,8 +1820,10 @@ function _attrs_content(data, nodeAccessor, scopeId, tagName, serializeReason) {
1820
1820
  }
1821
1821
  function _attrs_partial(data, skip, nodeAccessor, scopeId, tagName) {
1822
1822
  let partial = {};
1823
- for (let key in data)
1824
- skip[key] || (partial[key] = data[key]);
1823
+ for (let name in data) {
1824
+ let key = isEventHandler(name) ? `on-${getEventHandlerName(name)}` : name;
1825
+ skip[key] || (partial[key] = data[name]);
1826
+ }
1825
1827
  return _attrs(partial, nodeAccessor, scopeId, tagName);
1826
1828
  }
1827
1829
  function _attrs_partial_content(data, skip, nodeAccessor, scopeId, tagName, serializeReason) {
@@ -1762,6 +1762,7 @@ function startSection(path7) {
1762
1762
  upstreamExpression: void 0,
1763
1763
  downstreamBinding: void 0,
1764
1764
  hasAbortSignal: false,
1765
+ readsOwner: false,
1765
1766
  isBranch: false
1766
1767
  };
1767
1768
  sections.push(section);
@@ -3754,6 +3755,9 @@ function getSignalFn(signal) {
3754
3755
  )
3755
3756
  );
3756
3757
  }
3758
+ if (isValue && getSerializeReason(section, binding)) {
3759
+ signal.hasSideEffect = true;
3760
+ }
3757
3761
  if (!signal.hasSideEffect) {
3758
3762
  return import_compiler22.types.arrowFunctionExpression(
3759
3763
  isValue ? [scopeIdentifier, getSignalValueIdentifier(signal)] : [scopeIdentifier],
@@ -3933,6 +3937,7 @@ function getResumeRegisterId(section, referencedBindings, type) {
3933
3937
  }
3934
3938
  function writeSignals(section) {
3935
3939
  const seen = /* @__PURE__ */ new Set();
3940
+ const written = /* @__PURE__ */ new Set();
3936
3941
  writeGetters(section);
3937
3942
  for (const signal of getSignals(section).values()) {
3938
3943
  writeSignal(signal);
@@ -4002,7 +4007,9 @@ function writeSignals(section) {
4002
4007
  signalStatements.push(signalDeclaration);
4003
4008
  }
4004
4009
  (0, import_babel_utils15.getProgram)().node.body.push(...signalStatements);
4010
+ written.add(signal);
4005
4011
  }
4012
+ return written;
4006
4013
  }
4007
4014
  function writeGetters(section) {
4008
4015
  forEach(section.bindings, (binding) => {
@@ -4295,7 +4302,7 @@ function writeHTMLResumeStatements(path7) {
4295
4302
  }
4296
4303
  }
4297
4304
  function getSetup(section) {
4298
- return section.hoistedTo ? getSignal(section, void 0).identifier : getSignals(section).get(void 0)?.identifier;
4305
+ return section.hoistedTo ? getSignal(section, void 0) : getSignals(section).get(void 0);
4299
4306
  }
4300
4307
  function replaceRenderNode(node, signal) {
4301
4308
  return replaceAssignedNode(node) || replaceBindingReadNode(node, signal) || replaceRegisteredFunctionNode(node);
@@ -4512,21 +4519,8 @@ function getRegisteredFnExpression(node) {
4512
4519
  // src/translator/visitors/program/dom.ts
4513
4520
  var dom_default = {
4514
4521
  translate: {
4515
- exit(program) {
4516
- forEachSectionReverse(getSectionMeta);
4522
+ enter(program) {
4517
4523
  const section = getSectionForBody(program);
4518
- const { walks, writes, decls } = getSectionMeta(section);
4519
- const domExports = program.node.extra.domExports;
4520
- const templateIdentifier = import_compiler23.types.identifier(domExports.template);
4521
- const walksIdentifier = import_compiler23.types.identifier(domExports.walks);
4522
- const setupIdentifier = import_compiler23.types.identifier(domExports.setup);
4523
- const inputBinding = program.node.params[0].extra?.binding;
4524
- const programInputSignal = inputBinding && !inputBinding.pruned ? initValue(inputBinding) : void 0;
4525
- let extraDecls = decls;
4526
- const styleFile = getStyleFile(program.hub.file);
4527
- if (styleFile) {
4528
- (0, import_babel_utils16.importDefault)(program.hub.file, styleFile);
4529
- }
4530
4524
  forEachSectionReverse((childSection) => {
4531
4525
  if (childSection !== section) {
4532
4526
  forEach(childSection.referencedClosures, (closure) => {
@@ -4550,11 +4544,32 @@ var dom_default = {
4550
4544
  }
4551
4545
  }
4552
4546
  });
4547
+ }
4548
+ });
4549
+ },
4550
+ exit(program) {
4551
+ forEachSectionReverse(getSectionMeta);
4552
+ const section = getSectionForBody(program);
4553
+ const { walks, writes, decls } = getSectionMeta(section);
4554
+ const domExports = program.node.extra.domExports;
4555
+ const templateIdentifier = import_compiler23.types.identifier(domExports.template);
4556
+ const walksIdentifier = import_compiler23.types.identifier(domExports.walks);
4557
+ const setupIdentifier = import_compiler23.types.identifier(domExports.setup);
4558
+ const inputBinding = program.node.params[0].extra?.binding;
4559
+ const programInputSignal = inputBinding && !inputBinding.pruned ? initValue(inputBinding) : void 0;
4560
+ let extraDecls = decls;
4561
+ const styleFile = getStyleFile(program.hub.file);
4562
+ if (styleFile) {
4563
+ (0, import_babel_utils16.importDefault)(program.hub.file, styleFile);
4564
+ }
4565
+ forEachSectionReverse((childSection) => {
4566
+ if (childSection !== section) {
4553
4567
  const tagParamsSignal = childSection.params && initValue(childSection.params);
4554
4568
  const tagParamsIdentifier = tagParamsSignal && signalHasStatements(tagParamsSignal) ? tagParamsSignal.identifier : void 0;
4555
4569
  const { walks: walks2, writes: writes2, decls: decls2 } = getSectionMeta(childSection);
4556
4570
  const setup = getSetup(childSection);
4557
- writeSignals(childSection);
4571
+ const written = writeSignals(childSection);
4572
+ const setupIdentifier2 = setup && written.has(setup) ? setup.identifier : void 0;
4558
4573
  if (!childSection.downstreamBinding || bindingHasProperty(
4559
4574
  childSection.downstreamBinding.binding,
4560
4575
  childSection.downstreamBinding.properties
@@ -4563,7 +4578,7 @@ var dom_default = {
4563
4578
  setBranchRendererArgs(childSection, [
4564
4579
  writes2,
4565
4580
  walks2,
4566
- setup,
4581
+ setupIdentifier2,
4567
4582
  tagParamsIdentifier
4568
4583
  ]);
4569
4584
  } else {
@@ -4573,7 +4588,7 @@ var dom_default = {
4573
4588
  ...replaceNullishAndEmptyFunctionsWith0([
4574
4589
  writes2,
4575
4590
  walks2,
4576
- setup,
4591
+ setupIdentifier2,
4577
4592
  tagParamsIdentifier,
4578
4593
  childSection.hoisted || childSection.isHoistThrough ? getSectionInstancesAccessorLiteral(childSection) : void 0
4579
4594
  ])
@@ -5279,6 +5294,8 @@ var program_default = {
5279
5294
  }
5280
5295
  if (isOutputHTML()) {
5281
5296
  html_default.translate.enter();
5297
+ } else {
5298
+ dom_default.translate.enter(program);
5282
5299
  }
5283
5300
  },
5284
5301
  exit(program) {
@@ -6299,10 +6316,10 @@ function getUsedAttrs(tagName, tag) {
6299
6316
  const seen = {};
6300
6317
  const { attributes } = tag;
6301
6318
  const maybeStaticAttrs = /* @__PURE__ */ new Set();
6319
+ const skipProps = /* @__PURE__ */ new Set();
6302
6320
  let spreadExpression;
6303
6321
  let skipExpression;
6304
6322
  let spreadProps;
6305
- let skipProps;
6306
6323
  let staticControllable;
6307
6324
  let staticContentAttr;
6308
6325
  let injectNonce = isInjectNonceTag(tagName);
@@ -6356,14 +6373,16 @@ function getUsedAttrs(tagName, tag) {
6356
6373
  if (staticControllable) {
6357
6374
  for (const attr of staticControllable.attrs) {
6358
6375
  if (attr) {
6359
- (skipProps ||= []).push(
6360
- toObjectProperty(attr.name, import_compiler32.types.numericLiteral(1))
6361
- );
6376
+ skipProps.add(attr.name);
6362
6377
  }
6363
6378
  }
6364
6379
  }
6365
6380
  for (const { name: name2 } of staticAttrs) {
6366
- (skipProps ||= []).push(toObjectProperty(name2, import_compiler32.types.numericLiteral(1)));
6381
+ if (isEventHandler(name2)) {
6382
+ skipProps.add(`on-${getEventHandlerName(name2)}`);
6383
+ } else {
6384
+ skipProps.add(name2);
6385
+ }
6367
6386
  }
6368
6387
  if (injectNonce) {
6369
6388
  injectNonce = false;
@@ -6379,8 +6398,13 @@ function getUsedAttrs(tagName, tag) {
6379
6398
  }
6380
6399
  spreadExpression = propsToExpression(spreadProps.reverse());
6381
6400
  }
6382
- if (skipProps) {
6383
- skipExpression = import_compiler32.types.objectExpression(skipProps);
6401
+ if (skipProps.size) {
6402
+ skipExpression = import_compiler32.types.objectExpression(
6403
+ Array.from(
6404
+ skipProps,
6405
+ (name2) => toObjectProperty(name2, import_compiler32.types.numericLiteral(1))
6406
+ )
6407
+ );
6384
6408
  }
6385
6409
  return {
6386
6410
  injectNonce,
@@ -8576,6 +8600,7 @@ function trackDomVarReferences(tag, binding) {
8576
8600
  } : void 0
8577
8601
  );
8578
8602
  if (refSection !== binding.section) {
8603
+ setReadsOwner(refSection, section);
8579
8604
  addOwnerSerializeReason(refSection, section, true);
8580
8605
  }
8581
8606
  }
@@ -9012,10 +9037,10 @@ function finalizeReferences() {
9012
9037
  const { name: name2, section } = binding;
9013
9038
  if (binding.type !== 0 /* dom */) {
9014
9039
  resolveBindingSources(binding);
9015
- forEach(
9016
- binding.assignmentSections,
9017
- (assignedSection) => addOwnerSerializeReason(assignedSection, section, true)
9018
- );
9040
+ forEach(binding.assignmentSections, (assignedSection) => {
9041
+ setReadsOwner(assignedSection, section);
9042
+ addOwnerSerializeReason(assignedSection, section, true);
9043
+ });
9019
9044
  if (find(section.bindings, ({ name: name3 }) => name3 === binding.name)) {
9020
9045
  binding.name = generateUid(name2);
9021
9046
  }
@@ -9063,6 +9088,7 @@ function finalizeReferences() {
9063
9088
  section2.referencedClosures,
9064
9089
  canonicalUpstreamAlias
9065
9090
  );
9091
+ setReadsOwner(section2, canonicalUpstreamAlias.section);
9066
9092
  addOwnerSerializeReason(
9067
9093
  section2,
9068
9094
  canonicalUpstreamAlias.section,
@@ -9077,6 +9103,7 @@ function finalizeReferences() {
9077
9103
  addSerializeReason(section, true);
9078
9104
  }
9079
9105
  forEach(section.referencedHoists, (hoistedBinding) => {
9106
+ setReadsOwner(section, hoistedBinding.section);
9080
9107
  addOwnerSerializeReason(section, hoistedBinding.section, true);
9081
9108
  });
9082
9109
  if (section.parent && section.isBranch && section.sectionAccessor && section.upstreamExpression) {
@@ -10052,6 +10079,13 @@ function addNumericPropertiesUntil(props, len) {
10052
10079
  }
10053
10080
  return result;
10054
10081
  }
10082
+ function setReadsOwner(from, to) {
10083
+ let cur = from;
10084
+ while (cur !== to && cur.parent) {
10085
+ cur.readsOwner = true;
10086
+ cur = cur.parent;
10087
+ }
10088
+ }
10055
10089
 
10056
10090
  // src/translator/core/await.ts
10057
10091
  var kDOMBinding = Symbol("await tag dom binding");
@@ -12606,7 +12640,7 @@ var dynamic_tag_default = {
12606
12640
  knownTagTranslateDOM(
12607
12641
  tag,
12608
12642
  propTree,
12609
- (binding, preferedName) => getSignal(definedBodySection, binding, preferedName).identifier,
12643
+ (binding, preferredName) => getSignal(definedBodySection, binding, preferredName).identifier,
12610
12644
  (section, childBinding) => {
12611
12645
  const signal = getSignal(definedBodySection, void 0);
12612
12646
  if (signalHasStatements(signal)) {
@@ -12624,6 +12658,22 @@ var dynamic_tag_default = {
12624
12658
  )
12625
12659
  )
12626
12660
  );
12661
+ } else if (definedBodySection.readsOwner) {
12662
+ addStatement(
12663
+ "render",
12664
+ section,
12665
+ void 0,
12666
+ import_compiler62.types.expressionStatement(
12667
+ import_compiler62.types.assignmentExpression(
12668
+ "=",
12669
+ toMemberExpression(
12670
+ createScopeReadExpression(childBinding, section),
12671
+ getAccessorProp().Owner
12672
+ ),
12673
+ getScopeExpression(section, definedBodySection.parent)
12674
+ )
12675
+ )
12676
+ );
12627
12677
  }
12628
12678
  }
12629
12679
  );
@@ -46,6 +46,7 @@ export interface Section {
46
46
  properties: Opt<string>;
47
47
  } | undefined;
48
48
  hasAbortSignal: boolean;
49
+ readsOwner: boolean;
49
50
  isBranch: boolean;
50
51
  content: null | {
51
52
  startType: ContentType;
@@ -45,10 +45,10 @@ export declare function addStatement(type: "render" | "effect", targetSection: S
45
45
  export declare function addValue(targetSection: Section, referencedBindings: ReferencedBindings, signal: Signal, value: t.Expression): void;
46
46
  export declare function getResumeRegisterId(section: Section, referencedBindings: string | ReferencedBindings, type?: string): string;
47
47
  export declare function getRegisterUID(section: Section, name: string): string;
48
- export declare function writeSignals(section: Section): void;
48
+ export declare function writeSignals(section: Section): Set<Signal>;
49
49
  export declare function writeRegisteredFns(): void;
50
50
  export declare function addHTMLEffectCall(section: Section, referencedBindings?: ReferencedBindings): void;
51
51
  export declare function writeHTMLResumeStatements(path: t.NodePath<t.MarkoTagBody | t.Program>): void;
52
- export declare function getSetup(section: Section): t.Identifier | undefined;
52
+ export declare function getSetup(section: Section): Signal | undefined;
53
53
  export declare function replaceRegisteredFunctionNode(node: t.Node): t.CallExpression | t.ClassPrivateProperty | t.ClassProperty | t.VariableDeclaration | t.Identifier | t.ObjectProperty | undefined;
54
54
  export {};
@@ -1,6 +1,7 @@
1
1
  import { types as t } from "@marko/compiler";
2
2
  declare const _default: {
3
3
  translate: {
4
+ enter(this: unknown, program: t.NodePath<t.Program>): void;
4
5
  exit(this: unknown, program: t.NodePath<t.Program>): void;
5
6
  };
6
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marko/runtime-tags",
3
- "version": "6.0.140",
3
+ "version": "6.0.141",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",