@barefootjs/jsx 0.39.6 → 0.39.8
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/attr-plan.d.ts +8 -1
- package/dist/adapters/attr-plan.d.ts.map +1 -1
- package/dist/adapters/callback-method.d.ts +44 -0
- package/dist/adapters/callback-method.d.ts.map +1 -1
- package/dist/adapters/component-props.d.ts +80 -13
- package/dist/adapters/component-props.d.ts.map +1 -1
- package/dist/adapters/computed-const.d.ts +52 -0
- package/dist/adapters/computed-const.d.ts.map +1 -0
- package/dist/adapters/dangerous-inner-html.d.ts +10 -0
- package/dist/adapters/dangerous-inner-html.d.ts.map +1 -1
- package/dist/adapters/dsl-template-adapter.d.ts +151 -0
- package/dist/adapters/dsl-template-adapter.d.ts.map +1 -0
- package/dist/adapters/element-shell.d.ts +44 -0
- package/dist/adapters/element-shell.d.ts.map +1 -0
- package/dist/adapters/interface.d.ts +2 -0
- package/dist/adapters/interface.d.ts.map +1 -1
- package/dist/adapters/jsx-adapter.d.ts +4 -0
- package/dist/adapters/jsx-adapter.d.ts.map +1 -1
- package/dist/adapters/literal-value.d.ts +2 -2
- package/dist/adapters/literal-value.d.ts.map +1 -1
- package/dist/adapters/parsed-expr-emitter.d.ts +27 -0
- package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
- package/dist/adapters/style-object.d.ts +33 -0
- package/dist/adapters/style-object.d.ts.map +1 -0
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/augment-inherited-props.d.ts +7 -0
- package/dist/augment-inherited-props.d.ts.map +1 -1
- package/dist/children-nullish.d.ts +22 -0
- package/dist/children-nullish.d.ts.map +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/expression-parser.d.ts +9 -19
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/fold-render-reassignments.d.ts +43 -0
- package/dist/fold-render-reassignments.d.ts.map +1 -0
- package/dist/free-refs.d.ts +15 -0
- package/dist/free-refs.d.ts.map +1 -1
- package/dist/index.d.ts +21 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24620 -23233
- package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/event-collision.d.ts +2 -1
- package/dist/ir-to-client-js/control-flow/plan/event-collision.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/insert.d.ts +2 -2
- package/dist/ir-to-client-js/control-flow/plan/insert.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/event-delegation.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts +10 -9
- package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts.map +1 -1
- package/dist/ir-to-client-js/csr-substitute.d.ts +0 -13
- package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-reactive.d.ts +1 -1
- package/dist/ir-to-client-js/emit-reactive.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-registration.d.ts +10 -8
- package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
- package/dist/ir-to-client-js/generate-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts +9 -19
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/identifiers.d.ts +6 -8
- package/dist/ir-to-client-js/identifiers.d.ts.map +1 -1
- package/dist/ir-to-client-js/imports.d.ts +23 -2
- package/dist/ir-to-client-js/imports.d.ts.map +1 -1
- package/dist/ir-to-client-js/index.d.ts.map +1 -1
- package/dist/ir-to-client-js/phases/props-extraction.d.ts +3 -2
- package/dist/ir-to-client-js/phases/props-extraction.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/declaration-emit.d.ts +5 -0
- package/dist/ir-to-client-js/plan/declaration-emit.d.ts.map +1 -1
- package/dist/ir-to-client-js/prop-handling.d.ts +11 -12
- package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
- package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts +1 -1
- package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
- package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
- package/dist/ir-to-client-js/rewrite-destructured-props.d.ts +1 -1
- package/dist/ir-to-client-js/rewrite-destructured-props.d.ts.map +1 -1
- package/dist/ir-to-client-js/safe-html.d.ts +20 -2
- package/dist/ir-to-client-js/safe-html.d.ts.map +1 -1
- package/dist/ir-to-client-js/types.d.ts +3 -3
- package/dist/ir-to-client-js/types.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +15 -11
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/nullable-signal-attr.d.ts +43 -12
- package/dist/nullable-signal-attr.d.ts.map +1 -1
- package/dist/prop-rewrite.d.ts +18 -0
- package/dist/prop-rewrite.d.ts.map +1 -1
- package/dist/props-binding.d.ts +43 -6
- package/dist/props-binding.d.ts.map +1 -1
- package/dist/relocate.d.ts +16 -0
- package/dist/relocate.d.ts.map +1 -1
- package/dist/scanner/js-scanner.d.ts.map +1 -1
- package/dist/scanner/js-scanner.js +30 -2
- package/dist/signal-prop-name-collision.d.ts +6 -5
- package/dist/signal-prop-name-collision.d.ts.map +1 -1
- package/dist/ssr-defaults.d.ts +28 -0
- package/dist/ssr-defaults.d.ts.map +1 -1
- package/dist/ssr-seed-plan.d.ts +37 -18
- package/dist/ssr-seed-plan.d.ts.map +1 -1
- package/dist/types.d.ts +162 -20
- package/dist/types.d.ts.map +1 -1
- package/dist/value-references.d.ts +21 -0
- package/dist/value-references.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +18 -18
- package/src/__tests__/adapter-output.test.ts +5 -3
- package/src/__tests__/analyzer.test.ts +33 -0
- package/src/__tests__/arithmetic-lowering.test.ts +44 -0
- package/src/__tests__/block-memo-type.test.ts +51 -0
- package/src/__tests__/callback-method.test.ts +75 -0
- package/src/__tests__/children-read.test.ts +226 -0
- package/src/__tests__/client-only-date-lowering.test.ts +2 -2
- package/src/__tests__/client-template-escape-soundness.test.ts +31 -1
- package/src/__tests__/component-props.test.ts +68 -1
- package/src/__tests__/computed-const.test.ts +101 -0
- package/src/__tests__/constant-inlining-tree.test.ts +136 -0
- package/src/__tests__/destructure-default-reads-earlier-param.test.ts +138 -0
- package/src/__tests__/dsl-template-adapter.test.ts +173 -0
- package/src/__tests__/element-shell.test.ts +78 -0
- package/src/__tests__/event-handler-verbatim.test.ts +73 -0
- package/src/__tests__/expression-parser.test.ts +1 -44
- package/src/__tests__/fold-render-reassignments.test.ts +96 -0
- package/src/__tests__/inlinable-local-method-call.test.ts +81 -0
- package/src/__tests__/memo-body-expr.test.ts +120 -0
- package/src/__tests__/nullable-signal-attr.test.ts +67 -3
- package/src/__tests__/prop-handling.test.ts +35 -16
- package/src/__tests__/props-alias-const.test.ts +65 -0
- package/src/__tests__/reference-graph-identifiers.test.ts +161 -0
- package/src/__tests__/runtime-import-detection.test.ts +134 -0
- package/src/__tests__/signal-prop-name-collision.test.ts +30 -0
- package/src/__tests__/signal-prop-seed.test.ts +90 -0
- package/src/__tests__/ssr-defaults.test.ts +19 -1
- package/src/__tests__/ssr-seed-plan.test.ts +173 -1
- package/src/__tests__/static-template-reachability.test.ts +137 -0
- package/src/__tests__/style-object-plan.test.ts +54 -0
- package/src/__tests__/zero-param-helper-inline.test.ts +57 -0
- package/src/adapters/attr-plan.ts +29 -1
- package/src/adapters/callback-method.ts +85 -0
- package/src/adapters/component-props.ts +130 -12
- package/src/adapters/computed-const.ts +185 -0
- package/src/adapters/dangerous-inner-html.ts +33 -0
- package/src/adapters/dsl-template-adapter.ts +248 -0
- package/src/adapters/element-shell.ts +160 -0
- package/src/adapters/interface.ts +8 -0
- package/src/adapters/jsx-adapter.ts +12 -6
- package/src/adapters/literal-value.ts +2 -2
- package/src/adapters/parsed-expr-emitter.ts +34 -0
- package/src/adapters/style-object.ts +61 -0
- package/src/analyzer.ts +382 -94
- package/src/augment-inherited-props.ts +12 -0
- package/src/children-nullish.ts +33 -0
- package/src/debug.ts +2 -2
- package/src/errors.ts +12 -0
- package/src/expression-parser.ts +56 -53
- package/src/fold-render-reassignments.ts +314 -0
- package/src/free-refs.ts +77 -17
- package/src/index.ts +27 -10
- package/src/ir-to-client-js/compute-inlinability.ts +122 -19
- package/src/ir-to-client-js/control-flow/plan/event-collision.ts +2 -1
- package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -2
- package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +3 -2
- package/src/ir-to-client-js/control-flow/stringify/event-listener.ts +13 -12
- package/src/ir-to-client-js/csr-substitute.ts +25 -37
- package/src/ir-to-client-js/emit-reactive.ts +2 -2
- package/src/ir-to-client-js/emit-registration.ts +31 -59
- package/src/ir-to-client-js/generate-init.ts +17 -1
- package/src/ir-to-client-js/html-template.ts +56 -120
- package/src/ir-to-client-js/identifiers.ts +75 -24
- package/src/ir-to-client-js/imports.ts +56 -19
- package/src/ir-to-client-js/index.ts +5 -3
- package/src/ir-to-client-js/init-declarations.ts +1 -1
- package/src/ir-to-client-js/phases/event-handlers.ts +2 -2
- package/src/ir-to-client-js/phases/props-extraction.ts +16 -15
- package/src/ir-to-client-js/plan/build-declaration-emit.ts +26 -52
- package/src/ir-to-client-js/plan/declaration-emit.ts +5 -0
- package/src/ir-to-client-js/prop-handling.ts +13 -54
- package/src/ir-to-client-js/prune-unused-prop-extractions.ts +7 -4
- package/src/ir-to-client-js/reactivity.ts +2 -2
- package/src/ir-to-client-js/rewrite-destructured-props.ts +27 -9
- package/src/ir-to-client-js/safe-html.ts +29 -35
- package/src/ir-to-client-js/stringify/declaration-emit.ts +1 -1
- package/src/ir-to-client-js/types.ts +3 -2
- package/src/ir-to-client-js/utils.ts +13 -26
- package/src/jsx-to-ir.ts +318 -130
- package/src/nullable-signal-attr.ts +156 -37
- package/src/prop-rewrite.ts +41 -0
- package/src/props-binding.ts +117 -7
- package/src/relocate.ts +40 -8
- package/src/scanner/__tests__/js-scanner.test.ts +37 -0
- package/src/scanner/js-scanner.ts +64 -4
- package/src/signal-prop-name-collision.ts +50 -24
- package/src/ssr-defaults.ts +47 -20
- package/src/ssr-seed-plan.ts +121 -29
- package/src/types.ts +165 -21
- package/src/value-references.ts +132 -0
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
* issue #1021 Stage B for the rationale.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
import ts from 'typescript'
|
|
15
|
+
import { isIdentifierLikeToken, isTriviaKind, iterateJsTokens } from '../scanner/js-scanner.ts'
|
|
16
|
+
|
|
14
17
|
/** JavaScript keywords and common globals to skip during identifier extraction. */
|
|
15
18
|
const KEYWORDS_AND_GLOBALS = new Set([
|
|
16
19
|
'true',
|
|
@@ -56,46 +59,94 @@ const KEYWORDS_AND_GLOBALS = new Set([
|
|
|
56
59
|
])
|
|
57
60
|
|
|
58
61
|
/**
|
|
59
|
-
*
|
|
62
|
+
* Words that can never name a binding in module (strict) code. Every other
|
|
63
|
+
* identifier-or-keyword token, contextual keywords included (`type`, `of`,
|
|
64
|
+
* `get`, …), can.
|
|
60
65
|
*/
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
if
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
const RESERVED_WORDS = new Set([
|
|
67
|
+
'await', 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do',
|
|
68
|
+
'else', 'enum', 'export', 'extends', 'false', 'finally', 'for', 'function', 'if', 'implements', 'import',
|
|
69
|
+
'in', 'instanceof', 'interface', 'let', 'new', 'null', 'package', 'private', 'protected', 'public',
|
|
70
|
+
'return', 'static', 'super', 'switch', 'this', 'throw', 'true', 'try', 'typeof', 'var', 'void', 'while',
|
|
71
|
+
'with', 'yield',
|
|
72
|
+
])
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Walk the tokens of `text` (`iterateJsTokens`, the shared JS lexer, which
|
|
76
|
+
* reads a regex literal as one token and closes template substitutions at
|
|
77
|
+
* their own `}`), calling `onName` for every identifier, member names
|
|
78
|
+
* included (`props.value` yields both: the reference graph reads a
|
|
79
|
+
* props-object member as a use of that prop), and `onSubstitution` with the
|
|
80
|
+
* source span of every outermost `${…}` body. String, regex and comment
|
|
81
|
+
* contents produce no names, and `$` is an identifier character, so
|
|
82
|
+
* `step$` / `$step` are found (#3536).
|
|
83
|
+
*
|
|
84
|
+
* A contextual keyword (`type`, `of`, `get`, …) is a legal binding name, so
|
|
85
|
+
* it is reported like an identifier; a reserved word is reported only as a
|
|
86
|
+
* member name (`props.default`).
|
|
87
|
+
*/
|
|
88
|
+
function scanNames(
|
|
89
|
+
text: string,
|
|
90
|
+
onName: (name: string) => void,
|
|
91
|
+
onSubstitution?: (start: number, end: number) => void,
|
|
92
|
+
): void {
|
|
93
|
+
// The source offset where each open template's current `${` body starts.
|
|
94
|
+
const bodyStarts: number[] = []
|
|
95
|
+
let prev: ts.SyntaxKind | undefined
|
|
96
|
+
for (const token of iterateJsTokens(text)) {
|
|
97
|
+
if (isTriviaKind(token.kind)) continue
|
|
98
|
+
if (token.kind === ts.SyntaxKind.TemplateHead) {
|
|
99
|
+
bodyStarts.push(token.end)
|
|
100
|
+
} else if (token.kind === ts.SyntaxKind.TemplateMiddle || token.kind === ts.SyntaxKind.TemplateTail) {
|
|
101
|
+
const bodyStart = bodyStarts.pop()
|
|
102
|
+
// Only an outermost body: a nested template stays inside its parent's.
|
|
103
|
+
if (bodyStart !== undefined && bodyStarts.length === 0) onSubstitution?.(bodyStart, token.pos)
|
|
104
|
+
if (token.kind === ts.SyntaxKind.TemplateMiddle) bodyStarts.push(token.end)
|
|
105
|
+
} else if (isIdentifierLikeToken(token.kind)) {
|
|
106
|
+
const name = text.slice(token.pos, token.end)
|
|
107
|
+
const isMemberName = prev === ts.SyntaxKind.DotToken || prev === ts.SyntaxKind.QuestionDotToken
|
|
108
|
+
if (isMemberName || !RESERVED_WORDS.has(name)) onName(name)
|
|
68
109
|
}
|
|
110
|
+
prev = token.kind
|
|
69
111
|
}
|
|
70
112
|
}
|
|
71
113
|
|
|
114
|
+
/** `text` as a template literal: already backtick-quoted, or quoted here. */
|
|
115
|
+
function asTemplateLiteral(text: string): string {
|
|
116
|
+
return text.startsWith('`') && text.endsWith('`') && text.length >= 2 ? text : `\`${text}\``
|
|
117
|
+
}
|
|
118
|
+
|
|
72
119
|
/**
|
|
73
|
-
*
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
120
|
+
* Extract identifiers from an expression string.
|
|
121
|
+
*/
|
|
122
|
+
export function extractIdentifiers(expr: string, set: Set<string>): void {
|
|
123
|
+
scanNames(expr, name => {
|
|
124
|
+
if (!isKeywordOrGlobal(name)) set.add(name)
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Yield each `${...}` substitution body inside a template-style string
|
|
130
|
+
* (backtick-quoted or not). Returns the inner expressions — the
|
|
131
|
+
* surrounding HTML / static text is stripped. Empty array when no
|
|
132
|
+
* substitutions are present. Nested braces and template literals inside a
|
|
133
|
+
* body are kept whole.
|
|
80
134
|
*/
|
|
81
135
|
export function extractTemplateExpressions(template: string): string[] {
|
|
82
|
-
const
|
|
136
|
+
const literal = asTemplateLiteral(template)
|
|
83
137
|
const out: string[] = []
|
|
84
|
-
|
|
85
|
-
while ((match = re.exec(template)) !== null) {
|
|
86
|
-
out.push(match[1])
|
|
87
|
-
}
|
|
138
|
+
scanNames(literal, () => {}, (start, end) => out.push(literal.slice(start, end)))
|
|
88
139
|
return out
|
|
89
140
|
}
|
|
90
141
|
|
|
91
142
|
/**
|
|
92
143
|
* Extract identifiers from template literal expressions.
|
|
93
|
-
*
|
|
144
|
+
* Only `${...}` substitutions are scanned; static text is not code.
|
|
94
145
|
*/
|
|
95
146
|
export function extractTemplateIdentifiers(template: string, set: Set<string>): void {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
147
|
+
scanNames(asTemplateLiteral(template), name => {
|
|
148
|
+
if (!isKeywordOrGlobal(name)) set.add(name)
|
|
149
|
+
})
|
|
99
150
|
}
|
|
100
151
|
|
|
101
152
|
/**
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import ts from 'typescript'
|
|
6
|
-
import type { ComponentIR, IRNode } from '../types.ts'
|
|
6
|
+
import type { CompilerError, ComponentIR, ImportInfo, IRNode, SourceLocation } from '../types.ts'
|
|
7
|
+
import { createError, ErrorCodes } from '../errors.ts'
|
|
7
8
|
import { isClientBuiltinName } from '../builtins.ts'
|
|
8
|
-
import { collectValueReferencedNames } from '../value-references.ts'
|
|
9
|
+
import { analyzeEmittedReferences, collectValueReferencedNames } from '../value-references.ts'
|
|
9
10
|
import { identifierCallPattern } from '../identifier-pattern.ts'
|
|
10
11
|
|
|
11
12
|
// All exports from @barefootjs/client/runtime that may be used in generated code
|
|
@@ -84,32 +85,68 @@ export const RUNTIME_MODULE = '@barefootjs/client/runtime'
|
|
|
84
85
|
export const IMPORT_PLACEHOLDER = '/* __BAREFOOTJS_DOM_IMPORTS__ */'
|
|
85
86
|
export const MODULE_CONSTANTS_PLACEHOLDER = '/* __MODULE_LEVEL_CONSTANTS__ */'
|
|
86
87
|
|
|
88
|
+
/** Runtime names `detectUsedImports` can report: the candidates plus the slot finders. */
|
|
89
|
+
const RUNTIME_IMPORT_NAMES: ReadonlySet<string> = new Set<string>([...RUNTIME_IMPORT_CANDIDATES, '$', '$c', '$t'])
|
|
90
|
+
|
|
87
91
|
/**
|
|
88
|
-
* Detect which @barefootjs/client/runtime functions
|
|
92
|
+
* Detect which @barefootjs/client/runtime functions the generated code uses:
|
|
93
|
+
* the runtime names it references without binding them itself (#3537). A
|
|
94
|
+
* module-level user helper emitted as `var insert = …`, or a parameter that
|
|
95
|
+
* happens to be called `qsa`, binds its name, so it neither pulls in the
|
|
96
|
+
* runtime import nor collides with it as a duplicate declaration.
|
|
97
|
+
*
|
|
98
|
+
* Falls back to the per-name call scan only when the code does not parse
|
|
99
|
+
* cleanly, where narrowing on a partial parse could drop a needed import.
|
|
89
100
|
*/
|
|
90
101
|
export function detectUsedImports(code: string): Set<string> {
|
|
102
|
+
const refs = analyzeEmittedReferences(code)
|
|
103
|
+
if (refs) return new Set([...refs.free].filter(name => RUNTIME_IMPORT_NAMES.has(name)))
|
|
91
104
|
const used = new Set<string>()
|
|
92
105
|
for (const name of RUNTIME_IMPORT_CANDIDATES) {
|
|
93
|
-
|
|
94
|
-
if (identifierCallPattern(name).test(code)) {
|
|
95
|
-
used.add(name)
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
// Shorthand finders need special detection ($ is not a word character)
|
|
99
|
-
if (/\$c\s*\(/.test(code)) {
|
|
100
|
-
used.add('$c')
|
|
101
|
-
}
|
|
102
|
-
// Match $t( for text node finders
|
|
103
|
-
if (/\$t\s*\(/.test(code)) {
|
|
104
|
-
used.add('$t')
|
|
105
|
-
}
|
|
106
|
-
// Match $( but not $c( or $t( - use negative lookahead
|
|
107
|
-
if (/\$\s*\(/.test(code)) {
|
|
108
|
-
used.add('$')
|
|
106
|
+
if (identifierCallPattern(name).test(code)) used.add(name)
|
|
109
107
|
}
|
|
108
|
+
if (/\$c\s*\(/.test(code)) used.add('$c')
|
|
109
|
+
if (/\$t\s*\(/.test(code)) used.add('$t')
|
|
110
|
+
if (/\$\s*\(/.test(code)) used.add('$')
|
|
110
111
|
return used
|
|
111
112
|
}
|
|
112
113
|
|
|
114
|
+
/**
|
|
115
|
+
* BF057 for each module-level binding of the user's that takes a runtime
|
|
116
|
+
* helper's name (#3537): a module-level declaration the client JS re-emits,
|
|
117
|
+
* or a value import from anything but the runtime itself, whose name the
|
|
118
|
+
* emitted `code` also calls. That call may be the compiler's own, which the
|
|
119
|
+
* user's binding would capture, so it is refused rather than guessed at.
|
|
120
|
+
* This is exactly the case that used to emit both the binding and a runtime
|
|
121
|
+
* import of the same name, a duplicate-declaration SyntaxError. A binding
|
|
122
|
+
* the code never calls (`const qsa = {…}` read as `qsa.step`) stays legal.
|
|
123
|
+
*/
|
|
124
|
+
export function runtimeNameCollisions(
|
|
125
|
+
declarations: readonly { name: string; loc: SourceLocation }[],
|
|
126
|
+
imports: readonly ImportInfo[],
|
|
127
|
+
code: string,
|
|
128
|
+
): CompilerError[] {
|
|
129
|
+
const runtimeSources = new Set([RUNTIME_MODULE, '@barefootjs/client'])
|
|
130
|
+
const bound = [...declarations]
|
|
131
|
+
for (const imp of imports) {
|
|
132
|
+
if (imp.isTypeOnly || runtimeSources.has(imp.source)) continue
|
|
133
|
+
for (const spec of imp.specifiers) {
|
|
134
|
+
if (!spec.isTypeOnly) bound.push({ name: spec.alias ?? spec.name, loc: imp.loc })
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const colliding = bound.filter(b => RUNTIME_IMPORT_NAMES.has(b.name))
|
|
138
|
+
if (colliding.length === 0) return []
|
|
139
|
+
const called = analyzeEmittedReferences(code)?.called
|
|
140
|
+
return colliding
|
|
141
|
+
.filter(b => called?.has(b.name) ?? true)
|
|
142
|
+
.map(b =>
|
|
143
|
+
createError(ErrorCodes.RUNTIME_HELPER_NAME_COLLISION, b.loc, {
|
|
144
|
+
message: `'${b.name}' is also a BarefootJS runtime helper, and the compiled client JS calls '${b.name}(…)'. ` +
|
|
145
|
+
'Rename the declaration, or import it under an alias.',
|
|
146
|
+
}),
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
|
|
113
150
|
/**
|
|
114
151
|
* Collect user-defined imports from @barefootjs/client (or the
|
|
115
152
|
* compiler-emitted /runtime subpath).
|
|
@@ -17,11 +17,12 @@ import { addConstantPropRefsToSet } from './init-declarations.ts'
|
|
|
17
17
|
import { canGenerateStaticTemplate, irToComponentTemplate, generateCsrTemplate } from './html-template.ts'
|
|
18
18
|
import { markupSlotIdsOf } from './markup-slots.ts'
|
|
19
19
|
import { PROPS_PARAM, initFunctionName, componentDefScopeFlags, isTransparentFragmentRoot } from './utils.ts'
|
|
20
|
+
import { collectReactiveGetterNames } from '../analyzer-context.ts'
|
|
20
21
|
import { buildInlinableConstants, csrInlinableConstantsFromCtx } from './emit-registration.ts'
|
|
21
22
|
import { buildEnvFromCtx } from './compute-inlinability.ts'
|
|
22
23
|
import { nameForRegistryRef, buildImportAliasMap, setActiveImportAliases } from './component-scope.ts'
|
|
23
24
|
import { resolveRestSpreadNames } from './prop-handling.ts'
|
|
24
|
-
import { IMPORT_PLACEHOLDER, RUNTIME_MODULE, detectUsedImports, collectExternalImports } from './imports.ts'
|
|
25
|
+
import { IMPORT_PLACEHOLDER, RUNTIME_MODULE, detectUsedImports, collectExternalImports, runtimeNameCollisions } from './imports.ts'
|
|
25
26
|
import { isInlinableInTemplate } from '../relocate.ts'
|
|
26
27
|
import { buildSourceMapFromIR, type SourceMapV3 } from './source-map.ts'
|
|
27
28
|
import { resolvePropDeclaredType, baseTypeName } from '../rich-type-evidence.ts'
|
|
@@ -317,7 +318,7 @@ function hasInitScopeOnlyConstant(ctx: ClientJsContext): boolean {
|
|
|
317
318
|
* Returns '' if a static template cannot be generated.
|
|
318
319
|
*/
|
|
319
320
|
function generateTemplateOnlyMount(ir: ComponentIR, ctx: ClientJsContext): string {
|
|
320
|
-
const
|
|
321
|
+
const reactiveGetterNames = collectReactiveGetterNames(ctx.signals, ctx.memos)
|
|
321
322
|
const graph = buildReferencesGraph(ctx, ir.root)
|
|
322
323
|
const { inlinableConstants, unsafeLocalNames } = buildInlinableConstants(ctx, graph, ir.root)
|
|
323
324
|
|
|
@@ -329,7 +330,7 @@ function generateTemplateOnlyMount(ir: ComponentIR, ctx: ClientJsContext): strin
|
|
|
329
330
|
|
|
330
331
|
let templateHtml: string | undefined
|
|
331
332
|
|
|
332
|
-
if (canGenerateStaticTemplate(ir.root,
|
|
333
|
+
if (canGenerateStaticTemplate(ir.root, reactiveGetterNames, inlinableConstants, unsafeLocalNames)) {
|
|
333
334
|
// `ctx.dynamicElements` is always empty on this template-only path
|
|
334
335
|
// (`needsClientJs(ctx)` gates it) — derived through the shared function
|
|
335
336
|
// anyway rather than special-casing "no markup slots here" (#2651).
|
|
@@ -390,6 +391,7 @@ function generateTemplateOnlyMount(ir: ComponentIR, ctx: ClientJsContext): strin
|
|
|
390
391
|
// same — without it, a constant whose value got inlined into the
|
|
391
392
|
// template (e.g. `useYjs(_p.x)`) leaves the template referencing a
|
|
392
393
|
// bare module-import name that's no longer imported (#1138 / #1133).
|
|
394
|
+
ctx.warnings.push(...runtimeNameCollisions([], ir.metadata.imports, generatedCode))
|
|
393
395
|
const externalImports = collectExternalImports(ir, generatedCode)
|
|
394
396
|
const allImports = externalImports.length > 0
|
|
395
397
|
? `${importLine}\n${externalImports.join('\n')}`
|
|
@@ -106,7 +106,7 @@ export function classifyLocalDeclarations(
|
|
|
106
106
|
moduleLevelSignals.push(signal)
|
|
107
107
|
continue
|
|
108
108
|
}
|
|
109
|
-
const controlledPropName = getControlledPropName(signal
|
|
109
|
+
const controlledPropName = getControlledPropName(signal)
|
|
110
110
|
if (controlledPropName) {
|
|
111
111
|
controlledSignals.push({ signal, propName: controlledPropName })
|
|
112
112
|
}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import type { ClientJsContext } from '../types.ts'
|
|
20
|
-
import { toDomEventName, varSlotId,
|
|
20
|
+
import { toDomEventName, varSlotId, wrapHandlerForTurn } from '../utils.ts'
|
|
21
21
|
import type { LoopDelegationIndex } from '../control-flow/plan/loop-delegation-index.ts'
|
|
22
22
|
|
|
23
23
|
export function emitEventHandlers(
|
|
@@ -35,7 +35,7 @@ export function emitEventHandlers(
|
|
|
35
35
|
// profiling run attributes the reactive work it triggers to this turn.
|
|
36
36
|
const wrappedHandler = ctx.profile
|
|
37
37
|
? wrapHandlerForTurn(event.handler, `${ctx.componentName}#handler:${elem.slotId}:${event.name}`)
|
|
38
|
-
:
|
|
38
|
+
: event.handler.trim()
|
|
39
39
|
if (elem.slotId === '__scope') {
|
|
40
40
|
lines.push(` if (__scope) __scope.addEventListener('${eventName}', ${wrappedHandler})`)
|
|
41
41
|
} else {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `props-extraction` phase — emit the one surviving one-time prop
|
|
3
|
-
* extraction, `const children = _p.children [?? <default>]
|
|
3
|
+
* extraction, `const children = _p.children [?? <default>]` (or
|
|
4
|
+
* `const kids = _p.children` for a renamed `{ children: kids }`).
|
|
4
5
|
*
|
|
5
6
|
* `children` must stay a ONE-TIME read: a prop's slot-children value is a
|
|
6
7
|
* getter that INSTANTIATES child components when read (see
|
|
@@ -18,13 +19,10 @@
|
|
|
18
19
|
* downstream code there reads `_p.X` directly via the late-stage rename.
|
|
19
20
|
*/
|
|
20
21
|
|
|
21
|
-
import type
|
|
22
|
+
import { type PropUsage, isChildrenPropParam } from '../../types.ts'
|
|
22
23
|
import { computePropsUsedAsConditions } from '../compute-prop-usage.ts'
|
|
23
24
|
import { propReadBase, propReadFallback } from '../../props-binding.ts'
|
|
24
25
|
import type { ClientJsContext } from '../types.ts'
|
|
25
|
-
import { PROPS_PARAM } from '../utils.ts'
|
|
26
|
-
|
|
27
|
-
const CHILDREN = 'children'
|
|
28
26
|
|
|
29
27
|
export function emitPropsExtraction(
|
|
30
28
|
lines: string[],
|
|
@@ -33,16 +31,19 @@ export function emitPropsExtraction(
|
|
|
33
31
|
propUsage: Map<string, PropUsage>,
|
|
34
32
|
): void {
|
|
35
33
|
if (ctx.propsObjectName) return
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
// The children prop's local binding: `children`, or the renamed local of
|
|
35
|
+
// `{ children: kids }` (`isChildrenPropParam`, #3572), which reads
|
|
36
|
+
// `_p.children` the same one-time way. A local named `children` that binds
|
|
37
|
+
// another prop (`{ items: children }`) is an ordinary prop, read live.
|
|
38
|
+
// `neededProps` holds only props-param locals, so a component with no
|
|
39
|
+
// children param has nothing to extract.
|
|
40
|
+
const prop = ctx.propsParams.find(isChildrenPropParam)
|
|
41
|
+
if (!prop) return
|
|
42
|
+
const local = prop.name
|
|
43
|
+
if (!neededProps.has(local)) return
|
|
43
44
|
|
|
44
|
-
const usedAsCondition = computePropsUsedAsConditions(ctx, neededProps).has(
|
|
45
|
-
const fallback = propReadFallback(prop, propUsage.get(
|
|
45
|
+
const usedAsCondition = computePropsUsedAsConditions(ctx, neededProps).has(local)
|
|
46
|
+
const fallback = propReadFallback(prop, propUsage.get(local), usedAsCondition)
|
|
46
47
|
const read = propReadBase(prop) + (fallback === null ? '' : ` ?? ${fallback}`)
|
|
47
|
-
lines.push(` const ${
|
|
48
|
+
lines.push(` const ${local} = ${read}`, '')
|
|
48
49
|
}
|
|
@@ -12,8 +12,8 @@ import type { ControlledSignal } from '../init-declarations.ts'
|
|
|
12
12
|
import type { Declaration } from '../declaration-sort.ts'
|
|
13
13
|
import type { ClientJsContext } from '../types.ts'
|
|
14
14
|
import type { ParamInfo, SignalInfo } from '../../types.ts'
|
|
15
|
-
import { inferDefaultValue, PROPS_PARAM } from '../utils.ts'
|
|
16
|
-
import { livePropReadExpr } from '../../props-binding.ts'
|
|
15
|
+
import { inferDefaultValue, PROPS_PARAM, readsBareProp } from '../utils.ts'
|
|
16
|
+
import { livePropReadExpr, propDefaultText } from '../../props-binding.ts'
|
|
17
17
|
import { signalFactoryInitializer, signalSecondBinding } from '../../signal-initializer.ts'
|
|
18
18
|
import type {
|
|
19
19
|
ControlledSignalEffectPlan,
|
|
@@ -113,7 +113,7 @@ function buildSignalPlan(
|
|
|
113
113
|
getter: signal.getter,
|
|
114
114
|
setter: signal.setter,
|
|
115
115
|
getterElided: signal.getterElided,
|
|
116
|
-
initialValueExpr: resolveSignalInitialValue(signal,
|
|
116
|
+
initialValueExpr: resolveSignalInitialValue(signal, lookups),
|
|
117
117
|
controlledEffect,
|
|
118
118
|
branchCondition: signal.branchCondition,
|
|
119
119
|
bfId: ctx.profile ? `${ctx.componentName}#signal:${signal.getter}` : undefined,
|
|
@@ -121,57 +121,28 @@ function buildSignalPlan(
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
/**
|
|
124
|
-
*
|
|
125
|
-
* 1.
|
|
126
|
-
* default
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
124
|
+
* The signal's initial value, decided from `SignalInfo.propSeed` (#3508):
|
|
125
|
+
* 1. A bare read of the props object (`props.X`, `props.row.count`) →
|
|
126
|
+
* `<it> ?? <inferred default>`, so the signal never starts as
|
|
127
|
+
* `undefined`.
|
|
128
|
+
* 2. A controlled signal seeded by a bare destructured binding →
|
|
129
|
+
* `_p.<caller key> ?? <the prop's default>`.
|
|
130
|
+
* 3. Anything else (a `??` / `||` fallback the user wrote, any other
|
|
131
|
+
* expression) → the initializer as written; `generateInit`'s
|
|
132
|
+
* `rewritePropsObjectRef` maps its `props.X` reads to `_p.X`.
|
|
133
133
|
*/
|
|
134
|
-
function resolveSignalInitialValue(
|
|
135
|
-
signal
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
// Case 1: bare `propsName.X` read — append the inferred default so the
|
|
145
|
-
// signal never starts as `undefined`.
|
|
146
|
-
if (startsWithPropsPrefix && !hasNullish) {
|
|
147
|
-
const propRef = `${PROPS_PARAM}.` + signal.initialValue.slice(propsPrefix.length)
|
|
148
|
-
return `${propRef} ?? ${inferDefaultValue(signal.type)}`
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const controlled = lookups.controlledBySignal.get(signal)
|
|
152
|
-
if (controlled) {
|
|
153
|
-
// Case 2a: user already wrote `??` — keep their default but rewrite
|
|
154
|
-
// a leading `propsName.` prefix.
|
|
155
|
-
if (hasNullish) {
|
|
156
|
-
if (ctx.propsObjectName && startsWithPropsPrefix) {
|
|
157
|
-
return `${PROPS_PARAM}.` + signal.initialValue.slice(propsPrefix.length)
|
|
158
|
-
}
|
|
159
|
-
return signal.initialValue
|
|
134
|
+
function resolveSignalInitialValue(signal: SignalInfo, lookups: DeclarationEmitLookups): string {
|
|
135
|
+
const seed = signal.propSeed
|
|
136
|
+
if (readsBareProp(signal)) return `${signal.initialValue} ?? ${inferDefaultValue(signal.type)}`
|
|
137
|
+
if (seed && seed.fallback === null) {
|
|
138
|
+
const controlled = lookups.controlledBySignal.get(signal)
|
|
139
|
+
if (controlled) {
|
|
140
|
+
const prop = lookups.propByName.get(controlled.propName)
|
|
141
|
+
const defaultVal = (prop && propDefaultText(prop)) ?? inferDefaultValue(signal.type)
|
|
142
|
+
// `_p` is always keyed by the caller-facing name (#2524 CSR half).
|
|
143
|
+
return `${PROPS_PARAM}.${prop?.sourceName ?? controlled.propName} ?? ${defaultVal}`
|
|
160
144
|
}
|
|
161
|
-
// Case 2b: synthesize the prop accessor + default.
|
|
162
|
-
const prop = lookups.propByName.get(controlled.propName)
|
|
163
|
-
const defaultVal = prop?.defaultValue ?? inferDefaultValue(signal.type)
|
|
164
|
-
// `_p` is always keyed by the caller-facing name (#2524 CSR half).
|
|
165
|
-
return `${PROPS_PARAM}.${prop?.sourceName ?? controlled.propName} ?? ${defaultVal}`
|
|
166
145
|
}
|
|
167
|
-
|
|
168
|
-
// Case 3: non-controlled `propsObjectName.X` (only when destructured-
|
|
169
|
-
// props mode is OFF — the destructured form has no `propsObjectName`).
|
|
170
|
-
if (ctx.propsObjectName && startsWithPropsPrefix) {
|
|
171
|
-
return `${PROPS_PARAM}.` + signal.initialValue.slice(propsPrefix.length)
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Case 4: fall-through.
|
|
175
146
|
return signal.initialValue
|
|
176
147
|
}
|
|
177
148
|
|
|
@@ -190,5 +161,8 @@ function buildControlledSignalEffect(
|
|
|
190
161
|
? livePropReadExpr(prop, undefined, false)
|
|
191
162
|
: `${PROPS_PARAM}.${controlled.propName}`
|
|
192
163
|
|
|
193
|
-
|
|
164
|
+
// A `||` fallback (`createSignal(props.value || '')`) also replaces a
|
|
165
|
+
// falsy prop, so the re-sync sets the initializer's value, not the raw prop.
|
|
166
|
+
const valueExpr = signal.propSeed?.fallback?.op === '||' ? signal.initialValue : undefined
|
|
167
|
+
return { setter: signal.setter, accessorExpr, valueExpr }
|
|
194
168
|
}
|
|
@@ -80,6 +80,11 @@ export interface ControlledSignalEffectPlan {
|
|
|
80
80
|
accessorExpr: string
|
|
81
81
|
/** Profile-mode IR-aligned id, appended as the `createEffect` 2nd arg (#1690). */
|
|
82
82
|
bfId?: string
|
|
83
|
+
/**
|
|
84
|
+
* When set, the value the effect sets once the prop is defined (the
|
|
85
|
+
* signal's initializer, for a `||` fallback); otherwise the prop itself.
|
|
86
|
+
*/
|
|
87
|
+
valueExpr?: string
|
|
83
88
|
}
|
|
84
89
|
|
|
85
90
|
export interface MemoEmitPlan {
|
|
@@ -172,61 +172,20 @@ export function expandConstantForReactivity(
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
/**
|
|
175
|
-
*
|
|
176
|
-
*
|
|
175
|
+
* The prop a signal is controlled by: its initializer reads that declared
|
|
176
|
+
* prop itself (not a member of it), bare or with a `??` / `||` fallback (`createSignal(props.checked)`,
|
|
177
|
+
* `createSignal(value ?? 0)`), so a createEffect re-syncs it when the
|
|
178
|
+
* parent's prop changes. Read from the analyzer's `SignalInfo.propSeed`, the
|
|
179
|
+
* same field `resolveSignalInitialValue` reads, never from the text (#3508).
|
|
177
180
|
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
* These signals need a createEffect to sync with parent's prop changes.
|
|
183
|
-
*
|
|
184
|
-
* Note: Props starting with "default" (e.g., defaultChecked, defaultValue) are
|
|
185
|
-
* excluded as they are initial values, not controlled props.
|
|
181
|
+
* Props starting with "default" (`defaultChecked`) are initial values, not
|
|
182
|
+
* controlled props, and an async factory's value (`createQuery(fn, {
|
|
183
|
+
* initial: props.posts })`, #3165) takes `initial` once, then comes from its
|
|
184
|
+
* own requests.
|
|
186
185
|
*/
|
|
187
|
-
export function getControlledPropName(
|
|
188
|
-
signal
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
): string | null {
|
|
192
|
-
// An async factory's value (`createQuery(fn, { initial: props.posts })`,
|
|
193
|
-
// #3165) takes `initial` once; later values come from its own requests, so
|
|
194
|
-
// it is never re-synced from the prop.
|
|
195
|
-
if (signal.factory) return null
|
|
196
|
-
const initialValue = signal.initialValue.trim()
|
|
197
|
-
const isDefaultProp = (propName: string) => propName.startsWith('default')
|
|
198
|
-
// Use the source-level props name for pattern matching (not the generated PROPS_PARAM)
|
|
199
|
-
const propsName = propsObjectName ?? 'props'
|
|
200
|
-
|
|
201
|
-
// Direct <propsName>.X reference, optionally with ?? or || fallback
|
|
202
|
-
// e.g., props.checked, p.value ?? 0, props.initial || ''
|
|
203
|
-
const propsPattern = new RegExp(`^${propsName}\\.(\\w+)(?:\\s*(?:\\?\\?|\\|\\|)\\s*.+)?$`)
|
|
204
|
-
const propsMatch = initialValue.match(propsPattern)
|
|
205
|
-
if (propsMatch) {
|
|
206
|
-
const propName = propsMatch[1]
|
|
207
|
-
if (propsParams.some((p) => p.name === propName) && !isDefaultProp(propName)) {
|
|
208
|
-
return propName
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// Simple prop name (e.g., checked in createSignal(checked))
|
|
213
|
-
if (/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(initialValue)) {
|
|
214
|
-
if (propsParams.some((p) => p.name === initialValue) && !isDefaultProp(initialValue)) {
|
|
215
|
-
return initialValue
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Prop with nullish coalescing or logical OR fallback
|
|
220
|
-
// e.g., checked ?? false, props.checked ?? false, p.value || ''
|
|
221
|
-
const fallbackPattern = new RegExp(`^(?:${propsName}\\.)?(\\w+)\\s*(?:\\?\\?|\\|\\|)\\s*.+$`)
|
|
222
|
-
const fallbackMatch = initialValue.match(fallbackPattern)
|
|
223
|
-
if (fallbackMatch) {
|
|
224
|
-
const propName = fallbackMatch[1]
|
|
225
|
-
if (propsParams.some((p) => p.name === propName) && !isDefaultProp(propName)) {
|
|
226
|
-
return propName
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return null
|
|
186
|
+
export function getControlledPropName(signal: SignalInfo): string | null {
|
|
187
|
+
const seed = signal.propSeed
|
|
188
|
+
if (signal.factory || !seed || seed.nested || !seed.declared) return null
|
|
189
|
+
return seed.propName.startsWith('default') ? null : seed.propName
|
|
231
190
|
}
|
|
232
191
|
|
|
@@ -40,7 +40,7 @@ import { PROPS_PARAM } from './utils.ts'
|
|
|
40
40
|
* Does `init` read `<objectName>.<key>` or `<objectName>.<key> ?? <fallback>`?
|
|
41
41
|
* The one recognizer for "a prop read initializer", shared by
|
|
42
42
|
* `propExtractionName` below (which additionally requires the bound name to
|
|
43
|
-
* equal `key`, and always reads off `_p`), `rewriteBodyAliasReads`
|
|
43
|
+
* equal `key` unless `key` is `children`, and always reads off `_p`), `rewriteBodyAliasReads`
|
|
44
44
|
* (`rewrite-destructured-props.ts`, which does not require the name match —
|
|
45
45
|
* a renamed alias's bound name differs from `key` by definition, but also
|
|
46
46
|
* always reads off `_p`), and `resolveBodyPropAliases` (`props-binding.ts`,
|
|
@@ -66,8 +66,11 @@ export function parsePropReadInitializer(
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/** Is `stmt` a single-declarator `const X = _p.X…` prop extraction whose
|
|
69
|
-
* initializer is `_p.X` or `_p.X ?? <default>`?
|
|
70
|
-
*
|
|
69
|
+
* initializer is `_p.X` or `_p.X ?? <default>`? The children prop's
|
|
70
|
+
* extraction may bind another name (`const kids = _p.children`, a renamed
|
|
71
|
+
* `{ children: kids }`, #3572): its eager read is the hazard this pass
|
|
72
|
+
* removes, so it matches under any name. Returns the bound name, or null
|
|
73
|
+
* when the statement is anything else. */
|
|
71
74
|
function propExtractionName(stmt: ts.Statement): string | null {
|
|
72
75
|
if (!ts.isVariableStatement(stmt)) return null
|
|
73
76
|
const decls = stmt.declarationList.declarations
|
|
@@ -76,7 +79,7 @@ function propExtractionName(stmt: ts.Statement): string | null {
|
|
|
76
79
|
if (!ts.isIdentifier(decl.name) || !decl.initializer) return null
|
|
77
80
|
|
|
78
81
|
const parsed = parsePropReadInitializer(decl.initializer)
|
|
79
|
-
if (parsed === null || parsed.key !== decl.name.text) return null
|
|
82
|
+
if (parsed === null || (parsed.key !== decl.name.text && parsed.key !== 'children')) return null
|
|
80
83
|
return decl.name.text
|
|
81
84
|
}
|
|
82
85
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Reactivity detection: reactive expression checking, event/ref collection.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { type IRNode, type IRElement, type IRComponent, type IRLoop, type IRProp, type LoopParamBinding, type OriginInfo, pickAttrMetaFromIR, isReactiveOrigin } from '../types.ts'
|
|
5
|
+
import { type IRNode, type IRElement, type IRComponent, type IRLoop, type IRProp, type LoopParamBinding, type OriginInfo, pickAttrMetaFromIR, isReactiveOrigin, isChildrenPropParam } from '../types.ts'
|
|
6
6
|
import type {
|
|
7
7
|
ClientJsContext,
|
|
8
8
|
ConditionalBranchEvent,
|
|
@@ -237,7 +237,7 @@ function needsEffectWrapperCore(
|
|
|
237
237
|
// Check individual prop names (excluding children which is server-rendered
|
|
238
238
|
// and should not trigger effect wrapping on the client)
|
|
239
239
|
for (const prop of ctx.propsParams) {
|
|
240
|
-
if (prop
|
|
240
|
+
if (isChildrenPropParam(prop)) continue
|
|
241
241
|
if (freeIdentifiers ? freeIdentifiers.has(prop.name) : tokenContainsIdent(expr, prop.name)) {
|
|
242
242
|
return true
|
|
243
243
|
}
|