@barefootjs/jsx 0.39.9 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/adapters/attr-plan.d.ts +1 -20
  2. package/dist/adapters/attr-plan.d.ts.map +1 -1
  3. package/dist/adapters/dsl-template-adapter.d.ts +77 -1
  4. package/dist/adapters/dsl-template-adapter.d.ts.map +1 -1
  5. package/dist/adapters/loop-plan.d.ts +41 -1
  6. package/dist/adapters/loop-plan.d.ts.map +1 -1
  7. package/dist/augment-inherited-props.d.ts.map +1 -1
  8. package/dist/css-layer-prefixer.d.ts.map +1 -1
  9. package/dist/debug.d.ts.map +1 -1
  10. package/dist/index.d.ts +4 -4
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +1965 -1862
  13. package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
  14. package/dist/ir-to-client-js/utils.d.ts +1 -1
  15. package/dist/jsx-to-ir.d.ts.map +1 -1
  16. package/dist/module-exports.d.ts.map +1 -1
  17. package/dist/scope/binding-scope.d.ts +2 -0
  18. package/dist/scope/binding-scope.d.ts.map +1 -1
  19. package/dist/template-parts.d.ts +1 -1
  20. package/dist/template-parts.d.ts.map +1 -1
  21. package/dist/types.d.ts +5 -1
  22. package/dist/types.d.ts.map +1 -1
  23. package/package.json +2 -2
  24. package/src/__tests__/attr-plan.test.ts +1 -14
  25. package/src/__tests__/client-template-escape-soundness.test.ts +17 -4
  26. package/src/__tests__/client-template-static-delimiters.test.ts +57 -0
  27. package/src/__tests__/dsl-template-adapter.test.ts +70 -0
  28. package/src/__tests__/extract-function-params.test.ts +37 -0
  29. package/src/__tests__/issue-2960-multi-root-cond-same-tag.test.ts +18 -0
  30. package/src/__tests__/jsx-text-linebreak-whitespace.test.ts +11 -0
  31. package/src/__tests__/loop-plan.test.ts +66 -1
  32. package/src/__tests__/template-parts-literal-boundary.test.ts +22 -0
  33. package/src/adapters/attr-plan.ts +2 -54
  34. package/src/adapters/dsl-template-adapter.ts +144 -2
  35. package/src/adapters/loop-plan.ts +67 -2
  36. package/src/augment-inherited-props.ts +5 -9
  37. package/src/css-layer-prefixer.ts +4 -5
  38. package/src/debug.ts +1 -0
  39. package/src/index.ts +11 -3
  40. package/src/ir-to-client-js/compute-inlinability.ts +1 -1
  41. package/src/ir-to-client-js/html-template.ts +52 -45
  42. package/src/ir-to-client-js/utils.ts +1 -1
  43. package/src/jsx-to-ir.ts +34 -20
  44. package/src/loop-destructure.ts +4 -1
  45. package/src/module-exports.ts +13 -21
  46. package/src/rich-type-refusal.ts +3 -1
  47. package/src/scope/binding-scope.ts +5 -0
  48. package/src/template-parts.ts +4 -2
  49. package/src/template-position-walk.ts +3 -1
  50. package/src/types.ts +2 -1
@@ -0,0 +1,22 @@
1
+ import { expect, test } from 'bun:test'
2
+ import { templatePartsToJsExpr } from '../template-parts'
3
+ import { parseExpression } from '../expression-parser'
4
+
5
+ for (const text of ['${notCode}', '`', '\\', '\\${notCode}', '"\'\n\r\t', '']) {
6
+ test(`template text stays literal: ${JSON.stringify(text)}`, () => {
7
+ const source = templatePartsToJsExpr([
8
+ { type: 'string', value: text },
9
+ { type: 'expression', expr: 'value', templateExpr: '_p.value', parsed: parseExpression('value') },
10
+ { type: 'string', value: text },
11
+ ])
12
+ expect(new Function('value', `return ${source}`)('}')).toBe(`${text}}${text}`)
13
+ })
14
+ }
15
+
16
+ test('template expression projection rewrites only the expression part', () => {
17
+ const source = templatePartsToJsExpr([
18
+ { type: 'string', value: '${value} ' },
19
+ { type: 'expression', expr: 'value', templateExpr: '_p.value', parsed: parseExpression('value') },
20
+ ], { useTemplate: true })
21
+ expect(new Function('_p', `return ${source}`)({ value: 'tail' })).toBe('${value} tail')
22
+ })
@@ -10,65 +10,13 @@
10
10
  * hash literal.
