@barefootjs/jsx 0.40.2 → 0.41.0

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.
Files changed (88) hide show
  1. package/dist/adapters/callback-method.d.ts +8 -1
  2. package/dist/adapters/callback-method.d.ts.map +1 -1
  3. package/dist/adapters/component-props.d.ts +3 -4
  4. package/dist/adapters/component-props.d.ts.map +1 -1
  5. package/dist/adapters/dsl-template-adapter.d.ts +3 -12
  6. package/dist/adapters/dsl-template-adapter.d.ts.map +1 -1
  7. package/dist/adapters/loop-row-type.d.ts +7 -0
  8. package/dist/adapters/loop-row-type.d.ts.map +1 -1
  9. package/dist/adapters/nil-reading.d.ts +15 -20
  10. package/dist/adapters/nil-reading.d.ts.map +1 -1
  11. package/dist/adapters/non-primitive-equality.d.ts +1 -1
  12. package/dist/adapters/parsed-expr-emitter.d.ts +11 -1
  13. package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
  14. package/dist/adapters/primitive-plan.d.ts +40 -11
  15. package/dist/adapters/primitive-plan.d.ts.map +1 -1
  16. package/dist/adapters/prop-classes.d.ts +5 -0
  17. package/dist/adapters/prop-classes.d.ts.map +1 -1
  18. package/dist/analyzer.d.ts.map +1 -1
  19. package/dist/index.d.ts +5 -6
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +390 -228
  22. package/dist/ir-to-client-js/child-props-object.d.ts +43 -1
  23. package/dist/ir-to-client-js/child-props-object.d.ts.map +1 -1
  24. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  25. package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts.map +1 -1
  26. package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
  27. package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
  28. package/dist/ir-to-client-js/imports.d.ts +2 -2
  29. package/dist/ir-to-client-js/imports.d.ts.map +1 -1
  30. package/dist/ir-to-client-js/phases/props-extraction.d.ts +3 -3
  31. package/dist/ir-to-client-js/plan/build-declaration-emit.d.ts.map +1 -1
  32. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts +3 -1
  33. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
  34. package/dist/jsx-to-ir.d.ts.map +1 -1
  35. package/dist/nullable-signal-attr.d.ts +4 -46
  36. package/dist/nullable-signal-attr.d.ts.map +1 -1
  37. package/dist/props-binding.d.ts +58 -13
  38. package/dist/props-binding.d.ts.map +1 -1
  39. package/dist/ssr-defaults.d.ts +39 -3
  40. package/dist/ssr-defaults.d.ts.map +1 -1
  41. package/package.json +2 -2
  42. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +6 -6
  43. package/src/__tests__/body-destructured-prop-default-arrow.test.ts +2 -2
  44. package/src/__tests__/body-destructured-props-live.test.ts +5 -5
  45. package/src/__tests__/client-js-generation.test.ts +3 -3
  46. package/src/__tests__/destructure-default-reads-earlier-param.test.ts +7 -7
  47. package/src/__tests__/destructured-props-live.test.ts +1 -1
  48. package/src/__tests__/issue-3861-object-spread-child.test.ts +102 -0
  49. package/src/__tests__/memo-body-expr.test.ts +2 -2
  50. package/src/__tests__/nil-reading.test.ts +3 -2
  51. package/src/__tests__/nullable-signal-attr.test.ts +30 -103
  52. package/src/__tests__/primitive-plan.test.ts +90 -12
  53. package/src/__tests__/prop-default-undefined-only.test.ts +115 -0
  54. package/src/__tests__/prop-references.test.ts +2 -2
  55. package/src/__tests__/props-destructuring.test.ts +17 -0
  56. package/src/__tests__/prune-unused-prop-extractions.test.ts +3 -3
  57. package/src/__tests__/renamed-body-destructure-template.test.ts +7 -7
  58. package/src/__tests__/rewrite-destructured-props.test.ts +1 -1
  59. package/src/__tests__/ssr-defaults.test.ts +113 -25
  60. package/src/__tests__/written-binding-substitution.test.ts +8 -8
  61. package/src/adapters/callback-method.ts +13 -5
  62. package/src/adapters/component-props.ts +3 -4
  63. package/src/adapters/dsl-template-adapter.ts +26 -28
  64. package/src/adapters/loop-row-type.ts +10 -0
  65. package/src/adapters/nil-reading.ts +23 -25
  66. package/src/adapters/non-primitive-equality.ts +1 -1
  67. package/src/adapters/parsed-expr-emitter.ts +31 -2
  68. package/src/adapters/primitive-plan.ts +84 -15
  69. package/src/adapters/prop-classes.ts +16 -3
  70. package/src/analyzer.ts +27 -7
  71. package/src/index.ts +4 -11
  72. package/src/ir-to-client-js/child-props-object.ts +140 -6
  73. package/src/ir-to-client-js/collect-elements.ts +7 -14
  74. package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +4 -2
  75. package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +4 -2
  76. package/src/ir-to-client-js/html-template.ts +18 -9
  77. package/src/ir-to-client-js/imports.ts +1 -1
  78. package/src/ir-to-client-js/phases/props-extraction.ts +11 -7
  79. package/src/ir-to-client-js/plan/build-declaration-emit.ts +40 -7
  80. package/src/ir-to-client-js/prune-unused-prop-extractions.ts +58 -5
  81. package/src/ir-to-client-js/rewrite-destructured-props.ts +31 -1
  82. package/src/jsx-to-ir.ts +15 -2
  83. package/src/nullable-signal-attr.ts +11 -138
  84. package/src/props-binding.ts +84 -19
  85. package/src/ssr-defaults.ts +100 -11
  86. package/dist/adapters/ambiguous-nil-arithmetic.d.ts +0 -42
  87. package/dist/adapters/ambiguous-nil-arithmetic.d.ts.map +0 -1
  88. package/src/adapters/ambiguous-nil-arithmetic.ts +0 -103
