@barefootjs/jsx 0.35.6 → 0.35.7
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/analyzer.d.ts.map +1 -1
- package/dist/index.js +30 -13
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/props-binding.d.ts +11 -0
- package/dist/props-binding.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/body-destructured-prop-default-arrow.test.ts +142 -0
- package/src/__tests__/issue-2960-multi-root-cond-same-tag.test.ts +141 -0
- package/src/analyzer.ts +14 -7
- package/src/ir-to-client-js/html-template.ts +65 -9
- package/src/ir-to-client-js/rewrite-destructured-props.ts +13 -1
- package/src/props-binding.ts +15 -1
package/dist/analyzer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyzer.d.ts","sourceRoot":"","sources":["../src/analyzer.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,YAAY,CAAA;AAG3B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAInE,OAAO,EACL,KAAK,eAAe,EAUrB,MAAM,uBAAuB,CAAA;AAqB9B;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAU/D;AA8BD;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf;IAAE,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC;IAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC,WAAW,CAAA;CAAE,GAAG,IAAI,CA8CpF;AAMD,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,mBAAmB,CAAC,EAAE,MAAM,EAC5B,OAAO,CAAC,EAAE,EAAE,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index.js
CHANGED
|
@@ -3396,9 +3396,12 @@ var EMPTY_SET = new Set;
|
|
|
3396
3396
|
function propReadBase(p) {
|
|
3397
3397
|
return `${PROPS_PARAM}.${p.sourceName ?? p.name}`;
|
|
3398
3398
|
}
|
|
3399
|
+
function coalesceDefaultText(defaultValue, defaultContainsArrow) {
|
|
3400
|
+
return defaultContainsArrow ? `(${defaultValue})` : defaultValue;
|
|
3401
|
+
}
|
|
3399
3402
|
function propReadFallback(p, usage, usedAsCondition) {
|
|
3400
3403
|
if (p.defaultValue)
|
|
3401
|
-
return
|
|
3404
|
+
return coalesceDefaultText(p.defaultValue, p.defaultContainsArrow);
|
|
3402
3405
|
if (usage?.usedAsLoopArray)
|
|
3403
3406
|
return "[]";
|
|
3404
3407
|
if (propHasPropertyAccess(usage) && !usedAsCondition)
|
|
@@ -4740,14 +4743,30 @@ function addCondAttrToTemplate(html, condId) {
|
|
|
4740
4743
|
return `<!--bf-cond-start:${condId}-->${html}<!--bf-cond-end:${condId}-->`;
|
|
4741
4744
|
}
|
|
4742
4745
|
function isSingleRootElement(html) {
|
|
4743
|
-
const
|
|
4746
|
+
const trimmed = html.trim();
|
|
4747
|
+
const match = trimmed.match(/^<(\w+)[\s>]/);
|
|
4744
4748
|
if (!match)
|
|
4745
4749
|
return false;
|
|
4746
|
-
|
|
4747
|
-
if (/^<\w+[^>]*\/>$/.test(html.trim()))
|
|
4750
|
+
if (/^<\w+[^>]*\/>$/.test(trimmed))
|
|
4748
4751
|
return true;
|
|
4749
|
-
const
|
|
4750
|
-
|
|
4752
|
+
const tagPattern = /<!--[\s\S]*?-->|<\/?[^\s/>]+[^>]*>/g;
|
|
4753
|
+
let depth = 0;
|
|
4754
|
+
let tagMatch;
|
|
4755
|
+
while (tagMatch = tagPattern.exec(trimmed)) {
|
|
4756
|
+
const raw = tagMatch[0];
|
|
4757
|
+
if (raw.startsWith("<!--"))
|
|
4758
|
+
continue;
|
|
4759
|
+
if (raw.endsWith("/>")) {
|
|
4760
|
+
if (depth === 0)
|
|
4761
|
+
return tagPattern.lastIndex === trimmed.length;
|
|
4762
|
+
continue;
|
|
4763
|
+
}
|
|
4764
|
+
depth += raw.startsWith("</") ? -1 : 1;
|
|
4765
|
+
if (depth === 0) {
|
|
4766
|
+
return tagPattern.lastIndex === trimmed.length;
|
|
4767
|
+
}
|
|
4768
|
+
}
|
|
4769
|
+
return false;
|
|
4751
4770
|
}
|
|
4752
4771
|
function irToComponentTemplate(node, inlinableConstants, restSpreadNames, propsObjectName, markupSlotIds, restPropsName) {
|
|
4753
4772
|
return irToComponentTemplateWithOpts(node, { inlinableConstants, restSpreadNames, propsObjectName, loopDepth: -1, markupSlotIds, restPropsName });
|
|
@@ -8504,10 +8523,9 @@ function collectConstant(node, ctx, _isModule, declarationKind = "const", isExpo
|
|
|
8504
8523
|
continue;
|
|
8505
8524
|
const localName = el.name.text;
|
|
8506
8525
|
const sourceKey = el.propertyName && ts14.isIdentifier(el.propertyName) ? el.propertyName.text : localName;
|
|
8507
|
-
const
|
|
8526
|
+
const defaultFields = el.initializer ? bindingElementDefaultFields(el.initializer, ctx) : undefined;
|
|
8508
8527
|
const baseValue = `${propsName}.${sourceKey}`;
|
|
8509
|
-
const value2 =
|
|
8510
|
-
const containsArrow2 = el.initializer ? nodeContainsArrow(el.initializer) : false;
|
|
8528
|
+
const value2 = defaultFields?.defaultValue !== undefined ? `${baseValue} ?? ${coalesceDefaultText(defaultFields.defaultValue, defaultFields.defaultContainsArrow)}` : baseValue;
|
|
8511
8529
|
const freeIdentifiers3 = el.initializer ? extractFreeIdentifiersFromNode(el.initializer) : new Set([propsName]);
|
|
8512
8530
|
const parsed2 = parseExpression(`(${value2.trim()})`);
|
|
8513
8531
|
ctx.localConstants.push({
|
|
@@ -8519,11 +8537,10 @@ function collectConstant(node, ctx, _isModule, declarationKind = "const", isExpo
|
|
|
8519
8537
|
type: null,
|
|
8520
8538
|
loc: getSourceLocation(node, ctx.sourceFile, ctx.filePath),
|
|
8521
8539
|
freeIdentifiers: freeIdentifiers3,
|
|
8522
|
-
containsArrow:
|
|
8540
|
+
containsArrow: defaultFields?.defaultContainsArrow,
|
|
8523
8541
|
origin: { phase: "hydrate", scope: "init", effect: "pure" }
|
|
8524
8542
|
});
|
|
8525
|
-
if (el.initializer) {
|
|
8526
|
-
const defaultFields = bindingElementDefaultFields(el.initializer, ctx);
|
|
8543
|
+
if (el.initializer && defaultFields) {
|
|
8527
8544
|
const existing = ctx.propsParams.find((p) => !p.isRest && p.sourceName === undefined && p.name === sourceKey);
|
|
8528
8545
|
if (localName === sourceKey) {
|
|
8529
8546
|
if (existing) {
|
|
@@ -23529,7 +23546,7 @@ function rewriteBodyAliasReads(code, ctx) {
|
|
|
23529
23546
|
located.set(decl.name.text, {
|
|
23530
23547
|
key: alias.key,
|
|
23531
23548
|
defaultValue: parsedInit.fallback?.getText(sourceFile),
|
|
23532
|
-
defaultContainsArrow: alias.defaultContainsArrow
|
|
23549
|
+
defaultContainsArrow: alias.defaultContainsArrow && !(parsedInit.fallback && ts22.isParenthesizedExpression(parsedInit.fallback))
|
|
23533
23550
|
});
|
|
23534
23551
|
spans.push([inner.getFullStart(), inner.getEnd()]);
|
|
23535
23552
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-template.d.ts","sourceRoot":"","sources":["../../src/ir-to-client-js/html-template.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAwC,MAAM,EAAU,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAGxI,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAG/C,OAAO,EAAqC,KAAK,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAEpF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAIjD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAIxD;;;;GAIG;AACH,wBAAgB,qBAAqB,IAAI;I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M,GAAG,IAAI,GAC9B,GAAG,CAAC,MAAM,CAAC,CAoDb;AAyYD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,OAAO,CAiBpF"}
|
package/dist/props-binding.d.ts
CHANGED
|
@@ -155,6 +155,17 @@ export declare function boundPropLocalNames(b: PropsParamBindings): ReadonlySet<
|
|
|
155
155
|
export type LivePropReadInfo = Pick<ParamInfo, 'name' | 'sourceName' | 'defaultValue' | 'defaultContainsArrow'>;
|
|
156
156
|
/** `_p.<callerKey>` — `_p` is always keyed by the caller-facing name (#2524 CSR half). */
|
|
157
157
|
export declare function propReadBase(p: LivePropReadInfo): string;
|
|
158
|
+
/**
|
|
159
|
+
* The text a destructure default contributes as the right operand of a `??`
|
|
160
|
+
* prop read. An arrow (or function-expression) default needs its own
|
|
161
|
+
* parens — `??` binds tighter than an arrow head, so `_p.onInput ?? () =>
|
|
162
|
+
* {}` is a SyntaxError. The one implementation of that decision, shared by
|
|
163
|
+
* `propReadFallback` below (every live `_p.X` read) and `collectConstant`'s
|
|
164
|
+
* body-destructure expansion (`analyzer.ts`, which builds
|
|
165
|
+
* `ConstantInfo.value`) — see #2940, where the analyzer built that value
|
|
166
|
+
* without this check and emitted invalid JS.
|
|
167
|
+
*/
|
|
168
|
+
export declare function coalesceDefaultText(defaultValue: string, defaultContainsArrow: boolean | undefined): string;
|
|
158
169
|
/**
|
|
159
170
|
* The `??` right-hand side for a prop read, or null when the bare read is
|
|
160
171
|
* correct. Precedence:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"props-binding.d.ts","sourceRoot":"","sources":["../src/props-binding.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAKpE;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAA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@@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barefootjs/jsx",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.7",
|
|
4
4
|
"description": "JSX compiler for BarefootJS - transforms JSX to server HTML + client JS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"directory": "packages/jsx"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@barefootjs/shared": "0.35.
|
|
52
|
+
"@barefootjs/shared": "0.35.7"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@barefootjs/client": ">=0.2.0",
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression for #2940: a BODY-destructured prop's arrow-function default
|
|
3
|
+
* (`const { fmt = (v) => 'v' + v } = props`) used to build
|
|
4
|
+
* `ConstantInfo.value` as a bare `props.fmt ?? (v) => 'v' + v` —
|
|
5
|
+
* `collectConstant`'s body-destructure branch (`analyzer.ts`) never checked
|
|
6
|
+
* whether the default contained an arrow/function expression before
|
|
7
|
+
* splicing it after `??`, unlike the PARAMETER-destructured sibling form,
|
|
8
|
+
* which already parenthesized via `ParamInfo.defaultContainsArrow`
|
|
9
|
+
* (`propReadFallback`, `props-binding.ts`).
|
|
10
|
+
*
|
|
11
|
+
* `a ?? (v) => expr` is not valid JS — an arrow function cannot appear
|
|
12
|
+
* directly as the right operand of `??` without parens — so this was a
|
|
13
|
+
* genuine SyntaxError in three places that all read `ConstantInfo.value`
|
|
14
|
+
* verbatim: the emitted client-JS init body, the Hono SSR component (the
|
|
15
|
+
* reference adapter also splices `value` unchanged), and every downstream
|
|
16
|
+
* pass that re-parses it (which silently gave up and skipped instead of
|
|
17
|
+
* crashing, masking the bug as a missed optimization rather than a syntax
|
|
18
|
+
* error).
|
|
19
|
+
*
|
|
20
|
+
* The fix routes the analyzer's `value`-building through the same
|
|
21
|
+
* `coalesceDefaultText` decision `propReadFallback` already used, so there
|
|
22
|
+
* is one implementation of "how does a `??` default get parenthesized",
|
|
23
|
+
* not two.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { describe, test, expect } from 'bun:test'
|
|
27
|
+
import ts from 'typescript'
|
|
28
|
+
import { analyzeComponent } from '../analyzer'
|
|
29
|
+
import { compileJSX } from '../index'
|
|
30
|
+
import { HonoAdapter } from '../../../adapter-hono/src/adapter/index'
|
|
31
|
+
|
|
32
|
+
const ARROW_DEFAULT_SOURCE = `
|
|
33
|
+
'use client'
|
|
34
|
+
function Child(props: { fmt?: (v: number) => string }) {
|
|
35
|
+
const { fmt = (v) => 'v' + v } = props
|
|
36
|
+
return <span>{fmt(1)}</span>
|
|
37
|
+
}
|
|
38
|
+
export { Child }
|
|
39
|
+
`
|
|
40
|
+
|
|
41
|
+
const RENAMED_ARROW_DEFAULT_SOURCE = `
|
|
42
|
+
'use client'
|
|
43
|
+
function Child(props: { fmt?: (v: number) => string }) {
|
|
44
|
+
const { fmt: f = (v) => 'v' + v } = props
|
|
45
|
+
return <span>{f(1)}</span>
|
|
46
|
+
}
|
|
47
|
+
export { Child }
|
|
48
|
+
`
|
|
49
|
+
|
|
50
|
+
// A HANDLER-scoped read (as opposed to a top-level reactive text position)
|
|
51
|
+
// goes through `rewriteBodyAliasReads` (`rewrite-destructured-props.ts`),
|
|
52
|
+
// which re-parses the analyzer's already-wrapped `ConstantInfo.value` and
|
|
53
|
+
// used to feed the still-`true` `defaultContainsArrow` flag back into
|
|
54
|
+
// `coalesceDefaultText`, double-wrapping the default a second time
|
|
55
|
+
// (`(_p.fmt ?? (((v) => 'v' + v)))(1)` instead of the minimal
|
|
56
|
+
// `(_p.fmt ?? ((v) => 'v' + v))(1)`) — pullfrog review on #2966.
|
|
57
|
+
const HANDLER_SCOPED_ARROW_DEFAULT_SOURCE = `
|
|
58
|
+
'use client'
|
|
59
|
+
import { createSignal } from '@barefootjs/client'
|
|
60
|
+
function ArrowDefaultFmt(props: { fmt?: (v: number) => string }) {
|
|
61
|
+
const { fmt = (v) => 'v' + v } = props
|
|
62
|
+
const [label, setLabel] = createSignal('none')
|
|
63
|
+
return <button onClick={() => setLabel(fmt(1))}>{label()}</button>
|
|
64
|
+
}
|
|
65
|
+
export { ArrowDefaultFmt }
|
|
66
|
+
`
|
|
67
|
+
|
|
68
|
+
function compile(source: string) {
|
|
69
|
+
return compileJSX(source, 'Child.tsx', { adapter: new HonoAdapter() })
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function parseDiagnosticCount(js: string): number {
|
|
73
|
+
const sourceFile = ts.createSourceFile('generated.js', js, ts.ScriptTarget.Latest, false, ts.ScriptKind.JS)
|
|
74
|
+
// @ts-expect-error - internal, but the established way this repo checks
|
|
75
|
+
// "did the generated code actually parse" (see client-template-escape-
|
|
76
|
+
// soundness.test.ts / map-body-no-silent-divergence.test.ts).
|
|
77
|
+
return sourceFile.parseDiagnostics?.length ?? 0
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
describe('body-destructured prop with an arrow-function default (#2940)', () => {
|
|
81
|
+
test('analyzer: `value` parenthesizes the arrow default', () => {
|
|
82
|
+
const ctx = analyzeComponent(ARROW_DEFAULT_SOURCE, 'Child.tsx')
|
|
83
|
+
const fmt = ctx.localConstants.find(c => c.name === 'fmt')
|
|
84
|
+
expect(fmt).toBeDefined()
|
|
85
|
+
expect(fmt?.value).toBe("props.fmt ?? ((v) => 'v' + v)")
|
|
86
|
+
expect(fmt?.containsArrow).toBe(true)
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
test('emitted client JS parses as valid JS, with no bare `?? (v) =>`', () => {
|
|
90
|
+
const warnings: unknown[][] = []
|
|
91
|
+
const originalWarn = console.warn
|
|
92
|
+
console.warn = (...args: unknown[]) => { warnings.push(args) }
|
|
93
|
+
let result: ReturnType<typeof compile>
|
|
94
|
+
try {
|
|
95
|
+
result = compile(ARROW_DEFAULT_SOURCE)
|
|
96
|
+
} finally {
|
|
97
|
+
console.warn = originalWarn
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const clientJs = result.files.find(f => f.type === 'clientJs')
|
|
101
|
+
expect(clientJs).toBeDefined()
|
|
102
|
+
const js = clientJs!.content
|
|
103
|
+
|
|
104
|
+
expect(js).not.toMatch(/\?\?\s*\(v\)\s*=>/)
|
|
105
|
+
expect(parseDiagnosticCount(js)).toBe(0)
|
|
106
|
+
|
|
107
|
+
// The two downstream passes that used to silently bail because the
|
|
108
|
+
// generated code didn't parse must now run to completion.
|
|
109
|
+
expect(warnings.some(w => String(w[0]).includes('rewriteDestructuredPropReads'))).toBe(false)
|
|
110
|
+
expect(warnings.some(w => String(w[0]).includes('pruneUnusedPropExtractions'))).toBe(false)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test('Hono SSR component also parenthesizes the default (the reference adapter splices `value` verbatim too)', () => {
|
|
114
|
+
const result = compile(ARROW_DEFAULT_SOURCE)
|
|
115
|
+
const ssrComponent = result.files.find(f => f.type === 'markedTemplate')
|
|
116
|
+
expect(ssrComponent).toBeDefined()
|
|
117
|
+
expect(ssrComponent!.content).not.toMatch(/\?\?\s*\(v\)\s*=>/)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
test('renamed alias (`{ fmt: f = (v) => ... }`) gets the same paren-wrap', () => {
|
|
121
|
+
const ctx = analyzeComponent(RENAMED_ARROW_DEFAULT_SOURCE, 'Child.tsx')
|
|
122
|
+
const f = ctx.localConstants.find(c => c.name === 'f')
|
|
123
|
+
expect(f).toBeDefined()
|
|
124
|
+
expect(f?.value).toBe("props.fmt ?? ((v) => 'v' + v)")
|
|
125
|
+
expect(f?.containsArrow).toBe(true)
|
|
126
|
+
|
|
127
|
+
const result = compile(RENAMED_ARROW_DEFAULT_SOURCE)
|
|
128
|
+
const clientJs = result.files.find(f => f.type === 'clientJs')
|
|
129
|
+
expect(parseDiagnosticCount(clientJs!.content)).toBe(0)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test('a handler-scoped read wraps the arrow default exactly once, not twice', () => {
|
|
133
|
+
const result = compile(HANDLER_SCOPED_ARROW_DEFAULT_SOURCE)
|
|
134
|
+
const clientJs = result.files.find(f => f.type === 'clientJs')
|
|
135
|
+
expect(clientJs).toBeDefined()
|
|
136
|
+
const js = clientJs!.content
|
|
137
|
+
|
|
138
|
+
expect(parseDiagnosticCount(js)).toBe(0)
|
|
139
|
+
expect(js).toContain("(_p.fmt ?? ((v) => 'v' + v))(1)")
|
|
140
|
+
expect(js).not.toContain("(_p.fmt ?? (((v) => 'v' + v)))(1)")
|
|
141
|
+
})
|
|
142
|
+
})
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #2960 — `addCondAttrToTemplate`'s `isSingleRootElement` heuristic
|
|
3
|
+
* mis-classified a multi-root ternary branch as a single element root
|
|
4
|
+
* whenever its LAST element happened to share its FIRST element's tag
|
|
5
|
+
* name (`<div>...</div><div>...</div>`): the check was "does the string
|
|
6
|
+
* end with a closing tag of the root's own tag name", which a second,
|
|
7
|
+
* unrelated sibling of the same tag name satisfies just as well as a
|
|
8
|
+
* genuine single root's own closing tag.
|
|
9
|
+
*
|
|
10
|
+
* Compiled wrong, this stamps `bf-c="<id>"` onto only the first element
|
|
11
|
+
* instead of comment-wrapping the whole branch — which routes the
|
|
12
|
+
* runtime's branch swap through `insert()`'s `updateElementConditional`
|
|
13
|
+
* (`fragment.firstChild`-only) instead of `updateFragmentConditional`
|
|
14
|
+
* (which moves every top-level node), silently dropping every sibling
|
|
15
|
+
* but the first on a live branch swap.
|
|
16
|
+
*/
|
|
17
|
+
import { describe, test, expect } from 'bun:test'
|
|
18
|
+
import { compileJSX } from '../compiler'
|
|
19
|
+
import { TestAdapter } from '../adapters/test-adapter'
|
|
20
|
+
import { addCondAttrToTemplate } from '../ir-to-client-js/html-template'
|
|
21
|
+
|
|
22
|
+
const adapter = new TestAdapter()
|
|
23
|
+
|
|
24
|
+
describe('#2960: multi-root cond branch whose roots share a tag name', () => {
|
|
25
|
+
test('comment-wraps a same-tag-name multi-root branch instead of stamping bf-c on only the first element', () => {
|
|
26
|
+
const source = `
|
|
27
|
+
'use client'
|
|
28
|
+
import { createSignal } from '@barefootjs/client'
|
|
29
|
+
|
|
30
|
+
export function Repro() {
|
|
31
|
+
const [open, setOpen] = createSignal(false)
|
|
32
|
+
return (
|
|
33
|
+
<div>
|
|
34
|
+
<button onClick={() => setOpen(true)}>open</button>
|
|
35
|
+
{open() === false ? (
|
|
36
|
+
<div id="welcome">Welcome</div>
|
|
37
|
+
) : (
|
|
38
|
+
<>
|
|
39
|
+
<div id="before">before</div>
|
|
40
|
+
<div id="after">after</div>
|
|
41
|
+
</>
|
|
42
|
+
)}
|
|
43
|
+
</div>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
`
|
|
47
|
+
|
|
48
|
+
const result = compileJSX(source, 'Repro.tsx', { adapter })
|
|
49
|
+
expect(result.errors).toHaveLength(0)
|
|
50
|
+
|
|
51
|
+
const clientJs = result.files.find(f => f.type === 'clientJs')
|
|
52
|
+
expect(clientJs).toBeDefined()
|
|
53
|
+
|
|
54
|
+
// The multi-root branch must be comment-wrapped ...
|
|
55
|
+
expect(clientJs!.content).toContain('bf-cond-start:')
|
|
56
|
+
expect(clientJs!.content).toContain('bf-cond-end:')
|
|
57
|
+
// ... and BOTH of its sibling elements must appear inside the
|
|
58
|
+
// template literal, not just the first one.
|
|
59
|
+
expect(clientJs!.content).toMatch(/id=\\?"before\\?"/)
|
|
60
|
+
expect(clientJs!.content).toMatch(/id=\\?"after\\?"/)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test('a genuine single-root branch (no same-tag sibling) still gets bf-c, not comment markers', () => {
|
|
64
|
+
const source = `
|
|
65
|
+
'use client'
|
|
66
|
+
import { createSignal } from '@barefootjs/client'
|
|
67
|
+
|
|
68
|
+
export function Simple() {
|
|
69
|
+
const [on, setOn] = createSignal(false)
|
|
70
|
+
return <div>{on() ? <span id="a">A</span> : <span id="b">B</span>}</div>
|
|
71
|
+
}
|
|
72
|
+
`
|
|
73
|
+
|
|
74
|
+
const result = compileJSX(source, 'Simple.tsx', { adapter })
|
|
75
|
+
expect(result.errors).toHaveLength(0)
|
|
76
|
+
|
|
77
|
+
const clientJs = result.files.find(f => f.type === 'clientJs')
|
|
78
|
+
expect(clientJs).toBeDefined()
|
|
79
|
+
expect(clientJs!.content).toContain('bf-c=')
|
|
80
|
+
expect(clientJs!.content).not.toContain('bf-cond-start:')
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
// The depth-tracking fix above must not widen which shapes are treated
|
|
84
|
+
// as "single root" beyond what the sibling `bf-c` splice regex
|
|
85
|
+
// (`html.replace(/^(<\w+)(\s|>)/, ...)`) can actually stamp — a
|
|
86
|
+
// self-closing root's own `/` or a hyphenated custom-element tag name
|
|
87
|
+
// both fail that splice. Every one of these must still come back
|
|
88
|
+
// comment-wrapped (never bare, unmodified HTML with neither `bf-c` nor
|
|
89
|
+
// markers, which would make `insert()` unable to find the branch at all).
|
|
90
|
+
describe('does not widen single-root detection into shapes the bf-c splice cannot stamp', () => {
|
|
91
|
+
const unstampable = [
|
|
92
|
+
['<input/>', 'self-closing void element root'],
|
|
93
|
+
['<my-widget>a</my-widget>', 'hyphenated custom-element root'],
|
|
94
|
+
['<my-widget>a</my-widget><my-widget>b</my-widget>', 'multi-root, same hyphenated tag'],
|
|
95
|
+
] as const
|
|
96
|
+
|
|
97
|
+
for (const [html, label] of unstampable) {
|
|
98
|
+
test(label, () => {
|
|
99
|
+
const result = addCondAttrToTemplate(html, 'c1')
|
|
100
|
+
expect(result).toContain('bf-cond-start:c1')
|
|
101
|
+
expect(result).toContain('bf-cond-end:c1')
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
// The depth-tracking walk must not treat BarefootJS's own marker
|
|
107
|
+
// comments (`<!--bf:sN-->`, its `<!--/-->` pair) as if they were real
|
|
108
|
+
// tags — an earlier version of this fix's tag-matching regex matched
|
|
109
|
+
// any `<...>` run indiscriminately, so a perfectly ordinary single-root
|
|
110
|
+
// branch with an internal reactive text slot got miscounted into an
|
|
111
|
+
// unbalanced depth and wrongly comment-wrapped instead of getting
|
|
112
|
+
// `bf-c`. Caught by `doc-examples.test.ts`'s snapshot drifting on the
|
|
113
|
+
// `count() > 0 ? <p>...</p> : <p>No items</p>` example.
|
|
114
|
+
test('a single root containing internal bf: slot marker comments still gets bf-c, not comment-wrap', () => {
|
|
115
|
+
const html = '<p bf="s2"><!--bf:s1-->${__bfSlot(count(), __slots)}<!--/--> items</p>'
|
|
116
|
+
const result = addCondAttrToTemplate(html, 's0')
|
|
117
|
+
expect(result).toContain('bf-c="s0"')
|
|
118
|
+
expect(result).not.toContain('bf-cond-start:')
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
// A self-closing/void root followed by a real sibling element
|
|
122
|
+
// (`<input .../><label>...</label>`, todo-app's "mark all as complete"
|
|
123
|
+
// branch) is genuinely two roots. The whole-string self-closing check
|
|
124
|
+
// only catches a self-closing tag with NOTHING else in the string, so
|
|
125
|
+
// this shape still reaches the depth-tracking walk — an earlier version
|
|
126
|
+
// of that walk unconditionally `continue`d past every self-closing tag
|
|
127
|
+
// on the theory that one could never be the outermost token by the time
|
|
128
|
+
// the walk runs, which is wrong: the initial tag-name gate only checks
|
|
129
|
+
// the tag name and the character right after it, not whether the tag
|
|
130
|
+
// later turns out to self-close. That version silently merged the
|
|
131
|
+
// `<input/>` and `<label>` into a false single root, stamping `bf-c`
|
|
132
|
+
// onto only the `<input/>` and dropping `<label>` on a live swap.
|
|
133
|
+
// Caught by `generate-expected-html.ts` drifting the `todo-app` fixture.
|
|
134
|
+
test('a self-closing root followed by a sibling element is multi-root, not single', () => {
|
|
135
|
+
const html = '<input id="toggle-all" class="toggle-all" type="checkbox" bf="s2" /><label for="toggle-all">Mark all as complete</label>'
|
|
136
|
+
const result = addCondAttrToTemplate(html, 's1')
|
|
137
|
+
expect(result).toContain('bf-cond-start:s1')
|
|
138
|
+
expect(result).toContain('bf-cond-end:s1')
|
|
139
|
+
expect(result).not.toContain('bf-c=')
|
|
140
|
+
})
|
|
141
|
+
})
|
package/src/analyzer.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type { ImportSpecifier, TypeInfo, ParamInfo, ReactiveFactoryInfo, Decline
|
|
|
11
11
|
import { parseExpression, parseBlockBodyTolerant, foldBlockToExpr, tsNodeToParsedExpr } from './expression-parser.ts'
|
|
12
12
|
import type { CallbackBodyAcceptor } from './adapters/interface.ts'
|
|
13
13
|
import { rewriteBarePropRefs } from './prop-rewrite.ts'
|
|
14
|
-
import { buildPropAliasMap } from './props-binding.ts'
|
|
14
|
+
import { buildPropAliasMap, coalesceDefaultText } from './props-binding.ts'
|
|
15
15
|
import { incrementCounter } from './instrumentation.ts'
|
|
16
16
|
import {
|
|
17
17
|
type AnalyzerContext,
|
|
@@ -3181,10 +3181,18 @@ function collectConstant(
|
|
|
3181
3181
|
if (!ts.isBindingElement(el) || !ts.isIdentifier(el.name) || el.dotDotDotToken) continue
|
|
3182
3182
|
const localName = el.name.text
|
|
3183
3183
|
const sourceKey = el.propertyName && ts.isIdentifier(el.propertyName) ? el.propertyName.text : localName
|
|
3184
|
-
|
|
3184
|
+
// Shared with the #2943 `ParamInfo` overlay below so "what does this
|
|
3185
|
+
// default look like" (source text, `defaultContainsArrow`) has one
|
|
3186
|
+
// computation, not two independently-drifting ones.
|
|
3187
|
+
const defaultFields = el.initializer ? bindingElementDefaultFields(el.initializer, ctx) : undefined
|
|
3185
3188
|
const baseValue = `${propsName}.${sourceKey}`
|
|
3186
|
-
|
|
3187
|
-
|
|
3189
|
+
// Parenthesize an arrow/function-expression default (#2940) — `??`
|
|
3190
|
+
// binds tighter than an arrow head, so a bare `props.fmt ?? (v) =>
|
|
3191
|
+
// ...` is a SyntaxError in the emitted JS. Same rule
|
|
3192
|
+
// `propReadFallback` already applies to every other live prop read.
|
|
3193
|
+
const value = defaultFields?.defaultValue !== undefined
|
|
3194
|
+
? `${baseValue} ?? ${coalesceDefaultText(defaultFields.defaultValue, defaultFields.defaultContainsArrow)}`
|
|
3195
|
+
: baseValue
|
|
3188
3196
|
const freeIdentifiers = el.initializer ? extractFreeIdentifiersFromNode(el.initializer) : new Set([propsName])
|
|
3189
3197
|
// Structured parse of `value`, same as the plain-identifier branch
|
|
3190
3198
|
// below (#2724 review finding): without this, a RENAMED destructure
|
|
@@ -3210,7 +3218,7 @@ function collectConstant(
|
|
|
3210
3218
|
type: null,
|
|
3211
3219
|
loc: getSourceLocation(node, ctx.sourceFile, ctx.filePath),
|
|
3212
3220
|
freeIdentifiers,
|
|
3213
|
-
containsArrow:
|
|
3221
|
+
containsArrow: defaultFields?.defaultContainsArrow,
|
|
3214
3222
|
// Body-level destructure-from-props is collected only when
|
|
3215
3223
|
// _isModule === false; binding lives in init scope.
|
|
3216
3224
|
origin: { phase: 'hydrate', scope: 'init', effect: 'pure' },
|
|
@@ -3233,8 +3241,7 @@ function collectConstant(
|
|
|
3233
3241
|
// this is a static, compile-time fact about the source, not a
|
|
3234
3242
|
// liveness question, so (unlike `resolveBodyPropAliases`'s
|
|
3235
3243
|
// `requireLiveRewriteSafe` gate) nothing here excludes them.
|
|
3236
|
-
if (el.initializer) {
|
|
3237
|
-
const defaultFields = bindingElementDefaultFields(el.initializer, ctx)
|
|
3244
|
+
if (el.initializer && defaultFields) {
|
|
3238
3245
|
const existing = ctx.propsParams.find(p => !p.isRest && p.sourceName === undefined && p.name === sourceKey)
|
|
3239
3246
|
if (localName === sourceKey) {
|
|
3240
3247
|
// Unrenamed: overlay onto the type-member entry `sourceKey`
|
|
@@ -1621,17 +1621,73 @@ export function addCondAttrToTemplate(html: string, condId: string): string {
|
|
|
1621
1621
|
return `<!--bf-cond-start:${condId}-->${html}<!--bf-cond-end:${condId}-->`
|
|
1622
1622
|
}
|
|
1623
1623
|
|
|
1624
|
-
/**
|
|
1624
|
+
/**
|
|
1625
|
+
* Check if HTML string has a single root element (not multiple siblings).
|
|
1626
|
+
*
|
|
1627
|
+
* Walks top-level tags tracking nesting depth rather than checking only
|
|
1628
|
+
* "does the string end with a closing tag of the root's tag name" — that
|
|
1629
|
+
* lexical shortcut matches `<div id="before">before</div><div id="after">after</div>`
|
|
1630
|
+
* (two sibling `<div>`s) as a false single root, because the STRING happens
|
|
1631
|
+
* to end in `</div>`, the same tag name the root opened with, even though
|
|
1632
|
+
* that closing tag belongs to the second, unrelated div (#2960). A
|
|
1633
|
+
* multi-root branch wrongly classified here gets `bf-c="<id>"` stamped
|
|
1634
|
+
* onto only its first element instead of being comment-wrapped, and
|
|
1635
|
+
* `insert()`'s runtime then drops every sibling but the first on a branch
|
|
1636
|
+
* swap (`updateElementConditional`'s `fragment.firstChild`).
|
|
1637
|
+
*/
|
|
1625
1638
|
function isSingleRootElement(html: string): boolean {
|
|
1626
|
-
|
|
1627
|
-
|
|
1639
|
+
const trimmed = html.trim()
|
|
1640
|
+
// Same gate as before this fix: only a tag name matching `\w+`,
|
|
1641
|
+
// followed immediately by whitespace or `>`, is recognized here — that
|
|
1642
|
+
// is exactly the shape `addCondAttrToTemplate`'s splice regex
|
|
1643
|
+
// (`html.replace(/^(<\w+)(\s|>)/, ...)`) can stamp `bf-c` onto. A root
|
|
1644
|
+
// this gate doesn't recognize (a self-closing tag's own `/`, a
|
|
1645
|
+
// hyphenated custom-element tag) falls through to `false`
|
|
1646
|
+
// (comment-wrap) unchanged from before — widening this gate without
|
|
1647
|
+
// also teaching the splice regex the same shapes would silently drop
|
|
1648
|
+
// BOTH the `bf-c` stamp and the comment-wrap fallback for those roots.
|
|
1649
|
+
const match = trimmed.match(/^<(\w+)[\s>]/)
|
|
1628
1650
|
if (!match) return false
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
//
|
|
1633
|
-
|
|
1634
|
-
|
|
1651
|
+
// Self-closing tags like <br/>, <input/> with nothing else.
|
|
1652
|
+
if (/^<\w+[^>]*\/>$/.test(trimmed)) return true
|
|
1653
|
+
|
|
1654
|
+
// Walk top-level tags tracking nesting depth — see the docstring above
|
|
1655
|
+
// for why (#2960). The comment alternative must come first so it wins at a `<!--`
|
|
1656
|
+
// position — without it, a BarefootJS marker comment like
|
|
1657
|
+
// `<!--bf:s1-->`/`<!--/-->` (a reactive text slot nested inside a
|
|
1658
|
+
// genuine single root) matches the generic tag alternative too (its
|
|
1659
|
+
// body has no `\s`, `/` or `>` before the closing `-->`) and gets
|
|
1660
|
+
// miscounted as an opening tag, throwing off the depth count for
|
|
1661
|
+
// perfectly ordinary single-root branches.
|
|
1662
|
+
const tagPattern = /<!--[\s\S]*?-->|<\/?[^\s/>]+[^>]*>/g
|
|
1663
|
+
let depth = 0
|
|
1664
|
+
let tagMatch: RegExpExecArray | null
|
|
1665
|
+
while ((tagMatch = tagPattern.exec(trimmed))) {
|
|
1666
|
+
const raw = tagMatch[0]
|
|
1667
|
+
if (raw.startsWith('<!--')) continue // HTML comment, not a tag: depth unchanged
|
|
1668
|
+
if (raw.endsWith('/>')) {
|
|
1669
|
+
// Self-closing/void tag (e.g. `<input .../>`). The whole-string
|
|
1670
|
+
// check above only catches a self-closing tag with NOTHING else in
|
|
1671
|
+
// the string — a self-closing root FOLLOWED by more content (e.g.
|
|
1672
|
+
// `<input .../><label>...</label>`, a genuine two-root branch) still
|
|
1673
|
+
// reaches here with the guard above already satisfied (it only
|
|
1674
|
+
// looks at the tag name and the very next character, not whether
|
|
1675
|
+
// the tag turns out to self-close). At depth 0 this tag completes a
|
|
1676
|
+
// whole top-level unit by itself, so treat it exactly like any
|
|
1677
|
+
// other tag's closing point: single root only if nothing follows.
|
|
1678
|
+
// Nested inside another element (depth > 0) it's just an ordinary
|
|
1679
|
+
// child and doesn't affect depth.
|
|
1680
|
+
if (depth === 0) return tagPattern.lastIndex === trimmed.length
|
|
1681
|
+
continue
|
|
1682
|
+
}
|
|
1683
|
+
depth += raw.startsWith('</') ? -1 : 1
|
|
1684
|
+
if (depth === 0) {
|
|
1685
|
+
// Back to depth 0: the root element's own closing tag. Single root
|
|
1686
|
+
// only if nothing else follows it.
|
|
1687
|
+
return tagPattern.lastIndex === trimmed.length
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
return false
|
|
1635
1691
|
}
|
|
1636
1692
|
|
|
1637
1693
|
/**
|
|
@@ -167,7 +167,19 @@ function rewriteBodyAliasReads(code: string, ctx: ClientJsContext): string {
|
|
|
167
167
|
located.set(decl.name.text, {
|
|
168
168
|
key: alias.key,
|
|
169
169
|
defaultValue: parsedInit.fallback?.getText(sourceFile),
|
|
170
|
-
|
|
170
|
+
// `alias.defaultContainsArrow` mirrors `c.containsArrow`, computed
|
|
171
|
+
// against the ORIGINAL initializer before #2940's fix wrapped an
|
|
172
|
+
// arrow/function-expression default in its own protective parens
|
|
173
|
+
// (`coalesceDefaultText`, `analyzer.ts`). `parsedInit.fallback`
|
|
174
|
+
// here re-parses that ALREADY-wrapped `ConstantInfo.value` text, so
|
|
175
|
+
// when the fallback is itself a `ParenthesizedExpression` the wrap
|
|
176
|
+
// has already happened — `livePropReadExpr` below must not apply
|
|
177
|
+
// `coalesceDefaultText` a second time, or a live handler-scoped
|
|
178
|
+
// read doubles up (`(_p.fmt ?? (((v) => ...)))(1)` instead of the
|
|
179
|
+
// minimal `(_p.fmt ?? ((v) => ...))(1)`).
|
|
180
|
+
defaultContainsArrow: alias.defaultContainsArrow && !(
|
|
181
|
+
parsedInit.fallback && ts.isParenthesizedExpression(parsedInit.fallback)
|
|
182
|
+
),
|
|
171
183
|
})
|
|
172
184
|
spans.push([inner.getFullStart(), inner.getEnd()])
|
|
173
185
|
}
|
package/src/props-binding.ts
CHANGED
|
@@ -244,6 +244,20 @@ export function propReadBase(p: LivePropReadInfo): string {
|
|
|
244
244
|
return `${PROPS_PARAM}.${p.sourceName ?? p.name}`
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
+
/**
|
|
248
|
+
* The text a destructure default contributes as the right operand of a `??`
|
|
249
|
+
* prop read. An arrow (or function-expression) default needs its own
|
|
250
|
+
* parens — `??` binds tighter than an arrow head, so `_p.onInput ?? () =>
|
|
251
|
+
* {}` is a SyntaxError. The one implementation of that decision, shared by
|
|
252
|
+
* `propReadFallback` below (every live `_p.X` read) and `collectConstant`'s
|
|
253
|
+
* body-destructure expansion (`analyzer.ts`, which builds
|
|
254
|
+
* `ConstantInfo.value`) — see #2940, where the analyzer built that value
|
|
255
|
+
* without this check and emitted invalid JS.
|
|
256
|
+
*/
|
|
257
|
+
export function coalesceDefaultText(defaultValue: string, defaultContainsArrow: boolean | undefined): string {
|
|
258
|
+
return defaultContainsArrow ? `(${defaultValue})` : defaultValue
|
|
259
|
+
}
|
|
260
|
+
|
|
247
261
|
/**
|
|
248
262
|
* The `??` right-hand side for a prop read, or null when the bare read is
|
|
249
263
|
* correct. Precedence:
|
|
@@ -263,7 +277,7 @@ export function propReadFallback(
|
|
|
263
277
|
usage: PropUsage | undefined,
|
|
264
278
|
usedAsCondition: boolean,
|
|
265
279
|
): string | null {
|
|
266
|
-
if (p.defaultValue) return
|
|
280
|
+
if (p.defaultValue) return coalesceDefaultText(p.defaultValue, p.defaultContainsArrow)
|
|
267
281
|
if (usage?.usedAsLoopArray) return '[]'
|
|
268
282
|
if (propHasPropertyAccess(usage) && !usedAsCondition) return '{}'
|
|
269
283
|
return null
|