marko 6.0.12 → 6.0.14

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
@@ -1338,7 +1338,7 @@ function createContent(id, template, walks, setup, params, closures, dynamicScop
1338
1338
  walks = walks ? walks.replace(/[^\0-1]+$/, "") : "";
1339
1339
  setup ||= void 0;
1340
1340
  params ||= void 0;
1341
- closures ||= void 0;
1341
+ closures = closures ? closures._ || closures : void 0;
1342
1342
  const clone = template ? (branch, ns) => {
1343
1343
  ((cloneCache[ns] ||= {})[template] ||= createCloneableHTML(
1344
1344
  template,
@@ -1507,7 +1507,7 @@ function loopClosure(valueAccessor, ownerLoopNodeAccessor, fn) {
1507
1507
  const loopScopeAccessor = "LoopScopeArray:" /* LoopScopeArray */ + ownerLoopNodeAccessor;
1508
1508
  const loopScopeMapAccessor = "LoopScopeMap:" /* LoopScopeMap */ + ownerLoopNodeAccessor;
1509
1509
  const ownerSignal = (ownerScope) => {
1510
- const scopes = ownerScope[loopScopeAccessor] || ownerScope[loopScopeMapAccessor]?.values() || [];
1510
+ const scopes = ownerScope[loopScopeAccessor] ||= ownerScope[loopScopeMapAccessor] ? [...ownerScope[loopScopeMapAccessor].values()] : [];
1511
1511
  const [firstScope] = scopes;
1512
1512
  if (firstScope) {
1513
1513
  queueRender(
@@ -1246,7 +1246,7 @@ function createContent(id, template, walks, setup, params, closures, dynamicScop
1246
1246
  walks = walks ? walks.replace(/[^\0-1]+$/, "") : "";
1247
1247
  setup ||= void 0;
1248
1248
  params ||= void 0;
1249
- closures ||= void 0;
1249
+ closures = closures ? closures._ || closures : void 0;
1250
1250
  const clone = template ? (branch, ns) => {
1251
1251
  ((cloneCache[ns] ||= {})[template] ||= createCloneableHTML(
1252
1252
  template,
@@ -1415,7 +1415,7 @@ function loopClosure(valueAccessor, ownerLoopNodeAccessor, fn) {
1415
1415
  const loopScopeAccessor = "LoopScopeArray:" /* LoopScopeArray */ + ownerLoopNodeAccessor;
1416
1416
  const loopScopeMapAccessor = "LoopScopeMap:" /* LoopScopeMap */ + ownerLoopNodeAccessor;
1417
1417
  const ownerSignal = (ownerScope) => {
1418
- const scopes = ownerScope[loopScopeAccessor] || ownerScope[loopScopeMapAccessor]?.values() || [];
1418
+ const scopes = ownerScope[loopScopeAccessor] ||= ownerScope[loopScopeMapAccessor] ? [...ownerScope[loopScopeMapAccessor].values()] : [];
1419
1419
  const [firstScope] = scopes;
1420
1420
  if (firstScope) {
1421
1421
  queueRender(
@@ -13,7 +13,13 @@ type SetupFn = (scope: Scope) => void;
13
13
  export declare function createBranch($global: Scope["$global"], renderer: Renderer | string, parentScope: Scope | undefined, parentNode: ParentNode): BranchScope;
14
14
  export declare function createAndSetupBranch($global: Scope["$global"], renderer: Renderer, parentScope: Scope | undefined, parentNode: ParentNode): BranchScope;
15
15
  export declare function setupBranch(renderer: Renderer, branch: BranchScope): BranchScope;
16
- export declare function createContent(id: string, template: string | 0, walks?: string | 0, setup?: SetupFn | 0, params?: Signal<unknown> | 0, closures?: Signal<unknown> | 0, dynamicScopesAccessor?: Accessor): (owner?: Scope) => Renderer;
17
- export declare function registerContent(id: string, template: string | 0, walks?: string | 0, setup?: SetupFn | 0, params?: Signal<unknown> | 0, closures?: Signal<unknown> | 0, dynamicScopesAccessor?: Accessor): (owner?: Scope) => Renderer;
18
- export declare function createRenderer(template: string | 0, walks?: string | 0, setup?: SetupFn | 0, params?: Signal<unknown> | 0, closures?: Signal<unknown> | 0): Renderer;
16
+ export declare function createContent(id: string, template: string | 0, walks?: string | 0, setup?: SetupFn | 0, params?: Signal<unknown> | 0, closures?: {
17
+ _: Signal<unknown>;
18
+ } | Signal<unknown> | 0, dynamicScopesAccessor?: Accessor): (owner?: Scope) => Renderer;
19
+ export declare function registerContent(id: string, template: string | 0, walks?: string | 0, setup?: SetupFn | 0, params?: Signal<unknown> | 0, closures?: {
20
+ _: Signal<unknown>;
21
+ } | Signal<unknown> | 0, dynamicScopesAccessor?: Accessor): (owner?: Scope) => Renderer;
22
+ export declare function createRenderer(template: string | 0, walks?: string | 0, setup?: SetupFn | 0, params?: Signal<unknown> | 0, closures?: {
23
+ _: Signal<unknown>;
24
+ } | Signal<unknown> | 0): Renderer;
19
25
  export {};
package/dist/dom.js CHANGED
@@ -884,7 +884,7 @@ function setupBranch(renderer, branch) {
884
884
  ), branch;
885
885
  }
886
886
  function createContent(id, template, walks, setup, params, closures, dynamicScopesAccessor) {
887
- walks = walks ? walks.replace(/[^\0-1]+$/, "") : "", setup ||= void 0, params ||= void 0, closures ||= void 0;
887
+ walks = walks ? walks.replace(/[^\0-1]+$/, "") : "", setup ||= void 0, params ||= void 0, closures = closures ? closures._ || closures : void 0;
888
888
  let clone = template ? (branch, ns) => {
889
889
  ((cloneCache[ns] ||= {})[template] ||= createCloneableHTML(
890
890
  template,
@@ -980,7 +980,7 @@ function intersection(id, fn, defaultPending = 1, scopeIdAccessor = /* @__KEY__
980
980
  }
981
981
  function loopClosure(valueAccessor, ownerLoopNodeAccessor, fn) {
982
982
  let childSignal = closure(valueAccessor, fn), loopScopeAccessor = "l" /* LoopScopeArray */ + ownerLoopNodeAccessor, loopScopeMapAccessor = "m" /* LoopScopeMap */ + ownerLoopNodeAccessor, ownerSignal = (ownerScope) => {
983
- let scopes = ownerScope[loopScopeAccessor] || ownerScope[loopScopeMapAccessor]?.values() || [], [firstScope] = scopes;
983
+ let scopes = ownerScope[loopScopeAccessor] ||= ownerScope[loopScopeMapAccessor] ? [...ownerScope[loopScopeMapAccessor].values()] : [], [firstScope] = scopes;
984
984
  firstScope && queueRender(
985
985
  ownerScope,
986
986
  () => {
package/dist/dom.mjs CHANGED
@@ -795,7 +795,7 @@ function setupBranch(renderer, branch) {
795
795
  ), branch;
796
796
  }
797
797
  function createContent(id, template, walks, setup, params, closures, dynamicScopesAccessor) {
798
- walks = walks ? walks.replace(/[^\0-1]+$/, "") : "", setup ||= void 0, params ||= void 0, closures ||= void 0;
798
+ walks = walks ? walks.replace(/[^\0-1]+$/, "") : "", setup ||= void 0, params ||= void 0, closures = closures ? closures._ || closures : void 0;
799
799
  let clone = template ? (branch, ns) => {
800
800
  ((cloneCache[ns] ||= {})[template] ||= createCloneableHTML(
801
801
  template,
@@ -891,7 +891,7 @@ function intersection(id, fn, defaultPending = 1, scopeIdAccessor = /* @__KEY__
891
891
  }
892
892
  function loopClosure(valueAccessor, ownerLoopNodeAccessor, fn) {
893
893
  let childSignal = closure(valueAccessor, fn), loopScopeAccessor = "l" /* LoopScopeArray */ + ownerLoopNodeAccessor, loopScopeMapAccessor = "m" /* LoopScopeMap */ + ownerLoopNodeAccessor, ownerSignal = (ownerScope) => {
894
- let scopes = ownerScope[loopScopeAccessor] || ownerScope[loopScopeMapAccessor]?.values() || [], [firstScope] = scopes;
894
+ let scopes = ownerScope[loopScopeAccessor] ||= ownerScope[loopScopeMapAccessor] ? [...ownerScope[loopScopeMapAccessor].values()] : [], [firstScope] = scopes;
895
895
  firstScope && queueRender(
896
896
  ownerScope,
897
897
  () => {
@@ -3203,7 +3203,9 @@ function getSignalFn(signal) {
3203
3203
  }
3204
3204
  forEach(signal.intersection, (intersection) => {
3205
3205
  signal.render.push(
3206
- import_compiler20.types.expressionStatement(import_compiler20.types.callExpression(intersection, [scopeIdentifier]))
3206
+ import_compiler20.types.expressionStatement(
3207
+ import_compiler20.types.callExpression(intersection.identifier, [scopeIdentifier])
3208
+ )
3207
3209
  );
3208
3210
  });
3209
3211
  if (isValue && binding.sources) {
@@ -3310,10 +3312,7 @@ function subscribe(provider, subscriber) {
3310
3312
  return;
3311
3313
  }
3312
3314
  const providerSignal = getSignal(subscriber.section, provider);
3313
- providerSignal.intersection = push(
3314
- providerSignal.intersection,
3315
- subscriber.identifier
3316
- );
3315
+ providerSignal.intersection = push(providerSignal.intersection, subscriber);
3317
3316
  }
3318
3317
  function generateSignalName(referencedBindings) {
3319
3318
  let name2;
@@ -3436,56 +3435,20 @@ function getRegisterUID(section, name2) {
3436
3435
  return id;
3437
3436
  }
3438
3437
  function writeSignals(section) {
3439
- forEach(section.hoisted, (binding) => {
3440
- for (const hoistedBinding of binding.hoists.values()) {
3441
- const accessors = [
3442
- binding.type === 0 /* dom */ ? import_compiler20.types.stringLiteral(
3443
- getAccessorPrefix().Getter + getScopeAccessor(binding)
3444
- ) : getScopeAccessorLiteral(binding)
3445
- ];
3446
- let currentSection = section;
3447
- while (currentSection && currentSection !== hoistedBinding.section) {
3448
- const parentSection = currentSection.parent;
3449
- if (parentSection) {
3450
- accessors.push(getSectionInstancesAccessorLiteral(currentSection));
3451
- }
3452
- currentSection = parentSection;
3453
- }
3454
- const hoistIdentifier = getHoistFunctionIdentifier(hoistedBinding);
3455
- (0, import_babel_utils14.getProgram)().node.body.push(
3456
- import_compiler20.types.variableDeclaration("const", [
3457
- import_compiler20.types.variableDeclarator(
3458
- hoistIdentifier,
3459
- hoistedBinding.downstreamExpressions.size ? callRuntime(
3460
- "register",
3461
- import_compiler20.types.stringLiteral(
3462
- getResumeRegisterId(
3463
- hoistedBinding.section,
3464
- hoistedBinding,
3465
- "hoist"
3466
- )
3467
- ),
3468
- callRuntime("hoist", ...accessors)
3469
- ) : callRuntime("hoist", ...accessors)
3470
- )
3471
- ])
3472
- );
3473
- if (hoistedBinding.downstreamExpressions.size) {
3474
- addValue(
3475
- hoistedBinding.section,
3476
- void 0,
3477
- initValue(hoistedBinding),
3478
- import_compiler20.types.callExpression(hoistIdentifier, [scopeIdentifier])
3479
- );
3480
- }
3481
- }
3482
- });
3483
- const signals = [...getSignals(section).values()].sort(sortSignals);
3484
- for (const signal of signals) {
3485
- traverseReplace(signal, "render", replaceRenderNode);
3438
+ const seen = /* @__PURE__ */ new Set();
3439
+ writeHoists(section);
3440
+ for (const signal of getSignals(section).values()) {
3441
+ writeSignal(signal);
3442
+ }
3443
+ function writeSignal(signal) {
3444
+ if (seen.has(signal)) return;
3445
+ seen.add(signal);
3486
3446
  for (const value2 of signal.values) {
3447
+ writeSignal(value2.signal);
3487
3448
  traverseReplace(value2, "value", replaceRenderNode);
3488
3449
  }
3450
+ forEach(signal.intersection, writeSignal);
3451
+ traverseReplace(signal, "render", replaceRenderNode);
3489
3452
  let effectDeclarator;
3490
3453
  if (signal.effect.length) {
3491
3454
  traverseReplace(signal, "effect", replaceEffectNode);
@@ -3519,7 +3482,7 @@ function writeSignals(section) {
3519
3482
  // This ignores writing out those signals in that case.
3520
3483
  signal.referencedBindings && !Array.isArray(signal.referencedBindings) && signal.referencedBindings.upstreamAlias && !signal.referencedBindings.property && import_compiler20.types.isFunction(value) && import_compiler20.types.isBlockStatement(value.body) && !value.body.body.length
3521
3484
  ) {
3522
- continue;
3485
+ return;
3523
3486
  }
3524
3487
  if (import_compiler20.types.isCallExpression(value)) {
3525
3488
  replaceNullishAndEmptyFunctionsWith0(value.arguments);
@@ -3550,6 +3513,52 @@ function writeSignals(section) {
3550
3513
  (0, import_babel_utils14.getProgram)().node.body.push(...signalStatements);
3551
3514
  }
3552
3515
  }
3516
+ function writeHoists(section) {
3517
+ forEach(section.hoisted, (binding) => {
3518
+ for (const hoistedBinding of binding.hoists.values()) {
3519
+ const accessors = [
3520
+ binding.type === 0 /* dom */ ? import_compiler20.types.stringLiteral(
3521
+ getAccessorPrefix().Getter + getScopeAccessor(binding)
3522
+ ) : getScopeAccessorLiteral(binding)
3523
+ ];
3524
+ let currentSection = section;
3525
+ while (currentSection && currentSection !== hoistedBinding.section) {
3526
+ const parentSection = currentSection.parent;
3527
+ if (parentSection) {
3528
+ accessors.push(getSectionInstancesAccessorLiteral(currentSection));
3529
+ }
3530
+ currentSection = parentSection;
3531
+ }
3532
+ const hoistIdentifier = getHoistFunctionIdentifier(hoistedBinding);
3533
+ (0, import_babel_utils14.getProgram)().node.body.push(
3534
+ import_compiler20.types.variableDeclaration("const", [
3535
+ import_compiler20.types.variableDeclarator(
3536
+ hoistIdentifier,
3537
+ hoistedBinding.downstreamExpressions.size ? callRuntime(
3538
+ "register",
3539
+ import_compiler20.types.stringLiteral(
3540
+ getResumeRegisterId(
3541
+ hoistedBinding.section,
3542
+ hoistedBinding,
3543
+ "hoist"
3544
+ )
3545
+ ),
3546
+ callRuntime("hoist", ...accessors)
3547
+ ) : callRuntime("hoist", ...accessors)
3548
+ )
3549
+ ])
3550
+ );
3551
+ if (hoistedBinding.downstreamExpressions.size) {
3552
+ addValue(
3553
+ hoistedBinding.section,
3554
+ void 0,
3555
+ initValue(hoistedBinding),
3556
+ import_compiler20.types.callExpression(hoistIdentifier, [scopeIdentifier])
3557
+ );
3558
+ }
3559
+ }
3560
+ });
3561
+ }
3553
3562
  function writeRegisteredFns() {
3554
3563
  const registeredFns = registeredFnsForProgram.get((0, import_babel_utils14.getProgram)().node);
3555
3564
  const statements = [];
@@ -3608,27 +3617,6 @@ function toReturnedFunction(rawFn) {
3608
3617
  const fn = simplifyFunction(rawFn);
3609
3618
  return fn.type === "FunctionDeclaration" ? [fn, import_compiler20.types.returnStatement(fn.id)] : [import_compiler20.types.returnStatement(fn)];
3610
3619
  }
3611
- function sortSignals(a, b) {
3612
- const aReferencedBindings = getReferencedBindings(a);
3613
- const bReferencedBindings = getReferencedBindings(b);
3614
- for (let i = Math.max(aReferencedBindings.length, bReferencedBindings.length) - 1; i >= 0; i--) {
3615
- const diff = (bReferencedBindings[i] ?? -1) - (aReferencedBindings[i] ?? -1);
3616
- if (diff !== 0) return diff;
3617
- }
3618
- return 0;
3619
- }
3620
- function getReferencedBindings({ referencedBindings: reserve }) {
3621
- if (!reserve) {
3622
- return [];
3623
- } else if (Array.isArray(reserve)) {
3624
- return reserve.map(getMappedId).sort();
3625
- } else {
3626
- return [getMappedId(reserve)];
3627
- }
3628
- }
3629
- function getMappedId(reference) {
3630
- return (reference.type === 0 /* dom */ ? 1 : 0) * 1e4 + reference.id;
3631
- }
3632
3620
  function addHTMLEffectCall(section, referencedBindings) {
3633
3621
  addStatement("effect", section, referencedBindings, void 0, false);
3634
3622
  }
@@ -4052,7 +4040,7 @@ var dom_default = {
4052
4040
  const tagParamsSignal = childSection.params && initValue(childSection.params);
4053
4041
  const { walks: walks2, writes: writes2, setup: setup2 } = getSectionMeta(childSection);
4054
4042
  const identifier = import_compiler21.types.identifier(childSection.name);
4055
- const referencedClosures = childSection.referencedClosures ? import_compiler21.types.arrowFunctionExpression(
4043
+ const referencedClosures = childSection.referencedClosures ? Array.isArray(childSection.referencedClosures) ? import_compiler21.types.arrowFunctionExpression(
4056
4044
  [scopeIdentifier],
4057
4045
  toFirstExpressionOrBlock(
4058
4046
  toArray(childSection.referencedClosures, (closure) => {
@@ -4068,7 +4056,7 @@ var dom_default = {
4068
4056
  );
4069
4057
  })
4070
4058
  )
4071
- ) : void 0;
4059
+ ) : getSignal(childSection, childSection.referencedClosures).identifier : void 0;
4072
4060
  const renderer = getSectionParentIsOwner(childSection) ? callRuntime(
4073
4061
  "createRenderer",
4074
4062
  ...replaceNullishAndEmptyFunctionsWith0([
@@ -4684,7 +4672,7 @@ function mergeReferences(section, target, nodes) {
4684
4672
  return targetExtra;
4685
4673
  }
4686
4674
  function compareReferences(a, b) {
4687
- return a === b ? 0 : Array.isArray(a) ? Array.isArray(b) ? compareIntersections(a, b) : -1 : Array.isArray(b) ? 1 : bindingUtil.compare(a, b);
4675
+ return a === b ? 0 : a ? b ? Array.isArray(a) ? Array.isArray(b) ? compareIntersections(a, b) : -1 : Array.isArray(b) ? 1 : bindingUtil.compare(a, b) : 1 : b ? -1 : 0;
4688
4676
  }
4689
4677
  function compareIntersections(a, b) {
4690
4678
  const len = a.length;
@@ -1,5 +1,5 @@
1
1
  import { types as t } from "@marko/compiler";
2
- import { type Many, type OneMany, type Opt, Sorted } from "./optional";
2
+ import { type Many, type Opt, Sorted } from "./optional";
3
3
  import { type Section } from "./sections";
4
4
  declare const kIsInvoked: unique symbol;
5
5
  export declare const kBranchSerializeReason: unique symbol;
@@ -74,7 +74,7 @@ export declare function trackParamsReferences(body: t.NodePath<t.MarkoTagBody |
74
74
  export declare function trackHoistedReference(referencePath: t.NodePath<t.Identifier>, binding: Binding): void;
75
75
  export declare function setReferencesScope(path: t.NodePath<any>): void;
76
76
  export declare function mergeReferences<T extends t.Node>(section: Section, target: T, nodes: (t.Node | undefined)[]): NonNullable<T["extra"]>;
77
- export declare function compareReferences(a: OneMany<Binding>, b: OneMany<Binding>): number;
77
+ export declare function compareReferences(a: ReferencedBindings, b: ReferencedBindings): number;
78
78
  export declare function finalizeReferences(): void;
79
79
  export declare const intersectionMeta: WeakMap<Intersection, {
80
80
  id: number;
@@ -14,7 +14,7 @@ export type Signal = {
14
14
  signal: Signal;
15
15
  value: t.Expression;
16
16
  }>;
17
- intersection: Opt<t.Expression>;
17
+ intersection: Opt<Signal>;
18
18
  render: t.Statement[];
19
19
  renderReferencedBindings: ReferencedBindings;
20
20
  effect: t.Statement[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.12",
3
+ "version": "6.0.14",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",