marko 6.0.11 → 6.0.13

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.
@@ -2909,25 +2909,27 @@ var return_default = {
2909
2909
  const section = getSection(tag);
2910
2910
  const attrs2 = getKnownAttrValues(tag.node);
2911
2911
  if (attrs2.value) {
2912
- addValue(
2912
+ addStatement(
2913
+ "render",
2913
2914
  section,
2914
2915
  attrs2.value.extra?.referencedBindings,
2915
- {
2916
- identifier: importRuntime("tagVarSignal"),
2917
- hasDownstreamIntersections: () => true
2918
- },
2919
- attrs2.value
2916
+ import_compiler17.types.expressionStatement(
2917
+ callRuntime("tagVarSignal", scopeIdentifier, attrs2.value)
2918
+ )
2920
2919
  );
2921
2920
  }
2922
2921
  if (attrs2.valueChange) {
2923
- addValue(
2922
+ addStatement(
2923
+ "render",
2924
2924
  section,
2925
2925
  attrs2.valueChange.extra?.referencedBindings,
2926
- {
2927
- identifier: importRuntime("setTagVarChange"),
2928
- hasDownstreamIntersections: () => false
2929
- },
2930
- attrs2.valueChange
2926
+ import_compiler17.types.expressionStatement(
2927
+ callRuntime(
2928
+ "setTagVarChange",
2929
+ scopeIdentifier,
2930
+ attrs2.valueChange
2931
+ )
2932
+ )
2931
2933
  );
2932
2934
  }
2933
2935
  tag.remove();
@@ -2950,16 +2952,17 @@ var return_default = {
2950
2952
  // src/translator/util/get-defined-binding-expression.ts
2951
2953
  var import_compiler18 = require("@marko/compiler");
2952
2954
  function getDeclaredBindingExpression(binding) {
2953
- if (binding.declared || !binding.upstreamAlias) {
2954
- return import_compiler18.types.identifier(binding.name);
2955
- } else if (binding.property !== void 0) {
2955
+ const canonicalBinding = getCanonicalBinding(binding);
2956
+ if (canonicalBinding.declared || !canonicalBinding.upstreamAlias) {
2957
+ return import_compiler18.types.identifier(canonicalBinding.name);
2958
+ } else if (canonicalBinding.property !== void 0) {
2956
2959
  return toMemberExpression(
2957
- getDeclaredBindingExpression(binding.upstreamAlias),
2958
- binding.property,
2959
- binding.upstreamAlias.nullable
2960
+ getDeclaredBindingExpression(canonicalBinding.upstreamAlias),
2961
+ canonicalBinding.property,
2962
+ canonicalBinding.upstreamAlias.nullable
2960
2963
  );
2961
2964
  } else {
2962
- return getDeclaredBindingExpression(binding.upstreamAlias);
2965
+ return getDeclaredBindingExpression(canonicalBinding.upstreamAlias);
2963
2966
  }
2964
2967
  }
2965
2968
 
@@ -3066,37 +3069,6 @@ function getSignal(section, referencedBindings, name2 = generateSignalName(refer
3066
3069
  effect: [],
3067
3070
  effectReferencedBindings: void 0,
3068
3071
  subscribers: [],
3069
- hasDownstreamIntersections: () => {
3070
- let hasDownstreamIntersections = !!signal.intersection;
3071
- if (!hasDownstreamIntersections) {
3072
- for (const value of signal.values) {
3073
- if (value.signal.hasDownstreamIntersections()) {
3074
- hasDownstreamIntersections = true;
3075
- break;
3076
- }
3077
- }
3078
- }
3079
- if (!hasDownstreamIntersections) {
3080
- if (!Array.isArray(referencedBindings) && referencedBindings) {
3081
- for (const alias of referencedBindings.aliases) {
3082
- if (getSignal(section, alias).hasDownstreamIntersections()) {
3083
- hasDownstreamIntersections = true;
3084
- break;
3085
- }
3086
- }
3087
- if (!hasDownstreamIntersections) {
3088
- for (const [, alias] of referencedBindings.propertyAliases) {
3089
- if (getSignal(section, alias).hasDownstreamIntersections()) {
3090
- hasDownstreamIntersections = true;
3091
- break;
3092
- }
3093
- }
3094
- }
3095
- }
3096
- }
3097
- signal.hasDownstreamIntersections = () => hasDownstreamIntersections;
3098
- return hasDownstreamIntersections;
3099
- },
3100
3072
  build: unimplementedBuild,
3101
3073
  export: !!exportName
3102
3074
  }
@@ -3119,17 +3091,18 @@ function getSignal(section, referencedBindings, name2 = generateSignalName(refer
3119
3091
  };
3120
3092
  } else if (referencedBindings.section !== section && bindingUtil.find(section.referencedClosures, referencedBindings)) {
3121
3093
  signal.build = () => {
3094
+ const canonicalClosure = getCanonicalBinding(referencedBindings);
3122
3095
  const render = getSignalFn(signal);
3123
3096
  const closureSignalBuilder = getClosureSignalBuilder(section);
3124
- return !closureSignalBuilder || isDynamicClosure(section, referencedBindings) ? callRuntime(
3097
+ return !closureSignalBuilder || isDynamicClosure(section, canonicalClosure) ? callRuntime(
3125
3098
  "dynamicClosureRead",
3126
- getScopeAccessorLiteral(referencedBindings),
3099
+ getScopeAccessorLiteral(canonicalClosure),
3127
3100
  render,
3128
- isImmediateOwner(section, referencedBindings) ? void 0 : import_compiler20.types.arrowFunctionExpression(
3101
+ isImmediateOwner(section, canonicalClosure) ? void 0 : import_compiler20.types.arrowFunctionExpression(
3129
3102
  [scopeIdentifier],
3130
- getScopeExpression(section, referencedBindings.section)
3103
+ getScopeExpression(section, canonicalClosure.section)
3131
3104
  )
3132
- ) : getClosureSignalBuilder(section)(referencedBindings, render);
3105
+ ) : getClosureSignalBuilder(section)(canonicalClosure, render);
3133
3106
  };
3134
3107
  }
3135
3108
  }
@@ -3142,7 +3115,7 @@ function initValue(binding, runtimeHelper = "value") {
3142
3115
  const fn = getSignalFn(signal);
3143
3116
  const isParamBinding = !binding.upstreamAlias && (binding.type === 3 /* param */ || binding.type === 2 /* input */);
3144
3117
  const isNakedAlias = binding.upstreamAlias && !binding.property;
3145
- const needsGuard = !isNakedAlias && (binding.downstreamExpressions.size || fn.type === "ArrowFunctionExpression" && fn.body.body.length > 0);
3118
+ const needsGuard = !isNakedAlias && (binding.closureSections || binding.downstreamExpressions.size || fn.type === "ArrowFunctionExpression" && fn.body.body.length > 0);
3146
3119
  const needsCache = needsGuard || signal.intersection;
3147
3120
  const needsMarks = isParamBinding || signal.intersection;
3148
3121
  if (needsCache || needsMarks || binding.hoists.size) {
@@ -3171,7 +3144,6 @@ function getSignalFn(signal) {
3171
3144
  const isIntersection = Array.isArray(binding);
3172
3145
  const isBinding = binding && !isIntersection;
3173
3146
  const isValue = isBinding && binding.section === section;
3174
- let canUseCalleeDirectly = !signal.render.length;
3175
3147
  if (isBinding && (signal.renderReferencedBindings || binding.aliases.size || binding.propertyAliases.size)) {
3176
3148
  const valueParam = import_compiler20.types.identifier(binding.name);
3177
3149
  if (binding.loc) {
@@ -3184,15 +3156,17 @@ function getSignalFn(signal) {
3184
3156
  if (isValue) {
3185
3157
  for (const alias of binding.aliases) {
3186
3158
  const aliasSignal = getSignal(alias.section, alias);
3187
- signal.render.push(
3188
- import_compiler20.types.expressionStatement(
3189
- import_compiler20.types.callExpression(aliasSignal.identifier, [
3190
- scopeIdentifier,
3191
- import_compiler20.types.identifier(binding.name),
3192
- ...getTranslatedExtraArgs(aliasSignal)
3193
- ])
3194
- )
3195
- );
3159
+ if (aliasSignal.render.length || aliasSignal.values.length || aliasSignal.effect.length) {
3160
+ signal.render.push(
3161
+ import_compiler20.types.expressionStatement(
3162
+ import_compiler20.types.callExpression(aliasSignal.identifier, [
3163
+ scopeIdentifier,
3164
+ import_compiler20.types.identifier(binding.name),
3165
+ ...getTranslatedExtraArgs(aliasSignal)
3166
+ ])
3167
+ )
3168
+ );
3169
+ }
3196
3170
  }
3197
3171
  for (const [key, alias] of binding.propertyAliases) {
3198
3172
  const aliasSignal = getSignal(alias.section, alias);
@@ -3212,26 +3186,33 @@ function getSignalFn(signal) {
3212
3186
  }
3213
3187
  }
3214
3188
  for (const value of signal.values) {
3215
- signal.render.push(
3216
- import_compiler20.types.expressionStatement(
3217
- import_compiler20.types.callExpression(value.signal.identifier, [
3218
- value.scope,
3219
- value.value,
3220
- ...getTranslatedExtraArgs(value.signal)
3221
- ])
3222
- )
3223
- );
3189
+ const valSignal = value.signal;
3190
+ if (!valSignal.referencedBindings || Array.isArray(valSignal.referencedBindings) || !valSignal.referencedBindings.upstreamAlias || valSignal.referencedBindings.property || valSignal.effect.length || valSignal.render.length || valSignal.values.length) {
3191
+ signal.render.push(
3192
+ import_compiler20.types.expressionStatement(
3193
+ import_compiler20.types.callExpression(value.signal.identifier, [
3194
+ scopeIdentifier,
3195
+ value.value,
3196
+ ...getTranslatedExtraArgs(value.signal)
3197
+ ])
3198
+ )
3199
+ );
3200
+ } else {
3201
+ signal.render.push(import_compiler20.types.expressionStatement(value.value));
3202
+ }
3224
3203
  }
3225
3204
  forEach(signal.intersection, (intersection) => {
3226
3205
  signal.render.push(
3227
- import_compiler20.types.expressionStatement(import_compiler20.types.callExpression(intersection, [scopeIdentifier]))
3206
+ import_compiler20.types.expressionStatement(
3207
+ import_compiler20.types.callExpression(intersection.identifier, [scopeIdentifier])
3208
+ )
3228
3209
  );
3229
3210
  });
3230
- if (isValue) {
3211
+ if (isValue && binding.sources) {
3231
3212
  let dynamicClosureArgs;
3232
3213
  let dynamicClosureSignalIdentifier;
3233
- forEach(binding.closureSections, (closureSection) => {
3234
- if (binding.sources) {
3214
+ if (binding.sources) {
3215
+ forEach(binding.closureSections, (closureSection) => {
3235
3216
  if (isDynamicClosure(closureSection, binding)) {
3236
3217
  if (!dynamicClosureArgs) {
3237
3218
  dynamicClosureArgs = [];
@@ -3258,17 +3239,17 @@ function getSignalFn(signal) {
3258
3239
  )
3259
3240
  );
3260
3241
  }
3242
+ });
3243
+ if (dynamicClosureSignalIdentifier) {
3244
+ (signal.prependStatements ||= []).push(
3245
+ import_compiler20.types.variableDeclaration("const", [
3246
+ import_compiler20.types.variableDeclarator(
3247
+ dynamicClosureSignalIdentifier,
3248
+ callRuntime("dynamicClosure", ...dynamicClosureArgs)
3249
+ )
3250
+ ])
3251
+ );
3261
3252
  }
3262
- });
3263
- if (dynamicClosureSignalIdentifier) {
3264
- (signal.prependStatements ||= []).push(
3265
- import_compiler20.types.variableDeclaration("const", [
3266
- import_compiler20.types.variableDeclarator(
3267
- dynamicClosureSignalIdentifier,
3268
- callRuntime("dynamicClosure", ...dynamicClosureArgs)
3269
- )
3270
- ])
3271
- );
3272
3253
  }
3273
3254
  }
3274
3255
  if (signal.effect.length) {
@@ -3289,22 +3270,22 @@ function getSignalFn(signal) {
3289
3270
  ])
3290
3271
  );
3291
3272
  }
3292
- if (canUseCalleeDirectly && signal.render.length === 1) {
3273
+ if (signal.render.length === 1) {
3293
3274
  const render = signal.render[0];
3294
3275
  if (render.type === "ExpressionStatement") {
3295
3276
  const { expression } = render;
3296
3277
  if (expression.type === "CallExpression") {
3297
3278
  const args = expression.arguments;
3298
3279
  if (params.length >= args.length) {
3299
- for (let i = args.length; i--; ) {
3280
+ let i = args.length;
3281
+ for (; i--; ) {
3300
3282
  const param = params[i];
3301
3283
  const arg = args[i];
3302
3284
  if (arg.type !== "Identifier" || param.name !== arg.name) {
3303
- canUseCalleeDirectly = false;
3304
3285
  break;
3305
3286
  }
3306
3287
  }
3307
- if (canUseCalleeDirectly) {
3288
+ if (i === -1) {
3308
3289
  return expression.callee;
3309
3290
  }
3310
3291
  }
@@ -3331,10 +3312,7 @@ function subscribe(provider, subscriber) {
3331
3312
  return;
3332
3313
  }
3333
3314
  const providerSignal = getSignal(subscriber.section, provider);
3334
- providerSignal.intersection = push(
3335
- providerSignal.intersection,
3336
- subscriber.identifier
3337
- );
3315
+ providerSignal.intersection = push(providerSignal.intersection, subscriber);
3338
3316
  }
3339
3317
  function generateSignalName(referencedBindings) {
3340
3318
  let name2;
@@ -3404,13 +3382,12 @@ function addRenderReferences(signal, referencedBindings) {
3404
3382
  referencedBindings
3405
3383
  );
3406
3384
  }
3407
- function addValue(targetSection, referencedBindings, signal, value, scope = scopeIdentifier) {
3385
+ function addValue(targetSection, referencedBindings, signal, value) {
3408
3386
  const parentSignal = getSignal(targetSection, referencedBindings);
3409
3387
  addRenderReferences(parentSignal, referencedBindings);
3410
3388
  parentSignal.values.push({
3411
3389
  signal,
3412
- value,
3413
- scope
3390
+ value
3414
3391
  });
3415
3392
  }
3416
3393
  function getResumeRegisterId(section, referencedBindings, type) {
@@ -3458,56 +3435,20 @@ function getRegisterUID(section, name2) {
3458
3435
  return id;
3459
3436
  }
3460
3437
  function writeSignals(section) {
3461
- forEach(section.hoisted, (binding) => {
3462
- for (const hoistedBinding of binding.hoists.values()) {
3463
- const accessors = [
3464
- binding.type === 0 /* dom */ ? import_compiler20.types.stringLiteral(
3465
- getAccessorPrefix().Getter + getScopeAccessor(binding)
3466
- ) : getScopeAccessorLiteral(binding)
3467
- ];
3468
- let currentSection = section;
3469
- while (currentSection && currentSection !== hoistedBinding.section) {
3470
- const parentSection = currentSection.parent;
3471
- if (parentSection) {
3472
- accessors.push(getSectionInstancesAccessorLiteral(currentSection));
3473
- }
3474
- currentSection = parentSection;
3475
- }
3476
- const hoistIdentifier = getHoistFunctionIdentifier(hoistedBinding);
3477
- (0, import_babel_utils14.getProgram)().node.body.push(
3478
- import_compiler20.types.variableDeclaration("const", [
3479
- import_compiler20.types.variableDeclarator(
3480
- hoistIdentifier,
3481
- hoistedBinding.downstreamExpressions.size ? callRuntime(
3482
- "register",
3483
- import_compiler20.types.stringLiteral(
3484
- getResumeRegisterId(
3485
- hoistedBinding.section,
3486
- hoistedBinding,
3487
- "hoist"
3488
- )
3489
- ),
3490
- callRuntime("hoist", ...accessors)
3491
- ) : callRuntime("hoist", ...accessors)
3492
- )
3493
- ])
3494
- );
3495
- if (hoistedBinding.downstreamExpressions.size) {
3496
- addValue(
3497
- hoistedBinding.section,
3498
- void 0,
3499
- initValue(hoistedBinding),
3500
- import_compiler20.types.callExpression(hoistIdentifier, [scopeIdentifier])
3501
- );
3502
- }
3503
- }
3504
- });
3505
- const signals = [...getSignals(section).values()].sort(sortSignals);
3506
- for (const signal of signals) {
3507
- 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);
3508
3446
  for (const value2 of signal.values) {
3447
+ writeSignal(value2.signal);
3509
3448
  traverseReplace(value2, "value", replaceRenderNode);
3510
3449
  }
3450
+ forEach(signal.intersection, writeSignal);
3451
+ traverseReplace(signal, "render", replaceRenderNode);
3511
3452
  let effectDeclarator;
3512
3453
  if (signal.effect.length) {
3513
3454
  traverseReplace(signal, "effect", replaceEffectNode);
@@ -3535,6 +3476,14 @@ function writeSignals(section) {
3535
3476
  );
3536
3477
  }
3537
3478
  let value = signal.build();
3479
+ if (
3480
+ // It's possible for aliases to render nothing
3481
+ // if they're only consumed in effects/closures.
3482
+ // This ignores writing out those signals in that case.
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
3484
+ ) {
3485
+ return;
3486
+ }
3538
3487
  if (import_compiler20.types.isCallExpression(value)) {
3539
3488
  replaceNullishAndEmptyFunctionsWith0(value.arguments);
3540
3489
  }
@@ -3564,6 +3513,52 @@ function writeSignals(section) {
3564
3513
  (0, import_babel_utils14.getProgram)().node.body.push(...signalStatements);
3565
3514
  }
3566
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
+ }
3567
3562
  function writeRegisteredFns() {
3568
3563
  const registeredFns = registeredFnsForProgram.get((0, import_babel_utils14.getProgram)().node);
3569
3564
  const statements = [];
@@ -3622,27 +3617,6 @@ function toReturnedFunction(rawFn) {
3622
3617
  const fn = simplifyFunction(rawFn);
3623
3618
  return fn.type === "FunctionDeclaration" ? [fn, import_compiler20.types.returnStatement(fn.id)] : [import_compiler20.types.returnStatement(fn)];
3624
3619
  }
3625
- function sortSignals(a, b) {
3626
- const aReferencedBindings = getReferencedBindings(a);
3627
- const bReferencedBindings = getReferencedBindings(b);
3628
- for (let i = Math.max(aReferencedBindings.length, bReferencedBindings.length) - 1; i >= 0; i--) {
3629
- const diff = (bReferencedBindings[i] ?? -1) - (aReferencedBindings[i] ?? -1);
3630
- if (diff !== 0) return diff;
3631
- }
3632
- return 0;
3633
- }
3634
- function getReferencedBindings({ referencedBindings: reserve }) {
3635
- if (!reserve) {
3636
- return [];
3637
- } else if (Array.isArray(reserve)) {
3638
- return reserve.map(getMappedId).sort();
3639
- } else {
3640
- return [getMappedId(reserve)];
3641
- }
3642
- }
3643
- function getMappedId(reference) {
3644
- return (reference.type === 0 /* dom */ ? 1 : 0) * 1e4 + reference.id;
3645
- }
3646
3620
  function addHTMLEffectCall(section, referencedBindings) {
3647
3621
  addStatement("effect", section, referencedBindings, void 0, false);
3648
3622
  }
@@ -4403,14 +4377,24 @@ function createBinding(name2, type, section, upstreamAlias, property, loc = null
4403
4377
  function trackVarReferences(tag, type, upstreamAlias) {
4404
4378
  const tagVar = tag.node.var;
4405
4379
  if (tagVar) {
4406
- const section = getOrCreateSection(tag);
4407
4380
  const canonicalUpstreamAlias = getCanonicalBinding(upstreamAlias);
4381
+ if (canonicalUpstreamAlias) {
4382
+ createBindingsAndTrackReferences(
4383
+ tagVar,
4384
+ canonicalUpstreamAlias.type,
4385
+ tag.scope,
4386
+ canonicalUpstreamAlias.section,
4387
+ canonicalUpstreamAlias,
4388
+ void 0
4389
+ );
4390
+ return canonicalUpstreamAlias;
4391
+ }
4408
4392
  createBindingsAndTrackReferences(
4409
4393
  tagVar,
4410
- upstreamAlias ? upstreamAlias.type : type,
4394
+ type,
4411
4395
  tag.scope,
4412
- section,
4413
- canonicalUpstreamAlias,
4396
+ getOrCreateSection(tag),
4397
+ void 0,
4414
4398
  void 0
4415
4399
  );
4416
4400
  return tagVar.extra?.binding;
@@ -4419,13 +4403,19 @@ function trackVarReferences(tag, type, upstreamAlias) {
4419
4403
  function trackParamsReferences(body, type, upstreamAlias) {
4420
4404
  const params = body.node.params;
4421
4405
  if (body.node.body.length && params.length) {
4422
- const section = getOrCreateSection(body);
4423
4406
  const canonicalUpstreamAlias = getCanonicalBinding(upstreamAlias);
4407
+ let section;
4408
+ if (canonicalUpstreamAlias) {
4409
+ section = canonicalUpstreamAlias.section;
4410
+ type = canonicalUpstreamAlias.type;
4411
+ } else {
4412
+ section = getOrCreateSection(body);
4413
+ }
4424
4414
  const paramsBinding = canonicalUpstreamAlias || ((body.node.extra ??= {}).binding = createBinding(
4425
4415
  generateUid("params"),
4426
4416
  type,
4427
4417
  section,
4428
- canonicalUpstreamAlias,
4418
+ void 0,
4429
4419
  void 0
4430
4420
  ));
4431
4421
  section.params = paramsBinding;
@@ -4682,7 +4672,7 @@ function mergeReferences(section, target, nodes) {
4682
4672
  return targetExtra;
4683
4673
  }
4684
4674
  function compareReferences(a, b) {
4685
- 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;
4686
4676
  }
4687
4677
  function compareIntersections(a, b) {
4688
4678
  const len = a.length;
@@ -4774,8 +4764,9 @@ function finalizeReferences() {
4774
4764
  section: section2
4775
4765
  } of binding.downstreamExpressions) {
4776
4766
  if (section2 !== binding.section) {
4777
- binding.closureSections = sectionUtil.add(
4778
- binding.closureSections,
4767
+ const canonicalUpstreamAlias = getCanonicalBinding(binding);
4768
+ canonicalUpstreamAlias.closureSections = sectionUtil.add(
4769
+ canonicalUpstreamAlias.closureSections,
4779
4770
  section2
4780
4771
  );
4781
4772
  section2.referencedClosures = bindingUtil.add(
@@ -4784,8 +4775,8 @@ function finalizeReferences() {
4784
4775
  );
4785
4776
  addOwnersSerializeReason(
4786
4777
  section2,
4787
- binding.section,
4788
- binding.sources,
4778
+ canonicalUpstreamAlias.section,
4779
+ !!isEffect || canonicalUpstreamAlias.sources,
4789
4780
  getAccessorProp().Owner
4790
4781
  );
4791
4782
  }
@@ -5130,18 +5121,20 @@ function getAllTagReferenceNodes(tag, referenceNodes = []) {
5130
5121
  return referenceNodes;
5131
5122
  }
5132
5123
  function getScopeAccessorLiteral(binding, includeId) {
5124
+ const canonicalBinding = getCanonicalBinding(binding);
5133
5125
  if (isOptimize()) {
5134
- return import_compiler24.types.numericLiteral(binding.id);
5126
+ return import_compiler24.types.numericLiteral(canonicalBinding.id);
5135
5127
  }
5136
5128
  return import_compiler24.types.stringLiteral(
5137
- binding.name + (includeId || binding.type === 0 /* dom */ ? `/${binding.id}` : "")
5129
+ canonicalBinding.name + (includeId || canonicalBinding.type === 0 /* dom */ ? `/${canonicalBinding.id}` : "")
5138
5130
  );
5139
5131
  }
5140
5132
  function getScopeAccessor(binding, includeId) {
5133
+ const canonicalBinding = getCanonicalBinding(binding);
5141
5134
  if (isOptimize()) {
5142
- return binding.id + "";
5135
+ return canonicalBinding.id + "";
5143
5136
  }
5144
- return binding.name + (includeId || binding.type === 0 /* dom */ ? `/${binding.id}` : "");
5137
+ return canonicalBinding.name + (includeId || canonicalBinding.type === 0 /* dom */ ? `/${canonicalBinding.id}` : "");
5145
5138
  }
5146
5139
  function getDebugScopeAccess(binding) {
5147
5140
  let root = binding;
@@ -6786,25 +6779,6 @@ var for_default = {
6786
6779
  import_compiler33.types.identifier(bodySection.name)
6787
6780
  );
6788
6781
  };
6789
- const params = node.body.params;
6790
- signal.hasDownstreamIntersections = () => {
6791
- for (const param of params) {
6792
- const binding = param.extra?.binding;
6793
- if (binding) {
6794
- for (const {
6795
- referencedBindings: referencedBindings2
6796
- } of binding.downstreamExpressions) {
6797
- if (getSignal(
6798
- bodySection,
6799
- referencedBindings2
6800
- ).hasDownstreamIntersections()) {
6801
- return true;
6802
- }
6803
- }
6804
- }
6805
- }
6806
- return false;
6807
- };
6808
6782
  const forAttrs = getKnownAttrValues(node);
6809
6783
  const loopArgs = getBaseArgsInForTag(forType, forAttrs);
6810
6784
  if (forAttrs.by) {
@@ -9531,7 +9505,6 @@ var try_default = {
9531
9505
  signal,
9532
9506
  propsToExpression(translatedAttrs.properties)
9533
9507
  );
9534
- signal.hasDownstreamIntersections = () => true;
9535
9508
  tag.remove();
9536
9509
  }
9537
9510
  }
@@ -10298,20 +10271,6 @@ function translateDOM(tag) {
10298
10271
  tagName
10299
10272
  );
10300
10273
  const inputExport = childExports.input;
10301
- if (inputExport) {
10302
- writeAttrsToExports(tag, inputExport, `${getTagName(tag) || "tag"}_input`, {
10303
- circular: childFile.opts.filename === file.opts.filename,
10304
- tagSection,
10305
- relativePath,
10306
- childScopeBinding,
10307
- attrTagCallsByTag: void 0
10308
- });
10309
- }
10310
- write2`${(0, import_babel_utils47.importNamed)(file, relativePath, childExports.template, `${tagName}_template`)}`;
10311
- injectWalks(
10312
- tag,
10313
- (0, import_babel_utils47.importNamed)(file, relativePath, childExports.walks, `${tagName}_walks`)
10314
- );
10315
10274
  if (node.var) {
10316
10275
  const source = initValue(
10317
10276
  // TODO: support destructuring
@@ -10348,6 +10307,20 @@ function translateDOM(tag) {
10348
10307
  ])
10349
10308
  )
10350
10309
  );
10310
+ if (inputExport) {
10311
+ writeAttrsToExports(tag, inputExport, `${getTagName(tag) || "tag"}_input`, {
10312
+ circular: childFile.opts.filename === file.opts.filename,
10313
+ tagSection,
10314
+ relativePath,
10315
+ childScopeBinding,
10316
+ attrTagCallsByTag: void 0
10317
+ });
10318
+ }
10319
+ write2`${(0, import_babel_utils47.importNamed)(file, relativePath, childExports.template, `${tagName}_template`)}`;
10320
+ injectWalks(
10321
+ tag,
10322
+ (0, import_babel_utils47.importNamed)(file, relativePath, childExports.walks, `${tagName}_walks`)
10323
+ );
10351
10324
  tag.remove();
10352
10325
  }
10353
10326
  function getTagRelativePath(tag) {
@@ -10502,14 +10475,18 @@ function writeAttrsToExports(tag, templateExport, importAlias, info) {
10502
10475
  templateExport.id,
10503
10476
  importAlias
10504
10477
  );
10505
- addValue(
10478
+ addStatement(
10479
+ "render",
10506
10480
  info.tagSection,
10507
10481
  // technically this should be `arg.extra?.referencedBindings`
10508
10482
  // but we should probably ensure all other references are dropped in this case before we do that.
10509
10483
  tag.node.extra?.referencedBindings,
10510
- identifierToSignal(tagInputIdentifier),
10511
- import_compiler56.types.isSpreadElement(arg) ? import_compiler56.types.memberExpression(arg.argument, import_compiler56.types.numericLiteral(0), true) : arg,
10512
- createScopeReadExpression(info.tagSection, info.childScopeBinding)
10484
+ import_compiler56.types.expressionStatement(
10485
+ import_compiler56.types.callExpression(tagInputIdentifier, [
10486
+ createScopeReadExpression(info.tagSection, info.childScopeBinding),
10487
+ import_compiler56.types.isSpreadElement(arg) ? import_compiler56.types.memberExpression(arg.argument, import_compiler56.types.numericLiteral(0), true) : arg
10488
+ ])
10489
+ )
10513
10490
  );
10514
10491
  return;
10515
10492
  }
@@ -10565,12 +10542,16 @@ function writeAttrsToExports(tag, templateExport, importAlias, info) {
10565
10542
  translatedProps = callRuntime("attrTag", translatedProps);
10566
10543
  }
10567
10544
  }
10568
- addValue(
10545
+ addStatement(
10546
+ "render",
10569
10547
  info.tagSection,
10570
10548
  referencedBindings,
10571
- identifierToSignal(tagInputIdentifier),
10572
- translatedProps,
10573
- createScopeReadExpression(info.tagSection, info.childScopeBinding)
10549
+ import_compiler56.types.expressionStatement(
10550
+ import_compiler56.types.callExpression(tagInputIdentifier, [
10551
+ createScopeReadExpression(info.tagSection, info.childScopeBinding),
10552
+ translatedProps
10553
+ ])
10554
+ )
10574
10555
  );
10575
10556
  return;
10576
10557
  }
@@ -10642,18 +10623,25 @@ function writeAttrsToExports(tag, templateExport, importAlias, info) {
10642
10623
  `${importAlias}_${attrTagMeta.name}`
10643
10624
  );
10644
10625
  decls.push(import_compiler56.types.variableDeclarator(getAttrTagIdentifier(attrTagMeta)));
10645
- addValue(
10626
+ addStatement("render", info.tagSection, referencedBindings, [
10627
+ import_compiler56.types.variableDeclaration("let", decls),
10628
+ ...statements
10629
+ ]);
10630
+ addStatement(
10631
+ "render",
10646
10632
  info.tagSection,
10647
10633
  referencedBindings,
10648
- identifierToSignal(attrExportIdentifier),
10649
- getAttrTagIdentifier(attrTagMeta),
10650
- createScopeReadExpression(info.tagSection, info.childScopeBinding)
10634
+ import_compiler56.types.expressionStatement(
10635
+ import_compiler56.types.callExpression(attrExportIdentifier, [
10636
+ createScopeReadExpression(
10637
+ info.tagSection,
10638
+ info.childScopeBinding
10639
+ ),
10640
+ getAttrTagIdentifier(attrTagMeta)
10641
+ ])
10642
+ )
10651
10643
  );
10652
10644
  }
10653
- addStatement("render", info.tagSection, referencedBindings, [
10654
- import_compiler56.types.variableDeclaration("let", decls),
10655
- ...statements
10656
- ]);
10657
10645
  }
10658
10646
  }
10659
10647
  const bodySection = tag.node.body.extra?.section;
@@ -10666,13 +10654,17 @@ function writeAttrsToExports(tag, templateExport, importAlias, info) {
10666
10654
  templateExport.props.content.id,
10667
10655
  `${importAlias}_content`
10668
10656
  );
10669
- addValue(
10657
+ addStatement(
10658
+ "render",
10670
10659
  info.tagSection,
10671
10660
  void 0,
10672
10661
  // TODO: pretty sure content needs to have the reference group of it's param defaults.
10673
- identifierToSignal(contentExportIdentifier),
10674
- import_compiler56.types.callExpression(import_compiler56.types.identifier(bodySection.name), [scopeIdentifier]),
10675
- createScopeReadExpression(info.tagSection, info.childScopeBinding)
10662
+ import_compiler56.types.expressionStatement(
10663
+ import_compiler56.types.callExpression(contentExportIdentifier, [
10664
+ createScopeReadExpression(info.tagSection, info.childScopeBinding),
10665
+ import_compiler56.types.callExpression(import_compiler56.types.identifier(bodySection.name), [scopeIdentifier])
10666
+ ])
10667
+ )
10676
10668
  );
10677
10669
  }
10678
10670
  }
@@ -10704,12 +10696,16 @@ function writeAttrsToExports(tag, templateExport, importAlias, info) {
10704
10696
  childAttrExports.id,
10705
10697
  `${importAlias}_${attr2.name}`
10706
10698
  );
10707
- addValue(
10699
+ addStatement(
10700
+ "render",
10708
10701
  info.tagSection,
10709
10702
  attr2.value.extra?.referencedBindings,
10710
- identifierToSignal(attrExportIdentifier),
10711
- attr2.value,
10712
- createScopeReadExpression(info.tagSection, info.childScopeBinding)
10703
+ import_compiler56.types.expressionStatement(
10704
+ import_compiler56.types.callExpression(attrExportIdentifier, [
10705
+ createScopeReadExpression(info.tagSection, info.childScopeBinding),
10706
+ attr2.value
10707
+ ])
10708
+ )
10713
10709
  );
10714
10710
  }
10715
10711
  const missing = new Set(Object.keys(templateExport.props));
@@ -10735,12 +10731,16 @@ function writeAttrsToExports(tag, templateExport, importAlias, info) {
10735
10731
  childAttrExports.id,
10736
10732
  `${importAlias}_${name2}`
10737
10733
  );
10738
- addValue(
10734
+ addStatement(
10735
+ "render",
10739
10736
  info.tagSection,
10740
10737
  referencedBindings,
10741
- identifierToSignal(attrExportIdentifier),
10742
- getMissingPropValue(name2),
10743
- createScopeReadExpression(info.tagSection, info.childScopeBinding)
10738
+ import_compiler56.types.expressionStatement(
10739
+ import_compiler56.types.callExpression(attrExportIdentifier, [
10740
+ createScopeReadExpression(info.tagSection, info.childScopeBinding),
10741
+ getMissingPropValue(name2)
10742
+ ])
10743
+ )
10744
10744
  );
10745
10745
  }
10746
10746
  }
@@ -10791,18 +10791,9 @@ function callStatement(id, ...args) {
10791
10791
  function callExpression(id, ...args) {
10792
10792
  return import_compiler56.types.callExpression(id, args.filter(Boolean));
10793
10793
  }
10794
- function identifierToSignal(identifier) {
10795
- return {
10796
- identifier,
10797
- hasDownstreamIntersections: always
10798
- };
10799
- }
10800
10794
  function buildUndefined2() {
10801
10795
  return import_compiler56.types.unaryExpression("void", import_compiler56.types.numericLiteral(0));
10802
10796
  }
10803
- function always() {
10804
- return true;
10805
- }
10806
10797
 
10807
10798
  // src/translator/visitors/tag/dynamic-tag.ts
10808
10799
  var import_compiler57 = require("@marko/compiler");
@@ -11031,7 +11022,6 @@ var dynamic_tag_default = {
11031
11022
  ];
11032
11023
  }
11033
11024
  }
11034
- signal.hasDownstreamIntersections = () => true;
11035
11025
  addValue(section, tagExtra.referencedBindings, signal, tagExpression);
11036
11026
  tag.remove();
11037
11027
  }
@@ -1,3 +1,3 @@
1
1
  import { types as t } from "@marko/compiler";
2
- import type { Binding } from "./references";
2
+ import { type Binding } from "./references";
3
3
  export declare function getDeclaredBindingExpression(binding: Binding): t.Identifier | t.OptionalMemberExpression | t.MemberExpression;
@@ -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;
@@ -11,21 +11,14 @@ export type Signal = {
11
11
  build: () => t.Expression;
12
12
  register?: boolean;
13
13
  values: Array<{
14
- signal: {
15
- identifier: t.Identifier | t.MemberExpression;
16
- hasDownstreamIntersections: () => boolean;
17
- buildDeclaration?: () => t.VariableDeclaration;
18
- extraArgs?: t.Expression[];
19
- };
14
+ signal: Signal;
20
15
  value: t.Expression;
21
- scope: t.Expression;
22
16
  }>;
23
- intersection: Opt<t.Expression>;
17
+ intersection: Opt<Signal>;
24
18
  render: t.Statement[];
25
19
  renderReferencedBindings: ReferencedBindings;
26
20
  effect: t.Statement[];
27
21
  effectReferencedBindings: ReferencedBindings;
28
- hasDownstreamIntersections: () => boolean;
29
22
  hasDynamicSubscribers?: true;
30
23
  export: boolean;
31
24
  extraArgs?: t.Expression[];
@@ -41,15 +34,10 @@ export declare const getHTMLSectionStatements: (section: Section) => t.Statement
41
34
  export declare function getHoistFunctionIdentifier(hoistedBinding: Binding): t.Identifier;
42
35
  export declare function getSignal(section: Section, referencedBindings: ReferencedBindings, name?: string): Signal;
43
36
  export declare function initValue(binding: Binding, runtimeHelper?: "value" | "state"): Signal;
44
- export declare function getDestructureSignal(bindingIdentifiersByName: Record<string, t.Identifier> | t.Identifier[], destructurePattern: t.LVal): {
45
- readonly identifier: t.Identifier;
46
- build(canCallOnlyWhenDirty?: boolean): t.ArrowFunctionExpression;
47
- hasDownstreamIntersections(): boolean;
48
- } | undefined;
49
37
  export declare function subscribe(provider: ReferencedBindings, subscriber: Signal): void;
50
38
  export declare function replaceNullishAndEmptyFunctionsWith0(args: (t.Expression | undefined | false)[]): t.Expression[];
51
39
  export declare function addStatement(type: "render" | "effect", targetSection: Section, referencedBindings: ReferencedBindings, statement: t.Statement | t.Statement[], usedReferences?: ReferencedBindings[] | false): void;
52
- export declare function addValue(targetSection: Section, referencedBindings: ReferencedBindings, signal: Signal["values"][number]["signal"], value: t.Expression, scope?: t.Expression): void;
40
+ export declare function addValue(targetSection: Section, referencedBindings: ReferencedBindings, signal: Signal["values"][number]["signal"], value: t.Expression): void;
53
41
  export declare function getResumeRegisterId(section: Section, referencedBindings: string | ReferencedBindings, type?: string): string;
54
42
  export declare function getRegisterUID(section: Section, name: string): string;
55
43
  export declare function writeSignals(section: Section): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.11",
3
+ "version": "6.0.13",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",