@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.
- package/dist/adapters/callback-method.d.ts +8 -1
- package/dist/adapters/callback-method.d.ts.map +1 -1
- package/dist/adapters/component-props.d.ts +3 -4
- package/dist/adapters/component-props.d.ts.map +1 -1
- package/dist/adapters/dsl-template-adapter.d.ts +3 -12
- package/dist/adapters/dsl-template-adapter.d.ts.map +1 -1
- package/dist/adapters/loop-row-type.d.ts +7 -0
- package/dist/adapters/loop-row-type.d.ts.map +1 -1
- package/dist/adapters/nil-reading.d.ts +15 -20
- package/dist/adapters/nil-reading.d.ts.map +1 -1
- package/dist/adapters/non-primitive-equality.d.ts +1 -1
- package/dist/adapters/parsed-expr-emitter.d.ts +11 -1
- package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
- package/dist/adapters/primitive-plan.d.ts +40 -11
- package/dist/adapters/primitive-plan.d.ts.map +1 -1
- package/dist/adapters/prop-classes.d.ts +5 -0
- package/dist/adapters/prop-classes.d.ts.map +1 -1
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/index.d.ts +5 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +390 -228
- package/dist/ir-to-client-js/child-props-object.d.ts +43 -1
- package/dist/ir-to-client-js/child-props-object.d.ts.map +1 -1
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/imports.d.ts +2 -2
- package/dist/ir-to-client-js/imports.d.ts.map +1 -1
- package/dist/ir-to-client-js/phases/props-extraction.d.ts +3 -3
- package/dist/ir-to-client-js/plan/build-declaration-emit.d.ts.map +1 -1
- package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts +3 -1
- package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/nullable-signal-attr.d.ts +4 -46
- package/dist/nullable-signal-attr.d.ts.map +1 -1
- package/dist/props-binding.d.ts +58 -13
- package/dist/props-binding.d.ts.map +1 -1
- package/dist/ssr-defaults.d.ts +39 -3
- package/dist/ssr-defaults.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +6 -6
- package/src/__tests__/body-destructured-prop-default-arrow.test.ts +2 -2
- package/src/__tests__/body-destructured-props-live.test.ts +5 -5
- package/src/__tests__/client-js-generation.test.ts +3 -3
- package/src/__tests__/destructure-default-reads-earlier-param.test.ts +7 -7
- package/src/__tests__/destructured-props-live.test.ts +1 -1
- package/src/__tests__/issue-3861-object-spread-child.test.ts +102 -0
- package/src/__tests__/memo-body-expr.test.ts +2 -2
- package/src/__tests__/nil-reading.test.ts +3 -2
- package/src/__tests__/nullable-signal-attr.test.ts +30 -103
- package/src/__tests__/primitive-plan.test.ts +90 -12
- package/src/__tests__/prop-default-undefined-only.test.ts +115 -0
- package/src/__tests__/prop-references.test.ts +2 -2
- package/src/__tests__/props-destructuring.test.ts +17 -0
- package/src/__tests__/prune-unused-prop-extractions.test.ts +3 -3
- package/src/__tests__/renamed-body-destructure-template.test.ts +7 -7
- package/src/__tests__/rewrite-destructured-props.test.ts +1 -1
- package/src/__tests__/ssr-defaults.test.ts +113 -25
- package/src/__tests__/written-binding-substitution.test.ts +8 -8
- package/src/adapters/callback-method.ts +13 -5
- package/src/adapters/component-props.ts +3 -4
- package/src/adapters/dsl-template-adapter.ts +26 -28
- package/src/adapters/loop-row-type.ts +10 -0
- package/src/adapters/nil-reading.ts +23 -25
- package/src/adapters/non-primitive-equality.ts +1 -1
- package/src/adapters/parsed-expr-emitter.ts +31 -2
- package/src/adapters/primitive-plan.ts +84 -15
- package/src/adapters/prop-classes.ts +16 -3
- package/src/analyzer.ts +27 -7
- package/src/index.ts +4 -11
- package/src/ir-to-client-js/child-props-object.ts +140 -6
- package/src/ir-to-client-js/collect-elements.ts +7 -14
- package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +4 -2
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +4 -2
- package/src/ir-to-client-js/html-template.ts +18 -9
- package/src/ir-to-client-js/imports.ts +1 -1
- package/src/ir-to-client-js/phases/props-extraction.ts +11 -7
- package/src/ir-to-client-js/plan/build-declaration-emit.ts +40 -7
- package/src/ir-to-client-js/prune-unused-prop-extractions.ts +58 -5
- package/src/ir-to-client-js/rewrite-destructured-props.ts +31 -1
- package/src/jsx-to-ir.ts +15 -2
- package/src/nullable-signal-attr.ts +11 -138
- package/src/props-binding.ts +84 -19
- package/src/ssr-defaults.ts +100 -11
- package/dist/adapters/ambiguous-nil-arithmetic.d.ts +0 -42
- package/dist/adapters/ambiguous-nil-arithmetic.d.ts.map +0 -1
- 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
|
-
}
|