@barefootjs/jsx 0.39.9 → 0.40.1
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/ambiguous-nil-arithmetic.d.ts +41 -0
- package/dist/adapters/ambiguous-nil-arithmetic.d.ts.map +1 -0
- package/dist/adapters/attr-plan.d.ts +1 -20
- package/dist/adapters/attr-plan.d.ts.map +1 -1
- package/dist/adapters/boolean-carrier.d.ts +31 -0
- package/dist/adapters/boolean-carrier.d.ts.map +1 -0
- package/dist/adapters/component-props.d.ts +22 -7
- package/dist/adapters/component-props.d.ts.map +1 -1
- package/dist/adapters/computed-const.d.ts +17 -0
- package/dist/adapters/computed-const.d.ts.map +1 -1
- package/dist/adapters/dsl-template-adapter.d.ts +95 -2
- package/dist/adapters/dsl-template-adapter.d.ts.map +1 -1
- package/dist/adapters/loop-plan.d.ts +41 -1
- package/dist/adapters/loop-plan.d.ts.map +1 -1
- package/dist/adapters/number-value.d.ts +43 -0
- package/dist/adapters/number-value.d.ts.map +1 -0
- package/dist/analyzer-context.d.ts +7 -0
- package/dist/analyzer-context.d.ts.map +1 -1
- package/dist/analyzer.d.ts +34 -0
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/augment-inherited-props.d.ts.map +1 -1
- package/dist/css-layer-prefixer.d.ts.map +1 -1
- package/dist/debug.d.ts.map +1 -1
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/index.d.ts +10 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2102 -1344
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-component-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts +29 -0
- package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-lazy-row.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/build-lazy-row.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-reactive-effects.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/inner-loop.d.ts +5 -4
- package/dist/ir-to-client-js/control-flow/plan/inner-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/loop-child-arm.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/loop-child-arm.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +15 -0
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/reactive-effects.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/reactive-effects.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts +20 -0
- package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/lazy-row.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts +3 -2
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/build-static-array-child-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/static-array-child-init.d.ts +7 -1
- package/dist/ir-to-client-js/plan/static-array-child-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
- package/dist/ir-to-client-js/safe-html.d.ts +9 -3
- package/dist/ir-to-client-js/safe-html.d.ts.map +1 -1
- package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/types.d.ts +30 -0
- package/dist/ir-to-client-js/types.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +9 -1
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/module-exports.d.ts.map +1 -1
- package/dist/nullable-signal-attr.d.ts +29 -3
- package/dist/nullable-signal-attr.d.ts.map +1 -1
- package/dist/props-binding.d.ts +27 -3
- package/dist/props-binding.d.ts.map +1 -1
- package/dist/scope/binding-scope.d.ts +24 -1
- package/dist/scope/binding-scope.d.ts.map +1 -1
- package/dist/scope/root-prop-alias.d.ts +14 -1
- package/dist/scope/root-prop-alias.d.ts.map +1 -1
- package/dist/signal-prop-name-collision.d.ts.map +1 -1
- package/dist/ssr-defaults.d.ts +4 -2
- package/dist/ssr-defaults.d.ts.map +1 -1
- package/dist/ssr-seed-plan.d.ts +14 -0
- package/dist/ssr-seed-plan.d.ts.map +1 -1
- package/dist/template-parts.d.ts +1 -1
- package/dist/template-parts.d.ts.map +1 -1
- package/dist/types.d.ts +35 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/attr-plan.test.ts +1 -14
- package/src/__tests__/binding-scope-ratchet.test.ts +12 -2
- package/src/__tests__/boolean-carrier.test.ts +74 -0
- package/src/__tests__/client-template-escape-soundness.test.ts +17 -4
- package/src/__tests__/client-template-static-delimiters.test.ts +57 -0
- package/src/__tests__/component-props.test.ts +14 -0
- package/src/__tests__/computed-const.test.ts +85 -0
- package/src/__tests__/dsl-template-adapter.test.ts +70 -0
- package/src/__tests__/expression-parser.test.ts +24 -0
- package/src/__tests__/extract-function-params.test.ts +37 -0
- package/src/__tests__/issue-2960-multi-root-cond-same-tag.test.ts +18 -0
- package/src/__tests__/issue-3688-props-spread-child-csr.test.ts +142 -0
- package/src/__tests__/jsx-text-linebreak-whitespace.test.ts +11 -0
- package/src/__tests__/loop-plan.test.ts +66 -1
- package/src/__tests__/loop-row-prop-read.test.ts +111 -0
- package/src/__tests__/memo-body-expr.test.ts +137 -0
- package/src/__tests__/nullable-signal-attr.test.ts +97 -2
- package/src/__tests__/profile-binding-ids.test.ts +14 -0
- package/src/__tests__/root-prop-alias.test.ts +34 -1
- package/src/__tests__/signal-prop-name-collision.test.ts +102 -2
- package/src/__tests__/source-file-cache.test.ts +105 -0
- package/src/__tests__/ssr-seed-plan.test.ts +43 -0
- package/src/__tests__/template-parts-literal-boundary.test.ts +41 -0
- package/src/adapters/ambiguous-nil-arithmetic.ts +94 -0
- package/src/adapters/attr-plan.ts +8 -56
- package/src/adapters/boolean-carrier.ts +76 -0
- package/src/adapters/component-props.ts +28 -8
- package/src/adapters/computed-const.ts +206 -7
- package/src/adapters/dsl-template-adapter.ts +183 -2
- package/src/adapters/loop-plan.ts +67 -2
- package/src/adapters/number-value.ts +95 -0
- package/src/analyzer-context.ts +8 -0
- package/src/analyzer.ts +187 -66
- package/src/augment-inherited-props.ts +5 -9
- package/src/css-layer-prefixer.ts +4 -5
- package/src/debug.ts +1 -0
- package/src/expression-parser.ts +4 -1
- package/src/index.ts +23 -5
- package/src/ir-to-client-js/collect-elements.ts +104 -46
- package/src/ir-to-client-js/compute-inlinability.ts +2 -2
- package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +15 -1
- package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +79 -4
- package/src/ir-to-client-js/control-flow/plan/build-lazy-row.ts +3 -0
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +1 -0
- package/src/ir-to-client-js/control-flow/plan/build-reactive-effects.ts +1 -0
- package/src/ir-to-client-js/control-flow/plan/inner-loop.ts +5 -4
- package/src/ir-to-client-js/control-flow/plan/loop-child-arm.ts +2 -0
- package/src/ir-to-client-js/control-flow/plan/loop.ts +12 -0
- package/src/ir-to-client-js/control-flow/plan/reactive-effects.ts +2 -0
- package/src/ir-to-client-js/control-flow/shared.ts +3 -2
- package/src/ir-to-client-js/control-flow/stringify/claim-plan.ts +27 -0
- package/src/ir-to-client-js/control-flow/stringify/component-loop.ts +8 -2
- package/src/ir-to-client-js/control-flow/stringify/event-listener.ts +8 -1
- package/src/ir-to-client-js/control-flow/stringify/inner-loop.ts +8 -7
- package/src/ir-to-client-js/control-flow/stringify/lazy-row.ts +8 -7
- package/src/ir-to-client-js/control-flow/stringify/loop-child-arm.ts +4 -4
- package/src/ir-to-client-js/control-flow/stringify/loop.ts +3 -3
- package/src/ir-to-client-js/control-flow/stringify/reactive-effects.ts +6 -6
- package/src/ir-to-client-js/emit-reactive.ts +1 -1
- package/src/ir-to-client-js/html-template.ts +122 -75
- package/src/ir-to-client-js/plan/build-static-array-child-init.ts +11 -1
- package/src/ir-to-client-js/plan/static-array-child-init.ts +7 -1
- package/src/ir-to-client-js/reactivity.ts +14 -0
- package/src/ir-to-client-js/safe-html.ts +11 -4
- package/src/ir-to-client-js/stringify/static-array-child-init.ts +6 -4
- package/src/ir-to-client-js/types.ts +23 -0
- package/src/ir-to-client-js/utils.ts +16 -2
- package/src/jsx-to-ir.ts +112 -55
- package/src/loop-destructure.ts +4 -1
- package/src/module-exports.ts +13 -21
- package/src/nullable-signal-attr.ts +134 -13
- package/src/props-binding.ts +54 -3
- package/src/rich-type-refusal.ts +3 -1
- package/src/scope/binding-scope.ts +35 -2
- package/src/scope/root-prop-alias.ts +17 -1
- package/src/signal-prop-name-collision.ts +113 -22
- package/src/ssr-defaults.ts +10 -4
- package/src/ssr-seed-plan.ts +82 -17
- package/src/template-parts.ts +25 -3
- package/src/template-position-walk.ts +3 -1
- package/src/types.ts +32 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which values are JS numbers, for backends whose own number
|
|
3
|
+
* stringification differs from JS's `Number::toString` (Perl prints
|
|
4
|
+
* `%.15g` and spells the infinities `Inf`), and whose equality operators
|
|
5
|
+
* need the operand's type.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ParsedExpr } from '../expression-parser.ts'
|
|
9
|
+
import type { SsrSeedPlan } from '../ssr-seed-plan.ts'
|
|
10
|
+
import type { ComponentIR, TypeInfo } from '../types.ts'
|
|
11
|
+
import { isNumericArithmeticResult } from './parsed-expr-emitter.ts'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Number-typed signals, memos, props and same-file local consts: a strict
|
|
15
|
+
* equality against one of them keeps Perl's numeric `==` / `!=`, where an
|
|
16
|
+
* operand of unknown type goes through the runtime's `strict_eq`
|
|
17
|
+
* (`emitPerlEquality`). `names` holds the bare spellings (a getter, a
|
|
18
|
+
* destructured prop, a const), `props` the caller-facing keys a
|
|
19
|
+
* `props.<key>` member reads. Whether a binding shadows a name is the
|
|
20
|
+
* caller's scope question.
|
|
21
|
+
*/
|
|
22
|
+
export function collectNumberValueNames(ir: Pick<ComponentIR, 'metadata'>): { names: Set<string>; props: Set<string> } {
|
|
23
|
+
const isNumber = (type: TypeInfo | null | undefined): boolean =>
|
|
24
|
+
type?.kind === 'primitive' && type.primitive === 'number'
|
|
25
|
+
const names = new Set<string>()
|
|
26
|
+
const props = new Set<string>()
|
|
27
|
+
for (const s of ir.metadata.signals) {
|
|
28
|
+
if (isNumber(s.type)) names.add(s.getter)
|
|
29
|
+
}
|
|
30
|
+
for (const m of ir.metadata.memos ?? []) {
|
|
31
|
+
if (isNumber(m.type)) names.add(m.name)
|
|
32
|
+
}
|
|
33
|
+
for (const p of ir.metadata.propsParams) {
|
|
34
|
+
if (!isNumber(p.type)) continue
|
|
35
|
+
props.add(p.sourceName ?? p.name)
|
|
36
|
+
if (!ir.metadata.propsObjectName) names.add(p.name)
|
|
37
|
+
}
|
|
38
|
+
for (const c of ir.metadata.localConstants) {
|
|
39
|
+
if (isNumber(c.type)) names.add(c.name)
|
|
40
|
+
}
|
|
41
|
+
return { names, props }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Whether an expression yields a JS NUMBER: arithmetic
|
|
46
|
+
* ({@link isNumericArithmeticResult}), a read of a name `isNumberName`
|
|
47
|
+
* accepts — a zero-argument getter call, a `props.<key>` member, or a bare
|
|
48
|
+
* identifier — or a ternary with such a branch. Backends whose own number
|
|
49
|
+
* stringification differs from JS (Perl spells the infinities `Inf` and
|
|
50
|
+
* prints `%.15g`) route such a value through their `Number::toString`
|
|
51
|
+
* helper wherever JS stringifies it: an output position, or an operand of
|
|
52
|
+
* string concatenation (#3711). Whether a binding shadows the name is
|
|
53
|
+
* `isNumberName`'s scope question.
|
|
54
|
+
*/
|
|
55
|
+
export function isNumberValuedExpr(
|
|
56
|
+
expr: ParsedExpr | null | undefined,
|
|
57
|
+
isStringName: (n: string, componentProperty?: boolean) => boolean,
|
|
58
|
+
isNumberName: (n: string, componentProperty?: boolean) => boolean,
|
|
59
|
+
): boolean {
|
|
60
|
+
if (!expr) return false
|
|
61
|
+
if (isNumericArithmeticResult(expr, isStringName)) return true
|
|
62
|
+
// Either branch may be the value printed; the helper passes a string
|
|
63
|
+
// branch through unchanged.
|
|
64
|
+
if (expr.kind === 'conditional') {
|
|
65
|
+
return isNumberValuedExpr(expr.consequent, isStringName, isNumberName) ||
|
|
66
|
+
isNumberValuedExpr(expr.alternate, isStringName, isNumberName)
|
|
67
|
+
}
|
|
68
|
+
if (expr.kind === 'call') return expr.callee.kind === 'identifier' && expr.args.length === 0 && isNumberName(expr.callee.name)
|
|
69
|
+
if (expr.kind === 'member') {
|
|
70
|
+
return !expr.computed && expr.object.kind === 'identifier' && expr.object.name === 'props' && isNumberName(expr.property, true)
|
|
71
|
+
}
|
|
72
|
+
return expr.kind === 'identifier' && isNumberName(expr.name)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Signals and memos whose in-template seed (a `derived` step of the SSR seed
|
|
77
|
+
* plan) is a JS number by construction: arithmetic, or a read of a
|
|
78
|
+
* number-typed name or of an earlier such seed (an identity memo). Their
|
|
79
|
+
* declared type is often `unknown` (`createMemo(() => count() / 0)` infers
|
|
80
|
+
* none without a checker), so the seed's shape is the evidence (#3711).
|
|
81
|
+
*/
|
|
82
|
+
export function numberValuedSeedNames(
|
|
83
|
+
plan: SsrSeedPlan,
|
|
84
|
+
isStringName: (n: string, componentProperty?: boolean) => boolean,
|
|
85
|
+
isNumberName: (n: string, componentProperty?: boolean) => boolean,
|
|
86
|
+
): Set<string> {
|
|
87
|
+
const names = new Set<string>()
|
|
88
|
+
const isNumber = (n: string, componentProperty?: boolean) =>
|
|
89
|
+
isNumberName(n, componentProperty) || (!componentProperty && names.has(n))
|
|
90
|
+
for (const step of plan.steps) {
|
|
91
|
+
if (step.kind !== 'derived' || step.origin === 'prop') continue
|
|
92
|
+
if (isNumberValuedExpr(step.parsed, isStringName, isNumber)) names.add(step.name)
|
|
93
|
+
}
|
|
94
|
+
return names
|
|
95
|
+
}
|
package/src/analyzer-context.ts
CHANGED
|
@@ -189,6 +189,13 @@ export interface AnalyzerContext {
|
|
|
189
189
|
* extraction. Flushed into `signals` at the end of visitComponentBody.
|
|
190
190
|
*/
|
|
191
191
|
signalTupleRefs: Map<string, PendingSignalTuple>
|
|
192
|
+
/**
|
|
193
|
+
* Writers of a signal seed's / memo body's client template text
|
|
194
|
+
* (`SignalInfo.templateInitialValue`, `MemoInfo.templateBodyExpr`), run
|
|
195
|
+
* once the whole component body is walked so the props bindings they read
|
|
196
|
+
* live are decided against every body binding (`templatePropReadParams`).
|
|
197
|
+
*/
|
|
198
|
+
templatePropReadWriters: Array<() => void>
|
|
192
199
|
|
|
193
200
|
// Props
|
|
194
201
|
propsType: TypeInfo | null
|
|
@@ -291,6 +298,7 @@ export function createAnalyzerContext(
|
|
|
291
298
|
reactiveShapedHelpers: new Set(),
|
|
292
299
|
cleanFactoryImports: new Set(),
|
|
293
300
|
signalTupleRefs: new Map(),
|
|
301
|
+
templatePropReadWriters: [],
|
|
294
302
|
|
|
295
303
|
propsType: null,
|
|
296
304
|
propsParams: [],
|
package/src/analyzer.ts
CHANGED
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
import ts from 'typescript'
|
|
10
10
|
import { foldRenderReassignmentsInSource } from './fold-render-reassignments.ts'
|
|
11
11
|
import { CLIENT_DIRECTIVE_INTERIOR_RE, USE_CLIENT_DIRECTIVE, isUseClientDirectiveText } from './directives.ts'
|
|
12
|
-
import type { ImportSpecifier, TypeInfo, ParamInfo, PropDefaultPart, PropDefaultRead, ReactiveFactoryInfo, DeclinedReactiveFactory, RequiredFactoryImport, FactoryRenameSite, SourceLocation, SignalFactoryCall, MemoInfo } from './types.ts'
|
|
12
|
+
import type { ImportSpecifier, TypeInfo, ParamInfo, PropDefaultPart, PropDefaultRead, ReactiveFactoryInfo, DeclinedReactiveFactory, RequiredFactoryImport, FactoryRenameSite, SourceLocation, SignalFactoryCall, MemoInfo, SignalInfo } from './types.ts'
|
|
13
13
|
import { CALLBACK_METHODS, parseExpression, parseBlockBodyTolerant, foldBlockToExpr, tsNodeToParsedExpr, stringifyParsedExpr, type ParsedExpr } from './expression-parser.ts'
|
|
14
14
|
import type { CallbackBodyAcceptor } from './adapters/interface.ts'
|
|
15
15
|
import { collectAssignmentTargets, rewriteBarePropRefs, splitScopedValueRefs } from './prop-rewrite.ts'
|
|
16
16
|
import { isEventHandlerName } from './event-handler-name.ts'
|
|
17
|
-
import { buildPropAliasMap, coalesceDefaultText, livePropReadExpr, signalPropSeed } from './props-binding.ts'
|
|
17
|
+
import { buildPropAliasMap, coalesceDefaultText, livePropReadExpr, signalPropSeed, templatePropReadParams } from './props-binding.ts'
|
|
18
18
|
import { incrementCounter } from './instrumentation.ts'
|
|
19
19
|
import {
|
|
20
20
|
type AnalyzerContext,
|
|
@@ -150,10 +150,26 @@ export function createProgramForFile(
|
|
|
150
150
|
source: string,
|
|
151
151
|
filePath: string,
|
|
152
152
|
hostOptions: { currentDirectory?: string } = {}
|
|
153
|
+
): { program: ts.Program; sourceFile: ts.SourceFile; checker: ts.TypeChecker } | null {
|
|
154
|
+
return buildProgramForFile(source, filePath, hostOptions)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* `createProgramForFile`, plus `sourceFiles`: Programs built one after
|
|
159
|
+
* another share parsed (and bound) SourceFiles through it. Every file the
|
|
160
|
+
* host serves, `source` included, is parsed once per distinct text. Not
|
|
161
|
+
* exported from the package: every Program built here has the same compiler
|
|
162
|
+
* options, which is what makes sharing bound SourceFiles between them safe
|
|
163
|
+
* (see `SourceFileCache`).
|
|
164
|
+
*/
|
|
165
|
+
function buildProgramForFile(
|
|
166
|
+
source: string,
|
|
167
|
+
filePath: string,
|
|
168
|
+
hostOptions: { currentDirectory?: string; sourceFiles?: SourceFileCache },
|
|
153
169
|
): { program: ts.Program; sourceFile: ts.SourceFile; checker: ts.TypeChecker } | null {
|
|
154
170
|
incrementCounter('programCreations')
|
|
155
171
|
try {
|
|
156
|
-
const { currentDirectory } = hostOptions
|
|
172
|
+
const { currentDirectory, sourceFiles } = hostOptions
|
|
157
173
|
const resolveFrom = (fileName: string): string =>
|
|
158
174
|
currentDirectory === undefined ? path.resolve(fileName) : path.resolve(currentDirectory, fileName)
|
|
159
175
|
const normalizedPath = resolveFrom(filePath)
|
|
@@ -176,8 +192,13 @@ export function createProgramForFile(
|
|
|
176
192
|
...(currentDirectory === undefined ? {} : { getCurrentDirectory: () => currentDirectory }),
|
|
177
193
|
getSourceFile(fileName, languageVersion) {
|
|
178
194
|
if (resolveFrom(fileName) === normalizedPath) {
|
|
195
|
+
if (sourceFiles) return sourceFiles.get(fileName, languageVersion, source, VIRTUAL_SOURCE_PARSE)
|
|
179
196
|
return ts.createSourceFile(fileName, source, languageVersion, true, ts.ScriptKind.TSX)
|
|
180
197
|
}
|
|
198
|
+
if (sourceFiles) {
|
|
199
|
+
const text = defaultHost.readFile(fileName)
|
|
200
|
+
return text === undefined ? undefined : sourceFiles.get(fileName, languageVersion, text, DISK_FILE_PARSE)
|
|
201
|
+
}
|
|
181
202
|
return defaultHost.getSourceFile(fileName, languageVersion)
|
|
182
203
|
},
|
|
183
204
|
fileExists(fileName) {
|
|
@@ -232,12 +253,79 @@ function rewriteSourceForAnalysis(
|
|
|
232
253
|
* implementation for every harness that compiles under relative names:
|
|
233
254
|
* the conformance harness (`packages/adapter-tests/src/harness-program.ts`)
|
|
234
255
|
* and the docs-example suite (`doc-examples.test.ts`).
|
|
256
|
+
*
|
|
257
|
+
* Every Program it builds draws on one process-wide `SourceFileCache` that
|
|
258
|
+
* is never evicted, so it suits a test process over a fixed corpus. Do not
|
|
259
|
+
* call it from a long-running watcher.
|
|
235
260
|
*/
|
|
236
261
|
export function createAnchoredProgram(source: string, filename: string, anchorDir: string): ts.Program | undefined {
|
|
237
262
|
if (!needsTypeBasedDetection(source)) return undefined
|
|
238
|
-
return
|
|
263
|
+
return buildProgramForFile(source, filename, { currentDirectory: anchorDir, sourceFiles: anchoredSourceFiles })?.program
|
|
239
264
|
}
|
|
240
265
|
|
|
266
|
+
/**
|
|
267
|
+
* Parsed SourceFiles shared by consecutive Programs, keyed by file name, the
|
|
268
|
+
* parse options the Program asks for, and the text. A file is parsed once per
|
|
269
|
+
* distinct text: a file that changed on disk (a rebuilt `@barefootjs/client`
|
|
270
|
+
* `dist`) is parsed again, never served stale, and the many different sources
|
|
271
|
+
* a harness compiles under one virtual name (`component.tsx`) each keep their
|
|
272
|
+
* own entry.
|
|
273
|
+
*
|
|
274
|
+
* A reused SourceFile also keeps its binding, so a Program built from cached
|
|
275
|
+
* files costs module resolution and checker setup, not a parse of
|
|
276
|
+
* `lib.*.d.ts` and every imported declaration (~430 ms → ~30 ms per Program
|
|
277
|
+
* in the conformance harness, #3666). Sharing SourceFiles between Programs
|
|
278
|
+
* with the same compiler options is how TypeScript's own DocumentRegistry
|
|
279
|
+
* serves language services. The Programs themselves are not shared: a
|
|
280
|
+
* checker assigns type ids in the order it is queried, so one reused across
|
|
281
|
+
* compiles could make a compile's output depend on what ran before it.
|
|
282
|
+
*
|
|
283
|
+
* Only for Programs built with the same compiler options: the cache does not
|
|
284
|
+
* key on them. Entries are never evicted, which suits a test process over a
|
|
285
|
+
* fixed corpus, not a long-running watcher.
|
|
286
|
+
*/
|
|
287
|
+
export class SourceFileCache {
|
|
288
|
+
private readonly files = new Map<string, Map<string, ts.SourceFile>>()
|
|
289
|
+
|
|
290
|
+
get(
|
|
291
|
+
fileName: string,
|
|
292
|
+
languageVersion: ts.ScriptTarget | ts.CreateSourceFileOptions,
|
|
293
|
+
text: string,
|
|
294
|
+
parse: SourceFileParse,
|
|
295
|
+
): ts.SourceFile {
|
|
296
|
+
const key = `${fileName}\0${parseOptionsKey(languageVersion)}\0${parse.scriptKind ?? ''}\0${parse.setParentNodes}`
|
|
297
|
+
let byText = this.files.get(key)
|
|
298
|
+
if (!byText) {
|
|
299
|
+
byText = new Map()
|
|
300
|
+
this.files.set(key, byText)
|
|
301
|
+
}
|
|
302
|
+
const cached = byText.get(text)
|
|
303
|
+
if (cached) return cached
|
|
304
|
+
const parsed = ts.createSourceFile(fileName, text, languageVersion, parse.setParentNodes, parse.scriptKind)
|
|
305
|
+
byText.set(text, parsed)
|
|
306
|
+
return parsed
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** How `SourceFileCache` parses a file; part of its key. */
|
|
311
|
+
export interface SourceFileParse {
|
|
312
|
+
scriptKind?: ts.ScriptKind
|
|
313
|
+
setParentNodes: boolean
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** The virtual source, parsed as `createProgramForFile` always parsed it. */
|
|
317
|
+
const VIRTUAL_SOURCE_PARSE: SourceFileParse = { scriptKind: ts.ScriptKind.TSX, setParentNodes: true }
|
|
318
|
+
/** A file read from disk, parsed the way the default compiler host parses it. */
|
|
319
|
+
const DISK_FILE_PARSE: SourceFileParse = { setParentNodes: false }
|
|
320
|
+
|
|
321
|
+
function parseOptionsKey(languageVersion: ts.ScriptTarget | ts.CreateSourceFileOptions): string {
|
|
322
|
+
if (typeof languageVersion === 'number') return String(languageVersion)
|
|
323
|
+
return `${languageVersion.languageVersion}:${languageVersion.impliedNodeFormat ?? ''}:${languageVersion.jsDocParsingMode ?? ''}`
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** The cache behind every `createAnchoredProgram` Program in this process. */
|
|
327
|
+
const anchoredSourceFiles = new SourceFileCache()
|
|
328
|
+
|
|
241
329
|
/**
|
|
242
330
|
* Parse a signal's initializer into the IR, and record which prop it seeds
|
|
243
331
|
* from and with what fallback (#3508).
|
|
@@ -1527,37 +1615,29 @@ function collectSignal(node: ts.VariableDeclaration, ctx: AnalyzerContext): void
|
|
|
1527
1615
|
// the binding actually in scope rather than a hardcoded canonical name (#2057).
|
|
1528
1616
|
const envFactory = envReader ? callExpr.expression.getText(ctx.sourceFile) : undefined
|
|
1529
1617
|
|
|
1530
|
-
//
|
|
1531
|
-
//
|
|
1532
|
-
//
|
|
1533
|
-
// `template:` arrow's module-scope SSR fallback —
|
|
1534
|
-
// closure over `initXxx`'s `const size = _p.size`
|
|
1535
|
-
//
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
if (!ctx.propsObjectName && callExpr.arguments[0]) {
|
|
1539
|
-
const propNames = new Set(ctx.propsParams.map(p => p.name))
|
|
1540
|
-
if (propNames.size > 0) {
|
|
1541
|
-
const propAliases = buildPropAliasMap(ctx.propsParams)
|
|
1542
|
-
templateInitialValue = rewriteBarePropRefs(initialValue, callExpr.arguments[0], propNames, undefined, propAliases, destructuredPropTemplateRead(ctx))
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
|
|
1546
|
-
ctx.signals.push({
|
|
1618
|
+
// A signal's initial value referencing a bare destructured prop
|
|
1619
|
+
// (`createSignal(size ?? 1)` with `{ size }: { size?: number }`, #2265,
|
|
1620
|
+
// or a `(props)`-arg component's body destructure binding) needs
|
|
1621
|
+
// `_p.size` for the CSR `template:` arrow's module-scope SSR fallback —
|
|
1622
|
+
// that arrow isn't a closure over `initXxx`'s `const size = _p.size`
|
|
1623
|
+
// extraction (`deferTemplatePropRead`).
|
|
1624
|
+
const seedNode = callExpr.arguments[0]
|
|
1625
|
+
const signal: SignalInfo = {
|
|
1547
1626
|
getter,
|
|
1548
1627
|
setter,
|
|
1549
1628
|
getterElided: getterElided || undefined,
|
|
1550
1629
|
initialValue,
|
|
1551
1630
|
typedInitialValue: typedInitialValue !== initialValue ? typedInitialValue : undefined,
|
|
1552
|
-
templateInitialValue,
|
|
1553
1631
|
type,
|
|
1554
1632
|
loc: getSourceLocation(node, ctx.sourceFile, ctx.filePath),
|
|
1555
|
-
initialFreeIdentifiers:
|
|
1556
|
-
? extractFreeIdentifiersFromNode(
|
|
1633
|
+
initialFreeIdentifiers: seedNode
|
|
1634
|
+
? extractFreeIdentifiersFromNode(seedNode)
|
|
1557
1635
|
: new Set(),
|
|
1558
1636
|
envReader,
|
|
1559
1637
|
envFactory,
|
|
1560
|
-
}
|
|
1638
|
+
}
|
|
1639
|
+
ctx.signals.push(signal)
|
|
1640
|
+
if (seedNode) deferTemplatePropRead(initialValue, seedNode, ctx, text => { signal.templateInitialValue = text })
|
|
1561
1641
|
}
|
|
1562
1642
|
|
|
1563
1643
|
/**
|
|
@@ -1623,28 +1703,15 @@ function collectFactorySignal(
|
|
|
1623
1703
|
type = inferTypeFromValue(initialValue)
|
|
1624
1704
|
}
|
|
1625
1705
|
|
|
1626
|
-
// Destructured-arg components (#2265): the CSR `template:` arrow's
|
|
1627
|
-
// module-scope fallback needs `_p.<name>` for a bare destructured prop in
|
|
1628
|
-
// `initial`, same as a `createSignal` initial value.
|
|
1629
|
-
let templateInitialValue: string | undefined
|
|
1630
|
-
if (!ctx.propsObjectName && initialNode.kind === 'expression') {
|
|
1631
|
-
const propNames = new Set(ctx.propsParams.map(p => p.name))
|
|
1632
|
-
if (propNames.size > 0) {
|
|
1633
|
-
const propAliases = buildPropAliasMap(ctx.propsParams)
|
|
1634
|
-
templateInitialValue = rewriteBarePropRefs(initialValue, initialNode.node, propNames, undefined, propAliases, destructuredPropTemplateRead(ctx))
|
|
1635
|
-
}
|
|
1636
|
-
}
|
|
1637
|
-
|
|
1638
1706
|
const argTexts = callExpr.arguments.map(arg => ctx.getJS(arg))
|
|
1639
1707
|
const requestArg = callExpr.arguments[0]
|
|
1640
1708
|
|
|
1641
|
-
|
|
1709
|
+
const signal: SignalInfo = {
|
|
1642
1710
|
getter: valueName ?? `__bfGet_${action}`,
|
|
1643
1711
|
setter: null,
|
|
1644
1712
|
getterElided: getterElided || undefined,
|
|
1645
1713
|
initialValue,
|
|
1646
1714
|
typedInitialValue: typedInitialValue !== undefined && typedInitialValue !== initialValue ? typedInitialValue : undefined,
|
|
1647
|
-
templateInitialValue,
|
|
1648
1715
|
type,
|
|
1649
1716
|
loc: getSourceLocation(node, ctx.sourceFile, ctx.filePath),
|
|
1650
1717
|
initialFreeIdentifiers,
|
|
@@ -1656,7 +1723,14 @@ function collectFactorySignal(
|
|
|
1656
1723
|
requestFreeIdentifiers: requestArg ? extractFreeIdentifiersFromNode(requestArg) : new Set(),
|
|
1657
1724
|
action,
|
|
1658
1725
|
},
|
|
1659
|
-
}
|
|
1726
|
+
}
|
|
1727
|
+
ctx.signals.push(signal)
|
|
1728
|
+
// The CSR `template:` arrow's module-scope fallback needs `_p.<name>` for
|
|
1729
|
+
// a bare destructured prop in `initial`, same as a `createSignal` initial
|
|
1730
|
+
// value (#2265).
|
|
1731
|
+
if (initialNode.kind === 'expression') {
|
|
1732
|
+
deferTemplatePropRead(initialValue, initialNode.node, ctx, text => { signal.templateInitialValue = text })
|
|
1733
|
+
}
|
|
1660
1734
|
}
|
|
1661
1735
|
|
|
1662
1736
|
/**
|
|
@@ -2062,33 +2136,33 @@ function memoStructuredBody(
|
|
|
2062
2136
|
}
|
|
2063
2137
|
|
|
2064
2138
|
/**
|
|
2065
|
-
* `MemoInfo.bodyExpr` / `bodyExprIsCall`
|
|
2066
|
-
*
|
|
2139
|
+
* `MemoInfo.bodyExpr` / `bodyExprIsCall` from the callback's body node
|
|
2140
|
+
* (#3510).
|
|
2067
2141
|
*/
|
|
2068
2142
|
function memoBodyFields(
|
|
2069
2143
|
body: { node: ts.Node; call: boolean },
|
|
2070
2144
|
ctx: AnalyzerContext,
|
|
2071
|
-
): Pick<MemoInfo, 'bodyExpr' | 'bodyExprIsCall'
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2145
|
+
): Pick<MemoInfo, 'bodyExpr' | 'bodyExprIsCall'> {
|
|
2146
|
+
return { bodyExpr: asMemoBodyExpr(ctx.getJS(body.node), body.call), bodyExprIsCall: body.call || undefined }
|
|
2147
|
+
}
|
|
2148
|
+
|
|
2149
|
+
function asMemoBodyExpr(text: string, call: boolean): string {
|
|
2150
|
+
return call ? `(${text})()` : text
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
/**
|
|
2154
|
+
* `MemoInfo.templateBodyExpr`: the memo twin of the signal
|
|
2155
|
+
* `templateInitialValue` rewrite (#2265). A memo body referencing a bare
|
|
2156
|
+
* destructured prop (`createMemo(() => value * 10)` with
|
|
2157
|
+
* `{ value }: { value: number }`) is inlined into the CSR `template:` arrow
|
|
2158
|
+
* by `buildSignalMemoEnv`, and that arrow runs at module scope — it is not a
|
|
2159
|
+
* closure over `initXxx`'s `const value = _p.value` extraction, so the bare
|
|
2160
|
+
* ref must become `_p.value` (adapter-tests scope-gate, #2468 sweep).
|
|
2161
|
+
*/
|
|
2162
|
+
function deferMemoTemplateBody(memo: MemoInfo, body: { node: ts.Node; call: boolean }, ctx: AnalyzerContext): void {
|
|
2163
|
+
deferTemplatePropRead(ctx.getJS(body.node), body.node, ctx, text => {
|
|
2164
|
+
memo.templateBodyExpr = text === undefined ? undefined : asMemoBodyExpr(text, body.call)
|
|
2165
|
+
})
|
|
2092
2166
|
}
|
|
2093
2167
|
|
|
2094
2168
|
function collectMemo(node: ts.VariableDeclaration, ctx: AnalyzerContext): void {
|
|
@@ -2169,6 +2243,7 @@ function collectMemo(node: ts.VariableDeclaration, ctx: AnalyzerContext): void {
|
|
|
2169
2243
|
: new Set(),
|
|
2170
2244
|
}
|
|
2171
2245
|
ctx.memos.push(memo)
|
|
2246
|
+
if (body) deferMemoTemplateBody(memo, body, ctx)
|
|
2172
2247
|
markBlockMemo(memo, blockTyped, body?.node, ctx)
|
|
2173
2248
|
}
|
|
2174
2249
|
|
|
@@ -3676,6 +3751,32 @@ function destructuredPropTemplateRead(ctx: AnalyzerContext): (localName: string,
|
|
|
3676
3751
|
return (localName, callerKey) => livePropReadExpr(byName.get(localName) ?? { name: localName, sourceName: callerKey }, undefined, false)
|
|
3677
3752
|
}
|
|
3678
3753
|
|
|
3754
|
+
/**
|
|
3755
|
+
* Queue the client template text of a signal seed or memo body: `text` (the
|
|
3756
|
+
* source of `node`) with each read of a props binding the template reads live
|
|
3757
|
+
* (`templatePropReadParams`) rewritten to that read, or undefined when it
|
|
3758
|
+
* reads none, handed to `write` by `writeTemplatePropReads`. In a
|
|
3759
|
+
* `(props)`-arg component such a binding is a body destructure binding holding
|
|
3760
|
+
* its prop (`const { b: local = d } = props`), so a memo over it reads the
|
|
3761
|
+
* default just as markup does. The set is decided once the whole body is
|
|
3762
|
+
* walked: a binding written later no longer holds its prop, and a local
|
|
3763
|
+
* function or constant declared later keeps its own meaning.
|
|
3764
|
+
*/
|
|
3765
|
+
function deferTemplatePropRead(text: string, node: ts.Node, ctx: AnalyzerContext, write: (text: string | undefined) => void): void {
|
|
3766
|
+
ctx.templatePropReadWriters.push(() => {
|
|
3767
|
+
const readable = templatePropReadParams(ctx)
|
|
3768
|
+
if (readable.length === 0) return
|
|
3769
|
+
const propNames = new Set(readable.map(p => p.name))
|
|
3770
|
+
write(rewriteBarePropRefs(text, node, propNames, undefined, buildPropAliasMap(readable), destructuredPropTemplateRead(ctx)))
|
|
3771
|
+
})
|
|
3772
|
+
}
|
|
3773
|
+
|
|
3774
|
+
/** Run the writers `deferTemplatePropRead` queued, against the walked body. */
|
|
3775
|
+
function writeTemplatePropReads(ctx: AnalyzerContext): void {
|
|
3776
|
+
for (const write of ctx.templatePropReadWriters) write()
|
|
3777
|
+
ctx.templatePropReadWriters.length = 0
|
|
3778
|
+
}
|
|
3779
|
+
|
|
3679
3780
|
/**
|
|
3680
3781
|
* The default-value-shaped fields a binding element's own `initializer`
|
|
3681
3782
|
* contributes to a `ParamInfo` — `defaultValue`'s source text, `parsed`'s
|
|
@@ -4166,6 +4267,7 @@ function extractProps(param: ts.ParameterDeclaration, ctx: AnalyzerContext): voi
|
|
|
4166
4267
|
const info: ParamInfo = {
|
|
4167
4268
|
name: localName,
|
|
4168
4269
|
type: resolvedType,
|
|
4270
|
+
...unresolvedDeclaredType(member),
|
|
4169
4271
|
// The type's `?` and a destructure default (`{ x = 1 }`) both mean
|
|
4170
4272
|
// the caller may omit the prop.
|
|
4171
4273
|
optional: !!member?.optional || !!element.initializer,
|
|
@@ -4423,20 +4525,38 @@ function localObjectMemberTypesFor(ctx: AnalyzerContext): LocalObjectMemberTypes
|
|
|
4423
4525
|
* `isResolvableMemberType`'s own docstring for why the structural cases
|
|
4424
4526
|
* are safe to admit and why those three still are not.
|
|
4425
4527
|
*/
|
|
4528
|
+
/**
|
|
4529
|
+
* A destructured binding's member type: `type` when it resolves to a
|
|
4530
|
+
* concrete representation (`isResolvableMemberType`), and the declared
|
|
4531
|
+
* type as written (`declared`), which `ParamInfo.declaredType` carries when
|
|
4532
|
+
* `type` does not resolve.
|
|
4533
|
+
*/
|
|
4534
|
+
interface DestructuredMemberType {
|
|
4535
|
+
type: TypeInfo | null
|
|
4536
|
+
declared: TypeInfo | null
|
|
4537
|
+
optional: boolean
|
|
4538
|
+
}
|
|
4539
|
+
|
|
4540
|
+
/** `ParamInfo.declaredType` for a member whose declared type did not resolve to `type`. */
|
|
4541
|
+
function unresolvedDeclaredType(member: DestructuredMemberType | undefined): Pick<ParamInfo, 'declaredType'> {
|
|
4542
|
+
return member && !member.type && member.declared ? { declaredType: member.declared } : {}
|
|
4543
|
+
}
|
|
4544
|
+
|
|
4426
4545
|
function collectMemberTypes(
|
|
4427
4546
|
typeNode: ts.TypeNode,
|
|
4428
4547
|
ctx: AnalyzerContext
|
|
4429
|
-
): Map<string,
|
|
4548
|
+
): Map<string, DestructuredMemberType> | null {
|
|
4430
4549
|
const localObjectMembers = localObjectMemberTypesFor(ctx)
|
|
4431
4550
|
const fromMembers = (
|
|
4432
4551
|
members: ts.NodeArray<ts.TypeElement>
|
|
4433
|
-
): Map<string,
|
|
4434
|
-
const map = new Map<string,
|
|
4552
|
+
): Map<string, DestructuredMemberType> => {
|
|
4553
|
+
const map = new Map<string, DestructuredMemberType>()
|
|
4435
4554
|
for (const member of members) {
|
|
4436
4555
|
if (ts.isPropertySignature(member) && member.name) {
|
|
4437
4556
|
const info = member.type ? typeNodeToTypeInfo(member.type, ctx.sourceFile) : null
|
|
4438
4557
|
map.set(member.name.getText(ctx.sourceFile), {
|
|
4439
4558
|
type: info && isResolvableMemberType(info, localObjectMembers) ? info : null,
|
|
4559
|
+
declared: info,
|
|
4440
4560
|
optional: !!member.questionToken,
|
|
4441
4561
|
})
|
|
4442
4562
|
}
|
|
@@ -4707,6 +4827,7 @@ function validateContext(ctx: AnalyzerContext): void {
|
|
|
4707
4827
|
// downstream inlining never re-embeds their stale initializer text (#2910).
|
|
4708
4828
|
markMutatedConstants(ctx)
|
|
4709
4829
|
markWrittenBindings(ctx)
|
|
4830
|
+
writeTemplatePropReads(ctx)
|
|
4710
4831
|
|
|
4711
4832
|
// BF052: init statements that write to an identifier with no visible
|
|
4712
4833
|
// declaration cause a ReferenceError in ESM strict mode. Flag them
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import ts from 'typescript'
|
|
14
14
|
|
|
15
|
-
import type { ComponentIR, IRMetadata, IRNode, IRElement, TypeInfo } from './types.ts'
|
|
15
|
+
import type { ComponentIR, IRMetadata, IRNode, IRElement, IRTemplatePart, TypeInfo } from './types.ts'
|
|
16
16
|
import { isBooleanAttr } from './html-constants.ts'
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -290,10 +290,10 @@ export function augmentInheritedPropAccesses(ir: ComponentIR): void {
|
|
|
290
290
|
// component renders it. Classify these reads as nillable (`unknown`)
|
|
291
291
|
// unless a `?? <literal>` pins a concrete type.
|
|
292
292
|
for (const prop of (node as unknown as { props?: IRElement['attrs'] }).props ?? []) {
|
|
293
|
-
const v = prop.value as { kind?: string; expr?: string; parts?:
|
|
293
|
+
const v = prop.value as { kind?: string; expr?: string; parts?: IRTemplatePart[] }
|
|
294
294
|
if (v?.parts) {
|
|
295
295
|
for (const part of v.parts) {
|
|
296
|
-
if (part.type === '
|
|
296
|
+
if (part.type === 'expression') scan(part.expr)
|
|
297
297
|
else if (part.type === 'ternary') {
|
|
298
298
|
scan(part.condition)
|
|
299
299
|
scan(part.whenTrue)
|
|
@@ -311,11 +311,7 @@ export function augmentInheritedPropAccesses(ir: ComponentIR): void {
|
|
|
311
311
|
kind?: string
|
|
312
312
|
expr?: string
|
|
313
313
|
presenceOrUndefined?: boolean
|
|
314
|
-
parts?:
|
|
315
|
-
| { type: 'string'; value: string }
|
|
316
|
-
| { type: 'ternary'; condition: string; whenTrue: string; whenFalse: string }
|
|
317
|
-
| { type: 'lookup'; key: string }
|
|
318
|
-
>
|
|
314
|
+
parts?: IRTemplatePart[]
|
|
319
315
|
}
|
|
320
316
|
// Template-literal attr values (`className={\`… \${props.className ??
|
|
321
317
|
// ''}\`}`) carry their `props.X` reads inside the parts structure,
|
|
@@ -324,7 +320,7 @@ export function augmentInheritedPropAccesses(ir: ComponentIR): void {
|
|
|
324
320
|
// textual field of every part shape.
|
|
325
321
|
if (v?.parts) {
|
|
326
322
|
for (const part of v.parts) {
|
|
327
|
-
if (part.type === '
|
|
323
|
+
if (part.type === 'expression') scan(part.expr)
|
|
328
324
|
else if (part.type === 'ternary') {
|
|
329
325
|
scan(part.condition)
|
|
330
326
|
scan(part.whenTrue)
|
|
@@ -174,10 +174,10 @@ function collectAndPrefixAttrs(
|
|
|
174
174
|
break
|
|
175
175
|
case 'template': {
|
|
176
176
|
prefixIRTemplateParts(attr.value.parts, layerName)
|
|
177
|
-
// Extract constant references from
|
|
177
|
+
// Extract constant references from expression parts
|
|
178
178
|
for (const part of attr.value.parts) {
|
|
179
|
-
if (part.type === '
|
|
180
|
-
collectConstantRefs(part.
|
|
179
|
+
if (part.type === 'expression') {
|
|
180
|
+
collectConstantRefs(part.expr, referencedConstants, constantNames)
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
break
|
|
@@ -211,8 +211,7 @@ function prefixIRTemplateParts(parts: IRTemplatePart[], layerName: string): void
|
|
|
211
211
|
if (part.type === 'ternary') {
|
|
212
212
|
part.whenTrue = prefixClassString(part.whenTrue, layerName)
|
|
213
213
|
part.whenFalse = prefixClassString(part.whenFalse, layerName)
|
|
214
|
-
} else if (part.type === 'string'
|
|
215
|
-
// Only prefix pure static text (no ${expr} references)
|
|
214
|
+
} else if (part.type === 'string') {
|
|
216
215
|
part.value = prefixClassString(part.value, layerName)
|
|
217
216
|
}
|
|
218
217
|
}
|
package/src/debug.ts
CHANGED
|
@@ -2365,6 +2365,7 @@ function attrValueToString(value: AttrValue): string | null {
|
|
|
2365
2365
|
case 'template':
|
|
2366
2366
|
return value.parts
|
|
2367
2367
|
.map(p => {
|
|
2368
|
+
if (p.type === 'expression') return p.expr
|
|
2368
2369
|
if (p.type === 'ternary') return `${p.condition} ${p.whenTrue} ${p.whenFalse}`
|
|
2369
2370
|
if (p.type === 'lookup') return p.key
|
|
2370
2371
|
return ''
|
package/src/expression-parser.ts
CHANGED
|
@@ -1029,7 +1029,10 @@ function convertNode(node: ts.Node, raw: string): ParsedExpr {
|
|
|
1029
1029
|
if (ts.isNumericLiteral(argNode)) {
|
|
1030
1030
|
return { kind: 'member', object, property: argNode.text, computed: true, optional: !!node.questionDotToken }
|
|
1031
1031
|
}
|
|
1032
|
-
|
|
1032
|
+
// A no-substitution template literal key (`` obj[`key`] ``) is the
|
|
1033
|
+
// same static key as `obj['key']` — fold both so every adapter sees
|
|
1034
|
+
// one shape (#3763).
|
|
1035
|
+
if (ts.isStringLiteralLike(argNode)) {
|
|
1033
1036
|
return { kind: 'member', object, property: argNode.text, computed: true, optional: !!node.questionDotToken }
|
|
1034
1037
|
}
|
|
1035
1038
|
// Variable / expression index (`selected()[index]`, `rows[i + 1]`):
|