package/dist/index.js CHANGED
@@ -3923,6 +3923,7 @@ var RUNTIME_IMPORT_CANDIDATES = [
3923
3923
  "createContext",
3924
3924
  "useContext",
3925
3925
  "forwardProps",
3926
+ "spreadChildProps",
3926
3927
  "applyRestAttrs",
3927
3928
  "splitProps",
3928
3929
  "spreadAttrs",
@@ -5035,17 +5036,37 @@ function computePropsUsedAsConditions(ctx, propNames) {
5035
5036
  // src/ir-to-client-js/prune-unused-prop-extractions.ts
5036
5037
  import ts10 from "typescript";
5037
5038
  function parsePropReadInitializer(init, objectName = PROPS_PARAM) {
5039
+ const defaulted = parseDefaultedPropRead(init, objectName);
5040
+ if (defaulted)
5041
+ return { ...defaulted, coalescesNull: false };
5038
5042
  let core = init;
5039
5043
  let fallback = null;
5040
5044
  if (ts10.isBinaryExpression(core) && core.operatorToken.kind === ts10.SyntaxKind.QuestionQuestionToken) {
5041
5045
  fallback = core.right;
5042
5046
  core = core.left;
5043
5047
  }
5044
- if (!ts10.isPropertyAccessExpression(core))
5048
+ const key = propReadKey(core, objectName);
5049
+ return key === null ? null : { key, fallback, coalescesNull: fallback !== null };
5050
+ }
5051
+ function propReadKey(expr, objectName) {
5052
+ if (!ts10.isPropertyAccessExpression(expr))
5053
+ return null;
5054
+ if (!ts10.isIdentifier(expr.expression) || expr.expression.text !== objectName)
5055
+ return null;
5056
+ return expr.name.text;
5057
+ }
5058
+ function parseDefaultedPropRead(init, objectName) {
5059
+ if (!ts10.isConditionalExpression(init))
5045
5060
  return null;
5046
- if (!ts10.isIdentifier(core.expression) || core.expression.text !== objectName)
5061
+ const test = init.condition;
5062
+ if (!ts10.isBinaryExpression(test) || test.operatorToken.kind !== ts10.SyntaxKind.EqualsEqualsEqualsToken)
5047
5063
  return null;
5048
- return { key: core.name.text, fallback };
5064
+ if (!ts10.isIdentifier(test.right) || test.right.text !== "undefined")
5065
+ return null;
5066
+ const key = propReadKey(test.left, objectName);
5067
+ if (key === null || propReadKey(init.whenFalse, objectName) !== key)
5068
+ return null;
5069
+ return { key, fallback: init.whenTrue };
5049
5070
  }
5050
5071
  function propExtractionName(stmt) {
5051
5072
  if (!ts10.isVariableStatement(stmt))
@@ -5059,8 +5080,28 @@ function propExtractionName(stmt) {
5059
5080
  const parsed = parsePropReadInitializer(decl.initializer);
5060
5081
  if (parsed === null || parsed.key !== decl.name.text && parsed.key !== "children")
5061
5082
  return null;
5083
+ if (parsed.fallback !== null && mayHaveSideEffect(parsed.fallback))
5084
+ return null;
5062
5085
  return decl.name.text;
5063
5086
  }
5087
+ function isAssignmentOperator(kind) {
5088
+ return kind >= ts10.SyntaxKind.FirstAssignment && kind <= ts10.SyntaxKind.LastAssignment;
5089
+ }
5090
+ function mayHaveSideEffect(expr) {
5091
+ if (ts10.isArrowFunction(expr) || ts10.isFunctionExpression(expr))
5092
+ return false;
5093
+ if (ts10.isBinaryExpression(expr) && isAssignmentOperator(expr.operatorToken.kind))
5094
+ return true;
5095
+ if (ts10.isPrefixUnaryExpression(expr) || ts10.isPostfixUnaryExpression(expr)) {
5096
+ const op = expr.operator;
5097
+ if (op === ts10.SyntaxKind.PlusPlusToken || op === ts10.SyntaxKind.MinusMinusToken)
5098
+ return true;
5099
+ }
5100
+ if (ts10.isCallExpression(expr) || ts10.isNewExpression(expr) || ts10.isDeleteExpression(expr) || ts10.isAwaitExpression(expr) || ts10.isYieldExpression(expr) || ts10.isTaggedTemplateExpression(expr)) {
5101
+ return true;
5102
+ }
5103
+ return ts10.forEachChild(expr, (child) => mayHaveSideEffect(child) ? true : undefined) ?? false;
5104
+ }
5064
5105
  function pruneUnusedPropExtractions(code) {
5065
5106
  for (let round = 0;round < 10; round++) {
5066
5107
  const referenced = collectValueReferencedNames(code);
@@ -5258,25 +5299,47 @@ function propReadBase(p) {
5258
5299
  function coalesceDefaultText(defaultValue, defaultContainsArrow) {
5259
5300
  return defaultContainsArrow ? `(${defaultValue})` : defaultValue;
5260
5301
  }
5261
- function propReadFallback(p, usage, usedAsCondition) {
5262
- const defaultText = propDefaultText(p);
5302
+ function propReadFallback(p, usage, usedAsCondition, retained) {
5303
+ const defaultText = propDefaultText(p, retained);
5263
5304
  if (defaultText)
5264
- return coalesceDefaultText(defaultText, p.defaultContainsArrow);
5305
+ return { kind: p.coalescesNull ? "guard" : "default", text: coalesceDefaultText(defaultText, p.defaultContainsArrow) };
5265
5306
  if (usage?.usedAsLoopArray)
5266
- return "[]";
5307
+ return { kind: "guard", text: "[]" };
5267
5308
  if (propHasPropertyAccess(usage) && !usedAsCondition)
5268
- return "{}";
5309
+ return { kind: "guard", text: "{}" };
5269
5310
  return null;
5270
5311
  }
5271
- function propDefaultText(p) {
5312
+ function composePropRead(base, fallback) {
5313
+ if (fallback === null)
5314
+ return base;
5315
+ return fallback.kind === "default" ? `${base} === undefined ? ${fallback.text} : ${base}` : `${base} ?? ${fallback.text}`;
5316
+ }
5317
+ function propDefaultText(p, retained = EMPTY_SET) {
5272
5318
  if (!p.defaultParts)
5273
5319
  return p.defaultValue;
5274
- return p.defaultParts.map((part) => part.kind === "text" ? part.text : livePropReadExpr(part.param, undefined, false)).join("");
5320
+ return p.defaultParts.map((part) => {
5321
+ if (part.kind === "text")
5322
+ return part.text;
5323
+ return retained.has(part.param.name) ? part.param.name : livePropReadExpr(part.param, undefined, false, retained);
5324
+ }).join("");
5275
5325
  }
5276
- function livePropReadExpr(p, usage, usedAsCondition) {
5326
+ function retainedPropLocals(b) {
5327
+ const names = new Set;
5328
+ if (b.propsObjectName === null) {
5329
+ for (const p of b.propsParams)
5330
+ if (!p.isRest && !keepsDeclaredValue(p))
5331
+ names.add(p.name);
5332
+ }
5333
+ for (const c of b.localConstants) {
5334
+ if (c.propsDestructure && !c.isModule && !keepsDeclaredValue(c))
5335
+ names.add(c.name);
5336
+ }
5337
+ return names;
5338
+ }
5339
+ function livePropReadExpr(p, usage, usedAsCondition, retained) {
5277
5340
  const base = propReadBase(p);
5278
- const fallback = propReadFallback(p, usage, usedAsCondition);
5279
- return fallback === null ? base : `(${base} ?? ${fallback})`;
5341
+ const fallback = propReadFallback(p, usage, usedAsCondition, retained);
5342
+ return fallback === null ? base : `(${composePropRead(base, fallback)})`;
5280
5343
  }
5281
5344
  function resolveAliasOrigin(constantValues, name, terminal) {
5282
5345
  const visited = new Set;
@@ -5371,7 +5434,7 @@ function signalSecondBinding(signal) {
5371
5434
 
5372
5435
  // src/assignment-target.ts
5373
5436
  import ts12 from "typescript";
5374
- function isAssignmentOperator(kind) {
5437
+ function isAssignmentOperator2(kind) {
5375
5438
  return kind >= ts12.SyntaxKind.FirstAssignment && kind <= ts12.SyntaxKind.LastAssignment;
5376
5439
  }
5377
5440
  function isTransparentWrapper(n) {
@@ -5401,7 +5464,7 @@ function isAssignmentTargetIdentifier(id) {
5401
5464
  return parent.operator === ts12.SyntaxKind.PlusPlusToken || parent.operator === ts12.SyntaxKind.MinusMinusToken;
5402
5465
  }
5403
5466
  if (ts12.isBinaryExpression(parent)) {
5404
- return parent.left === node && isAssignmentOperator(parent.operatorToken.kind);
5467
+ return parent.left === node && isAssignmentOperator2(parent.operatorToken.kind);
5405
5468
  }
5406
5469
  if ((ts12.isForOfStatement(parent) || ts12.isForInStatement(parent)) && parent.initializer === node)
5407
5470
  return true;
@@ -5831,6 +5894,130 @@ function isHydrationPayloadPropName(name) {
5831
5894
  return !isEventHandlerName(name) && !name.startsWith("__");
5832
5895
  }
5833
5896
 
5897
+ // src/ir-to-client-js/child-props-object.ts
5898
+ function isSpreadPropName(name) {
5899
+ return name.startsWith("...");
5900
+ }
5901
+ function lastPropsObjectSpreadIndex(props) {
5902
+ let at = -1;
5903
+ props.forEach((p, index) => {
5904
+ if (p.value.kind === "spread" && p.value.propsObject === true)
5905
+ at = index;
5906
+ });
5907
+ return at;
5908
+ }
5909
+ function callerFirstPropExpr(name, expr) {
5910
+ const key = codeSafeStringLiteral(name);
5911
+ return `(${key} in ${PROPS_PARAM} ? ${PROPS_PARAM}[${key}] : ${expr})`;
5912
+ }
5913
+ function isObjectSpreadProp(prop) {
5914
+ return isSpreadPropName(prop.name) && prop.value.kind === "spread" && prop.value.callerBag === undefined;
5915
+ }
5916
+ function codeSafeStringArray(values) {
5917
+ return `[${values.map(codeSafeStringLiteral).join(",")}]`;
5918
+ }
5919
+ function objectLiteral(entries) {
5920
+ return entries.length > 0 ? `{ ${entries.join(", ")} }` : "{}";
5921
+ }
5922
+ function lastObjectSpreadIndex(props) {
5923
+ let at = -1;
5924
+ props.forEach((p, index) => {
5925
+ if (isObjectSpreadProp(p))
5926
+ at = index;
5927
+ });
5928
+ return at;
5929
+ }
5930
+ function mergedExplicitPropExpr(props, index, expr, spreadOf) {
5931
+ const name = props[index].name;
5932
+ const key = codeSafeStringLiteral(name);
5933
+ let merged = expr;
5934
+ let last = null;
5935
+ for (let at = index + 1;at < props.length; at++) {
5936
+ const prop = props[at];
5937
+ if (prop.value.kind === "spread" && prop.value.propsObject === true) {
5938
+ if (last !== "props")
5939
+ merged = callerFirstPropExpr(name, merged);
5940
+ last = "props";
5941
+ } else if (isObjectSpreadProp(prop)) {
5942
+ merged = `((__s) => __s != null && ${key} in Object(__s) ? Object(__s)[${key}] : ${merged})(${spreadOf(prop)})`;
5943
+ last = "object";
5944
+ }
5945
+ }
5946
+ return merged;
5947
+ }
5948
+ function childPropsObjectExpr(props, valueOf, options = {}) {
5949
+ if (lastObjectSpreadIndex(props) >= 0)
5950
+ return spreadPartsExpr(props, valueOf, options);
5951
+ const spreadAt = lastPropsObjectSpreadIndex(props);
5952
+ const entries = [];
5953
+ const explicitNames = [];
5954
+ props.forEach((prop, index) => {
5955
+ if (isSpreadPropName(prop.name))
5956
+ return;
5957
+ const value = valueOf(prop);
5958
+ if (!value)
5959
+ return;
5960
+ explicitNames.push(prop.name);
5961
+ const key = quotePropName(prop.name);
5962
+ if (index < spreadAt) {
5963
+ entries.push(`get ${key}() { return ${callerFirstPropExpr(prop.name, value.expr)} }`);
5964
+ } else {
5965
+ entries.push(explicitEntry(key, value));
5966
+ }
5967
+ });
5968
+ entries.push(...options.trailing ?? []);
5969
+ const object = objectLiteral(entries);
5970
+ if (spreadAt < 0 && !options.forwardCaller)
5971
+ return object;
5972
+ return `forwardProps(${PROPS_PARAM}, ${object}, ${codeSafeStringArray(explicitNames)})`;
5973
+ }
5974
+ function explicitEntry(key, value) {
5975
+ return value.getter ? `get ${key}() { return ${value.expr} }` : `${key}: ${value.expr}`;
5976
+ }
5977
+ function spreadPartsExpr(props, valueOf, options) {
5978
+ const parts = [];
5979
+ let entries = [];
5980
+ const explicitNames = [];
5981
+ let mergesCaller = false;
5982
+ const flush = () => {
5983
+ if (entries.length > 0)
5984
+ parts.push(objectLiteral(entries));
5985
+ entries = [];
5986
+ };
5987
+ for (const prop of props) {
5988
+ if (prop.value.kind === "spread" && prop.value.propsObject === true) {
5989
+ flush();
5990
+ parts.push(`() => ${PROPS_PARAM}`);
5991
+ mergesCaller = true;
5992
+ continue;
5993
+ }
5994
+ if (prop.value.kind === "spread" && prop.value.callerBag === "rest" && options.restBag !== undefined) {
5995
+ flush();
5996
+ parts.push(options.restBag);
5997
+ mergesCaller = true;
5998
+ continue;
5999
+ }
6000
+ if (isSpreadPropName(prop.name) && !isObjectSpreadProp(prop))
6001
+ continue;
6002
+ const value = valueOf(prop);
6003
+ if (!value)
6004
+ continue;
6005
+ if (isObjectSpreadProp(prop)) {
6006
+ flush();
6007
+ parts.push(`() => (${value.expr})`);
6008
+ continue;
6009
+ }
6010
+ explicitNames.push(prop.name);
6011
+ entries.push(explicitEntry(quotePropName(prop.name), value));
6012
+ }
6013
+ entries.push(...options.trailing ?? []);
6014
+ flush();
6015
+ const merged = `spreadChildProps(${parts.join(", ")})`;
6016
+ if (!options.forwardCaller || mergesCaller)
6017
+ return merged;
6018
+ return `forwardProps(${PROPS_PARAM}, ${merged}, ${codeSafeStringArray(explicitNames)})`;
6019
+ }
6020
+
5834
6021
  // src/ir-to-client-js/html-template.ts
5835
6022
  function escapeStaticTemplateHtml(text) {
5836
6023
  return escapeHtml(text).replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
@@ -6043,8 +6230,9 @@ function renderTemplateAttrPart(attr, attrName, wrap, restSpreadNames) {
6043
6230
  function keepsTemplateComponentProp(p) {
6044
6231
  if (p.name === "key")
6045
6232
  return false;
6046
- if (p.name === "..." || p.name.startsWith("..."))
6047
- return p.value.kind === "spread" && p.value.propsObject === true;
6233
+ if (p.name === "..." || p.name.startsWith("...")) {
6234
+ return p.value.kind === "spread" && (p.value.propsObject === true || isObjectSpreadProp(p));
6235
+ }
6048
6236
  return true;
6049
6237
  }
6050
6238
  function templatePropEntry(p, valueExpr) {
@@ -7045,7 +7233,9 @@ function computeDeferredChildSlots(node, ctx, inlinableConstants, unsafeLocalNam
7045
7233
  }
7046
7234
  if (n.slotId) {
7047
7235
  const dropped = n.props.some((p) => {
7048
- if (p.name === "..." || p.name.startsWith("...") || p.name === "key")
7236
+ if (p.name === "key")
7237
+ return false;
7238
+ if ((p.name === "..." || p.name.startsWith("...")) && !isObjectSpreadProp(p))
7049
7239
  return false;
7050
7240
  if (p.name === "ref")
7051
7241
  return false;
@@ -9125,17 +9315,20 @@ function deriveStashFromDefaults(defaults, props) {
9125
9315
  continue;
9126
9316
  }
9127
9317
  if (d.isRestProps) {
9128
- extra[name] = name in props ? props[name] : d.value;
9318
+ extra[name] = name in props ? props[name] : fallbackOf(d);
9129
9319
  continue;
9130
9320
  }
9131
9321
  if (d.propName !== undefined && d.propName in props && props[d.propName] != null) {
9132
9322
  extra[name] = props[d.propName];
9133
9323
  } else {
9134
- extra[name] = d.value;
9324
+ extra[name] = fallbackOf(d);
9135
9325
  }
9136
9326
  }
9137
9327
  return extra;
9138
9328
  }
9329
+ function fallbackOf(d) {
9330
+ return "value" in d ? decodeUndefinedMembers(d.value) : null;
9331
+ }
9139
9332
  var UNRESOLVED = Symbol("unresolved");
9140
9333
  var NO_RETURN = Symbol("no-return");
9141
9334
  function addPropSsrDefaults(metadata, propsLike, out) {
@@ -9150,7 +9343,7 @@ function addPropSsrDefaults(metadata, propsLike, out) {
9150
9343
  const value = tryStaticEval(p.defaultValue, { bindings: {}, propsLike });
9151
9344
  out[p.name] = { propName: callerPropName, value: resultToJsonable(value) };
9152
9345
  } else {
9153
- out[p.name] = { propName: callerPropName, value: null };
9346
+ out[p.name] = { propName: callerPropName };
9154
9347
  }
9155
9348
  }
9156
9349
  }
@@ -9246,7 +9439,40 @@ function extractSsrDefaults(metadata) {
9246
9439
  out[name] = { propName: name, value: null };
9247
9440
  }
9248
9441
  }
9249
- return Object.keys(out).length === 0 ? undefined : out;
9442
+ return Object.keys(out).length === 0 ? undefined : encodeSeedValues(out);
9443
+ }
9444
+ function encodeSeedValues(out) {
9445
+ for (const d of new Set(Object.values(out))) {
9446
+ if ("value" in d)
9447
+ d.value = encodeUndefinedMembers(d.value);
9448
+ }
9449
+ return out;
9450
+ }
9451
+ var UNDEFINED_SENTINEL = Object.freeze({ $undef: true });
9452
+ function encodeUndefinedMembers(v) {
9453
+ const member = (x) => x === undefined ? { ...UNDEFINED_SENTINEL } : encodeUndefinedMembers(x);
9454
+ if (Array.isArray(v))
9455
+ return v.map(member);
9456
+ if (v !== null && typeof v === "object") {
9457
+ return Object.fromEntries(Object.entries(v).map(([k, x]) => [k.startsWith("$") ? `$${k}` : k, member(x)]));
9458
+ }
9459
+ return v;
9460
+ }
9461
+ function decodeUndefinedMembers(v) {
9462
+ if (isUndefinedSentinel(v))
9463
+ return;
9464
+ if (Array.isArray(v))
9465
+ return v.map(decodeUndefinedMembers);
9466
+ if (v !== null && typeof v === "object") {
9467
+ return Object.fromEntries(Object.entries(v).map(([k, x]) => [k.startsWith("$$") ? k.slice(1) : k, decodeUndefinedMembers(x)]));
9468
+ }
9469
+ return v;
9470
+ }
9471
+ function isUndefinedSentinel(v) {
9472
+ if (v === null || typeof v !== "object" || Array.isArray(v))
9473
+ return false;
9474
+ const keys = Object.keys(v);
9475
+ return keys.length === 1 && keys[0] === "$undef" && v.$undef === true;
9250
9476
  }
9251
9477
  function localConstValuesByName(metadata) {
9252
9478
  const out = new Map;
@@ -9415,7 +9641,7 @@ function evalNode(node, ctx) {
9415
9641
  const v = evalNode(prop.initializer, ctx);
9416
9642
  if (v === UNRESOLVED)
9417
9643
  return UNRESOLVED;
9418
- obj[key] = v === undefined ? null : v;
9644
+ obj[key] = v;
9419
9645
  }
9420
9646
  return obj;
9421
9647
  }
@@ -9427,7 +9653,7 @@ function evalNode(node, ctx) {
9427
9653
  const v = evalNode(elem, ctx);
9428
9654
  if (v === UNRESOLVED)
9429
9655
  return UNRESOLVED;
9430
- arr.push(v === undefined ? null : v);
9656
+ arr.push(v);
9431
9657
  }
9432
9658
  return arr;
9433
9659
  }
@@ -9474,7 +9700,7 @@ function evalNode(node, ctx) {
9474
9700
  const v = evalNode(arrow.body, { ...ctx, bindings: localBindings });
9475
9701
  if (v === UNRESOLVED)
9476
9702
  return UNRESOLVED;
9477
- mapped.push(v === undefined ? null : v);
9703
+ mapped.push(v);
9478
9704
  }
9479
9705
  return mapped;
9480
9706
  }
@@ -11028,7 +11254,7 @@ function extractAssignedIdentifiersFromNode(node) {
11028
11254
  if (ts23.isArrowFunction(n) || ts23.isFunctionExpression(n) || ts23.isFunctionDeclaration(n) || ts23.isMethodDeclaration(n) || ts23.isGetAccessorDeclaration(n) || ts23.isSetAccessorDeclaration(n) || ts23.isConstructorDeclaration(n)) {
11029
11255
  return;
11030
11256
  }
11031
- if (ts23.isBinaryExpression(n) && isAssignmentOperator2(n.operatorToken.kind)) {
11257
+ if (ts23.isBinaryExpression(n) && isAssignmentOperator3(n.operatorToken.kind)) {
11032
11258
  addFromTarget(n.left);
11033
11259
  }
11034
11260
  if (ts23.isPrefixUnaryExpression(n) || ts23.isPostfixUnaryExpression(n)) {
@@ -11089,7 +11315,7 @@ function extractMutatedIdentifiersFromNode(node) {
11089
11315
  if (ts23.isArrowFunction(n) || ts23.isFunctionExpression(n) || ts23.isFunctionDeclaration(n) || ts23.isMethodDeclaration(n) || ts23.isGetAccessorDeclaration(n) || ts23.isSetAccessorDeclaration(n) || ts23.isConstructorDeclaration(n)) {
11090
11316
  return;
11091
11317
  }
11092
- if (ts23.isBinaryExpression(n) && isAssignmentOperator2(n.operatorToken.kind)) {
11318
+ if (ts23.isBinaryExpression(n) && isAssignmentOperator3(n.operatorToken.kind)) {
11093
11319
  if (ts23.isPropertyAccessExpression(n.left) || ts23.isElementAccessExpression(n.left)) {
11094
11320
  const root = rootIdentifierOf(n.left);
11095
11321
  if (root)
@@ -11122,7 +11348,7 @@ function extractMutatedIdentifiersFromNode(node) {
11122
11348
  visit3(node);
11123
11349
  return ids;
11124
11350
  }
11125
- function isAssignmentOperator2(kind) {
11351
+ function isAssignmentOperator3(kind) {
11126
11352
  return kind === ts23.SyntaxKind.EqualsToken || kind === ts23.SyntaxKind.PlusEqualsToken || kind === ts23.SyntaxKind.MinusEqualsToken || kind === ts23.SyntaxKind.AsteriskEqualsToken || kind === ts23.SyntaxKind.SlashEqualsToken || kind === ts23.SyntaxKind.PercentEqualsToken || kind === ts23.SyntaxKind.AsteriskAsteriskEqualsToken || kind === ts23.SyntaxKind.AmpersandEqualsToken || kind === ts23.SyntaxKind.BarEqualsToken || kind === ts23.SyntaxKind.CaretEqualsToken || kind === ts23.SyntaxKind.LessThanLessThanEqualsToken || kind === ts23.SyntaxKind.GreaterThanGreaterThanEqualsToken || kind === ts23.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken || kind === ts23.SyntaxKind.AmpersandAmpersandEqualsToken || kind === ts23.SyntaxKind.BarBarEqualsToken || kind === ts23.SyntaxKind.QuestionQuestionEqualsToken;
11127
11353
  }
11128
11354
  function collectLocalDeclarations(root) {
@@ -12457,8 +12683,8 @@ function collectKeysFromMembers(members, ctx) {
12457
12683
  }
12458
12684
  return keys;
12459
12685
  }
12460
- function isResolvableMemberType(info, localObjectMembers, visiting = new Set) {
12461
- const recurse = (t) => isResolvableMemberType(t, localObjectMembers, visiting);
12686
+ function isResolvableMemberType(info, localObjectMembers, visiting = new Set, nested = false) {
12687
+ const recurse = (t) => isResolvableMemberType(t, localObjectMembers, visiting, true);
12462
12688
  switch (info.kind) {
12463
12689
  case "primitive":
12464
12690
  return info.primitive === "string" || info.primitive === "number" || info.primitive === "boolean";
@@ -12471,16 +12697,24 @@ function isResolvableMemberType(info, localObjectMembers, visiting = new Set) {
12471
12697
  if (!members)
12472
12698
  return false;
12473
12699
  const inner = new Set(visiting).add(info.raw);
12474
- return members.every((t) => isResolvableMemberType(t, localObjectMembers, inner));
12700
+ return members.every((t) => isResolvableMemberType(t, localObjectMembers, inner, true));
12475
12701
  }
12476
12702
  case "array":
12477
12703
  return !!info.elementType && recurse(info.elementType);
12478
12704
  case "object":
12479
12705
  return info.properties !== undefined && info.properties.every((prop) => recurse(prop.type));
12706
+ case "union":
12707
+ return nested && isNilUnionOfResolvable(info, recurse);
12480
12708
  default:
12481
12709
  return false;
12482
12710
  }
12483
12711
  }
12712
+ function isNilUnionOfResolvable(info, resolves) {
12713
+ const isNil = (t) => t.kind === "primitive" && (t.primitive === "null" || t.primitive === "undefined");
12714
+ const members = info.unionTypes ?? [];
12715
+ const present = members.filter((t) => !isNil(t));
12716
+ return present.length > 0 && present.length < members.length && present.every(resolves);
12717
+ }
12484
12718
  function localObjectMemberTypesFor(ctx) {
12485
12719
  const cache = new Map;
12486
12720
  const lookup = (name) => {
@@ -15294,7 +15528,7 @@ function findAssignedNames(bodyText, candidates) {
15294
15528
  }
15295
15529
  };
15296
15530
  const visit3 = (node) => {
15297
- if (ts25.isBinaryExpression(node) && isAssignmentOperator3(node.operatorToken.kind)) {
15531
+ if (ts25.isBinaryExpression(node) && isAssignmentOperator4(node.operatorToken.kind)) {
15298
15532
  record(node.left);
15299
15533
  } else if ((ts25.isPrefixUnaryExpression(node) || ts25.isPostfixUnaryExpression(node)) && (node.operator === ts25.SyntaxKind.PlusPlusToken || node.operator === ts25.SyntaxKind.MinusMinusToken)) {
15300
15534
  record(node.operand);
@@ -15323,7 +15557,7 @@ function closeOverWritersOfMutableBindings(primaryRefs, declarations, mutableNam
15323
15557
  }
15324
15558
  return reachable;
15325
15559
  }
15326
- function isAssignmentOperator3(kind) {
15560
+ function isAssignmentOperator4(kind) {
15327
15561
  return kind >= ts25.SyntaxKind.FirstAssignment && kind <= ts25.SyntaxKind.LastAssignment;
15328
15562
  }
15329
15563
  function extractFunctionParams(value) {
@@ -19834,11 +20068,18 @@ function closedRestSpreadSource(attr, ctx) {
19834
20068
  let expr = attr.expression;
19835
20069
  while (ts27.isParenthesizedExpression(expr))
19836
20070
  expr = expr.expression;
19837
- if (!ts27.isIdentifier(expr) || expr.text !== restName)
20071
+ if (!ts27.isIdentifier(expr) || !isRestBinding(expr.text, restName, ctx))
19838
20072
  return null;
19839
20073
  const source = ctx.analyzer.restPropsOmittedKeys && ctx.analyzer.propsObjectName ? ctx.analyzer.propsObjectName : restName;
19840
20074
  return source !== restName && ctx.scope.isBound(source) ? null : source;
19841
20075
  }
20076
+ function isRestBinding(name, restName, ctx) {
20077
+ if (name === restName)
20078
+ return true;
20079
+ if (ctx.scope.isBound(name))
20080
+ return false;
20081
+ return resolveAliasOrigin(childrenAliasHops(ctx.analyzer), name, (n) => n === restName ? true : null) === true;
20082
+ }
19842
20083
  function refuseBodyRestSpreadUnderShadowedProps(attr, ctx) {
19843
20084
  const restName = ctx.analyzer.restPropsName;
19844
20085
  const propsName = ctx.analyzer.propsObjectName;
@@ -19849,7 +20090,7 @@ function refuseBodyRestSpreadUnderShadowedProps(attr, ctx) {
19849
20090
  let expr = attr.expression;
19850
20091
  while (ts27.isParenthesizedExpression(expr))
19851
20092
  expr = expr.expression;
19852
- if (!ts27.isIdentifier(expr) || expr.text !== restName)
20093
+ if (!ts27.isIdentifier(expr) || !isRestBinding(expr.text, restName, ctx))
19853
20094
  return false;
19854
20095
  ctx.analyzer.errors.push({
19855
20096
  code: "BF101",
@@ -22117,47 +22358,6 @@ function emitMultiRootTemplateCloneLines(template, indent, varEl, varExtras) {
22117
22358
  ];
22118
22359
  }
22119
22360
 
22120
- // src/ir-to-client-js/child-props-object.ts
22121
- function isSpreadPropName(name) {
22122
- return name.startsWith("...");
22123
- }
22124
- function lastPropsObjectSpreadIndex(props) {
22125
- let at = -1;
22126
- props.forEach((p, index) => {
22127
- if (p.value.kind === "spread" && p.value.propsObject === true)
22128
- at = index;
22129
- });
22130
- return at;
22131
- }
22132
- function callerFirstPropExpr(name, expr) {
22133
- const key = JSON.stringify(name);
22134
- return `(${key} in ${PROPS_PARAM} ? ${PROPS_PARAM}[${key}] : ${expr})`;
22135
- }
22136
- function childPropsObjectExpr(props, valueOf, options = {}) {
22137
- const spreadAt = lastPropsObjectSpreadIndex(props);
22138
- const entries = [];
22139
- const explicitNames = [];
22140
- props.forEach((prop, index) => {
22141
- if (isSpreadPropName(prop.name))
22142
- return;
22143
- const value = valueOf(prop);
22144
- if (!value)
22145
- return;
22146
- explicitNames.push(prop.name);
22147
- const key = quotePropName(prop.name);
22148
- if (index < spreadAt) {
22149
- entries.push(`get ${key}() { return ${callerFirstPropExpr(prop.name, value.expr)} }`);
22150
- } else {
22151
- entries.push(value.getter ? `get ${key}() { return ${value.expr} }` : `${key}: ${value.expr}`);
22152
- }
22153
- });
22154
- entries.push(...options.trailing ?? []);
22155
- const object = entries.length > 0 ? `{ ${entries.join(", ")} }` : "{}";
22156
- if (spreadAt < 0 && !options.forwardCaller)
22157
- return object;
22158
- return `forwardProps(${PROPS_PARAM}, ${object}, ${JSON.stringify(explicitNames)})`;
22159
- }
22160
-
22161
22361
  // src/ir-to-client-js/collect-elements.ts
22162
22362
  import { classifyDOMProp as classifyDOMProp2 } from "@barefootjs/shared";
22163
22363
  var EMPTY_RENDER_EXPRS = new Set(["null", "undefined", "false", "''", '""', "``"]);
@@ -22414,9 +22614,6 @@ function componentInitPropValue(prop, ctx) {
22414
22614
  return { expr: "true", getter: false };
22415
22615
  }
22416
22616
  }
22417
- function mergedMirrorExpr(name, expr, index, spreadAt) {
22418
- return index < spreadAt ? callerFirstPropExpr(name, expr) : expr;
22419
- }
22420
22617
  function callerBagSpreadOrigin(value, ctx) {
22421
22618
  if (value.kind !== "spread" || value.callerBag === undefined)
22422
22619
  return null;
@@ -22436,12 +22633,13 @@ function buildComponentPropsExpr(props, ctx) {
22436
22633
  const expr = p.value.kind === "spread" ? p.value.expr : p.value.expr;
22437
22634
  return resolveRestSpreadOrigin(ctx, expr) !== null;
22438
22635
  });
22636
+ const consumedKeys = ctx.propsParams.map((p) => p.sourceName ?? p.name);
22439
22637
  return childPropsObjectExpr(props, (prop) => componentInitPropValue(prop, ctx), {
22440
- forwardCaller: knownSpreadProp !== undefined
22638
+ forwardCaller: knownSpreadProp !== undefined,
22639
+ restBag: `forwardProps(${PROPS_PARAM}, {}, ${codeSafeStringArray(consumedKeys)})`
22441
22640
  });
22442
22641
  }
22443
22642
  function collectReactiveChildProps(node, ctx) {
22444
- const spreadAt = lastPropsObjectSpreadIndex(node.props);
22445
22643
  for (const [index, prop] of node.props.entries()) {
22446
22644
  if (prop.name === "..." || prop.name.startsWith("..."))
22447
22645
  continue;
@@ -22462,7 +22660,7 @@ function collectReactiveChildProps(node, ctx) {
22462
22660
  slotId: node.slotId,
22463
22661
  propName: prop.name,
22464
22662
  attrName,
22465
- expression: mergedMirrorExpr(prop.name, expandedValue, index, spreadAt),
22663
+ expression: mergedExplicitPropExpr(node.props, index, expandedValue, (spread) => expandDynamicPropValue(attrValueToString(spread.value), ctx)),
22466
22664
  ...pickAttrMetaFromIR(prop)
22467
22665
  });
22468
22666
  }
@@ -22626,7 +22824,6 @@ function collectElements(node, ctx, siblingOffsets, insideConditional = false) {
22626
22824
  },
22627
22825
  component: ({ node: c, descend, descendJsxChildren }) => {
22628
22826
  if (c.slotId) {
22629
- const spreadAt = lastPropsObjectSpreadIndex(c.props);
22630
22827
  for (const [index, prop] of c.props.entries()) {
22631
22828
  if (prop.value.kind === "jsx-children")
22632
22829
  continue;
@@ -22643,7 +22840,7 @@ function collectElements(node, ctx, siblingOffsets, insideConditional = false) {
22643
22840
  ctx.reactiveProps.push({
22644
22841
  slotId: c.slotId,
22645
22842
  propName: prop.name,
22646
- expression: mergedMirrorExpr(prop.name, value, index, spreadAt),
22843
+ expression: mergedExplicitPropExpr(c.props, index, value, (spread) => expandDynamicPropValue(attrValueToString(spread.value), ctx)),
22647
22844
  componentName: c.name
22648
22845
  });
22649
22846
  }
@@ -24103,7 +24300,7 @@ function buildDeclarationEmitPlan(decl, ctx, lookups) {
24103
24300
  kind: "constant",
24104
24301
  keyword: c.declarationKind ?? "const",
24105
24302
  name: c.name,
24106
- valueExpr: c.value !== undefined ? c.value : null
24303
+ valueExpr: bodyDestructureValue(c, ctx) ?? (c.value !== undefined ? c.value : null)
24107
24304
  };
24108
24305
  }
24109
24306
  case "signal":
@@ -24167,12 +24364,26 @@ function resolveSignalInitialValue(signal, lookups) {
24167
24364
  const controlled = lookups.controlledBySignal.get(signal);
24168
24365
  if (controlled) {
24169
24366
  const prop = lookups.propByName.get(controlled.propName);
24170
- const defaultVal = (prop && propDefaultText(prop)) ?? inferDefaultValue(signal.type);
24171
- return `${PROPS_PARAM}.${prop?.sourceName ?? controlled.propName} ?? ${defaultVal}`;
24367
+ const defaultText = prop && propDefaultText(prop);
24368
+ const base = `${PROPS_PARAM}.${prop?.sourceName ?? controlled.propName}`;
24369
+ return composePropRead(base, defaultText ? { kind: "default", text: coalesceDefaultText(defaultText, prop.defaultContainsArrow) } : { kind: "guard", text: inferDefaultValue(signal.type) });
24172
24370
  }
24173
24371
  }
24174
24372
  return signal.initialValue;
24175
24373
  }
24374
+ function bodyDestructureValue(c, ctx) {
24375
+ const sourceKey = c.propsDestructure?.sourceKey;
24376
+ if (sourceKey === undefined || ctx.propsObjectName === null)
24377
+ return null;
24378
+ const param = ctx.propsParams.find((p) => p.name === c.name && (p.sourceName ?? p.name) === sourceKey);
24379
+ const defaultText = param?.defaultValue;
24380
+ if (!param || !defaultText)
24381
+ return null;
24382
+ return composePropRead(`${ctx.propsObjectName}.${sourceKey}`, {
24383
+ kind: "default",
24384
+ text: coalesceDefaultText(defaultText, param.defaultContainsArrow)
24385
+ });
24386
+ }
24176
24387
  function buildControlledSignalEffect(signal, lookups) {
24177
24388
  const controlled = lookups.controlledBySignal.get(signal);
24178
24389
  if (!controlled)
@@ -24730,7 +24941,8 @@ function wrapAttrValueExpression(value, wrap) {
24730
24941
  case "spread":
24731
24942
  return {
24732
24943
  ...AttrValueOf.spread(wrap(value.expr), value.templateExpr ? wrap(value.templateExpr) : undefined),
24733
- ...value.propsObject && { propsObject: true }
24944
+ ...value.propsObject && { propsObject: true },
24945
+ ...value.callerBag !== undefined && { callerBag: value.callerBag }
24734
24946
  };
24735
24947
  }
24736
24948
  }
@@ -25255,7 +25467,7 @@ function findImpureNode(root, primableNames) {
25255
25467
  found = "function or class expression";
25256
25468
  return;
25257
25469
  }
25258
- if (ts28.isBinaryExpression(node) && isAssignmentOperator4(node.operatorToken.kind)) {
25470
+ if (ts28.isBinaryExpression(node) && isAssignmentOperator5(node.operatorToken.kind)) {
25259
25471
  found = "assignment";
25260
25472
  return;
25261
25473
  }
@@ -25264,7 +25476,7 @@ function findImpureNode(root, primableNames) {
25264
25476
  visit3(root);
25265
25477
  return found;
25266
25478
  }
25267
- function isAssignmentOperator4(kind) {
25479
+ function isAssignmentOperator5(kind) {
25268
25480
  return kind >= ts28.SyntaxKind.FirstAssignment && kind <= ts28.SyntaxKind.LastAssignment;
25269
25481
  }
25270
25482
 
@@ -25735,7 +25947,8 @@ function wrapAttrValueExpression2(value, wrap) {
25735
25947
  case "spread":
25736
25948
  return {
25737
25949
  ...AttrValueOf.spread(wrap(value.expr), value.templateExpr ? wrap(value.templateExpr) : undefined),
25738
- ...value.propsObject && { propsObject: true }
25950
+ ...value.propsObject && { propsObject: true },
25951
+ ...value.callerBag !== undefined && { callerBag: value.callerBag }
25739
25952
  };
25740
25953
  }
25741
25954
  }
@@ -26396,7 +26609,7 @@ function emitPropsExtraction(lines, ctx, neededProps, propUsage) {
26396
26609
  return;
26397
26610
  const usedAsCondition = computePropsUsedAsConditions(ctx, neededProps).has(local);
26398
26611
  const fallback = propReadFallback(prop, propUsage.get(local), usedAsCondition);
26399
- const read = propReadBase(prop) + (fallback === null ? "" : ` ?? ${fallback}`);
26612
+ const read = composePropRead(propReadBase(prop), fallback);
26400
26613
  lines.push(` ${keepsDeclaredValue(prop) ? "const" : "let"} ${local} = ${read}`, "");
26401
26614
  }
26402
26615
  function emitWrittenPropLocals(lines, ctx, propUsage) {
@@ -26404,9 +26617,10 @@ function emitWrittenPropLocals(lines, ctx, propUsage) {
26404
26617
  if (written.length === 0)
26405
26618
  return;
26406
26619
  const usedAsCondition = computePropsUsedAsConditions(ctx, new Set(written.map((p) => p.name)));
26620
+ const retained = retainedPropLocals(ctx);
26407
26621
  for (const prop of written) {
26408
- const fallback = propReadFallback(prop, propUsage.get(prop.name), usedAsCondition.has(prop.name));
26409
- lines.push(` let ${prop.name} = ${propReadBase(prop)}${fallback === null ? "" : ` ?? ${fallback}`}`);
26622
+ const fallback = propReadFallback(prop, propUsage.get(prop.name), usedAsCondition.has(prop.name), retained);
26623
+ lines.push(` let ${prop.name} = ${composePropRead(propReadBase(prop), fallback)}`);
26410
26624
  }
26411
26625
  lines.push("");
26412
26626
  }
@@ -29195,12 +29409,27 @@ function bodyAliasDefaultParts(ctx, local, key) {
29195
29409
  const param = ctx.propsParams.find((p) => !p.isRest && p.name === local && (p.sourceName ?? p.name) === key);
29196
29410
  return param?.defaultParts ? { defaultParts: param.defaultParts } : {};
29197
29411
  }
29412
+ function keepAliasesReadingRetainedLocals(aliases, ctx) {
29413
+ const retained = new Set(ctx.localConstants.filter((c) => c.propsDestructure && !c.isModule && !aliases.has(c.name)).map((c) => c.name));
29414
+ for (let changed = true;changed; ) {
29415
+ changed = false;
29416
+ for (const [local, alias] of aliases) {
29417
+ const parts = bodyAliasDefaultParts(ctx, local, alias.key).defaultParts ?? [];
29418
+ if (!parts.some((part) => part.kind === "param" && retained.has(part.param.name)))
29419
+ continue;
29420
+ aliases.delete(local);
29421
+ retained.add(local);
29422
+ changed = true;
29423
+ }
29424
+ }
29425
+ }
29198
29426
  function rewriteBodyAliasReads(code, ctx) {
29199
29427
  const aliases = resolveBodyPropAliases(ctx.localConstants, ctx.propsObjectName);
29200
29428
  for (const [local, alias] of aliases) {
29201
29429
  if (alias.key === "children")
29202
29430
  aliases.delete(local);
29203
29431
  }
29432
+ keepAliasesReadingRetainedLocals(aliases, ctx);
29204
29433
  if (aliases.size === 0)
29205
29434
  return code;
29206
29435
  if (![...aliases.keys()].some((name) => identifierPattern(name).test(code)))
@@ -29233,6 +29462,7 @@ function rewriteBodyAliasReads(code, ctx) {
29233
29462
  located.set(decl.name.text, {
29234
29463
  key: alias.key,
29235
29464
  defaultValue: parsedInit.fallback?.getText(sourceFile),
29465
+ coalescesNull: parsedInit.coalescesNull,
29236
29466
  defaultContainsArrow: alias.defaultContainsArrow && !(parsedInit.fallback && ts30.isParenthesizedExpression(parsedInit.fallback)),
29237
29467
  ...bodyAliasDefaultParts(ctx, decl.name.text, alias.key)
29238
29468
  });
@@ -29255,6 +29485,7 @@ function rewriteBodyAliasReads(code, ctx) {
29255
29485
  sourceName: info.key,
29256
29486
  defaultValue: info.defaultValue,
29257
29487
  defaultContainsArrow: info.defaultContainsArrow,
29488
+ coalescesNull: info.coalescesNull,
29258
29489
  ...info.defaultParts && { defaultParts: info.defaultParts }
29259
29490
  };
29260
29491
  return livePropReadExpr(prop, undefined, false);
@@ -31859,7 +32090,12 @@ function operandFacts(expr, typing) {
31859
32090
  }
31860
32091
  }
31861
32092
  function decide(op, proof, target, helper) {
31862
- return target[op]?.includes(proof) ? { mode: "native", op, proof } : { mode: "helper", op, helper, proof };
32093
+ return claimsNative(op, proof, target) ? { mode: "native", op, proof } : { mode: "helper", op, helper, proof };
32094
+ }
32095
+ function claimsNative(op, proof, target) {
32096
+ if (proof === "unproven")
32097
+ return false;
32098
+ return target[op]?.includes(proof) ?? false;
31863
32099
  }
31864
32100
  function pairProof(left, right) {
31865
32101
  const l = provenPrimitive(left);
@@ -31881,6 +32117,21 @@ function isNilLiteralOperand(expr, typing) {
31881
32117
  function isNullishTest(op, left, right, typing) {
31882
32118
  return (op === "===" || op === "!==" || op === "==" || op === "!=") && (isNilLiteralOperand(left, typing) || isNilLiteralOperand(right, typing));
31883
32119
  }
32120
+ function planNilTest(op, left, right, typing) {
32121
+ const nilTest = (helper) => ({ mode: "helper", op: "nil-test", helper, proof: "unproven" });
32122
+ if (op === "==" || op === "!=")
32123
+ return nilTest("is_nullish");
32124
+ const literal = nilTestOperand(left, right, typing) === left ? right : left;
32125
+ return nilTest(literal.kind === "literal" ? "is_null" : "is_undefined");
32126
+ }
32127
+ function nilTestOperand(left, right, typing) {
32128
+ return isNilLiteralOperand(right, typing) ? left : right;
32129
+ }
32130
+ function refuseUnspelledNilTest(plan) {
32131
+ if (plan?.op !== "nil-test" || plan.mode !== "helper")
32132
+ return;
32133
+ throw new Error(`[barefootjs] the primitive plan names the \`${plan.helper}\` nil test (a target that carries \`undefined\`), ` + "but this emitter has no spelling for it (spec/js-undefined-value.md)");
32134
+ }
31884
32135
  var ELEMENT_READ_METHODS = new Set(["at", "find", "findLast"]);
31885
32136
  function elementReadReceiver(expr) {
31886
32137
  if (expr.kind === "index-access")
@@ -31903,6 +32154,7 @@ function mayHoldObject(expr, typing, isObjectTypeName = () => false) {
31903
32154
  }
31904
32155
  var NON_PRIMITIVE_EQUALITY_REASON = "non-primitive-strict-equality";
31905
32156
  function strictEqSpelling(op, left, right, plan) {
32157
+ refuseUnspelledNilTest(plan);
31906
32158
  if (op !== "===" && op !== "!==")
31907
32159
  return null;
31908
32160
  if (isNilLiteralOperand(left) || isNilLiteralOperand(right))
@@ -31949,14 +32201,14 @@ function planNumericBinary(op, left, right, target) {
31949
32201
  }
31950
32202
  function planBinary(expr, typing, target) {
31951
32203
  const { op } = expr;
32204
+ if (isNullishTest(op, expr.left, expr.right, typing))
32205
+ return planNilTest(op, expr.left, expr.right, typing);
31952
32206
  const isPrimitiveOp = op === "===" || op === "!==" || op === "+" || op in RELATIONAL_HELPERS || op === "-" || op === "*" || op === "/" || op === "%";
31953
32207
  if (!isPrimitiveOp)
31954
32208
  return null;
31955
32209
  const left = operandFacts(expr.left, typing);
31956
32210
  const right = operandFacts(expr.right, typing);
31957
32211
  if (op === "===" || op === "!==") {
31958
- if (isNullishTest(op, expr.left, expr.right, typing))
31959
- return null;
31960
32212
  if (mayHoldObject(expr.left, typing) || mayHoldObject(expr.right, typing)) {
31961
32213
  return { mode: "refuse", op: "strict-eq", reason: NON_PRIMITIVE_EQUALITY_REASON };
31962
32214
  }
@@ -32532,7 +32784,7 @@ function arithmeticOperandCoercion(op, operand, other, ctx, isShadowed = () => f
32532
32784
  const seed = arithmeticOperandSeed(operand, ctx, isShadowed);
32533
32785
  if (seed === "absent")
32534
32786
  return "undefined";
32535
- return seed === "either" ? "null" : seed;
32787
+ return seed === "either" ? null : seed;
32536
32788
  }
32537
32789
  var RELATIONAL_OPS = new Set(["<", "<=", ">", ">="]);
32538
32790
  function relationalOperandCoercion(operand, ctx, isShadowed) {
@@ -32543,77 +32795,6 @@ function relationalOperandCoercion(operand, ctx, isShadowed) {
32543
32795
  return null;
32544
32796
  return scalarPropRead(operand, ctx, isShadowed)?.nil === "undefined" ? "undefined-keep" : null;
32545
32797
  }
32546
- function arithmeticOperandNilIsAmbiguous(op, operand, other, ctx, isShadowed = () => false) {
32547
- return ambiguousNilFamily(op, operand, other, ctx, isShadowed) !== null;
32548
- }
32549
- function ambiguousNilFamily(op, operand, other, ctx, isShadowed = () => false) {
32550
- const relational = RELATIONAL_OPS.has(op);
32551
- if (!relational && !isNumericArithmetic(op, other))
32552
- return null;
32553
- if (arithmeticOperandSeed(operand, ctx, isShadowed) === "either")
32554
- return "number";
32555
- if (!relational)
32556
- return null;
32557
- const scalar = scalarPropRead(operand, ctx, isShadowed);
32558
- return scalar?.nil === "either" ? scalar.family : null;
32559
- }
32560
- function ambiguousNilArithmeticOperands(expr, ctx, scope = BindingScope.EMPTY) {
32561
- return ambiguousNilOperands(expr, ctx, scope).map((found) => found.operand);
32562
- }
32563
- function ambiguousNilOperands(expr, ctx, scope = BindingScope.EMPTY) {
32564
- const found = [];
32565
- const visit3 = (e, at) => {
32566
- if (e.kind === "arrow") {
32567
- visit3(e.body, at.enterCallback(e.params));
32568
- return;
32569
- }
32570
- for (const [op, operand, other] of arithmeticOperandsOf(e)) {
32571
- const family = ambiguousNilFamily(op, operand, other, ctx, at.asShadowPredicate());
32572
- if (family !== null)
32573
- found.push({ operand, family });
32574
- }
32575
- for (const child of parsedExprChildren2(e))
32576
- visit3(child, at);
32577
- };
32578
- if (!ctx.nullableNumberProps?.size && !ctx.nullableScalarProps?.size)
32579
- return found;
32580
- visit3(expr, scope);
32581
- return found;
32582
- }
32583
- function arithmeticOperandsOf(e) {
32584
- if (e.kind === "binary")
32585
- return [[e.op, e.left, e.right], [e.op, e.right, e.left]];
32586
- if (e.kind === "unary" && (e.op === "-" || e.op === "+"))
32587
- return [[e.op, e.argument, undefined]];
32588
- return [];
32589
- }
32590
- function parsedExprChildren2(e) {
32591
- switch (e.kind) {
32592
- case "call":
32593
- return [e.callee, ...e.args];
32594
- case "member":
32595
- return [e.object];
32596
- case "index-access":
32597
- return [e.object, e.index];
32598
- case "binary":
32599
- case "logical":
32600
- return [e.left, e.right];
32601
- case "unary":
32602
- return [e.argument];
32603
- case "conditional":
32604
- return [e.test, e.consequent, e.alternate];
32605
- case "template-literal":
32606
- return e.parts.flatMap((p) => p.type === "expression" ? [p.expr] : []);
32607
- case "array-literal":
32608
- return e.elements;
32609
- case "array-method":
32610
- return [e.object, ...e.args, ...e.method === "flat" && e.depthExpr ? [e.depthExpr] : []];
32611
- case "object-literal":
32612
- return e.properties.map((p) => p.kind === "spread" ? p.expr : p.value);
32613
- default:
32614
- return [];
32615
- }
32616
- }
32617
32798
  function isNumericArithmetic(op, other) {
32618
32799
  return NULL_COERCING_ARITHMETIC_OPS.has(op) || op === "+" && (other === undefined || isNumberLiteral(other));
32619
32800
  }
@@ -32648,6 +32829,9 @@ function loopRowType(types, loop, scope) {
32648
32829
  const type = valueType(types, loop.arrayParsed, scope);
32649
32830
  return arrayElementType(type) ?? null;
32650
32831
  }
32832
+ function declaredValueType(types, expr, scope) {
32833
+ return valueType(types, expr, scope);
32834
+ }
32651
32835
  function valueType(types, expr, scope) {
32652
32836
  switch (expr.kind) {
32653
32837
  case "identifier": {
@@ -32817,46 +33001,6 @@ function isRootPropsObject(expr, isBound, propsObject) {
32817
33001
  return expr.kind === "identifier" && expr.name === propsObject && !isBound(expr.name);
32818
33002
  }
32819
33003
 
32820
- // src/adapters/ambiguous-nil-arithmetic.ts
32821
- function arithmeticCoercionOrRefuse(op, operand, other, ctx, isShadowed, sink) {
32822
- const family = ambiguousNilFamily(op, operand, other, ctx, isShadowed);
32823
- if (family !== null)
32824
- recordAmbiguousNilArithmetic(exprToString(operand), family, sink);
32825
- return arithmeticOperandCoercion(op, operand, other, ctx, isShadowed);
32826
- }
32827
- function refuseAmbiguousNilArithmetic(expr, ctx, scope, sink) {
32828
- for (const { operand, family } of ambiguousNilOperands(expr, ctx, scope)) {
32829
- recordAmbiguousNilArithmetic(exprToString(operand), family, sink);
32830
- }
32831
- }
32832
- function refuseAmbiguousNilMemoArithmetic(memos, ctx, sink) {
32833
- for (const memo of memos) {
32834
- if (memo.parsed)
32835
- refuseAmbiguousNilArithmetic(memo.parsed, ctx, BindingScope.EMPTY, sink);
32836
- }
32837
- }
32838
- function recordAmbiguousNilArithmetic(operandText, family, sink) {
32839
- const message = ambiguousNilMessage(operandText, family);
32840
- if (sink.errors.some((e) => e.code === "BF101" && e.message === message))
32841
- return;
32842
- sink.errors.push({
32843
- code: "BF101",
32844
- severity: "error",
32845
- message,
32846
- loc: { file: `${sink.componentName}.tsx`, start: { line: 1, column: 0 }, end: { line: 1, column: 0 } },
32847
- suggestion: {
32848
- message: `Declare the prop as only optional (\`?: ${family}\`) or only nullable (\`: ${family} | null\`), or give it a default value.`,
32849
- escape: [{ kind: "rewrite" }]
32850
- }
32851
- });
32852
- }
32853
- function ambiguousNilMessage(operandText, family) {
32854
- if (family === "number") {
32855
- return `Arithmetic over \`${operandText}\` reads a number prop declared both optional and nullable (\`?: number | null\`). JS reads it as \`undefined\` when the caller omits it (\`NaN\` in arithmetic) and as \`0\` when it is \`null\`, but a template engine holds both as the same nil, so the server render cannot tell which one it is.`;
32856
- }
32857
- return `A comparison over \`${operandText}\` reads a ${family} prop declared both optional and nullable (\`?: ${family} | null\`). JS reads it as \`undefined\` when the caller omits it (\`NaN\`, so the comparison is false) and as \`null\` when it is \`null\` (\`0\`), but a template engine holds both as the same nil, so the server render cannot tell which one it is.`;
32858
- }
32859
-
32860
33004
  // src/adapters/non-primitive-equality.ts
32861
33005
  function refusedComparisons(expr, typing, isObjectTypeName) {
32862
33006
  const found = [];
@@ -33252,9 +33396,9 @@ function numericOperand(operand, facts) {
33252
33396
  }
33253
33397
  function stringOperand(operand, facts) {
33254
33398
  const reading = readingOf(facts);
33255
- if (reading === null)
33399
+ if (reading === null || reading === "either")
33256
33400
  return operand;
33257
- return coalesce(operand, facts, stringLiteral2(reading === "either" ? "" : reading));
33401
+ return coalesce(operand, facts, stringLiteral2(reading));
33258
33402
  }
33259
33403
  var PRIMITIVE_TYPES = new Set(["number", "string", "boolean"]);
33260
33404
  function isExactly2(facts, type) {
@@ -33432,8 +33576,8 @@ var PREDICATE_EVAL = {
33432
33576
  function isPredicateMethod(method) {
33433
33577
  return Object.hasOwn(PREDICATE_EVAL, method);
33434
33578
  }
33435
- function evalBody(body, bound, propsObject, typing) {
33436
- const read = typing ? rewriteNilReadingsDeep(body, typing.enterCallback([...bound])) : body;
33579
+ function evalBody(body, bound, propsObject, site) {
33580
+ const read = site ? rewriteNilReadingsDeep(body, site.typing.enterCallback([...bound])) : body;
33437
33581
  const lifted = liftPropsReads(read, bound, propsObject);
33438
33582
  const json = serializeParsedExpr(lifted.body);
33439
33583
  if (json === null)
@@ -33815,10 +33959,17 @@ function collectBooleanTypedProps(ir) {
33815
33959
  }
33816
33960
  function collectNullableOptionalProps(ir) {
33817
33961
  return new Set([
33818
- ...ir.metadata.propsParams.filter((p) => p.defaultValue === undefined && !p.isRest && (p.type?.kind !== "primitive" || p.optional)).map((p) => p.name),
33962
+ ...ir.metadata.propsParams.filter((p) => !p.isRest && (p.defaultValue === undefined ? p.type?.kind !== "primitive" || p.optional : admitsNull(p.declaredType ?? p.type))).map((p) => p.name),
33819
33963
  ...ir.metadata.restPropsExpandedKeys
33820
33964
  ]);
33821
33965
  }
33966
+ function admitsNull(type) {
33967
+ if (!type)
33968
+ return false;
33969
+ if (type.kind === "primitive")
33970
+ return type.primitive === "null";
33971
+ return type.kind === "union" && (type.unionTypes ?? []).some(admitsNull);
33972
+ }
33822
33973
  function isBooleanTypedPropRef(expr, ctx) {
33823
33974
  let bare = expr.trim();
33824
33975
  if (ctx.propsObjectName && bare.startsWith(`${ctx.propsObjectName}.`)) {
@@ -33976,12 +34127,9 @@ class DslTemplateAdapter extends BaseAdapter {
33976
34127
  }
33977
34128
  }
33978
34129
  arithmeticCoercion(op, operand, other, isShadowed) {
33979
- return arithmeticCoercionOrRefuse(op, operand, other, this.nullishAttrCtx, isShadowed, this.ambiguousNilSink());
33980
- }
33981
- refuseAmbiguousNilArithmeticIn(expr, params) {
33982
- refuseAmbiguousNilArithmetic(expr, this.nullishAttrCtx, this.scope.enterCallback(params), this.ambiguousNilSink());
34130
+ return arithmeticOperandCoercion(op, operand, other, this.nullishAttrCtx, isShadowed);
33983
34131
  }
33984
- ambiguousNilSink() {
34132
+ errorSink() {
33985
34133
  return { errors: this.errors, componentName: this.componentName };
33986
34134
  }
33987
34135
  loopPlanFor(loop, spelling) {
@@ -34067,10 +34215,13 @@ ${children}` : children;
34067
34215
  this.rootPropAliases = rootPropAliasNames(ir, this.propsParams.map((p) => p.name));
34068
34216
  this.scope = BindingScope.forComponent(this.propsObjectName);
34069
34217
  this.nullableOptionalProps = collectNullableOptionalProps(ir);
34070
- this.nullableSignalGetters = collectNullableSignalGetters(ir);
34071
34218
  this.nullishAttrCtx = collectNullishAttrContext(ir);
34072
34219
  this.stringValueNames = this.stringValueNamesFor(ir);
34073
34220
  this.declaredTypes = declaredValueTypes(ir);
34221
+ this.nullableSignalGetters = new Set([
34222
+ ...collectNullableSignalGetters(ir),
34223
+ ...memberSeededNilSignals(ir, this.declaredTypes, this.scope)
34224
+ ]);
34074
34225
  this.operandTyping = collectOperandTyping(ir.metadata, { namedFields: this.declaredTypes.namedFields });
34075
34226
  this.moduleStringConsts = collectModuleStringConsts(ir.metadata.localConstants);
34076
34227
  this._searchParamsLocals = searchParamsLocalNames(ir.metadata);
@@ -34091,10 +34242,12 @@ ${children}` : children;
34091
34242
  if (!options?.siblingTemplatesRegistered) {
34092
34243
  this.errors.push(...collectImportedLoopChildComponentErrors(ir, this.componentName, this.loopChildDiagnosticName));
34093
34244
  }
34094
- refuseAmbiguousNilMemoArithmetic(ir.metadata.memos ?? [], this.nullishAttrCtx, this.ambiguousNilSink());
34095
- refuseNonPrimitiveStrictEquality(ir, this.operandTyping, this.ambiguousNilSink());
34245
+ refuseNonPrimitiveStrictEquality(ir, this.operandTyping, this.errorSink());
34096
34246
  }
34097
34247
  }
34248
+ function memberSeededNilSignals(ir, types, scope) {
34249
+ return (ir.metadata.signals ?? []).filter((s) => s.parsed?.kind === "member" && factsOfType(declaredValueType(types, s.parsed, scope)).types.has("nil")).map((s) => s.getter);
34250
+ }
34098
34251
  // src/adapters/jsx-adapter.ts
34099
34252
  import { BF_SCOPE as BF_SCOPE4, BF_SLOT, BF_COND } from "@barefootjs/shared";
34100
34253
  class JsxAdapter extends BaseAdapter {
@@ -34829,6 +34982,15 @@ function withNilReadings(expr, emitter) {
34829
34982
  return expr;
34830
34983
  return rewriteNilReadings(expr, emitter.primitives.typing());
34831
34984
  }
34985
+ function dispatchBinary(expr, emitter, emit) {
34986
+ const plan = primitivePlanFor(expr, emitter);
34987
+ if (plan?.op === "nil-test" && plan.mode === "helper" && emitter.nilTest) {
34988
+ const operand = nilTestOperand(expr.left, expr.right, emitter.primitives.typing());
34989
+ return emitter.nilTest(plan.helper, expr.op === "!==" || expr.op === "!=", operand, emit);
34990
+ }
34991
+ refuseUnspelledNilTest(plan);
34992
+ return emitter.binary(expr.op, expr.left, expr.right, emit, plan);
34993
+ }
34832
34994
  function withNilReadingBody(arrow, emitter) {
34833
34995
  const body = rewriteNilReadingsDeep(arrow.body, emitter.primitives.typing().enterCallback(arrow.params));
34834
34996
  return body === arrow.body ? arrow : { ...arrow, body };
@@ -34867,7 +35029,7 @@ function dispatchParsedExpr(original, emitter, sites) {
34867
35029
  case "index-access":
34868
35030
  return emitter.indexAccess(expr.object, expr.index, emit, primitivePlanFor(expr, emitter));
34869
35031
  case "binary":
34870
- return emitter.binary(expr.op, expr.left, expr.right, emit, primitivePlanFor(expr, emitter));
35032
+ return dispatchBinary(expr, emitter, emit);
34871
35033
  case "unary": {
34872
35034
  const folded = foldNegatedNumberLiteral(expr);
34873
35035
  if (folded)
@@ -38620,9 +38782,8 @@ export {
38620
38782
  relationalHelper,
38621
38783
  registerLoweringPlugin,
38622
38784
  registerBuiltinLoweringPlugins,
38785
+ refuseUnspelledNilTest,
38623
38786
  refuseNonPrimitiveStrictEquality,
38624
- refuseAmbiguousNilMemoArithmetic,
38625
- refuseAmbiguousNilArithmetic,
38626
38787
  queryHrefPlugin,
38627
38788
  queryHrefLocalNames,
38628
38789
  queryHrefArgs,
@@ -38660,6 +38821,7 @@ export {
38660
38821
  nullishChainParts,
38661
38822
  nullableSignalAttrGetter,
38662
38823
  nullablePropsYieldedBy,
38824
+ nilTestOperand,
38663
38825
  nestedCallbackRefusal,
38664
38826
  needsTypeBasedDetection,
38665
38827
  needsToString,
@@ -38792,6 +38954,7 @@ export {
38792
38954
  escapeBraceDelimiters,
38793
38955
  envSignalReaderFor,
38794
38956
  envSignalLocalNames,
38957
+ encodeUndefinedMembers,
38795
38958
  enableCompilerInstrumentation,
38796
38959
  emitParsedValue,
38797
38960
  emitParsedExpr,
@@ -38805,6 +38968,7 @@ export {
38805
38968
  describeFallback,
38806
38969
  derivesScopeFromSlot,
38807
38970
  deriveStashFromDefaults,
38971
+ decodeUndefinedMembers,
38808
38972
  declaredValueTypes,
38809
38973
  decideClientOnlyElision,
38810
38974
  dangerousInnerHtmlMetacharViolation,
@@ -38861,22 +39025,20 @@ export {
38861
39025
  attrValueMayBeNullish,
38862
39026
  asCallbackMethodCall,
38863
39027
  arrayElementType,
38864
- arithmeticOperandNilIsAmbiguous,
38865
39028
  arithmeticOperandIsUndefined,
38866
39029
  arithmeticOperandIsNull,
38867
39030
  arithmeticOperandCoercion,
38868
39031
  arithmeticHelper,
38869
- arithmeticCoercionOrRefuse,
38870
39032
  applyCssLayerPrefix,
38871
39033
  analyzeWastedReReruns,
38872
39034
  analyzeHotSubscribers,
38873
39035
  analyzeComponent,
38874
39036
  analyzeClientNeeds,
38875
39037
  analyzeBatchAdvisor,
38876
- ambiguousNilArithmeticOperands,
38877
39038
  __resetLoweringPluginsForTest,
38878
39039
  USE_CLIENT_DIRECTIVE,
38879
39040
  UNKNOWN_FACTS,
39041
+ UNDEFINED_SENTINEL,
38880
39042
  TestAdapter,
38881
39043
  SourceMapGenerator,
38882
39044
  SORT_KEY_TYPES,