11
11
  */
12
12
 
13
- import { exprToString, isSupported, parseExpression, type ParsedExpr } from '../expression-parser.ts'
14
- import type { LoweringMatcher } from '../lowering-registry.ts'
13
+ import { exprToString, parseExpression, type ParsedExpr } from '../expression-parser.ts'
15
14
  import { attrValueMayBeNullish, nullableSignalAttrGetter, type NullishAttrContext } from '../nullable-signal-attr.ts'
16
- import type { CompilerError, ConstantInfo, ExpressionAttr, SpreadAttr } from '../types.ts'
15
+ import type { ConstantInfo, ExpressionAttr, SpreadAttr } from '../types.ts'
17
16
  import { isBooleanAttr } from '../html-constants.ts'
18
17
 
19
18
  const IDENTIFIER = /^[A-Za-z_$][\w$]*$/
20
19
 
21
- /**
22
- * Whether an attribute value is a shape no template lowers: a JS object
23
- * literal (`style={{…}}` aside, which the adapter lowers first) or a
24
- * tagged template literal (`cn\`base ${tone()}\``). Returns the refusal, with
25
- * the support gate's reason when it gives one, or `null` when the value
26
- * goes on to {@link planAttrExpression}. The adapter reports BF101 in its own
27
- * words. A value starting with neither shape is never parsed here.
28
- */
29
- export function unsupportedAttrExpression(
30
- expr: string,
31
- loweringMatchers: readonly LoweringMatcher[],
32
- ): { reason: string | undefined } | null {
33
- let probe = expr.trim()
34
- while (probe.startsWith('(')) probe = probe.slice(1).trimStart()
35
- const startsAsObjectLiteral = probe.startsWith('{')
36
- const hasTaggedTemplate = /[A-Za-z_$][\w$]*\s*`/.test(probe)
37
- if (!startsAsObjectLiteral && !hasTaggedTemplate) return null
38
- const parsed = parseExpression(expr.trim())
39
- const support = isSupported(parsed, { loweringMatchers })
40
- if (parsed.kind !== 'unsupported' && support.supported) return null
41
- return { reason: support.reason ?? (parsed.kind === 'unsupported' ? parsed.reason : undefined) }
42
- }
43
-
44
- /**
45
- * The BF101 for an attribute value {@link unsupportedAttrExpression}
46
- * refuses, worded for one adapter (`adapterLabel`, e.g. `Mojo`) and its
47
- * template language (`languageLabel`, e.g. `Embedded Perl`); `null` when the
48
- * value goes on to {@link planAttrExpression}.
49
- */
50
- export function unsupportedAttrExpressionError(
51
- expr: string,
52
- attrName: string,
53
- loweringMatchers: readonly LoweringMatcher[],
54
- componentName: string,
55
- adapterLabel: string,
56
- languageLabel: string,
57
- ): CompilerError | null {
58
- const refusal = unsupportedAttrExpression(expr, loweringMatchers)
59
- if (!refusal) return null
60
- const reasonLine = refusal.reason ? `\n${refusal.reason}` : ''
61
- return {
62
- code: 'BF101',
63
- severity: 'error',
64
- message: `Expression not supported on attribute '${attrName}': ${expr.trim()}${reasonLine}`,
65
- loc: { file: componentName + '.tsx', start: { line: 1, column: 0 }, end: { line: 1, column: 0 } },
66
- suggestion: {
67
- message: `The ${adapterLabel} adapter cannot lower JS object literals or tagged-template-literal expressions into ${languageLabel}. Move the expression into a \`'use client'\` component (so hydration computes it), or expand it into discrete attributes whose values are values the adapter can lower.`,
68
- },
69
- }
70
- }
71
-
72
20
  /**
73
21
  * The emission of an `{expr}` attribute value.
74
22
  *
@@ -14,12 +14,21 @@ import {
14
14
  type NullishAttrContext,
15
15
  } from '../nullable-signal-attr.ts'
16
16
  import { BindingScope } from '../scope/binding-scope.ts'
17
- import { rootPropAliasNames } from '../scope/root-prop-alias.ts'
18
- import type { CompilerError, ComponentIR, IRIfStatement, IRMetadata } from '../types.ts'
17
+ import { rootPropAliasesForLoop, rootPropAliasNames } from '../scope/root-prop-alias.ts'
18
+ import type {
19
+ CompilerError,
20
+ ComponentIR,
21
+ ConstantInfo,
22
+ IRIfStatement,
23
+ IRLoop,
24
+ IRMetadata,
25
+ PreambleValueDeclaration,
26
+ } from '../types.ts'
19
27
  import { collectImportedLoopChildComponentErrors } from './component-tree.ts'
20
28
  import { computedConstContext, type ComputedConstContext } from './computed-const.ts'
21
29
  import { searchParamsLocalNames } from './env-signal.ts'
22
30
  import { BaseAdapter, type AdapterGenerateOptions, type AdapterOutput } from './interface.ts'
31
+ import { type LoopPlan, type LoopPlanContext, planLoop } from './loop-plan.ts'
23
32
  import { collectBooleanTypedProps, collectNullableOptionalProps } from './prop-classes.ts'
24
33
  import { templateNameCollisionErrors } from './template-name-collisions.ts'
25
34
 
@@ -34,6 +43,56 @@ export interface TemplateIdentifierSpelling {
34
43
  label: string
35
44
  }
36
45
 
46
+ /**
47
+ * An adapter's spelling of a loop row's window ({@link DslTemplateAdapter.renderLoopRow}).
48
+ * Each hook runs under the row's scope.
49
+ */
50
+ export interface LoopRowSpelling {
51
+ /** Runs first, before anything in the row renders: the adapter's own per-row bookkeeping. */
52
+ enter?(row: BindingScope, outside: BindingScope): void
53
+ /** A `.map()` preamble declaration as a per-row local (#2447). */
54
+ preamble(declaration: PreambleValueDeclaration): string
55
+ /** The whole-item-conditional `<!--bf-loop-i:KEY-->` anchor for the key expression `key`. */
56
+ keyAnchor(key: string): string
57
+ }
58
+
59
+ /** A loop row rendered under its own scope. */
60
+ export interface LoopRow {
61
+ /** The scope outside the loop, current again once the row is rendered. */
62
+ outside: BindingScope
63
+ /** `outside.enterLoopRow(loop)`: the scope the row rendered under. */
64
+ row: BindingScope
65
+ /** The props the row's bindings newly shadow, each with its root alias (#3314). */
66
+ rootAliases: { name: string; alias: string }[]
67
+ /** One spelled local per preamble declaration, in source order. */
68
+ preamble: string[]
69
+ /** The children, after the key anchor of a whole-item-conditional body. */
70
+ body: string
71
+ }
72
+
73
+ /** The parts of a {@link LoopPlanContext} each adapter spells. */
74
+ export type LoopPlanSpelling<Spelled> = Pick<
75
+ LoopPlanContext<Spelled>,
76
+ 'resolveLiteralConst' | 'callbackLowering' | 'spellStatic'
77
+ >
78
+
79
+ /**
80
+ * An adapter's wording of the refusals a {@link LoopPlan} decides
81
+ * ({@link DslTemplateAdapter.recordLoopPlanRefusals}).
82
+ */
83
+ export interface LoopRefusalSpelling {
84
+ /** The BF104 message for a destructure pattern `param` that no template binds. */
85
+ destructureMessage(param: string): string
86
+ /** The BF104 suggestion. */
87
+ destructureSuggestion: string
88
+ /**
89
+ * BF101 for a source naming a const no template binds: the engine name
90
+ * the shared wording uses ("Jinja", "MiniJinja", …), or the adapter's own
91
+ * recording of it.
92
+ */
93
+ unresolvableConst: string | ((constant: ConstantInfo) => void)
94
+ }
95
+
37
96
  export abstract class DslTemplateAdapter extends BaseAdapter {
38
97
  // ===========================================================================
39
98
  // Per-compile state, set at `generate()` entry
@@ -127,6 +186,12 @@ export abstract class DslTemplateAdapter extends BaseAdapter {
127
186
  protected importAliases: Map<string, string> = new Map()
128
187
  /** Numbers the children captures of a child component that has no slot id. */
129
188
  protected childrenCaptureCounter = 0
189
+ /**
190
+ * True while a loop row's children render ({@link renderLoopRow}): a
191
+ * component inside takes the loop-child naming, and a child prop that
192
+ * needs a per-instance value has none to read.
193
+ */
194
+ protected inLoop = false
130
195
 
131
196
  // ===========================================================================
132
197
  // What each adapter supplies
@@ -158,6 +223,82 @@ export abstract class DslTemplateAdapter extends BaseAdapter {
158
223
  this.scope = outer
159
224
  }
160
225
  }
226
+
227
+ /** {@link planLoop} against the current scope and the component's constants. */
228
+ protected loopPlanFor<Spelled>(loop: IRLoop, spelling: LoopPlanSpelling<Spelled>): LoopPlan<Spelled> {
229
+ return planLoop(loop, { scope: this.scope, localConstants: this.localConstants ?? [], ...spelling })
230
+ }
231
+
232
+ /**
233
+ * Record the refusals `plan` decided for `loop`, at the loop's location:
234
+ * BF104 for a destructure pattern no template binds, then BF101 for a
235
+ * source naming a computed const no template binds (#3473). The plan
236
+ * decides; the adapter only words them.
237
+ */
238
+ protected recordLoopPlanRefusals(loop: IRLoop, plan: LoopPlan<unknown>, spelling: LoopRefusalSpelling): void {
239
+ const loc = loop.loc ?? { file: this.componentName + '.tsx', start: { line: 1, column: 0 }, end: { line: 1, column: 0 } }
240
+ if (plan.destructure === 'unlowerable') {
241
+ this.errors.push({
242
+ code: 'BF104',
243
+ severity: 'error',
244
+ message: spelling.destructureMessage(loop.param),
245
+ loc,
246
+ suggestion: { message: spelling.destructureSuggestion },
247
+ })
248
+ }
249
+ const constant = plan.unresolvableConst
250
+ if (!constant) return
251
+ if (typeof spelling.unresolvableConst === 'function') {
252
+ spelling.unresolvableConst(constant)
253
+ return
254
+ }
255
+ this.errors.push({
256
+ code: 'BF101',
257
+ severity: 'error',
258
+ message: `Loop array \`${constant.name}\` is a const (module- or function-scope) computed value (\`${constant.value}\`) that the ${spelling.unresolvableConst} adapter cannot bind as a template variable — only numeric/string-literal locals inline at their use site.`,
259
+ loc,
260
+ suggestion: {
261
+ message:
262
+ 'Pre-compute the array server-side and pass it as a prop, or mark the loop position as @client-only so it runs in JS on the client.',
263
+ escape: [{ kind: 'prop-precompute' }, { kind: 'client-directive' }],
264
+ },
265
+ })
266
+ }
267
+
268
+ /**
269
+ * A loop row's window (#3473): the row's scope entered around everything
270
+ * that evaluates per row (the preamble locals' initializers, the children,
271
+ * the whole-item-conditional key anchor) and the outer scope restored
272
+ * after. The children render under `inLoop`; the key anchor, after them,
273
+ * does not. The preamble converts first, so a later initializer sees an
274
+ * earlier local, as in the source block.
275
+ *
276
+ * What sits outside the window stays the adapter's: the loop header, the
277
+ * sort, and the filter predicate, which a filter callback's own frame
278
+ * scopes rather than the `.map()` row.
279
+ */
280
+ protected renderLoopRow(loop: IRLoop, spelling: LoopRowSpelling): LoopRow {
281
+ const outside = this.scope
282
+ const row = outside.enterLoopRow(loop)
283
+ return this.renderInScope(row, () => {
284
+ spelling.enter?.(row, outside)
285
+ const preamble = (loop.preamble?.declarations ?? []).map(d => spelling.preamble(d))
286
+ const children = this.renderInLoop(() => this.renderChildren(loop.children))
287
+ const body = loop.bodyIsItemConditional && loop.key ? `${spelling.keyAnchor(loop.key)}\n${children}` : children
288
+ return { outside, row, rootAliases: rootPropAliasesForLoop(outside, row, this.rootPropAliases), preamble, body }
289
+ })
290
+ }
291
+
292
+ private renderInLoop<T>(render: () => T): T {
293
+ const outer = this.inLoop
294
+ this.inLoop = true
295
+ try {
296
+ return render()
297
+ } finally {
298
+ this.inLoop = outer
299
+ }
300
+ }
301
+
161
302
  /** The root `if` statement of a component with conditional returns. */
162
303
  protected abstract renderIfStatement(ifStmt: IRIfStatement): string
163
304
  /** The script registrations the template starts with. */
@@ -236,6 +377,7 @@ export abstract class DslTemplateAdapter extends BaseAdapter {
236
377
  this.computedConsts = computedConstContext(ir.metadata, name => this.scope.isBound(name))
237
378
  this.importAliases = buildImportAliasMap(ir.metadata.imports ?? [])
238
379
  this.childrenCaptureCounter = 0
380
+ this.inLoop = false
239
381
  this.errors = []
240
382
  this.resetAdapterState(ir)
241
383
  }
@@ -8,14 +8,15 @@
8
8
  * captures need an alias, how the filter predicate reads on the row, and
9
9
  * which locals the row binds for its index and its destructure bindings.
10
10
  * {@link planLoop} makes those decisions once, against the scope outside the
11
- * loop. The adapter keeps the spelling:
11
+ * loop; {@link savedLoopBindings} decides, against the row's scope, which
12
+ * row bindings a backend without loop-scoped `set` saves and restores. The adapter keeps the spelling:
12
13
  * the loop header, the row bindings, the diagnostics' wording, and the order
13
14
  * it emits them in.
14
15
  */
15
16
 
16
17
  import { type ParsedExpr, parseExpression, renameFreeIdentifiers, type SortComparator } from '../expression-parser.ts'
17
18
  import { isLowerableLoopDestructure } from '../loop-destructure.ts'
18
- import type { BindingScope } from '../scope/binding-scope.ts'
19
+ import type { BindingScope, ScopeBindingSource } from '../scope/binding-scope.ts'
19
20
  import { resolveStaticLoopSource } from '../static-literal.ts'
20
21
  import type { ConstantInfo, IRLoop, LoopBindingPathSegment } from '../types.ts'
21
22
  import {
@@ -141,6 +142,70 @@ export function spellSortedSource(sort: SortPlan | null, recv: string, spelling:
141
142
  return recv
142
143
  }
143
144
 
145
+ /**
146
+ * The names a loop's for-header binds: the key and the value of an
147
+ * `entries` object iteration, the param of a `keys` / `values` one, and the
148
+ * item var of an array iteration when it is the param itself. A backend
149
+ * whose for-header scopes its targets to the loop passes these to
150
+ * {@link savedLoopBindings} as names it restores itself.
151
+ */
152
+ export function loopHeaderTargets(loop: IRLoop, plan: Pick<LoopPlan<unknown>, 'itemVar'>): string[] {
153
+ if (loop.objectIteration === 'entries') return [loop.index ?? loop.param, loop.param]
154
+ return loop.objectIteration || plan.itemVar === loop.param ? [loop.param] : []
155
+ }
156
+
157
+ /** Where a loop row sits, for {@link savedLoopBindings}. */
158
+ export interface LoopRowScopes {
159
+ /** The scope outside the loop. */
160
+ outside: BindingScope
161
+ /** `outside.enterLoopRow(loop)`. */
162
+ row: BindingScope
163
+ /** The template-level names: signals, memos, props and constants. */
164
+ templateLevelNames: ReadonlySet<string>
165
+ }
166
+
167
+ const SAVE_ORDER: readonly ScopeBindingSource[] = ['item', 'index', 'destructure', 'preamble']
168
+
169
+ /** A row binding a loop saves before its header and restores after its end. */
170
+ export interface SavedLoopBinding {
171
+ name: string
172
+ /** The template variable that holds the outer value across the loop. */
173
+ temporary: string
174
+ }
175
+
176
+ /**
177
+ * The row bindings a backend whose `set` is not loop-scoped (Pebble, Twig,
178
+ * Blade) saves before the loop and restores after it (#3386, #3391): each
179
+ * name the row binds that already means something outside it, an enclosing
180
+ * row's binding or a template-level name. JS scopes the callback's bindings
181
+ * to the row; without the restore the last row's value leaks past the loop.
182
+ * They come in the order a row binds them in a template: the for-header's
183
+ * item, the index local, each destructure local, each preamble local.
184
+ *
185
+ * `skip` names the bindings the backend restores itself: those its
186
+ * for-header scopes to the loop ({@link loopHeaderTargets}), or a root prop
187
+ * it restores through its alias. `temporary` spells the holder of the
188
+ * `ordinal`-th saved name; a holder that collides with a row binding or a
189
+ * template-level name gets `_` appended until it does not.
190
+ */
191
+ export function savedLoopBindings(
192
+ scopes: LoopRowScopes,
193
+ skip: Iterable<string>,
194
+ temporary: (name: string, ordinal: number) => string,
195
+ ): SavedLoopBinding[] {
196
+ const skipped = new Set(skip)
197
+ const rank = (name: string) => SAVE_ORDER.indexOf(scopes.row.lookup(name)?.binding.source ?? 'param')
198
+ return scopes.row
199
+ .innermostNames()
200
+ .filter((name) => !skipped.has(name) && (scopes.templateLevelNames.has(name) || scopes.outside.isBound(name)))
201
+ .sort((a, b) => rank(a) - rank(b))
202
+ .map((name, ordinal) => {
203
+ let held = temporary(name, ordinal)
204
+ while (scopes.row.isBound(held) || scopes.templateLevelNames.has(held)) held += '_'
205
+ return { name, temporary: held }
206
+ })
207
+ }
208
+
144
209
  /**
145
210
  * The `.filter()` predicate a `.filter().map()` loop tests on each row: the
146
211
  * predicate with the names it reads renamed for the row, or the refusal of a
@@ -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?: Array<{ type: string } & Record<string, string>> }
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 === 'string') scan(part.value)
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?: Array<
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 === 'string') scan(part.value)
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 ${expr} in string parts
177
+ // Extract constant references from expression parts
178
178
  for (const part of attr.value.parts) {
179
- if (part.type === 'string' && part.value.includes('${')) {
180
- collectConstantRefs(part.value, referencedConstants, constantNames)
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' && !part.value.includes('${')) {
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/index.ts CHANGED
@@ -108,7 +108,13 @@ export { generateModuleExports, extractFunctionParams, formatParamWithType, find
108
108
  // Adapters
109
109
  export { BaseAdapter } from './adapters/interface.ts'
110
110
  export { DslTemplateAdapter } from './adapters/dsl-template-adapter.ts'
111
- export type { TemplateIdentifierSpelling } from './adapters/dsl-template-adapter.ts'
111
+ export type {
112
+ LoopPlanSpelling,
113
+ LoopRefusalSpelling,
114
+ LoopRow,
115
+ LoopRowSpelling,
116
+ TemplateIdentifierSpelling,
117
+ } from './adapters/dsl-template-adapter.ts'
112
118
  // Dependency-free adapter for tooling that only needs client JS (e.g. the
113
119
  // profiler scenario driver) — the client output is adapter-independent.
114
120
  export { TestAdapter, testAdapter } from './adapters/test-adapter.ts'
@@ -183,9 +189,9 @@ export type {
183
189
  export { derivesScopeFromSlot } from './adapters/child-scope.ts'
184
190
  export { childTemplateName, componentPropKey, isEmptyComponentProps, planComponentProps, propsSpreadParam, resolveComponentPropKeys, spellComponentProps } from './adapters/component-props.ts'
185
191
  export type { ComponentPropEntry, ComponentPropSegment, ComponentPropSpelling, ComponentPropsOptions, ComponentPropsParam, EarlierComponentProps, ResolvedComponentProp, SpelledComponentPropSegment } from './adapters/component-props.ts'
186
- export { parseUndefinedAlternateTernary, planAttrExpression, planSpreadAttr, unsupportedAttrExpression, unsupportedAttrExpressionError } from './adapters/attr-plan.ts'
192
+ export { parseUndefinedAlternateTernary, planAttrExpression, planSpreadAttr, } from './adapters/attr-plan.ts'
187
193
  export type { AttrExpressionPlan, AttrPlanContext, SpreadAttrPlan, SpreadPlanContext, UndefinedAlternateTernary } from './adapters/attr-plan.ts'
188
- export { planLoop, spellDestructureLocals, spellFilteredRow, spellSortedSource } from './adapters/loop-plan.ts'
194
+ export { loopHeaderTargets, planLoop, savedLoopBindings, spellDestructureLocals, spellFilteredRow, spellSortedSource } from './adapters/loop-plan.ts'
189
195
  export { computedConstContext, inlineComputedConstAttr, inlineComputedConsts } from './adapters/computed-const.ts'
190
196
  export type { ComputedConstContext } from './adapters/computed-const.ts'
191
197
  export type {
@@ -196,7 +202,9 @@ export type {
196
202
  LoopFilterSpelling,
197
203
  LoopPlan,
198
204
  LoopPlanContext,
205
+ LoopRowScopes,
199
206
  LoopSortSpelling,
207
+ SavedLoopBinding,
200
208
  } from './adapters/loop-plan.ts'
201
209
  export { evaluateStaticLiteral, isFullyStaticLiteral, resolveStaticLoopSource } from './static-literal.ts'
202
210
  export {
@@ -636,7 +636,7 @@ function collectTemplateRiskyNames(irRoot: IRNode): Set<string> {
636
636
  // Mirror the emitter's input source for each template position
637
637
  // (`transformExpr` in html-template.ts uses `templateExpr ?? expr`).
638
638
  // The `template*` rewrites — bare prop refs to `_p.X`, plus
639
- // `IRTemplateLiteral` parts' `templateValue`/`templateCondition`/
639
+ // `IRTemplateLiteral` parts' `templateExpr`/`templateCondition`/
640
640
  // `templateKey` — are what `transformExpr` actually substitutes
641
641
  // through, so the diagnostic gate needs to look at the same string.
642
642
  // Reading the raw form would drift from emission and could miss /