marko 6.0.1 → 6.0.2

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.
@@ -1518,6 +1518,22 @@ var reasonExprs = /* @__PURE__ */ new WeakMap();
1518
1518
  var keyedReasonExprs = /* @__PURE__ */ new WeakMap();
1519
1519
  var serializeKeysByBinding = /* @__PURE__ */ new WeakMap();
1520
1520
  var serializeKeyBySourceModifier = {};
1521
+ function forceOwnersSerialize(from, to, prop) {
1522
+ let cur = from;
1523
+ while (cur !== to && cur.parent) {
1524
+ forceSectionSerialize(cur, prop);
1525
+ cur = cur.parent;
1526
+ }
1527
+ }
1528
+ function addOwnersSerializeReason(from, to, reason, prop) {
1529
+ if (reason) {
1530
+ let cur = from;
1531
+ while (cur !== to && cur.parent) {
1532
+ addSectionSerializeReason(cur, reason, prop);
1533
+ cur = cur.parent;
1534
+ }
1535
+ }
1536
+ }
1521
1537
  function forceSectionSerialize(section, prop) {
1522
1538
  if (prop) {
1523
1539
  forceSerializeKey(section, getSectionPropSerializeReasonKey(section, prop));
@@ -1961,7 +1977,6 @@ function startSection(path5) {
1961
1977
  bindings: void 0,
1962
1978
  hoisted: void 0,
1963
1979
  isHoistThrough: void 0,
1964
- assignments: void 0,
1965
1980
  serializeReason: void 0,
1966
1981
  serializeReasons: /* @__PURE__ */ new Map(),
1967
1982
  content: getContentInfo(path5),
@@ -2105,9 +2120,6 @@ var isSerializedSection = (section) => {
2105
2120
  }
2106
2121
  return true;
2107
2122
  };
2108
- function isSectionWithHoists(section) {
2109
- return !!(section.hoisted || section.isHoistThrough || section.referencedHoists);
2110
- }
2111
2123
  function isImmediateOwner(section, binding) {
2112
2124
  return section.parent?.id === binding.section.id;
2113
2125
  }
@@ -2811,7 +2823,7 @@ var return_default = {
2811
2823
  }
2812
2824
  if (attrs2.valueChange) {
2813
2825
  forceSectionSerialize(
2814
- getSection(tag),
2826
+ getOrCreateSection(tag),
2815
2827
  getAccessorProp().TagVariableChange
2816
2828
  );
2817
2829
  }
@@ -3588,12 +3600,8 @@ function writeHTMLResumeStatements(path5) {
3588
3600
  const body = path5.node.body;
3589
3601
  const allSignals = Array.from(getSignals(section).values());
3590
3602
  const scopeIdIdentifier = getScopeIdIdentifier(section);
3591
- const serializeOwnersUntilBinding = (binding) => serializeOwners(section, binding.section);
3592
- forEach(section.assignments, serializeOwnersUntilBinding);
3593
- forEach(section.referencedHoists, serializeOwnersUntilBinding);
3594
3603
  forEach(section.referencedClosures, (closure) => {
3595
3604
  if (closure.sources) {
3596
- serializeOwnersUntilBinding(closure);
3597
3605
  if (isDynamicClosure(section, closure)) {
3598
3606
  const closureSignal = getSignal(closure.section, closure);
3599
3607
  let identifier = htmlDynamicClosureInstancesIdentifier.get(closureSignal);
@@ -3722,6 +3730,23 @@ function writeHTMLResumeStatements(path5) {
3722
3730
  )
3723
3731
  );
3724
3732
  });
3733
+ if (section.parent) {
3734
+ const ownerAccessor = getAccessorProp().Owner;
3735
+ const ownerReason = getSectionSerializeReason(section, ownerAccessor);
3736
+ if (ownerReason) {
3737
+ const getOwnerExpr = callRuntime(
3738
+ "ensureScopeWithId",
3739
+ getScopeIdIdentifier(section.parent)
3740
+ );
3741
+ serializedLookup.delete(ownerAccessor);
3742
+ serializedProperties.push(
3743
+ toObjectProperty(
3744
+ ownerAccessor,
3745
+ sectionSerializeReason && (sectionSerializeReason === ownerReason || sectionSerializeReason !== true && ownerReason !== true && compareSerializeReasons(sectionSerializeReason, ownerReason) === 0) ? getOwnerExpr : getExprIfSerialized(ownerReason, getOwnerExpr)
3746
+ )
3747
+ );
3748
+ }
3749
+ }
3725
3750
  for (const [key, { expression, reason }] of serializedLookup) {
3726
3751
  serializedProperties.push(
3727
3752
  toObjectProperty(key, getExprIfSerialized(reason, expression))
@@ -3806,23 +3831,6 @@ function writeHTMLResumeStatements(path5) {
3806
3831
  body.push(import_compiler20.types.returnStatement(returnIdentifier));
3807
3832
  }
3808
3833
  }
3809
- function serializeOwners(from, to) {
3810
- const ownerProp = getAccessorProp().Owner;
3811
- let cur = from;
3812
- while (cur !== to) {
3813
- const parent = cur.parent;
3814
- if (!parent) break;
3815
- const serialized = getSerializedAccessors(cur);
3816
- nonAnalyzedForceSerializedSection.add(cur);
3817
- cur = parent;
3818
- if (!serialized.has(ownerProp)) {
3819
- serialized.set(ownerProp, {
3820
- expression: callRuntime("ensureScopeWithId", getScopeIdIdentifier(cur)),
3821
- reason: true
3822
- });
3823
- }
3824
- }
3825
- }
3826
3834
  function getSetup(section) {
3827
3835
  return getSignals(section).get(void 0)?.identifier;
3828
3836
  }
@@ -4321,6 +4329,7 @@ function createBinding(name2, type, section, upstreamAlias, property, loc = null
4321
4329
  property,
4322
4330
  declared,
4323
4331
  closureSections: void 0,
4332
+ assignmentSections: void 0,
4324
4333
  excludeProperties: void 0,
4325
4334
  serializeSources: void 0,
4326
4335
  sources: void 0,
@@ -4418,7 +4427,6 @@ function trackHoistedReference(referencePath, binding) {
4418
4427
  currentSection = currentSection.parent;
4419
4428
  }
4420
4429
  }
4421
- extra.hoistedBinding = hoistedBinding;
4422
4430
  if (isInvokedFunction(referencePath)) {
4423
4431
  extra.read = createRead(hoistedBinding, void 0);
4424
4432
  extra.section = referenceSection;
@@ -4461,7 +4469,10 @@ function trackAssignment(assignment, binding) {
4461
4469
  forEachIdentifier(assignment.node, (id) => {
4462
4470
  if (id.name === binding.name) {
4463
4471
  const extra = id.extra ??= {};
4464
- section.assignments = bindingUtil.add(section.assignments, binding);
4472
+ binding.assignmentSections = sectionUtil.add(
4473
+ binding.assignmentSections,
4474
+ section
4475
+ );
4465
4476
  extra.assignment = binding;
4466
4477
  extra.section = section;
4467
4478
  }
@@ -4707,6 +4718,10 @@ function finalizeReferences() {
4707
4718
  if (binding.hoists.size) {
4708
4719
  forceBindingSerialize(binding.section, binding);
4709
4720
  }
4721
+ forEach(
4722
+ binding.assignmentSections,
4723
+ (assignedSection) => forceOwnersSerialize(assignedSection, section, getAccessorProp().Owner)
4724
+ );
4710
4725
  if (find(section.bindings, ({ name: name3 }) => name3 === binding.name)) {
4711
4726
  binding.name = generateUid(name2);
4712
4727
  }
@@ -4726,6 +4741,12 @@ function finalizeReferences() {
4726
4741
  section2.referencedClosures,
4727
4742
  binding
4728
4743
  );
4744
+ addOwnersSerializeReason(
4745
+ section2,
4746
+ binding.section,
4747
+ binding.serializeSources,
4748
+ getAccessorProp().Owner
4749
+ );
4729
4750
  }
4730
4751
  if (isEffect) {
4731
4752
  forEach(
@@ -4736,9 +4757,16 @@ function finalizeReferences() {
4736
4757
  }
4737
4758
  }
4738
4759
  forEachSection((section) => {
4739
- if (isSectionWithHoists(section)) {
4760
+ if (section.isHoistThrough) {
4740
4761
  forceSectionSerialize(section);
4741
4762
  }
4763
+ forEach(section.referencedHoists, (hoistedBinding) => {
4764
+ forceOwnersSerialize(
4765
+ section,
4766
+ hoistedBinding.section,
4767
+ getAccessorProp().Owner
4768
+ );
4769
+ });
4742
4770
  if (section.parent && section.isBranch && section.sectionAccessor && section.upstreamExpression) {
4743
4771
  addSectionSerializeReasonRef(section, getDirectClosures(section));
4744
4772
  addSectionSerializeReasonExpr(section, section.upstreamExpression);
@@ -5756,22 +5784,27 @@ var native_tag_default = {
5756
5784
  );
5757
5785
  }
5758
5786
  if (node.var) {
5759
- forceSectionSerialize(tagSection);
5760
5787
  forceBindingSerialize(tagSection, nodeBinding);
5761
- const varBinding = tag.scope.getBinding(node.var.name);
5762
- for (const referencePath of varBinding.referencePaths) {
5763
- const referenceSection = getSection(referencePath);
5764
- setReferencesScope(referencePath);
5765
- if (!isSameOrChildSection(tagSection, referenceSection)) {
5788
+ for (const ref of tag.scope.getBinding(node.var.name).referencePaths) {
5789
+ const refSection = getOrCreateSection(ref);
5790
+ setReferencesScope(ref);
5791
+ if (isSameOrChildSection(tagSection, refSection)) {
5792
+ forceOwnersSerialize(
5793
+ refSection,
5794
+ tagSection,
5795
+ getAccessorProp().Owner
5796
+ );
5797
+ if (!isInvokedFunction(ref)) {
5798
+ tagExtra[kGetterId] ||= getRegisterUID(
5799
+ tagSection,
5800
+ nodeBinding.name
5801
+ );
5802
+ }
5803
+ } else {
5766
5804
  trackHoistedReference(
5767
- referencePath,
5805
+ ref,
5768
5806
  nodeBinding
5769
5807
  );
5770
- } else if (!isInvokedFunction(referencePath)) {
5771
- tagExtra[kGetterId] ||= getRegisterUID(
5772
- tagSection,
5773
- nodeBinding.name
5774
- );
5775
5808
  }
5776
5809
  }
5777
5810
  } else if (hasEventHandlers || spreadReferenceNodes) {
@@ -5804,12 +5837,6 @@ var native_tag_default = {
5804
5837
  const varBinding = tag.scope.getBinding(varName);
5805
5838
  const getterId = tagExtra[kGetterId];
5806
5839
  if (isHTML) {
5807
- for (const reference of varBinding.referencePaths) {
5808
- const referenceSection = getSection(reference);
5809
- if (!reference.node.extra?.hoist) {
5810
- serializeOwners(referenceSection, tagSection);
5811
- }
5812
- }
5813
5840
  translateVar(
5814
5841
  tag,
5815
5842
  callRuntime(
@@ -5838,8 +5865,8 @@ var native_tag_default = {
5838
5865
  );
5839
5866
  }
5840
5867
  for (const reference of varBinding.referencePaths) {
5841
- if (!reference.node.extra?.hoistedBinding) {
5842
- const referenceSection = getSection(reference);
5868
+ const referenceSection = getSection(reference);
5869
+ if (isSameOrChildSection(tagSection, referenceSection)) {
5843
5870
  if (isInvokedFunction(reference)) {
5844
5871
  reference.parentPath.replaceWith(
5845
5872
  import_compiler31.types.expressionStatement(
@@ -7347,9 +7374,19 @@ var html_script_default = {
7347
7374
  if (node.var) {
7348
7375
  forceBindingSerialize(tagSection, nodeBinding);
7349
7376
  for (const ref of tag.scope.getBinding(node.var.name).referencePaths) {
7350
- if (!isInvokedFunction(ref)) {
7351
- tagExtra[kGetterId3] = getRegisterUID(tagSection, "#script");
7352
- break;
7377
+ const refSection = getOrCreateSection(ref);
7378
+ setReferencesScope(ref);
7379
+ if (isSameOrChildSection(tagSection, refSection)) {
7380
+ forceOwnersSerialize(
7381
+ refSection,
7382
+ tagSection,
7383
+ getAccessorProp().Owner
7384
+ );
7385
+ if (!tagExtra[kGetterId3] && !isInvokedFunction(ref)) {
7386
+ tagExtra[kGetterId3] = getRegisterUID(tagSection, "#script");
7387
+ }
7388
+ } else {
7389
+ trackHoistedReference(ref, nodeBinding);
7353
7390
  }
7354
7391
  }
7355
7392
  } else if (hasEventHandlers || spreadReferenceNodes) {
@@ -7374,11 +7411,6 @@ var html_script_default = {
7374
7411
  if (hasVar) {
7375
7412
  const getterId = tagExtra[kGetterId3];
7376
7413
  if (isHTML) {
7377
- const varName = tag.node.var.name;
7378
- const references = tag.scope.getBinding(varName).referencePaths;
7379
- for (const reference of references) {
7380
- serializeOwners(getSection(reference), tagSection);
7381
- }
7382
7414
  translateVar(
7383
7415
  tag,
7384
7416
  callRuntime(
@@ -7754,9 +7786,19 @@ var html_style_default = {
7754
7786
  if (node.var) {
7755
7787
  forceBindingSerialize(tagSection, nodeBinding);
7756
7788
  for (const ref of tag.scope.getBinding(node.var.name).referencePaths) {
7757
- if (!isInvokedFunction(ref)) {
7758
- tagExtra[kGetterId4] = getRegisterUID(tagSection, "#style");
7759
- break;
7789
+ const refSection = getOrCreateSection(ref);
7790
+ setReferencesScope(ref);
7791
+ if (isSameOrChildSection(tagSection, refSection)) {
7792
+ forceOwnersSerialize(
7793
+ refSection,
7794
+ tagSection,
7795
+ getAccessorProp().Owner
7796
+ );
7797
+ if (!tagExtra[kGetterId4] && !isInvokedFunction(ref)) {
7798
+ tagExtra[kGetterId4] = getRegisterUID(tagSection, "#style");
7799
+ }
7800
+ } else {
7801
+ trackHoistedReference(ref, nodeBinding);
7760
7802
  }
7761
7803
  }
7762
7804
  } else if (hasEventHandlers || spreadReferenceNodes) {
@@ -7781,11 +7823,6 @@ var html_style_default = {
7781
7823
  if (hasVar) {
7782
7824
  const getterId = tagExtra[kGetterId4];
7783
7825
  if (isHTML) {
7784
- const varName = tag.node.var.name;
7785
- const references = tag.scope.getBinding(varName).referencePaths;
7786
- for (const reference of references) {
7787
- serializeOwners(getSection(reference), tagSection);
7788
- }
7789
7826
  translateVar(
7790
7827
  tag,
7791
7828
  callRuntime(
@@ -8545,17 +8582,18 @@ var let_default = {
8545
8582
  "The `let` tag `valueChange` attribute must be a function."
8546
8583
  );
8547
8584
  }
8585
+ const tagSection = getOrCreateSection(tag);
8548
8586
  const binding = trackVarReferences(tag, 1 /* let */);
8549
8587
  setBindingValueExpr(
8550
8588
  binding,
8551
- mergeReferences(getOrCreateSection(tag), tag.node, [
8589
+ mergeReferences(tagSection, tag.node, [
8552
8590
  valueAttr?.value,
8553
8591
  valueChangeAttr?.value
8554
8592
  ])
8555
8593
  );
8556
8594
  if (valueChangeAttr) {
8557
8595
  forceBindingSerialize(
8558
- getSection(tag),
8596
+ tagSection,
8559
8597
  binding,
8560
8598
  getAccessorPrefix().TagVariableChange
8561
8599
  );
@@ -21,6 +21,7 @@ export interface Binding {
21
21
  loc: t.SourceLocation | null;
22
22
  section: Section;
23
23
  closureSections: Opt<Section>;
24
+ assignmentSections: Opt<Section>;
24
25
  sources: Opt<Binding>;
25
26
  serializeSources: undefined | SerializeReason;
26
27
  aliases: Set<Binding>;
@@ -45,7 +46,6 @@ declare module "@marko/compiler/dist/types" {
45
46
  section?: Section;
46
47
  referencedBindings?: ReferencedBindings;
47
48
  binding?: Binding;
48
- hoistedBinding?: Binding;
49
49
  assignment?: Binding;
50
50
  read?: {
51
51
  binding: Binding;
@@ -28,7 +28,6 @@ export interface Section {
28
28
  serializeReason: undefined | SerializeReason;
29
29
  serializeReasons: Map<symbol, SerializeReason>;
30
30
  isHoistThrough: true | undefined;
31
- assignments: ReferencedBindings;
32
31
  upstreamExpression: t.NodeExtra | undefined;
33
32
  downstreamBinding: Binding | undefined;
34
33
  hasAbortSignal: boolean;
@@ -53,7 +52,6 @@ export declare function startSection(path: t.NodePath<t.MarkoTagBody | t.Program
53
52
  export declare function getOrCreateSection(path: t.NodePath<any>): Section;
54
53
  export declare function getSectionForBody(body: t.NodePath<t.MarkoTagBody | t.Program>): Section | undefined;
55
54
  export declare function getSection(path: t.NodePath): Section;
56
- export declare function getParentSection(path: t.NodePath): Section;
57
55
  export declare const getScopeIdIdentifier: (section: Section) => t.Identifier;
58
56
  export declare const getSectionParentIsOwner: (section: Section) => boolean, setSectionParentIsOwner: (section: Section, value: boolean) => void;
59
57
  export declare const getScopeIdentifier: (section: Section, ignoreDefault?: boolean) => t.Identifier;
@@ -12,7 +12,8 @@ export type SerializeReason = true | DynamicSerializeReason;
12
12
  export type SerializeKey = symbol & {
13
13
  __serialize_key__: 1;
14
14
  };
15
- export declare function forceParentSectionsSerialize(from: Section, to?: Section): void;
15
+ export declare function forceOwnersSerialize(from: Section, to: Section, prop?: AccessorProp | symbol): void;
16
+ export declare function addOwnersSerializeReason(from: Section, to: Section, reason: undefined | boolean | SerializeReason, prop?: AccessorProp | symbol): void;
16
17
  export declare function forceSectionSerialize(section: Section, prop?: AccessorProp | symbol): void;
17
18
  export declare function forceBindingSerialize(section: Section, binding: Binding, prefix?: AccessorPrefix | symbol): void;
18
19
  export declare function isSectionForceSerialized(section: Section, prop?: AccessorProp | symbol): boolean;
@@ -56,7 +56,6 @@ export declare function writeSignals(section: Section): void;
56
56
  export declare function writeRegisteredFns(): void;
57
57
  export declare function addHTMLEffectCall(section: Section, referencedBindings?: ReferencedBindings): void;
58
58
  export declare function writeHTMLResumeStatements(path: t.NodePath<t.MarkoTagBody | t.Program>): void;
59
- export declare function serializeOwners(from: Section, to?: Section): void;
60
59
  export declare function getSetup(section: Section): t.Identifier | undefined;
61
60
  export declare function replaceRegisteredFunctionNode(node: t.Node): t.CallExpression | t.ClassPrivateProperty | t.ClassProperty | t.VariableDeclaration | t.Identifier | t.ObjectProperty | undefined;
62
61
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.1",
3
+ "version": "6.0.2",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",