@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
@@ -1,103 +0,0 @@
1
- import { exprToString, type ParsedExpr } from '../expression-parser.ts'
2
- import {
3
- ambiguousNilFamily,
4
- ambiguousNilOperands,
5
- arithmeticOperandCoercion,
6
- type AmbiguousNilFamily,
7
- type ArithmeticCoercion,
8
- type NullishAttrContext,
9
- } from '../nullable-signal-attr.ts'
10
- import { BindingScope } from '../scope/binding-scope.ts'
11
- import type { CompilerError, MemoInfo } from '../types.ts'
12
-
13
- /**
14
- * Where a template adapter records the refusal of an arithmetic operand
15
- * whose nil the declared type cannot classify (#3700).
16
- */
17
- export interface AmbiguousNilArithmeticSink {
18
- readonly errors: CompilerError[]
19
- readonly componentName: string
20
- }
21
-
22
- /**
23
- * The shared arithmetic-operand decision for a template adapter's emission
24
- * site: the coercion the adapter spells (`arithmeticOperandCoercion`), after
25
- * refusing (BF101) an operand that reads a number prop declared both
26
- * optional and nullable (`n?: number | null`, `arithmeticOperandNilIsAmbiguous`).
27
- * JS reads that prop as `undefined` when omitted (`NaN` in arithmetic) and
28
- * as `0` when `null`; the engine holds both as one nil, so any spelling
29
- * renders one of them wrong. Under a comparison the same holds for a string
30
- * or boolean prop declared `?: string | null` / `?: boolean | null` (#3824
31
- * step 3). Asked at the emission site so the operand is classified in the
32
- * scope it is read in (`isShadowed`). One error per operand text per compile.
33
- */
34
- export function arithmeticCoercionOrRefuse(
35
- op: string,
36
- operand: ParsedExpr,
37
- other: ParsedExpr | undefined,
38
- ctx: NullishAttrContext,
39
- isShadowed: (name: string) => boolean,
40
- sink: AmbiguousNilArithmeticSink,
41
- ): ArithmeticCoercion {
42
- const family = ambiguousNilFamily(op, operand, other, ctx, isShadowed)
43
- if (family !== null) recordAmbiguousNilArithmetic(exprToString(operand), family, sink)
44
- return arithmeticOperandCoercion(op, operand, other, ctx, isShadowed)
45
- }
46
-
47
- /**
48
- * Refuse (BF101) each arithmetic operand in a whole expression that a
49
- * template adapter lowers without asking {@link arithmeticCoercionOrRefuse}
50
- * per operator: a `.filter()` predicate, an expression the runtime evaluator
51
- * runs, a condition lowered by its own renderer (`ambiguousNilArithmeticOperands`).
52
- * `scope` is the scope the expression is read in.
53
- */
54
- export function refuseAmbiguousNilArithmetic(
55
- expr: ParsedExpr,
56
- ctx: NullishAttrContext,
57
- scope: BindingScope,
58
- sink: AmbiguousNilArithmeticSink,
59
- ): void {
60
- for (const { operand, family } of ambiguousNilOperands(expr, ctx, scope)) {
61
- recordAmbiguousNilArithmetic(exprToString(operand), family, sink)
62
- }
63
- }
64
-
65
- /**
66
- * Refuse the ambiguous arithmetic in the component's memo bodies. A template
67
- * adapter seeds every memo at SSR, and some seed a memo through a path that
68
- * never reaches its operator emitter (a static seed after a speculative
69
- * lowering, a constructor-time evaluation), so the bodies are checked as a
70
- * whole, in the component scope they are declared in.
71
- */
72
- export function refuseAmbiguousNilMemoArithmetic(
73
- memos: readonly MemoInfo[],
74
- ctx: NullishAttrContext,
75
- sink: AmbiguousNilArithmeticSink,
76
- ): void {
77
- for (const memo of memos) {
78
- if (memo.parsed) refuseAmbiguousNilArithmetic(memo.parsed, ctx, BindingScope.EMPTY, sink)
79
- }
80
- }
81
-
82
- function recordAmbiguousNilArithmetic(operandText: string, family: AmbiguousNilFamily, sink: AmbiguousNilArithmeticSink): void {
83
- const message = ambiguousNilMessage(operandText, family)
84
- if (sink.errors.some(e => e.code === 'BF101' && e.message === message)) return
85
- sink.errors.push({
86
- code: 'BF101',
87
- severity: 'error',
88
- message,
89
- loc: { file: `${sink.componentName}.tsx`, start: { line: 1, column: 0 }, end: { line: 1, column: 0 } },
90
- suggestion: {
91
- message: `Declare the prop as only optional (\`?: ${family}\`) or only nullable (\`: ${family} | null\`), or give it a default value.`,
92
- escape: [{ kind: 'rewrite' }],
93
- },
94
- })
95
- }
96
-
97
- /** The BF101 text for an operand {@link ambiguousNilFamily} matched; the numeric one predates #3824 step 3. */
98
- function ambiguousNilMessage(operandText: string, family: AmbiguousNilFamily): string {
99
- if (family === 'number') {
100
- 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.`
101
- }
102
- 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.`
103
- }