marko 6.0.84 → 6.0.85

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.
@@ -2660,10 +2660,7 @@ function withLeadingComment(node, value) {
2660
2660
 
2661
2661
  // src/translator/util/serialize-guard.ts
2662
2662
  function getSerializeGuard(reason, optional) {
2663
- return !reason ? import_compiler14.types.numericLiteral(0) : reason === true || reason.state ? optional ? void 0 : reason === true ? import_compiler14.types.numericLiteral(1) : withLeadingComment(
2664
- import_compiler14.types.numericLiteral(1),
2665
- mapToString(reason.state, ", ", getDebugName)
2666
- ) : getInputSerializeReasonGuard(reason);
2663
+ return !reason ? import_compiler14.types.numericLiteral(0) : reason === true || reason.state ? optional ? void 0 : reason === true ? import_compiler14.types.numericLiteral(1) : withLeadingComment(import_compiler14.types.numericLiteral(1), getDebugNames(reason.state)) : getInputSerializeReasonGuard(reason);
2667
2664
  }
2668
2665
  function getSerializeGuardForAny(reasons, optional) {
2669
2666
  if (!reasons || reasons === true) {
@@ -2675,10 +2672,7 @@ function getSerializeGuardForAny(reasons, optional) {
2675
2672
  let expr;
2676
2673
  for (const reason of reasons) {
2677
2674
  if (reason.state) {
2678
- return optional ? void 0 : withLeadingComment(
2679
- import_compiler14.types.numericLiteral(1),
2680
- mapToString(reason.state, ", ", getDebugName)
2681
- );
2675
+ return optional ? void 0 : withLeadingComment(import_compiler14.types.numericLiteral(1), getDebugNames(reason.state));
2682
2676
  }
2683
2677
  const guard = getSerializeGuard(reason, false);
2684
2678
  expr = expr ? import_compiler14.types.logicalExpression("||", expr, guard) : guard;
@@ -2699,7 +2693,7 @@ function getExprIfSerialized(reason, expr) {
2699
2693
  serializeIdentifier,
2700
2694
  withLeadingComment(
2701
2695
  import_compiler14.types.numericLiteral(getParamReasonGroupIndex(section, reasons)),
2702
- mapToString(reasons, ", ", getDebugName)
2696
+ getDebugNames(reasons)
2703
2697
  )
2704
2698
  ) : serializeIdentifier;
2705
2699
  orExpr = orExpr ? import_compiler14.types.logicalExpression("||", orExpr, guard) : guard;
@@ -2717,7 +2711,7 @@ function getInputSerializeReasonGuard(reason) {
2717
2711
  serializeIdentifier,
2718
2712
  withLeadingComment(
2719
2713
  import_compiler14.types.numericLiteral(getParamReasonGroupIndex(section, reasons)),
2720
- mapToString(reasons, ", ", getDebugName)
2714
+ getDebugNames(reasons)
2721
2715
  )
2722
2716
  ) : serializeIdentifier;
2723
2717
  expr = expr ? import_compiler14.types.logicalExpression("||", expr, guard) : guard;
@@ -3354,20 +3348,15 @@ function initValue(binding, isLet = false) {
3354
3348
  const signal = getSignal(section, binding);
3355
3349
  signal.build = () => {
3356
3350
  const fn = getSignalFn(signal);
3357
- const isParamBinding = !binding.upstreamAlias && (binding.type === 3 /* param */ || binding.type === 4 /* local */ || binding.type === 2 /* input */);
3358
- const isNakedAlias = binding.upstreamAlias && binding.property === void 0 && binding.excludeProperties === void 0;
3359
- const needsGuard = !isNakedAlias && (binding.closureSections || binding.downstreamExpressions.size || fn.type === "ArrowFunctionExpression" && fn.body.body.length > 0);
3360
- const needsCache = needsGuard || signal.intersection;
3361
- const needsMarks = isParamBinding || signal.intersection;
3362
- if (needsCache || needsMarks || binding.hoists.size) {
3363
- return callRuntime(
3364
- isLet ? "_let" : "_const",
3365
- getScopeAccessorLiteral(binding, isLet),
3366
- fn
3367
- );
3368
- } else {
3351
+ const isDirectAlias = binding.upstreamAlias && binding.property === void 0 && binding.excludeProperties === void 0;
3352
+ if (isDirectAlias || !signalHasStatements(signal)) {
3369
3353
  return fn;
3370
3354
  }
3355
+ return callRuntime(
3356
+ isLet ? "_let" : "_const",
3357
+ getScopeAccessorLiteral(binding, isLet),
3358
+ fn
3359
+ );
3371
3360
  };
3372
3361
  signal.valueAccessor = getScopeAccessorLiteral(binding);
3373
3362
  for (const alias of binding.aliases) {
@@ -3379,12 +3368,12 @@ function initValue(binding, isLet = false) {
3379
3368
  return signal;
3380
3369
  }
3381
3370
  function signalHasStatements(signal) {
3382
- if (signal.render.length || signal.effect.length || signal.values.length || signal.intersection) {
3371
+ if (signal.extraArgs || signal.render.length || signal.effect.length || signal.values.length || signal.intersection) {
3383
3372
  return true;
3384
3373
  }
3385
3374
  const binding = signal.referencedBindings;
3386
3375
  if (binding) {
3387
- if (!Array.isArray(binding) && binding.section === signal.section && (binding.aliases.size || binding.propertyAliases.size)) {
3376
+ if (!Array.isArray(binding) && (binding.closureSections || binding.type === 0 /* dom */ || binding.section === signal.section && (binding.hoists.size || binding.aliases.size || binding.propertyAliases.size))) {
3388
3377
  return true;
3389
3378
  }
3390
3379
  } else if (signal.section.referencedClosures) {
@@ -3411,7 +3400,7 @@ function getSignalFn(signal) {
3411
3400
  if (isValue) {
3412
3401
  for (const alias of binding.aliases) {
3413
3402
  const aliasSignal = getSignal(alias.section, alias);
3414
- if (aliasSignal.render.length || aliasSignal.values.length || aliasSignal.effect.length) {
3403
+ if (signalHasStatements(aliasSignal)) {
3415
3404
  if (alias.excludeProperties !== void 0) {
3416
3405
  const props = [];
3417
3406
  const aliasId = import_compiler22.types.identifier(alias.name);
@@ -3474,8 +3463,7 @@ function getSignalFn(signal) {
3474
3463
  }
3475
3464
  }
3476
3465
  for (const value of signal.values) {
3477
- const valSignal = value.signal;
3478
- if (!valSignal.referencedBindings || Array.isArray(valSignal.referencedBindings) || !valSignal.referencedBindings.upstreamAlias || valSignal.referencedBindings.property !== void 0 || valSignal.referencedBindings.excludeProperties !== void 0 || valSignal.effect.length || valSignal.render.length || valSignal.values.length) {
3466
+ if (signalHasStatements(value.signal)) {
3479
3467
  signal.render.push(
3480
3468
  import_compiler22.types.expressionStatement(
3481
3469
  import_compiler22.types.callExpression(value.signal.identifier, [
@@ -3486,7 +3474,14 @@ function getSignalFn(signal) {
3486
3474
  )
3487
3475
  );
3488
3476
  } else {
3489
- signal.render.push(import_compiler22.types.expressionStatement(value.value));
3477
+ signal.render.push(
3478
+ import_compiler22.types.expressionStatement(
3479
+ withLeadingComment(
3480
+ value.value,
3481
+ getDebugNames(value.signal.referencedBindings)
3482
+ )
3483
+ )
3484
+ );
3490
3485
  }
3491
3486
  }
3492
3487
  forEach(signal.intersection, (intersection) => {
@@ -3782,15 +3777,7 @@ function writeSignals(section) {
3782
3777
  );
3783
3778
  }
3784
3779
  let value = signal.build();
3785
- if (!value) {
3786
- return;
3787
- }
3788
- if (
3789
- // It's possible for aliases to render nothing
3790
- // if they're only consumed in effects/closures.
3791
- // This ignores writing out those signals in that case.
3792
- signal.referencedBindings && !Array.isArray(signal.referencedBindings) && signal.referencedBindings.upstreamAlias && signal.referencedBindings.property === void 0 && signal.referencedBindings.excludeProperties === void 0 && import_compiler22.types.isFunction(value) && import_compiler22.types.isBlockStatement(value.body) && !value.body.body.length
3793
- ) {
3780
+ if (!value || !signal.register && import_compiler22.types.isFunction(value) && import_compiler22.types.isBlockStatement(value.body) && !value.body.body.length) {
3794
3781
  return;
3795
3782
  }
3796
3783
  if (import_compiler22.types.isCallExpression(value)) {
@@ -4189,12 +4176,15 @@ function replaceAssignedNode(node) {
4189
4176
  case "UpdateExpression": {
4190
4177
  const { extra } = node.argument;
4191
4178
  if (isAssignedBindingExtra(extra)) {
4192
- const buildAssignment = getBuildAssignment(extra);
4193
- if (buildAssignment) {
4179
+ const builtAssignment = getBuildAssignment(extra)?.(
4180
+ extra.section,
4181
+ node
4182
+ );
4183
+ if (builtAssignment) {
4194
4184
  if (!node.prefix) {
4195
4185
  node.prefix = true;
4196
4186
  const replacement = import_compiler22.types.sequenceExpression([
4197
- buildAssignment(extra.section, node),
4187
+ builtAssignment,
4198
4188
  import_compiler22.types.binaryExpression(
4199
4189
  node.operator === "++" ? "-" : "+",
4200
4190
  node.argument,
@@ -4204,7 +4194,7 @@ function replaceAssignedNode(node) {
4204
4194
  updateExpressions.add(replacement);
4205
4195
  return replacement;
4206
4196
  }
4207
- return buildAssignment(extra.section, node);
4197
+ return builtAssignment;
4208
4198
  }
4209
4199
  }
4210
4200
  break;
@@ -4214,27 +4204,20 @@ function replaceAssignedNode(node) {
4214
4204
  case "Identifier": {
4215
4205
  const { extra } = node.left;
4216
4206
  if (isAssignedBindingExtra(extra)) {
4217
- const buildAssignment = getBuildAssignment(extra);
4218
- if (buildAssignment) {
4219
- if (bindingUtil.has(
4207
+ return getBuildAssignment(extra)?.(
4208
+ extra.section,
4209
+ bindingUtil.has(
4220
4210
  extra.fnExtra?.referencedBindingsInFunction,
4221
4211
  extra.assignment
4222
- )) {
4223
- return buildAssignment(extra.section, node);
4224
- } else {
4225
- return buildAssignment(
4226
- extra.section,
4227
- node.operator === "=" ? node.right : import_compiler22.types.binaryExpression(
4228
- node.operator.slice(
4229
- 0,
4230
- -1
4231
- ),
4232
- node.left,
4233
- node.right
4234
- )
4235
- );
4236
- }
4237
- }
4212
+ ) ? node : node.operator === "=" ? node.right : import_compiler22.types.binaryExpression(
4213
+ node.operator.slice(
4214
+ 0,
4215
+ -1
4216
+ ),
4217
+ node.left,
4218
+ node.right
4219
+ )
4220
+ ) || extra?.assignment && withLeadingComment(node.right, getDebugName(extra.assignment));
4238
4221
  }
4239
4222
  break;
4240
4223
  }
@@ -4247,18 +4230,27 @@ function replaceAssignedNode(node) {
4247
4230
  if (isAssignedBindingExtra(extra)) {
4248
4231
  const buildAssignment = getBuildAssignment(extra);
4249
4232
  if (buildAssignment) {
4250
- if (!bindingUtil.has(
4251
- extra.fnExtra?.referencedBindingsInFunction,
4252
- extra.assignment
4253
- )) {
4254
- id.name = generateUid(id.name);
4255
- (params ||= []).push(import_compiler22.types.identifier(id.name));
4256
- }
4257
- (assignments ||= []).push(
4258
- buildAssignment(extra.section, import_compiler22.types.identifier(id.name))
4233
+ const uid = generateUid(id.name);
4234
+ const builtAssignment = buildAssignment(
4235
+ extra.section,
4236
+ import_compiler22.types.identifier(uid)
4259
4237
  );
4238
+ if (builtAssignment) {
4239
+ if (!bindingUtil.has(
4240
+ extra.fnExtra?.referencedBindingsInFunction,
4241
+ extra.assignment
4242
+ )) {
4243
+ id.name = uid;
4244
+ }
4245
+ (params ||= []).push(import_compiler22.types.identifier(uid));
4246
+ (assignments ||= []).push(builtAssignment);
4247
+ return;
4248
+ }
4260
4249
  }
4261
4250
  }
4251
+ if (extra?.assignment) {
4252
+ (params ||= []).push(import_compiler22.types.identifier(id.name));
4253
+ }
4262
4254
  });
4263
4255
  if (assignments) {
4264
4256
  const resultId = generateUid("result");
@@ -4370,22 +4362,25 @@ var dom_default = {
4370
4362
  if (childSection !== section) {
4371
4363
  forEach(childSection.referencedClosures, (closure) => {
4372
4364
  const closureSignal = getSignal(childSection, closure);
4373
- addStatement(
4374
- "render",
4375
- childSection,
4376
- void 0,
4377
- import_compiler23.types.expressionStatement(
4378
- import_compiler23.types.callExpression(
4379
- isDynamicClosure(childSection, closure) ? closureSignal.identifier : import_compiler23.types.memberExpression(
4380
- closureSignal.identifier,
4381
- import_compiler23.types.identifier("_")
4382
- ),
4383
- [scopeIdentifier]
4365
+ if (signalHasStatements(closureSignal)) {
4366
+ addStatement(
4367
+ "render",
4368
+ childSection,
4369
+ void 0,
4370
+ import_compiler23.types.expressionStatement(
4371
+ import_compiler23.types.callExpression(
4372
+ isDynamicClosure(childSection, closure) ? closureSignal.identifier : import_compiler23.types.memberExpression(
4373
+ closureSignal.identifier,
4374
+ import_compiler23.types.identifier("_")
4375
+ ),
4376
+ [scopeIdentifier]
4377
+ )
4384
4378
  )
4385
- )
4386
- );
4379
+ );
4380
+ }
4387
4381
  });
4388
4382
  const tagParamsSignal = childSection.params && initValue(childSection.params);
4383
+ const tagParamsIdentifier = tagParamsSignal && signalHasStatements(tagParamsSignal) ? tagParamsSignal.identifier : void 0;
4389
4384
  const { walks: walks2, writes: writes2, setup: setup2, decls: decls2 } = getSectionMeta(childSection);
4390
4385
  writeSignals(childSection);
4391
4386
  if (!childSection.downstreamBinding || bindingHasDownstreamExpressions(childSection.downstreamBinding)) {
@@ -4395,7 +4390,7 @@ var dom_default = {
4395
4390
  writes2,
4396
4391
  walks2,
4397
4392
  setup2,
4398
- tagParamsSignal?.identifier
4393
+ tagParamsIdentifier
4399
4394
  ])
4400
4395
  ) : callRuntime(
4401
4396
  getSectionRegisterReasons(childSection) ? "_content_resume" : "_content",
@@ -4404,30 +4399,33 @@ var dom_default = {
4404
4399
  writes2,
4405
4400
  walks2,
4406
4401
  setup2,
4407
- tagParamsSignal?.identifier,
4402
+ tagParamsIdentifier,
4408
4403
  childSection.hoisted || childSection.isHoistThrough ? getSectionInstancesAccessorLiteral(childSection) : void 0
4409
4404
  ])
4410
4405
  );
4411
4406
  if (childSection.referencedLocalClosures) {
4412
- renderer = callRuntime(
4413
- "_content_closures",
4414
- renderer,
4415
- import_compiler23.types.objectExpression(
4416
- toArray(childSection.referencedLocalClosures, (closure) => {
4417
- const expr = getSignalFn(getSignal(childSection, closure));
4418
- const key = toPropertyName(getScopeAccessor(closure));
4419
- if (import_compiler23.types.isFunction(expr) && import_compiler23.types.isBlockStatement(expr.body)) {
4420
- return import_compiler23.types.objectMethod(
4421
- "method",
4422
- key,
4423
- expr.params,
4424
- expr.body
4425
- );
4426
- }
4427
- return import_compiler23.types.objectProperty(key, expr);
4428
- })
4429
- )
4430
- );
4407
+ const objProps = [];
4408
+ forEach(childSection.referencedLocalClosures, (closure) => {
4409
+ const closureSignal = getSignal(childSection, closure);
4410
+ const key = toPropertyName(getScopeAccessor(closure));
4411
+ if (signalHasStatements(closureSignal)) {
4412
+ const expr = getSignalFn(closureSignal);
4413
+ if (import_compiler23.types.isFunction(expr) && import_compiler23.types.isBlockStatement(expr.body)) {
4414
+ objProps.push(
4415
+ import_compiler23.types.objectMethod("method", key, expr.params, expr.body)
4416
+ );
4417
+ } else {
4418
+ objProps.push(import_compiler23.types.objectProperty(key, expr));
4419
+ }
4420
+ }
4421
+ });
4422
+ if (objProps.length) {
4423
+ renderer = callRuntime(
4424
+ "_content_closures",
4425
+ renderer,
4426
+ import_compiler23.types.objectExpression(objProps)
4427
+ );
4428
+ }
4431
4429
  }
4432
4430
  program.node.body.push(
4433
4431
  import_compiler23.types.variableDeclaration("const", [
@@ -6770,7 +6768,7 @@ function knownTagTranslateHTML(tag, tagIdentifier, contentSection, propTree) {
6770
6768
  import_compiler33.types.objectProperty(
6771
6769
  withLeadingComment(
6772
6770
  import_compiler33.types.numericLiteral(i),
6773
- mapToString(group.reason, ", ", getDebugName)
6771
+ getDebugNames(group.reason)
6774
6772
  ),
6775
6773
  getSerializeGuard(reason, false)
6776
6774
  )
@@ -8400,6 +8398,9 @@ function getDebugName(binding) {
8400
8398
  const { root, access } = getDebugScopeAccess(binding);
8401
8399
  return root.name + access;
8402
8400
  }
8401
+ function getDebugNames(refs) {
8402
+ return mapToString(refs, ", ", getDebugName);
8403
+ }
8403
8404
  function getSectionInstancesAccessor(section) {
8404
8405
  return section.sectionAccessor ? section.sectionAccessor.prefix + getScopeAccessor(section.sectionAccessor.binding) : getAccessorPrefix().ClosureScopes + section.id;
8405
8406
  }
@@ -10637,8 +10638,12 @@ var let_default = {
10637
10638
  signal.extraArgs = [valueChangeAttr.value];
10638
10639
  }
10639
10640
  signal.buildAssignment = (valueSection, value) => {
10640
- const scope = getScopeExpression(valueSection, signal.section);
10641
- return import_compiler48.types.callExpression(signal.identifier, [scope, value]);
10641
+ if (valueChangeAttr || signalHasStatements(signal)) {
10642
+ return import_compiler48.types.callExpression(signal.identifier, [
10643
+ getScopeExpression(valueSection, signal.section),
10644
+ value
10645
+ ]);
10646
+ }
10642
10647
  };
10643
10648
  } else {
10644
10649
  translateVar(tag, valueAttr.value, "let");
@@ -105,6 +105,7 @@ export declare function getDebugScopeAccess(binding: Binding): {
105
105
  access: string;
106
106
  };
107
107
  export declare function getDebugName(binding: Binding): string;
108
+ export declare function getDebugNames(refs: ReferencedBindings): string;
108
109
  export declare function getSectionInstancesAccessor(section: Section): string;
109
110
  export declare function getSectionInstancesAccessorLiteral(section: Section): t.StringLiteral | t.NumericLiteral | undefined;
110
111
  export declare function getReadReplacement(node: t.Identifier | t.MemberExpression): t.Node | undefined;
@@ -23,7 +23,7 @@ export type Signal = {
23
23
  export: boolean;
24
24
  extraArgs?: t.Expression[];
25
25
  prependStatements?: t.Statement[];
26
- buildAssignment?: (valueSection: Section, value: t.Expression) => t.Expression;
26
+ buildAssignment?: (valueSection: Section, value: t.Expression) => t.Expression | undefined;
27
27
  };
28
28
  type closureSignalBuilder = (closure: Binding, render: t.Expression) => t.Expression;
29
29
  export declare function setClosureSignalBuilder(tag: t.NodePath<t.MarkoTag>, builder: closureSignalBuilder): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.84",
3
+ "version": "6.0.85",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",