@barefootjs/jsx 0.39.0 → 0.39.2
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/interface.d.ts +19 -0
- package/dist/adapters/interface.d.ts.map +1 -1
- package/dist/adapters/jsx-adapter.d.ts.map +1 -1
- package/dist/adapters/parsed-expr-emitter.d.ts +2 -2
- package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
- package/dist/analyzer.d.ts +19 -0
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/compiler.d.ts.map +1 -1
- package/dist/debug.d.ts.map +1 -1
- package/dist/html-types.d.ts +5 -0
- package/dist/html-types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1455 -1139
- package/dist/ir-to-client-js/collect-elements.d.ts +17 -1
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/reactivity.d.ts +10 -2
- package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
- package/dist/ir-to-client-js/safe-html.d.ts +1 -1
- package/dist/ir-to-client-js/safe-html.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +11 -7
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/literal-member-index.d.ts +6 -0
- package/dist/literal-member-index.d.ts.map +1 -0
- package/dist/scope/binding-scope.d.ts +11 -0
- package/dist/scope/binding-scope.d.ts.map +1 -1
- package/dist/signal-prop-name-collision.d.ts +20 -0
- package/dist/signal-prop-name-collision.d.ts.map +1 -0
- package/dist/ssr-defaults.d.ts.map +1 -1
- package/dist/ssr-seed-plan.d.ts +3 -2
- package/dist/ssr-seed-plan.d.ts.map +1 -1
- package/dist/types.d.ts +44 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +4 -4
- package/src/__tests__/adapter-output.test.ts +142 -0
- package/src/__tests__/binding-scope.test.ts +27 -0
- package/src/__tests__/client-template-escape-soundness.test.ts +17 -0
- package/src/__tests__/conditional-nested-loop-bindings.test.ts +41 -0
- package/src/__tests__/create-mutation.test.ts +30 -0
- package/src/__tests__/create-query.test.ts +52 -0
- package/src/__tests__/debug.test.ts +83 -0
- package/src/__tests__/destructured-from-props-localconst-value.test.ts +3 -2
- package/src/__tests__/ir-fragment-transparency.test.ts +23 -0
- package/src/__tests__/issue-3240-nested-static-map-event-delegation.test.ts +245 -0
- package/src/__tests__/jsx-text-linebreak-whitespace.test.ts +80 -0
- package/src/__tests__/literal-member-index.test.ts +14 -0
- package/src/__tests__/loop-param-accessor-key-member-safety.test.ts +445 -0
- package/src/__tests__/signal-prop-name-collision.test.ts +171 -0
- package/src/__tests__/ssr-defaults.test.ts +6 -7
- package/src/__tests__/ssr-seed-plan.test.ts +23 -0
- package/src/__tests__/staged-ir/02-shadow-guards.test.ts +1 -1
- package/src/__tests__/staged-ir/08-relocate-unit.test.ts +6 -3
- package/src/adapters/interface.ts +19 -0
- package/src/adapters/jsx-adapter.ts +30 -20
- package/src/adapters/parsed-expr-emitter.ts +3 -3
- package/src/analyzer.ts +45 -11
- package/src/compiler.ts +78 -46
- package/src/debug.ts +34 -2
- package/src/html-types.ts +14 -0
- package/src/index.ts +2 -0
- package/src/ir-to-client-js/collect-elements.ts +72 -13
- package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +112 -3
- package/src/ir-to-client-js/reactivity.ts +31 -1
- package/src/ir-to-client-js/safe-html.ts +19 -6
- package/src/ir-to-client-js/utils.ts +130 -15
- package/src/jsx-to-ir.ts +89 -14
- package/src/literal-member-index.ts +12 -0
- package/src/scope/binding-scope.ts +31 -1
- package/src/signal-prop-name-collision.ts +164 -0
- package/src/ssr-defaults.ts +13 -5
- package/src/ssr-seed-plan.ts +26 -3
- package/src/types.ts +47 -0
|
@@ -219,9 +219,12 @@ describe('buildRelocateEnv: builds env from analyzer/IR state', () => {
|
|
|
219
219
|
}
|
|
220
220
|
`, 'Foo.tsx')
|
|
221
221
|
const env = buildRelocateEnv(ctx)
|
|
222
|
-
//
|
|
223
|
-
|
|
224
|
-
|
|
222
|
+
// The local getter is distinct from the bare prop. It must still
|
|
223
|
+
// classify as a getter, never as a prop eligible for lifting.
|
|
224
|
+
const getter = ctx.signals[0].getter
|
|
225
|
+
expect(env.bindings.get(getter)).toBe('signal-getter')
|
|
226
|
+
expect(env.propsForLift.has(getter)).toBe(false)
|
|
227
|
+
expect(env.bindings.get('count')).toBe('prop')
|
|
225
228
|
})
|
|
226
229
|
|
|
227
230
|
test('pure prop alias stays classified as prop (eligible for lift)', async () => {
|
|
@@ -242,6 +242,25 @@ export interface TemplateAdapter {
|
|
|
242
242
|
* Required for adapters that look up templates by filename (e.g. Mojolicious).
|
|
243
243
|
*/
|
|
244
244
|
templatesPerComponent?: boolean
|
|
245
|
+
/**
|
|
246
|
+
* `false` for an adapter whose `markedTemplate` output has no consumer at
|
|
247
|
+
* all — the whole file is discarded after compilation (CSR: the browser
|
|
248
|
+
* runs the compiled client JS, not a rendered template). Defaults to
|
|
249
|
+
* `true` (every other adapter: a template file is read by something,
|
|
250
|
+
* whether that's a backend framework's renderer or, for the reference
|
|
251
|
+
* `HonoAdapter`, the JS module itself).
|
|
252
|
+
*
|
|
253
|
+
* When `false`, `compileJSX` skips assembling `markedTemplate` content
|
|
254
|
+
* ENTIRELY for that adapter, including the file's module-level value
|
|
255
|
+
* exports (`export const` / `export function`) that would otherwise be
|
|
256
|
+
* appended unconditionally regardless of the adapter's own `generate()`
|
|
257
|
+
* output. Without this, a component file that also exports a plain value
|
|
258
|
+
* produces a `markedTemplate` whose only content is that export — which
|
|
259
|
+
* looks like real template output to a consumer like `@barefootjs/vite`'s
|
|
260
|
+
* `assertNoRealTemplateOutput`, even though nothing will ever read it
|
|
261
|
+
* (#3234).
|
|
262
|
+
*/
|
|
263
|
+
emitsTemplates?: boolean
|
|
245
264
|
/**
|
|
246
265
|
* Module specifier of the SSR shim for `@barefootjs/client` (and
|
|
247
266
|
* `/runtime`). When set, the compiler rewrites client-package imports in
|
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
IRTemplatePart,
|
|
13
13
|
ImportSpecifier,
|
|
14
14
|
} from '../types.ts'
|
|
15
|
+
import { isElidedFactoryGetter } from '../types.ts'
|
|
15
16
|
import { templatePartsToJsExpr } from '../template-parts.ts'
|
|
16
17
|
import { BF_SCOPE, BF_SLOT, BF_COND } from '@barefootjs/shared'
|
|
17
18
|
import { BaseAdapter } from './interface.ts'
|
|
@@ -150,26 +151,35 @@ export abstract class JsxAdapter extends BaseAdapter {
|
|
|
150
151
|
}
|
|
151
152
|
continue
|
|
152
153
|
}
|
|
153
|
-
//
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
//
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
154
|
+
// An elided async-factory value (#3245) has no getter binding in the
|
|
155
|
+
// source at all — `signal.getter` is a synthesized internal name that
|
|
156
|
+
// nothing in the template or event handlers ever references. Emitting
|
|
157
|
+
// its SSR stub would leak that compiler-internal name into the SSR
|
|
158
|
+
// module for a binding nothing reads; the action's own SSR stub
|
|
159
|
+
// (below) is unaffected and still emitted when referenced. See
|
|
160
|
+
// `isElidedFactoryGetter`'s docstring for the full rationale.
|
|
161
|
+
if (!isElidedFactoryGetter(signal)) {
|
|
162
|
+
// Create a getter that returns the initial value for SSR
|
|
163
|
+
const rawInitialValue = preserveTypes
|
|
164
|
+
? (signal.typedInitialValue ?? signal.initialValue)
|
|
165
|
+
: signal.initialValue
|
|
166
|
+
const initialValue = rawInitialValue.trim().startsWith('{') ? `(${rawInitialValue})` : rawInitialValue
|
|
167
|
+
|
|
168
|
+
// When preserveTypes and typedInitialValue is absent but signal.type has a meaningful
|
|
169
|
+
// type from a generic parameter, add a type assertion to prevent TS inference issues.
|
|
170
|
+
// A bare `object` raw is the analyzer's coarse KIND, not a real type — asserting
|
|
171
|
+
// `as object` only destroys the initializer's inferred literal type (a
|
|
172
|
+
// `{ x: 0, y: 0 }` signal getter stops matching `() => { x: number; y: number }`).
|
|
173
|
+
const needsTypeAssertion = preserveTypes
|
|
174
|
+
&& !signal.typedInitialValue
|
|
175
|
+
&& signal.type.kind !== 'unknown'
|
|
176
|
+
&& signal.type.kind !== 'primitive'
|
|
177
|
+
&& signal.type.raw !== 'object'
|
|
178
|
+
if (needsTypeAssertion) {
|
|
179
|
+
lines.push(` const ${signal.getter} = () => ${initialValue} as ${signal.type.raw}`)
|
|
180
|
+
} else {
|
|
181
|
+
lines.push(` const ${signal.getter} = () => ${initialValue}`)
|
|
182
|
+
}
|
|
173
183
|
}
|
|
174
184
|
|
|
175
185
|
// An async factory's action (#3165): the request function never runs on
|
|
@@ -244,14 +244,14 @@ export interface ParsedExprEmitter {
|
|
|
244
244
|
* Consumed by `===`/`!==` lowering on backends whose `==` is numeric
|
|
245
245
|
* (Perl `eq`/`ne`) and by `isStringConcatBinary` below.
|
|
246
246
|
*/
|
|
247
|
-
export function isStringTypedOperand(expr: ParsedExpr, isStringName: (n: string) => boolean): boolean {
|
|
247
|
+
export function isStringTypedOperand(expr: ParsedExpr, isStringName: (n: string, componentProperty?: boolean) => boolean): boolean {
|
|
248
248
|
if (expr.kind === 'literal' && expr.literalType === 'string') return true
|
|
249
249
|
if (expr.kind === 'template-literal') return true
|
|
250
250
|
if (expr.kind === 'call' && expr.callee.kind === 'identifier' && expr.args.length === 0) {
|
|
251
251
|
return isStringName(expr.callee.name)
|
|
252
252
|
}
|
|
253
253
|
if (expr.kind === 'member' && expr.object.kind === 'identifier' && expr.object.name === 'props') {
|
|
254
|
-
return isStringName(expr.property)
|
|
254
|
+
return isStringName(expr.property, true)
|
|
255
255
|
}
|
|
256
256
|
// A bare identifier (#2212): a destructured prop param or a same-file
|
|
257
257
|
// local const, string-typed per the caller's `isStringName` set — each
|
|
@@ -282,7 +282,7 @@ export function isStringConcatBinary(
|
|
|
282
282
|
op: string,
|
|
283
283
|
left: ParsedExpr,
|
|
284
284
|
right: ParsedExpr,
|
|
285
|
-
isStringName: (n: string) => boolean,
|
|
285
|
+
isStringName: (n: string, componentProperty?: boolean) => boolean,
|
|
286
286
|
): boolean {
|
|
287
287
|
return op === '+' && (isStringTypedOperand(left, isStringName) || isStringTypedOperand(right, isStringName))
|
|
288
288
|
}
|
package/src/analyzer.ts
CHANGED
|
@@ -32,6 +32,7 @@ import { CATALOGUED_RICH_TYPE_NAMES } from './date-lowering.ts'
|
|
|
32
32
|
import path from 'node:path'
|
|
33
33
|
import fs from 'node:fs'
|
|
34
34
|
import { signalSecondBinding } from './signal-initializer.ts'
|
|
35
|
+
import { separateLiteralSignalPropBindings, programWithSeparatedSource } from './signal-prop-name-collision.ts'
|
|
35
36
|
|
|
36
37
|
// =============================================================================
|
|
37
38
|
// TypeScript Program Creation
|
|
@@ -47,6 +48,40 @@ const REACTIVE_BRAND_PACKAGES = [
|
|
|
47
48
|
'@barefootjs/form',
|
|
48
49
|
]
|
|
49
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Is `id` sitting in a position where it names something rather than
|
|
53
|
+
* referencing a value — an object/class member key, a JSX attribute or
|
|
54
|
+
* intrinsic tag name, or a statement label? These positions merely SPELL an
|
|
55
|
+
* identifier's text without evaluating it as a variable reference, so any
|
|
56
|
+
* pass that resolves identifier text to a binding (a rename, an
|
|
57
|
+
* accessor-wrap, a free-reference scan) must leave them untouched.
|
|
58
|
+
*
|
|
59
|
+
* Shared by `classify()` below (factory-rename sites) and
|
|
60
|
+
* `rewriteIdentifierAsAccessor` (`ir-to-client-js/utils.ts`, #3239) — see
|
|
61
|
+
* CLAUDE.md's "one decision, two implementations" rule. Declaration-name
|
|
62
|
+
* positions (a parameter, `const`, `function`/`class` name) are
|
|
63
|
+
* deliberately NOT covered here: those introduce a new binding rather than
|
|
64
|
+
* naming an existing one, and the two callers disagree on how to handle a
|
|
65
|
+
* shadowing declaration (renaming wants to rename it too; accessor-wrapping
|
|
66
|
+
* deliberately wraps it so the shadow fails to parse), so each classifies
|
|
67
|
+
* those positions itself.
|
|
68
|
+
*/
|
|
69
|
+
export function isNonReferenceIdentifierPosition(id: ts.Identifier): boolean {
|
|
70
|
+
const p = id.parent
|
|
71
|
+
if (ts.isPropertyAccessExpression(p) && p.name === id) return true // obj.name tail (incl. ?. chains)
|
|
72
|
+
if (ts.isPropertyAssignment(p) && p.name === id) return true // { name: v } key
|
|
73
|
+
if (ts.isBindingElement(p) && p.propertyName === id) return true // { name: local } pattern key
|
|
74
|
+
if ((ts.isMethodDeclaration(p) || ts.isGetAccessorDeclaration(p) ||
|
|
75
|
+
ts.isSetAccessorDeclaration(p) || ts.isPropertyDeclaration(p) ||
|
|
76
|
+
ts.isEnumMember(p)) && p.name === id) return true // member keys
|
|
77
|
+
if (ts.isJsxAttribute(p) && p.name === id) return true // JSX attr name
|
|
78
|
+
if ((ts.isLabeledStatement(p) && p.label === id)
|
|
79
|
+
|| ((ts.isBreakStatement(p) || ts.isContinueStatement(p)) && p.label === id)) return true
|
|
80
|
+
if ((ts.isJsxOpeningElement(p) || ts.isJsxSelfClosingElement(p) || ts.isJsxClosingElement(p))
|
|
81
|
+
&& p.tagName === id && /^[a-z]/.test(id.text)) return true // intrinsic tag <div>
|
|
82
|
+
return false
|
|
83
|
+
}
|
|
84
|
+
|
|
50
85
|
/**
|
|
51
86
|
* Check if a source file needs ts.TypeChecker for static analysis.
|
|
52
87
|
* Reactive-brand detection requires the checker for library accessor patterns.
|
|
@@ -341,6 +376,15 @@ export function analyzeComponent(
|
|
|
341
376
|
if (parsed.kind !== 'unsupported') signal.parsed = parsed
|
|
342
377
|
}
|
|
343
378
|
|
|
379
|
+
const separatedSource = separateLiteralSignalPropBindings(ctx, isNonReferenceIdentifierPosition)
|
|
380
|
+
if (separatedSource !== null) {
|
|
381
|
+
// The checker supplied by the caller names the old AST. Re-analyze the
|
|
382
|
+
// structurally renamed source, preserving the shared-program contract
|
|
383
|
+
// (BF050), just as the reactive-factory prepass does above.
|
|
384
|
+
const separatedProgram = program && programWithSeparatedSource(program, filePath, separatedSource)
|
|
385
|
+
return analyzeComponent(separatedSource, filePath, targetComponentName, separatedProgram, acceptsCallbackBody, hadSharedProgram)
|
|
386
|
+
}
|
|
387
|
+
|
|
344
388
|
// #2040: fold a complete, value-producing block-bodied memo into a single
|
|
345
389
|
// expression so it flows through the same `parsed` path as an expression-bodied
|
|
346
390
|
// memo, instead of relying on per-idiom block recognizers (#1897 / #1945 /
|
|
@@ -5804,17 +5848,7 @@ function detectReactiveFactory(
|
|
|
5804
5848
|
if (!relevantNames.has(id.text)) return
|
|
5805
5849
|
const p = id.parent
|
|
5806
5850
|
// Pure-key / non-reference positions — never rename:
|
|
5807
|
-
if (
|
|
5808
|
-
if (ts.isPropertyAssignment(p) && p.name === id) return // { name: v } key
|
|
5809
|
-
if (ts.isBindingElement(p) && p.propertyName === id) return // { name: local } pattern key
|
|
5810
|
-
if ((ts.isMethodDeclaration(p) || ts.isGetAccessorDeclaration(p) ||
|
|
5811
|
-
ts.isSetAccessorDeclaration(p) || ts.isPropertyDeclaration(p) ||
|
|
5812
|
-
ts.isEnumMember(p)) && p.name === id) return // member keys
|
|
5813
|
-
if (ts.isJsxAttribute(p) && p.name === id) return // JSX attr name
|
|
5814
|
-
if ((ts.isLabeledStatement(p) && p.label === id) ||
|
|
5815
|
-
((ts.isBreakStatement(p) || ts.isContinueStatement(p)) && p.label === id)) return
|
|
5816
|
-
if ((ts.isJsxOpeningElement(p) || ts.isJsxSelfClosingElement(p) || ts.isJsxClosingElement(p)) &&
|
|
5817
|
-
p.tagName === id && /^[a-z]/.test(id.text)) return // intrinsic tag <div>
|
|
5851
|
+
if (isNonReferenceIdentifierPosition(id)) return
|
|
5818
5852
|
|
|
5819
5853
|
// Shorthand dual-role positions → expansion form (renaming must
|
|
5820
5854
|
// preserve the implied key): `{ name }` object literal / pattern.
|
package/src/compiler.ts
CHANGED
|
@@ -166,6 +166,14 @@ function compileMultipleComponents(
|
|
|
166
166
|
const files: FileOutput[] = []
|
|
167
167
|
const errors: CompileResult['errors'] = []
|
|
168
168
|
const adapter = options.adapter
|
|
169
|
+
// `emitsTemplates: false` (CSR) — nothing will ever read this file's
|
|
170
|
+
// markedTemplate, so every assembly step below (per-component module
|
|
171
|
+
// exports AND the combined multi-component template) skips straight to
|
|
172
|
+
// empty rather than trusting `generate()`'s own output to already be
|
|
173
|
+
// empty. One flag, read at both sites, so the invariant can't drift
|
|
174
|
+
// between them the way `moduleExports`-only skip did before it covered
|
|
175
|
+
// the combined-template site too (#3234).
|
|
176
|
+
const skipTemplateAssembly = adapter.emitsTemplates === false
|
|
169
177
|
|
|
170
178
|
// --- Pass 1: analyze + jsxToIR for ALL components ---
|
|
171
179
|
const entries: { componentIR: ComponentIR; ctx: ReturnType<typeof analyzeComponent> }[] = []
|
|
@@ -437,12 +445,14 @@ function compileMultipleComponents(
|
|
|
437
445
|
scriptAssets: options.scriptAssets,
|
|
438
446
|
preloadAssets: options.preloadAssets,
|
|
439
447
|
})
|
|
440
|
-
const moduleExports =
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
448
|
+
const moduleExports = skipTemplateAssembly
|
|
449
|
+
? ''
|
|
450
|
+
: generateModuleExports(
|
|
451
|
+
componentIR,
|
|
452
|
+
fileWideInlineExported,
|
|
453
|
+
options.rewriteRelativeImport,
|
|
454
|
+
{ skipValueDeclarations: adapterOutput.sections.moduleConstantsIncludeExports },
|
|
455
|
+
)
|
|
446
456
|
|
|
447
457
|
const s = adapterOutput.sections
|
|
448
458
|
const imports = s.imports
|
|
@@ -523,52 +533,66 @@ function compileMultipleComponents(
|
|
|
523
533
|
return { files, errors }
|
|
524
534
|
}
|
|
525
535
|
|
|
526
|
-
//
|
|
527
|
-
//
|
|
528
|
-
//
|
|
529
|
-
// `
|
|
530
|
-
//
|
|
531
|
-
//
|
|
532
|
-
//
|
|
533
|
-
//
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
536
|
+
// `generate()`'s own `sections` (imports/types/component) aren't
|
|
537
|
+
// guaranteed empty just because `moduleExports` was skipped above —
|
|
538
|
+
// nothing in the `TemplateAdapter` contract stops a future
|
|
539
|
+
// `emitsTemplates: false` adapter from returning non-empty sections.
|
|
540
|
+
// Reusing `skipTemplateAssembly` here mirrors `compileJSX`'s
|
|
541
|
+
// single-component short-circuit, so the invariant ("this adapter's
|
|
542
|
+
// markedTemplate is always empty") is enforced once per adapter, not
|
|
543
|
+
// once per adapter per component-count code path (#3234).
|
|
544
|
+
let combinedTemplate: string
|
|
545
|
+
if (skipTemplateAssembly) {
|
|
546
|
+
combinedTemplate = ''
|
|
547
|
+
} else {
|
|
548
|
+
// Merge imports from all components. Named imports from the same
|
|
549
|
+
// source are combined into their first occurrence rather than
|
|
550
|
+
// deduplicated by exact line: in a multi-component file each
|
|
551
|
+
// component emits its own `import { … } from '@barefootjs/hono/utils'`
|
|
552
|
+
// listing only the symbols it uses, so plain line-dedup leaves
|
|
553
|
+
// several statements that re-declare the same binding (e.g.
|
|
554
|
+
// `bfComment`). Bun tolerates the redeclaration, but stricter ESM
|
|
555
|
+
// parsers — including Deno, used to render the SSR template — reject
|
|
556
|
+
// it as a SyntaxError.
|
|
557
|
+
const mergedImports = mergeTemplateImports(
|
|
558
|
+
allOutputs.flatMap(o => (o.imports ? o.imports.split('\n') : [])),
|
|
559
|
+
)
|
|
560
|
+
|
|
561
|
+
// Combine unique type definitions
|
|
562
|
+
const seenTypes = new Set<string>()
|
|
563
|
+
const uniqueTypes: string[] = []
|
|
564
|
+
for (const output of allOutputs) {
|
|
565
|
+
if (output.types && !seenTypes.has(output.types)) {
|
|
566
|
+
seenTypes.add(output.types)
|
|
567
|
+
uniqueTypes.push(output.types)
|
|
568
|
+
}
|
|
545
569
|
}
|
|
546
|
-
}
|
|
547
570
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
571
|
+
// Deduplicate module-level exports across components
|
|
572
|
+
const seenModuleExports = new Set<string>()
|
|
573
|
+
const uniqueModuleExports: string[] = []
|
|
574
|
+
for (const output of allOutputs) {
|
|
575
|
+
if (output.moduleExports) {
|
|
576
|
+
for (const line of output.moduleExports.split('\n')) {
|
|
577
|
+
if (line.trim() && !seenModuleExports.has(line)) {
|
|
578
|
+
seenModuleExports.add(line)
|
|
579
|
+
uniqueModuleExports.push(line)
|
|
580
|
+
}
|
|
557
581
|
}
|
|
558
582
|
}
|
|
559
583
|
}
|
|
560
|
-
}
|
|
561
584
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
585
|
+
// Combine all components
|
|
586
|
+
combinedTemplate = [
|
|
587
|
+
mergedImports,
|
|
588
|
+
moduleStatementsOrdered.join('\n\n'),
|
|
589
|
+
uniqueTypes.join('\n\n'),
|
|
590
|
+
uniqueModuleExports.length > 0 ? uniqueModuleExports.join('\n') : '',
|
|
591
|
+
...allOutputs.map(o => o.component),
|
|
592
|
+
]
|
|
593
|
+
.filter(Boolean)
|
|
594
|
+
.join('\n\n')
|
|
595
|
+
}
|
|
572
596
|
|
|
573
597
|
files.push({
|
|
574
598
|
path: filePath.replace(/\.tsx?$/, adapter.extension),
|
|
@@ -856,6 +880,14 @@ export function compileJSX(
|
|
|
856
880
|
let content: string
|
|
857
881
|
if (adapter.templatesPerComponent) {
|
|
858
882
|
content = adapterOutput.template
|
|
883
|
+
} else if (adapter.emitsTemplates === false) {
|
|
884
|
+
// Nothing will ever read this file's markedTemplate (CSR) — skip
|
|
885
|
+
// assembly entirely, module-level value exports included. Otherwise a
|
|
886
|
+
// component file that also exports a plain constant/function would
|
|
887
|
+
// produce a markedTemplate whose only content is that export, which
|
|
888
|
+
// `@barefootjs/vite`'s `assertNoRealTemplateOutput` treats as real
|
|
889
|
+
// template output requiring a configured `templates` dir (#3234).
|
|
890
|
+
content = ''
|
|
859
891
|
} else {
|
|
860
892
|
const moduleExports = generateModuleExports(componentIR, undefined, options.rewriteRelativeImport, {
|
|
861
893
|
skipValueDeclarations: s.moduleConstantsIncludeExports,
|
package/src/debug.ts
CHANGED
|
@@ -23,6 +23,7 @@ import type {
|
|
|
23
23
|
SourceLocation,
|
|
24
24
|
OriginInfo,
|
|
25
25
|
} from './types.ts'
|
|
26
|
+
import { isElidedFactoryGetter } from './types.ts'
|
|
26
27
|
import { analyzeComponent, listComponentFunctions } from './analyzer.ts'
|
|
27
28
|
import { jsxToIR } from './jsx-to-ir.ts'
|
|
28
29
|
import { buildMetadata } from './compiler.ts'
|
|
@@ -567,7 +568,7 @@ export function buildGraphFromIR(ir: ComponentIR): ComponentGraph {
|
|
|
567
568
|
for (const f of factories) for (const dep of f.requestDeps) addConsumer(dep, `query:${f.key}`, true)
|
|
568
569
|
for (const m of memos) m.consumers = memoConsumers.get(m.name) ?? []
|
|
569
570
|
|
|
570
|
-
const signals: SignalNode[] = meta.signals.filter(s => !(s
|
|
571
|
+
const signals: SignalNode[] = meta.signals.filter(s => !isElidedFactoryGetter(s)).map(s => {
|
|
571
572
|
const factory = factoryOf.get(s)
|
|
572
573
|
return {
|
|
573
574
|
kind: 'signal',
|
|
@@ -2181,7 +2182,38 @@ function collectDomBindings(
|
|
|
2181
2182
|
// `hasFunctionCalls` without reactive-getter hit is the fallback case
|
|
2182
2183
|
// (e.g. `getItems().map(...)` with an opaque helper).
|
|
2183
2184
|
if (node.slotId) {
|
|
2184
|
-
|
|
2185
|
+
// #3246: `.filter()` / `.sort()` predicates are lifted off the chain
|
|
2186
|
+
// into `IRLoop.filterPredicate` / `.sortComparator` during IR
|
|
2187
|
+
// construction (`loop-chain.ts`) and kept separate from `array` — so
|
|
2188
|
+
// a signal/memo read inside either callback (`items().filter(t =>
|
|
2189
|
+
// filter() === 'all' || !t.done)`) never showed up in the loop's own
|
|
2190
|
+
// deps, even though that read is exactly why the loop re-renders.
|
|
2191
|
+
// (The `/* @client */` path keeps the whole chain in `array`, which
|
|
2192
|
+
// is why the edge was already there in that case.) Collect each
|
|
2193
|
+
// callback's reads too, shadow-guarded via the shared `BindingScope`
|
|
2194
|
+
// service — `enterCallback` exists for exactly this ("a filter
|
|
2195
|
+
// predicate's `x`, a sort comparator's `(a, b)`", see its doc
|
|
2196
|
+
// comment) — so a predicate/comparator that names its parameter the
|
|
2197
|
+
// same as an unrelated signal isn't mistaken for a real read of it.
|
|
2198
|
+
// Built on `scope` (not `childScope` below): the filter/sort
|
|
2199
|
+
// callback's own param(s) are a sibling scope to the loop row, not
|
|
2200
|
+
// nested under it.
|
|
2201
|
+
//
|
|
2202
|
+
// The `sortComparator` half is defensive: `classifySortOperand`
|
|
2203
|
+
// (expression-parser.ts) can't route a signal call into it under
|
|
2204
|
+
// today's grammar, so this branch is untested in practice.
|
|
2205
|
+
const { filterPredicate, sortComparator } = node
|
|
2206
|
+
const callbackDeps = (raw: string, params: string[]) => {
|
|
2207
|
+
const callbackScope = scope.enterCallback(params)
|
|
2208
|
+
return extractReactiveDeps(raw, signalGetters, memoNames).filter(name => !callbackScope.isBound(name))
|
|
2209
|
+
}
|
|
2210
|
+
const deps = [
|
|
2211
|
+
...new Set([
|
|
2212
|
+
...extractReactiveDeps(node.array, signalGetters, memoNames),
|
|
2213
|
+
...(filterPredicate ? callbackDeps(filterPredicate.raw, [filterPredicate.param]) : []),
|
|
2214
|
+
...(sortComparator ? callbackDeps(sortComparator.raw, [sortComparator.paramA, sortComparator.paramB]) : []),
|
|
2215
|
+
]),
|
|
2216
|
+
]
|
|
2185
2217
|
// An inner loop whose array reads an outer loop param (`r.tags.map(...)`)
|
|
2186
2218
|
// is reactive per item — use the resolved `arrayFreeIdentifiers`.
|
|
2187
2219
|
const loopReactive =
|
package/src/html-types.ts
CHANGED
|
@@ -93,6 +93,16 @@ export interface HTMLBaseAttributes extends BaseEventAttributes {
|
|
|
93
93
|
lang?: string
|
|
94
94
|
slot?: string
|
|
95
95
|
|
|
96
|
+
// Popover API (global attribute — any element can opt into being a popover).
|
|
97
|
+
// No `boolean` arm: `popover` isn't in BOOLEAN_ATTRS (`@barefootjs/shared`'s
|
|
98
|
+
// `dom-prop.ts`), so a boolean value stringifies instead of toggling the
|
|
99
|
+
// attribute's presence. `popover={false}` would render `popover="false"` —
|
|
100
|
+
// an invalid keyword the spec maps to `manual`, so the element is STILL a
|
|
101
|
+
// popover, not opted out — and the client runtime's `applyRestAttrs`
|
|
102
|
+
// disagrees by removing the attribute outright on `false`, an SSR/CSR
|
|
103
|
+
// mismatch. `popover={true}` renders `"true"`, also `manual`, not `auto`.
|
|
104
|
+
popover?: '' | 'auto' | 'manual' | 'hint'
|
|
105
|
+
|
|
96
106
|
// Data attributes
|
|
97
107
|
[key: `data-${string}`]: string | number | boolean | undefined
|
|
98
108
|
|
|
@@ -323,6 +333,8 @@ export interface ButtonHTMLAttributes extends Omit<HTMLBaseAttributes,
|
|
|
323
333
|
name?: string
|
|
324
334
|
type?: 'submit' | 'reset' | 'button'
|
|
325
335
|
value?: string
|
|
336
|
+
popovertarget?: string
|
|
337
|
+
popovertargetaction?: 'toggle' | 'show' | 'hide'
|
|
326
338
|
|
|
327
339
|
onClick?: MouseEventHandler<HTMLButtonElement>
|
|
328
340
|
onBlur?: FocusEventHandler<HTMLButtonElement>
|
|
@@ -363,6 +375,8 @@ export interface InputHTMLAttributes extends Omit<HTMLBaseAttributes,
|
|
|
363
375
|
name?: string
|
|
364
376
|
pattern?: string
|
|
365
377
|
placeholder?: string
|
|
378
|
+
popovertarget?: string
|
|
379
|
+
popovertargetaction?: 'toggle' | 'show' | 'hide'
|
|
366
380
|
readonly?: boolean | null
|
|
367
381
|
required?: boolean | null
|
|
368
382
|
size?: number
|
package/src/index.ts
CHANGED
|
@@ -87,6 +87,7 @@ export type {
|
|
|
87
87
|
RenderDivergences,
|
|
88
88
|
ImportInfo,
|
|
89
89
|
} from './types.ts'
|
|
90
|
+
export { isElidedFactoryGetter } from './types.ts'
|
|
90
91
|
|
|
91
92
|
// Analyzer
|
|
92
93
|
export { analyzeComponent, listComponentFunctions, listComponentFunctions as listExportedComponents, scanComponentFile, createProgramForFile, createAnchoredProgram, needsTypeBasedDetection, resolveRelativeImportToFile, REACTIVE_PRIMITIVES, BROWSER_ONLY_CLIENT_APIS, type AnalyzerContext, type ComponentFileScan } from './analyzer.ts'
|
|
@@ -237,6 +238,7 @@ export { isValueReferenceIdentifier, collectValueReferencedNames } from './value
|
|
|
237
238
|
// Expression Parser
|
|
238
239
|
export { parseExpression, tsNodeToParsedExpr, asCallbackMethodCall, CALLBACK_METHODS, sortComparatorFromArrow, serializeParsedExpr, freeVarsInBody, freeIdentifiers, materializeGetterCalls, isSupported, isSupportedValue, exprToString, stringifyParsedExpr, identifierPath, parseBlockBody, parseBlockBodyTolerant, foldBlockToExpr, predicateTernaryToLogical, containsHigherOrder, extractArrowBodyExpression, parseStyleObjectEntries, hasUnsafeStyleValue, parseProviderObjectLiteral, isFunctionShapedExpression, type ProviderObjectMember, type FoldBlockOptions } from './expression-parser.ts'
|
|
239
240
|
export type { StyleObjectEntry } from './expression-parser.ts'
|
|
241
|
+
export { literalMemberIndex } from './literal-member-index.ts'
|
|
240
242
|
export { PARSED_EXPR_KINDS, ARRAY_METHOD_NAMES, SORT_KEY_TYPES, SORT_KEY_TARGETS, SORT_KEY_DIRECTIONS } from './expression-parser.ts'
|
|
241
243
|
export type { ParsedExpr, ObjectLiteralProperty, ParsedStatement, SortComparator, SortKey, FlatDepth, SupportLevel, SupportResult, TemplatePart } from './expression-parser.ts'
|
|
242
244
|
export { buildLoopChainExpr } from './loop-chain.ts'
|