@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.
Files changed (192) hide show
  1. package/dist/adapters/attr-plan.d.ts +8 -1
  2. package/dist/adapters/attr-plan.d.ts.map +1 -1
  3. package/dist/adapters/callback-method.d.ts +44 -0
  4. package/dist/adapters/callback-method.d.ts.map +1 -1
  5. package/dist/adapters/component-props.d.ts +80 -13
  6. package/dist/adapters/component-props.d.ts.map +1 -1
  7. package/dist/adapters/computed-const.d.ts +52 -0
  8. package/dist/adapters/computed-const.d.ts.map +1 -0
  9. package/dist/adapters/dangerous-inner-html.d.ts +10 -0
  10. package/dist/adapters/dangerous-inner-html.d.ts.map +1 -1
  11. package/dist/adapters/dsl-template-adapter.d.ts +151 -0
  12. package/dist/adapters/dsl-template-adapter.d.ts.map +1 -0
  13. package/dist/adapters/element-shell.d.ts +44 -0
  14. package/dist/adapters/element-shell.d.ts.map +1 -0
  15. package/dist/adapters/interface.d.ts +2 -0
  16. package/dist/adapters/interface.d.ts.map +1 -1
  17. package/dist/adapters/jsx-adapter.d.ts +4 -0
  18. package/dist/adapters/jsx-adapter.d.ts.map +1 -1
  19. package/dist/adapters/literal-value.d.ts +2 -2
  20. package/dist/adapters/literal-value.d.ts.map +1 -1
  21. package/dist/adapters/parsed-expr-emitter.d.ts +27 -0
  22. package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
  23. package/dist/adapters/style-object.d.ts +33 -0
  24. package/dist/adapters/style-object.d.ts.map +1 -0
  25. package/dist/analyzer.d.ts.map +1 -1
  26. package/dist/augment-inherited-props.d.ts +7 -0
  27. package/dist/augment-inherited-props.d.ts.map +1 -1
  28. package/dist/children-nullish.d.ts +22 -0
  29. package/dist/children-nullish.d.ts.map +1 -0
  30. package/dist/errors.d.ts +1 -0
  31. package/dist/errors.d.ts.map +1 -1
  32. package/dist/expression-parser.d.ts +9 -19
  33. package/dist/expression-parser.d.ts.map +1 -1
  34. package/dist/fold-render-reassignments.d.ts +43 -0
  35. package/dist/fold-render-reassignments.d.ts.map +1 -0
  36. package/dist/free-refs.d.ts +15 -0
  37. package/dist/free-refs.d.ts.map +1 -1
  38. package/dist/index.d.ts +21 -14
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +24620 -23233
  41. package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
  42. package/dist/ir-to-client-js/control-flow/plan/event-collision.d.ts +2 -1
  43. package/dist/ir-to-client-js/control-flow/plan/event-collision.d.ts.map +1 -1
  44. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts +2 -2
  45. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts.map +1 -1
  46. package/dist/ir-to-client-js/control-flow/stringify/event-delegation.d.ts.map +1 -1
  47. package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts +10 -9
  48. package/dist/ir-to-client-js/control-flow/stringify/event-listener.d.ts.map +1 -1
  49. package/dist/ir-to-client-js/csr-substitute.d.ts +0 -13
  50. package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
  51. package/dist/ir-to-client-js/emit-reactive.d.ts +1 -1
  52. package/dist/ir-to-client-js/emit-reactive.d.ts.map +1 -1
  53. package/dist/ir-to-client-js/emit-registration.d.ts +10 -8
  54. package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
  55. package/dist/ir-to-client-js/generate-init.d.ts.map +1 -1
  56. package/dist/ir-to-client-js/html-template.d.ts +9 -19
  57. package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
  58. package/dist/ir-to-client-js/identifiers.d.ts +6 -8
  59. package/dist/ir-to-client-js/identifiers.d.ts.map +1 -1
  60. package/dist/ir-to-client-js/imports.d.ts +23 -2
  61. package/dist/ir-to-client-js/imports.d.ts.map +1 -1
  62. package/dist/ir-to-client-js/index.d.ts.map +1 -1
  63. package/dist/ir-to-client-js/phases/props-extraction.d.ts +3 -2
  64. package/dist/ir-to-client-js/phases/props-extraction.d.ts.map +1 -1
  65. package/dist/ir-to-client-js/plan/declaration-emit.d.ts +5 -0
  66. package/dist/ir-to-client-js/plan/declaration-emit.d.ts.map +1 -1
  67. package/dist/ir-to-client-js/prop-handling.d.ts +11 -12
  68. package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
  69. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts +1 -1
  70. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
  71. package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
  72. package/dist/ir-to-client-js/rewrite-destructured-props.d.ts +1 -1
  73. package/dist/ir-to-client-js/rewrite-destructured-props.d.ts.map +1 -1
  74. package/dist/ir-to-client-js/safe-html.d.ts +20 -2
  75. package/dist/ir-to-client-js/safe-html.d.ts.map +1 -1
  76. package/dist/ir-to-client-js/types.d.ts +3 -3
  77. package/dist/ir-to-client-js/types.d.ts.map +1 -1
  78. package/dist/ir-to-client-js/utils.d.ts +15 -11
  79. package/dist/ir-to-client-js/utils.d.ts.map +1 -1
  80. package/dist/jsx-to-ir.d.ts.map +1 -1
  81. package/dist/nullable-signal-attr.d.ts +43 -12
  82. package/dist/nullable-signal-attr.d.ts.map +1 -1
  83. package/dist/prop-rewrite.d.ts +18 -0
  84. package/dist/prop-rewrite.d.ts.map +1 -1
  85. package/dist/props-binding.d.ts +43 -6
  86. package/dist/props-binding.d.ts.map +1 -1
  87. package/dist/relocate.d.ts +16 -0
  88. package/dist/relocate.d.ts.map +1 -1
  89. package/dist/scanner/js-scanner.d.ts.map +1 -1
  90. package/dist/scanner/js-scanner.js +30 -2
  91. package/dist/signal-prop-name-collision.d.ts +6 -5
  92. package/dist/signal-prop-name-collision.d.ts.map +1 -1
  93. package/dist/ssr-defaults.d.ts +28 -0
  94. package/dist/ssr-defaults.d.ts.map +1 -1
  95. package/dist/ssr-seed-plan.d.ts +37 -18
  96. package/dist/ssr-seed-plan.d.ts.map +1 -1
  97. package/dist/types.d.ts +162 -20
  98. package/dist/types.d.ts.map +1 -1
  99. package/dist/value-references.d.ts +21 -0
  100. package/dist/value-references.d.ts.map +1 -1
  101. package/package.json +2 -2
  102. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +18 -18
  103. package/src/__tests__/adapter-output.test.ts +5 -3
  104. package/src/__tests__/analyzer.test.ts +33 -0
  105. package/src/__tests__/arithmetic-lowering.test.ts +44 -0
  106. package/src/__tests__/block-memo-type.test.ts +51 -0
  107. package/src/__tests__/callback-method.test.ts +75 -0
  108. package/src/__tests__/children-read.test.ts +226 -0
  109. package/src/__tests__/client-only-date-lowering.test.ts +2 -2
  110. package/src/__tests__/client-template-escape-soundness.test.ts +31 -1
  111. package/src/__tests__/component-props.test.ts +68 -1
  112. package/src/__tests__/computed-const.test.ts +101 -0
  113. package/src/__tests__/constant-inlining-tree.test.ts +136 -0
  114. package/src/__tests__/destructure-default-reads-earlier-param.test.ts +138 -0
  115. package/src/__tests__/dsl-template-adapter.test.ts +173 -0
  116. package/src/__tests__/element-shell.test.ts +78 -0
  117. package/src/__tests__/event-handler-verbatim.test.ts +73 -0
  118. package/src/__tests__/expression-parser.test.ts +1 -44
  119. package/src/__tests__/fold-render-reassignments.test.ts +96 -0
  120. package/src/__tests__/inlinable-local-method-call.test.ts +81 -0
  121. package/src/__tests__/memo-body-expr.test.ts +120 -0
  122. package/src/__tests__/nullable-signal-attr.test.ts +67 -3
  123. package/src/__tests__/prop-handling.test.ts +35 -16
  124. package/src/__tests__/props-alias-const.test.ts +65 -0
  125. package/src/__tests__/reference-graph-identifiers.test.ts +161 -0
  126. package/src/__tests__/runtime-import-detection.test.ts +134 -0
  127. package/src/__tests__/signal-prop-name-collision.test.ts +30 -0
  128. package/src/__tests__/signal-prop-seed.test.ts +90 -0
  129. package/src/__tests__/ssr-defaults.test.ts +19 -1
  130. package/src/__tests__/ssr-seed-plan.test.ts +173 -1
  131. package/src/__tests__/static-template-reachability.test.ts +137 -0
  132. package/src/__tests__/style-object-plan.test.ts +54 -0
  133. package/src/__tests__/zero-param-helper-inline.test.ts +57 -0
  134. package/src/adapters/attr-plan.ts +29 -1
  135. package/src/adapters/callback-method.ts +85 -0
  136. package/src/adapters/component-props.ts +130 -12
  137. package/src/adapters/computed-const.ts +185 -0
  138. package/src/adapters/dangerous-inner-html.ts +33 -0
  139. package/src/adapters/dsl-template-adapter.ts +248 -0
  140. package/src/adapters/element-shell.ts +160 -0
  141. package/src/adapters/interface.ts +8 -0
  142. package/src/adapters/jsx-adapter.ts +12 -6
  143. package/src/adapters/literal-value.ts +2 -2
  144. package/src/adapters/parsed-expr-emitter.ts +34 -0
  145. package/src/adapters/style-object.ts +61 -0
  146. package/src/analyzer.ts +382 -94
  147. package/src/augment-inherited-props.ts +12 -0
  148. package/src/children-nullish.ts +33 -0
  149. package/src/debug.ts +2 -2
  150. package/src/errors.ts +12 -0
  151. package/src/expression-parser.ts +56 -53
  152. package/src/fold-render-reassignments.ts +314 -0
  153. package/src/free-refs.ts +77 -17
  154. package/src/index.ts +27 -10
  155. package/src/ir-to-client-js/compute-inlinability.ts +122 -19
  156. package/src/ir-to-client-js/control-flow/plan/event-collision.ts +2 -1
  157. package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -2
  158. package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +3 -2
  159. package/src/ir-to-client-js/control-flow/stringify/event-listener.ts +13 -12
  160. package/src/ir-to-client-js/csr-substitute.ts +25 -37
  161. package/src/ir-to-client-js/emit-reactive.ts +2 -2
  162. package/src/ir-to-client-js/emit-registration.ts +31 -59
  163. package/src/ir-to-client-js/generate-init.ts +17 -1
  164. package/src/ir-to-client-js/html-template.ts +56 -120
  165. package/src/ir-to-client-js/identifiers.ts +75 -24
  166. package/src/ir-to-client-js/imports.ts +56 -19
  167. package/src/ir-to-client-js/index.ts +5 -3
  168. package/src/ir-to-client-js/init-declarations.ts +1 -1
  169. package/src/ir-to-client-js/phases/event-handlers.ts +2 -2
  170. package/src/ir-to-client-js/phases/props-extraction.ts +16 -15
  171. package/src/ir-to-client-js/plan/build-declaration-emit.ts +26 -52
  172. package/src/ir-to-client-js/plan/declaration-emit.ts +5 -0
  173. package/src/ir-to-client-js/prop-handling.ts +13 -54
  174. package/src/ir-to-client-js/prune-unused-prop-extractions.ts +7 -4
  175. package/src/ir-to-client-js/reactivity.ts +2 -2
  176. package/src/ir-to-client-js/rewrite-destructured-props.ts +27 -9
  177. package/src/ir-to-client-js/safe-html.ts +29 -35
  178. package/src/ir-to-client-js/stringify/declaration-emit.ts +1 -1
  179. package/src/ir-to-client-js/types.ts +3 -2
  180. package/src/ir-to-client-js/utils.ts +13 -26
  181. package/src/jsx-to-ir.ts +318 -130
  182. package/src/nullable-signal-attr.ts +156 -37
  183. package/src/prop-rewrite.ts +41 -0
  184. package/src/props-binding.ts +117 -7
  185. package/src/relocate.ts +40 -8
  186. package/src/scanner/__tests__/js-scanner.test.ts +37 -0
  187. package/src/scanner/js-scanner.ts +64 -4
  188. package/src/signal-prop-name-collision.ts +50 -24
  189. package/src/ssr-defaults.ts +47 -20
  190. package/src/ssr-seed-plan.ts +121 -29
  191. package/src/types.ts +165 -21
  192. package/src/value-references.ts +132 -0
@@ -46,9 +46,95 @@ export function isNullableSignal(signal: SignalInfo): boolean {
46
46
  return signal.type.kind === 'unknown' && isNullishLiteral(signal.parsed)
47
47
  }
48
48
 
49
- /** Getter names of the component's signals whose SSR value can be nullish. */
49
+ /**
50
+ * Getter names of the component's signals whose SSR value can be nullish:
51
+ * a nullable signal (`isNullableSignal`), or one whose seed can evaluate to
52
+ * an absent optional prop (`createSignal(props.label)`,
53
+ * `createSignal(wide ? props.label : 'narrow')`, #3567). The seed is read in
54
+ * the form the SSR seed plan resolved it to, so a hop through a
55
+ * component-scope const counts too.
56
+ */
50
57
  export function collectNullableSignalGetters(ir: ComponentIR): Set<string> {
51
- return new Set((ir.metadata.signals ?? []).filter(isNullableSignal).map(s => s.getter))
58
+ const absentReads = collectAbsentPropSeedReads(ir)
59
+ return new Set(
60
+ (ir.metadata.signals ?? []).filter(s => isNullableSignal(s) || absentReads.has(s.getter)).map(s => s.getter),
61
+ )
62
+ }
63
+
64
+ /**
65
+ * For each signal whose seed can evaluate to an absent optional prop, the
66
+ * props (by param name) it can read whole (#3567). The seed is read in the
67
+ * form the SSR seed plan resolved it to. A backend that types a prop by
68
+ * value (Go) flips each of these props to a nillable field so the absence
69
+ * survives into the signal.
70
+ */
71
+ export function collectAbsentPropSeedReads(ir: ComponentIR): Map<string, Set<string>> {
72
+ const nullableProps = collectNullablePropReads(ir)
73
+ const out = new Map<string, Set<string>>()
74
+ if (nullableProps.size === 0) return out
75
+ const resolved = new Map<string, ParsedExpr>()
76
+ for (const step of ir.metadata.ssrSeedPlan?.steps ?? []) {
77
+ if (step.kind === 'derived' && step.origin === 'signal') resolved.set(step.name, step.parsed)
78
+ }
79
+ for (const s of ir.metadata.signals ?? []) {
80
+ const reads = new Set<string>()
81
+ collectSeedPropReads(resolved.get(s.getter) ?? s.parsed, nullableProps, reads)
82
+ if (reads.size > 0) out.set(s.getter, reads)
83
+ }
84
+ return out
85
+ }
86
+
87
+ /**
88
+ * Reads of a prop that can be absent at SSR time (optional or typed with
89
+ * `undefined` / `null`, no default, not a rest param): the name a read
90
+ * uses (the binding name, or `<propsObjectName>.<key>` for a member read)
91
+ * mapped to the param name.
92
+ */
93
+ function collectNullablePropReads(ir: ComponentIR): ReadonlyMap<string, string> {
94
+ const names = new Map<string, string>()
95
+ const objectName = ir.metadata.propsObjectName
96
+ for (const p of ir.metadata.propsParams) {
97
+ if (p.isRest || p.defaultValue !== undefined) continue
98
+ if (!p.optional && !(p.type && admitsNullish(p.type))) continue
99
+ names.set(objectName ? `${objectName}.${p.sourceName ?? p.name}` : p.name, p.name)
100
+ }
101
+ return names
102
+ }
103
+
104
+ /**
105
+ * Add to `out` the params of `nullableProps` a seed's value can be read
106
+ * whole from: a bare read, a ternary branch, the right operand of `??` /
107
+ * `||`, or either operand of `&&`. A call, a member read past the prop, or
108
+ * any other shape produces its own value, so it does not count.
109
+ */
110
+ function collectSeedPropReads(
111
+ expr: ParsedExpr | undefined,
112
+ nullableProps: ReadonlyMap<string, string>,
113
+ out: Set<string>,
114
+ ): void {
115
+ if (!expr) return
116
+ const add = (key: string): void => {
117
+ const param = nullableProps.get(key)
118
+ if (param !== undefined) out.add(param)
119
+ }
120
+ switch (expr.kind) {
121
+ case 'identifier':
122
+ add(expr.name)
123
+ return
124
+ case 'member':
125
+ if (!expr.computed && expr.object.kind === 'identifier') add(`${expr.object.name}.${expr.property}`)
126
+ return
127
+ case 'conditional':
128
+ collectSeedPropReads(expr.consequent, nullableProps, out)
129
+ collectSeedPropReads(expr.alternate, nullableProps, out)
130
+ return
131
+ case 'logical':
132
+ if (expr.op === '&&') collectSeedPropReads(expr.left, nullableProps, out)
133
+ collectSeedPropReads(expr.right, nullableProps, out)
134
+ return
135
+ default:
136
+ return
137
+ }
52
138
  }
53
139
 
54
140
  /**
@@ -91,10 +177,23 @@ export interface NullishAttrContext {
91
177
  readonly memos: ReadonlyMap<string, MemoInfo>
92
178
  /** Props declared as a number that may be `null` or absent (`n: number |
93
179
  * null`, `n?: number`), by the name a read uses: the binding name, and
94
- * `<propsObjectName>.<key>` for a member read (#3474). */
95
- readonly nullableNumberProps?: ReadonlySet<string>
180
+ * `<propsObjectName>.<key>` for a member read (#3474), mapped to what the
181
+ * engine's nil stands for there (`NullableNumberPropNil`, #3533). */
182
+ readonly nullableNumberProps?: ReadonlyMap<string, NullableNumberPropNil>
96
183
  }
97
184
 
185
+ /**
186
+ * What a nullable number prop's nil stands for at SSR (#3533). JS reads an
187
+ * absent prop as `undefined` (`NaN` in arithmetic) and a `null` one as `0`,
188
+ * while a template engine holds both as the same nil, so the declared type
189
+ * decides. A prop whose type admits `null` (`n: number | null`) reads its
190
+ * nil as `null`. A prop that can only be absent (`n?: number`,
191
+ * `n: number | undefined`) reads it as `undefined`; a present value, `0`
192
+ * included, is unaffected. A prop that admits both (`n?: number | null`)
193
+ * keeps the `null` reading: its nil can be either.
194
+ */
195
+ export type NullableNumberPropNil = 'null' | 'undefined'
196
+
98
197
  export function collectNullishAttrContext(ir: ComponentIR): NullishAttrContext {
99
198
  const signals = ir.metadata.signals ?? []
100
199
  return {
@@ -110,23 +209,29 @@ export function collectNullishAttrContext(ir: ComponentIR): NullishAttrContext {
110
209
  }
111
210
  }
112
211
 
113
- /** Whether `type` is a number that admits `null` / `undefined` and no other family. */
114
- function isNullableNumberType(type: TypeInfo | undefined, optional: boolean): boolean {
115
- if (!type) return false
212
+ /**
213
+ * What the nil of a number prop that admits `null` / `undefined` and no other
214
+ * family stands for (`NullableNumberPropNil`); `null` for any other type.
215
+ */
216
+ function nullableNumberPropNil(type: TypeInfo | undefined, optional: boolean): NullableNumberPropNil | null {
217
+ if (!type) return null
116
218
  const members = type.kind === 'union' ? (type.unionTypes ?? []) : [type]
117
219
  const families = new Set(members.map(m => (m.kind === 'primitive' ? m.primitive : m.kind)))
118
- const nullable = optional || families.has('null') || families.has('undefined')
220
+ const admitsNull = families.has('null')
221
+ const nullable = optional || admitsNull || families.has('undefined')
119
222
  families.delete('null')
120
223
  families.delete('undefined')
121
- return nullable && families.size === 1 && families.has('number')
224
+ if (!nullable || families.size !== 1 || !families.has('number')) return null
225
+ return admitsNull ? 'null' : 'undefined'
122
226
  }
123
227
 
124
- function collectNullableNumberProps(ir: ComponentIR): ReadonlySet<string> {
125
- const names = new Set<string>()
228
+ function collectNullableNumberProps(ir: ComponentIR): ReadonlyMap<string, NullableNumberPropNil> {
229
+ const names = new Map<string, NullableNumberPropNil>()
126
230
  const objectName = ir.metadata.propsObjectName
127
231
  for (const p of ir.metadata.propsParams) {
128
- if (p.isRest || p.defaultValue !== undefined || !isNullableNumberType(p.type, p.optional)) continue
129
- names.add(objectName ? `${objectName}.${p.sourceName ?? p.name}` : p.name)
232
+ if (p.isRest || p.defaultValue !== undefined) continue
233
+ const nil = nullableNumberPropNil(p.type, p.optional)
234
+ if (nil !== null) names.set(objectName ? `${objectName}.${p.sourceName ?? p.name}` : p.name, nil)
130
235
  }
131
236
  return names
132
237
  }
@@ -140,8 +245,9 @@ function collectNullableNumberProps(ir: ComponentIR): ReadonlySet<string> {
140
245
  *
141
246
  * - a read of a nullable signal or of a memo whose type or body can be
142
247
  * nullish (`label()` with `label = createMemo(() => s())`);
143
- * - an optional member read (`user()?.name`), or a member read of a value
144
- * that can itself be nullish;
248
+ * - an optional member read (`user()?.name`), an index or computed-key read
249
+ * (`pair[1]`, `row[key]`), or a member read of a value that can itself be
250
+ * nullish;
145
251
  * - a ternary branch, or an `??` / `||` / `&&` operand the result can be;
146
252
  * - a literal `undefined` / `null`.
147
253
  *
@@ -178,10 +284,12 @@ export function attrValueMayBeNullish(
178
284
  visiting.delete(getter)
179
285
  return result
180
286
  }
287
+ // A computed key or an index (`pair[1]`, `row[key]`) reads `undefined`
288
+ // when it is out of range or absent (#3497).
181
289
  case 'member':
182
- return expr.optional || walk(expr.object, shadowed)
290
+ return expr.optional || expr.computed || walk(expr.object, shadowed)
183
291
  case 'index-access':
184
- return walk(expr.object, shadowed)
292
+ return true
185
293
  case 'conditional':
186
294
  return walk(expr.consequent, shadowed) || walk(expr.alternate, shadowed)
187
295
  case 'logical':
@@ -227,17 +335,25 @@ export function arithmeticOperandIsUndefined(
227
335
  return arithmeticOperandSeed(parsed, ctx, isShadowed) === 'undefined'
228
336
  }
229
337
 
338
+ /**
339
+ * What an arithmetic operand's SSR nil stands for: `'null'` / `'undefined'`
340
+ * when the operand is that value (a nullable number prop's `null` reading
341
+ * included), `'absent'` when it is a number prop that may be absent
342
+ * (`n?: number`), whose nil is `undefined` but which may hold a number.
343
+ */
344
+ type OperandSeed = 'null' | 'undefined' | 'absent' | null
345
+
230
346
  function arithmeticOperandSeed(
231
347
  parsed: ParsedExpr | undefined,
232
348
  ctx: NullishAttrContext,
233
349
  isShadowed: (name: string) => boolean,
234
- ): 'null' | 'undefined' | null {
350
+ ): OperandSeed {
235
351
  const visiting = new Set<string>()
236
- const walk = (expr: ParsedExpr, shadowed: (name: string) => boolean): 'null' | 'undefined' | null => {
352
+ const walk = (expr: ParsedExpr, shadowed: (name: string) => boolean): OperandSeed => {
237
353
  if (expr.kind === 'literal') return expr.literalType === 'null' ? 'null' : null
238
354
  if (expr.kind === 'identifier' && expr.name === 'undefined' && !shadowed('undefined')) return 'undefined'
239
355
  const prop = nullableNumberPropRead(expr, ctx, shadowed)
240
- if (prop) return 'null'
356
+ if (prop !== null) return prop === 'undefined' ? 'absent' : 'null'
241
357
  const getter = expr.kind === 'identifier' ? expr.name : bareGetterCallName(expr)
242
358
  if (getter === null || shadowed(getter)) return null
243
359
  if (ctx.nullSeededSignals?.has(getter)) return 'null'
@@ -253,22 +369,20 @@ function arithmeticOperandSeed(
253
369
  }
254
370
 
255
371
  /**
256
- * A read of a prop declared as a nullable number. Its SSR value may be
257
- * `null` or absent; it is coerced like a `null` operand. JS reads an absent
258
- * prop as `undefined` (`NaN` in arithmetic), which a template engine cannot
259
- * tell from `null` (the `omitted-optional-number-arithmetic` limitation).
372
+ * What the nil of a read of a prop declared as a nullable number stands for
373
+ * (`NullableNumberPropNil`), or `null` when the read is not such a prop.
260
374
  */
261
375
  function nullableNumberPropRead(
262
376
  expr: ParsedExpr,
263
377
  ctx: NullishAttrContext,
264
378
  shadowed: (name: string) => boolean,
265
- ): boolean {
266
- if (!ctx.nullableNumberProps?.size) return false
267
- if (expr.kind === 'identifier') return !shadowed(expr.name) && ctx.nullableNumberProps.has(expr.name)
379
+ ): NullableNumberPropNil | null {
380
+ if (!ctx.nullableNumberProps?.size) return null
381
+ if (expr.kind === 'identifier') return shadowed(expr.name) ? null : (ctx.nullableNumberProps.get(expr.name) ?? null)
268
382
  if (expr.kind === 'member' && !expr.computed && expr.object.kind === 'identifier' && !shadowed(expr.object.name)) {
269
- return ctx.nullableNumberProps.has(`${expr.object.name}.${expr.property}`)
383
+ return ctx.nullableNumberProps.get(`${expr.object.name}.${expr.property}`) ?? null
270
384
  }
271
- return false
385
+ return null
272
386
  }
273
387
 
274
388
  /**
@@ -282,18 +396,21 @@ export const NULL_COERCING_ARITHMETIC_OPS: ReadonlySet<string> = new Set(['-', '
282
396
 
283
397
  /** How a DSL adapter coerces an arithmetic operand (#3474): `'null'` reads a
284
398
  * nil as `0` (JS `ToNumber(null)`), `'undefined'` reads it as `NaN`
285
- * (`ToNumber(undefined)`), `null` leaves the operand as is. */
399
+ * (`ToNumber(undefined)`), `null` leaves the operand as is. Either coercion
400
+ * leaves a non-nil operand's value as it is. */
286
401
  export type ArithmeticCoercion = 'null' | 'undefined' | null
287
402
 
288
403
  /**
289
404
  * The one decision behind every DSL adapter's arithmetic over a nullish
290
405
  * operand (#3474). An operand known to be `null` / `undefined`
291
- * (`arithmeticOperandIsNull` / `arithmeticOperandIsUndefined`, or a nullable
292
- * number prop) is coerced under the operators JS applies `ToNumber` to
293
- * ({@link NULL_COERCING_ARITHMETIC_OPS}), and under `+` when the other
294
- * operand is a number literal, where `+` cannot concatenate. Each adapter
295
- * only spells the coercion; one whose engine already reads nil as `0`
296
- * spells `'null'` as the operand itself.
406
+ * (`arithmeticOperandIsNull` / `arithmeticOperandIsUndefined`), or a
407
+ * nullable number prop, whose nil reads as its type says
408
+ * (`NullableNumberPropNil`, #3533), is coerced under the operators JS
409
+ * applies `ToNumber` to ({@link NULL_COERCING_ARITHMETIC_OPS}), and under
410
+ * `+` when the other operand is a number literal, where `+` cannot
411
+ * concatenate. Unary minus applies `ToNumber` too: it passes `'-'` with no
412
+ * `other`. Each adapter only spells the coercion; one whose engine already
413
+ * reads nil as `0` spells `'null'` as the operand itself.
297
414
  */
298
415
  export function arithmeticOperandCoercion(
299
416
  op: string,
@@ -303,7 +420,9 @@ export function arithmeticOperandCoercion(
303
420
  isShadowed: (name: string) => boolean = () => false,
304
421
  ): ArithmeticCoercion {
305
422
  const numeric = NULL_COERCING_ARITHMETIC_OPS.has(op) || (op === '+' && isNumberLiteral(other))
306
- return numeric ? arithmeticOperandSeed(operand, ctx, isShadowed) : null
423
+ if (!numeric) return null
424
+ const seed = arithmeticOperandSeed(operand, ctx, isShadowed)
425
+ return seed === 'absent' ? 'undefined' : seed
307
426
  }
308
427
 
309
428
  function isNumberLiteral(expr: ParsedExpr | undefined): boolean {
@@ -213,6 +213,47 @@ export function rewriteScopedValueRefs(
213
213
  return result
214
214
  }
215
215
 
216
+ /** A piece of `splitScopedValueRefs`'s result: text between references, or one reference. */
217
+ export type ScopedValueRefPiece = { kind: 'text'; text: string } | { kind: 'ref'; name: string }
218
+
219
+ /**
220
+ * The structured twin of `rewriteScopedValueRefs`: the same scope-aware walk,
221
+ * but instead of splicing a replacement it splits `text` at each value
222
+ * reference to a name in `names`, so a later stage renders each reference by
223
+ * its own rule without touching the text again (#3531). A shorthand property
224
+ * (`{ off }`) keeps its key as text (`off: `) before the reference. Returns
225
+ * null when `text` doesn't parse as an expression, and an empty reference set
226
+ * leaves one `text` piece.
227
+ */
228
+ export function splitScopedValueRefs(text: string, names: ReadonlySet<string>): ScopedValueRefPiece[] | null {
229
+ const prefix = '('
230
+ const sf = ts.createSourceFile('__bf_scoped_split.ts', `${prefix}${text}\n)`, ts.ScriptTarget.Latest, true)
231
+ const parseDiagnostics = (sf as unknown as { parseDiagnostics?: unknown[] }).parseDiagnostics
232
+ if (parseDiagnostics && parseDiagnostics.length > 0) return null
233
+
234
+ const refs: Array<{ start: number; end: number; name: string; key?: string }> = []
235
+ walkWithScope(sf, (n, parent, shadowed) => {
236
+ if (shadowed || !names.has(n.text)) return
237
+ if (isNonValuePosition(n, parent)) return
238
+ const start = n.getStart(sf) - prefix.length
239
+ const end = n.getEnd() - prefix.length
240
+ if (start < 0 || end > text.length) return
241
+ const shorthand = parent !== undefined && ts.isShorthandPropertyAssignment(parent) && parent.name === n
242
+ refs.push({ start, end, name: n.text, ...(shorthand && { key: n.text }) })
243
+ })
244
+
245
+ const pieces: ScopedValueRefPiece[] = []
246
+ let cursor = 0
247
+ for (const ref of refs.sort((a, b) => a.start - b.start)) {
248
+ const before = text.slice(cursor, ref.start) + (ref.key !== undefined ? `${ref.key}: ` : '')
249
+ if (before !== '') pieces.push({ kind: 'text', text: before })
250
+ pieces.push({ kind: 'ref', name: ref.name })
251
+ cursor = ref.end
252
+ }
253
+ if (cursor < text.length) pieces.push({ kind: 'text', text: text.slice(cursor) })
254
+ return pieces
255
+ }
256
+
216
257
  /**
217
258
  * `applyScopedPropRefRewrite` specializes `rewriteScopedValueRefs` for
218
259
  * the destructured-prop case: the substitution defaults to
@@ -1,5 +1,6 @@
1
1
  import ts from 'typescript'
2
- import type { ConstantInfo, ParamInfo, PropUsage } from './types.ts'
2
+ import type { ConstantInfo, ParamInfo, PropUsage, SignalPropSeed } from './types.ts'
3
+ import type { ParsedExpr } from './expression-parser.ts'
3
4
  import { propHasPropertyAccess } from './ir-to-client-js/compute-prop-usage.ts'
4
5
  import { parsePropReadInitializer } from './ir-to-client-js/prune-unused-prop-extractions.ts'
5
6
  import { PROPS_PARAM } from './ir-to-client-js/utils.ts'
@@ -52,6 +53,99 @@ export function propsDestructureBinding(p: ParamInfo): string {
52
53
  return p.defaultValue ? `${binding} = ${p.defaultValue}` : binding
53
54
  }
54
55
 
56
+ /**
57
+ * The prop a parsed initializer reads off the props object: a bare
58
+ * `props.<key>` member read, or one with a `?? <default>` fallback.
59
+ * `null` for any other shape.
60
+ */
61
+ function parsedPropRead(
62
+ read: ParsedExpr | undefined,
63
+ propsObjectName: string,
64
+ ): { key: string; hasDefault: boolean } | null {
65
+ const hasDefault = read?.kind === 'logical' && read.op === '??'
66
+ const member = hasDefault ? read.left : read
67
+ if (member?.kind !== 'member' || member.computed || member.optional) return null
68
+ if (member.object.kind !== 'identifier' || member.object.name !== propsObjectName) return null
69
+ return { key: member.property, hasDefault }
70
+ }
71
+
72
+ /**
73
+ * Whether a component-scope const is the props-object read of its own prop,
74
+ * so a template may read the prop in its place: a bare alias
75
+ * (`const label = props.label`, read from its parsed initializer), or an
76
+ * un-renamed binding of a body destructure (`const { label = 'Default' } =
77
+ * props`, whose default the analyzer also records on the prop's `ParamInfo`).
78
+ *
79
+ * A hand-written `const label = props.label ?? 'Default'` has the same
80
+ * `value` text as that destructure but is NOT the prop: its default lives
81
+ * only in the const, and reading the prop instead drops it (#3501). The
82
+ * analyzer marks the destructure on `ConstantInfo.propsDestructure`, so the
83
+ * two are told apart by that field, not by the text. A reassignment that
84
+ * directly follows the declaration folds into the initializer
85
+ * (`fold-render-reassignments.ts`), so the binding keeps one value; one that
86
+ * cannot fold (`mutatedAfterDeclaration`) leaves no single value a template
87
+ * could inline, so the binding reads the prop it holds until reassigned.
88
+ */
89
+ export function isPropsAliasConst(
90
+ c: Pick<ConstantInfo, 'name' | 'parsed' | 'propsDestructure' | 'mutatedAfterDeclaration'>,
91
+ propsObjectName: string | null,
92
+ ): boolean {
93
+ if (propsObjectName === null) return false
94
+ if (c.propsDestructure) return c.propsDestructure.sourceKey === c.name
95
+ const read = parsedPropRead(c.parsed, propsObjectName)
96
+ return read !== null && read.key === c.name && (!read.hasDefault || c.mutatedAfterDeclaration === true)
97
+ }
98
+
99
+ /**
100
+ * How a parsed signal initializer reads a prop: a member chain rooted at the
101
+ * props object (`props.<name>`, `props.row.count`, `props.items[0]`) or a
102
+ * destructured binding `<name>`, bare or under a `??` / `||` fallback chain
103
+ * of one operator (`props.a ?? props.b ?? 0`). `null` for any other shape
104
+ * (`props.a && x`, `props.a + 1`, a call). A binding counts only when it is
105
+ * one of `propsParams`.
106
+ */
107
+ export function signalPropSeed(
108
+ parsed: ParsedExpr | undefined,
109
+ propsParams: readonly ParamInfo[],
110
+ propsObjectName: string | null,
111
+ ): SignalPropSeed | null {
112
+ if (!parsed) return null
113
+ const { read, fallback } = splitFallbackChain(parsed)
114
+ const declared = (name: string) => propsParams.some(p => p.name === name)
115
+ if (read.kind === 'identifier') {
116
+ return declared(read.name) ? { propName: read.name, via: 'binding', nested: false, declared: true, fallback } : null
117
+ }
118
+ const hop = propsMemberRoot(read, propsObjectName)
119
+ if (!hop) return null
120
+ return { propName: hop.property, via: 'member', nested: hop !== read, declared: declared(hop.property), fallback }
121
+ }
122
+
123
+ /**
124
+ * Split a left-associated `??` / `||` chain of ONE operator into its leftmost
125
+ * operand and the fallback after it: `(a ?? b) ?? 0` reads `a` with fallback
126
+ * `b ?? 0`. Anything else is a read with no fallback.
127
+ */
128
+ function splitFallbackChain(parsed: ParsedExpr): { read: ParsedExpr; fallback: SignalPropSeed['fallback'] } {
129
+ if (parsed.kind !== 'logical' || (parsed.op !== '??' && parsed.op !== '||')) return { read: parsed, fallback: null }
130
+ const op = parsed.op
131
+ const rights: ParsedExpr[] = []
132
+ let node: ParsedExpr = parsed
133
+ while (node.kind === 'logical' && node.op === op) {
134
+ rights.unshift(node.right)
135
+ node = node.left
136
+ }
137
+ const expr = rights.slice(1).reduce<ParsedExpr>((left, right) => ({ ...parsed, left, right }), rights[0])
138
+ return { read: node, fallback: { op, expr } }
139
+ }
140
+
141
+ /** The `props.<name>` hop a member / index chain is rooted at, or `null`. */
142
+ function propsMemberRoot(read: ParsedExpr, propsObjectName: string | null): Extract<ParsedExpr, { kind: 'member' }> | null {
143
+ let node = read
144
+ while ((node.kind === 'member' || node.kind === 'index-access') && !(node.object.kind === 'identifier')) node = node.object
145
+ if (node.kind !== 'member' || node.computed || node.optional) return null
146
+ return node.object.kind === 'identifier' && node.object.name === propsObjectName ? node : null
147
+ }
148
+
55
149
  /**
56
150
  * Local-name → caller-facing-key map for prop-reference rewrites —
57
151
  * entries only for `ParamInfo`s that actually rename (`sourceName` set,
@@ -120,10 +214,11 @@ export function resolveBodyDestructuredPropAliases(
120
214
  * Foo(props: Props)`) whose value is a PURE alias of a single caller-facing
121
215
  * prop — either a body destructure (`const { value } = props`, `const {
122
216
  * label = 'none' } = props`) or an equivalent bare member read (`const label
123
- * = props.label ?? 'fallback'`); the analyzer's IR can't distinguish the two
124
- * shapes (both parse to the same `ConstantInfo`), and neither can this
125
- * resolver — see `resolveBodyAliasReads`'s (`rewrite-destructured-props.ts`)
126
- * docstring for why that's the right call.
217
+ * = props.label ?? 'fallback'`). Both shapes share the same `value` text;
218
+ * the IR tells them apart via `ConstantInfo.propsDestructure` (#3501), but
219
+ * this resolver deliberately treats them alike — see
220
+ * `rewriteBodyAliasReads`'s (`rewrite-destructured-props.ts`) docstring for
221
+ * why that's the right call.
127
222
  */
128
223
  export interface BodyPropAlias {
129
224
  /** Caller-facing prop key (`props.<key>`). */
@@ -237,7 +332,7 @@ const EMPTY_SET: ReadonlySet<string> = new Set()
237
332
  * never bound a parameter — so callers synthesize one of these instead of a
238
333
  * full `ParamInfo` (which would need a fabricated `type`/`optional`).
239
334
  */
240
- export type LivePropReadInfo = Pick<ParamInfo, 'name' | 'sourceName' | 'defaultValue' | 'defaultContainsArrow'>
335
+ export type LivePropReadInfo = Pick<ParamInfo, 'name' | 'sourceName' | 'defaultValue' | 'defaultContainsArrow' | 'defaultParts'>
241
336
 
242
337
  /** `_p.<callerKey>` — `_p` is always keyed by the caller-facing name (#2524 CSR half). */
243
338
  export function propReadBase(p: LivePropReadInfo): string {
@@ -277,12 +372,27 @@ export function propReadFallback(
277
372
  usage: PropUsage | undefined,
278
373
  usedAsCondition: boolean,
279
374
  ): string | null {
280
- if (p.defaultValue) return coalesceDefaultText(p.defaultValue, p.defaultContainsArrow)
375
+ const defaultText = propDefaultText(p)
376
+ if (defaultText) return coalesceDefaultText(defaultText, p.defaultContainsArrow)
281
377
  if (usage?.usedAsLoopArray) return '[]'
282
378
  if (propHasPropertyAccess(usage) && !usedAsCondition) return '{}'
283
379
  return null
284
380
  }
285
381
 
382
+ /**
383
+ * A prop's destructure default as client JS. A default that reads an earlier
384
+ * binding of its own pattern (`{ off = false, on = off }`, #3531) renders each
385
+ * read as that prop's own live read (`_p.off ?? false`), since the emitted
386
+ * scope binds no `off`; any other default is its source text. Undefined when
387
+ * the prop has no default.
388
+ */
389
+ export function propDefaultText(p: LivePropReadInfo): string | undefined {
390
+ if (!p.defaultParts) return p.defaultValue
391
+ return p.defaultParts
392
+ .map(part => (part.kind === 'text' ? part.text : livePropReadExpr(part.param, undefined, false)))
393
+ .join('')
394
+ }
395
+
286
396
  /**
287
397
  * The live read of a destructured prop inside init scope, in the same shape
288
398
  * props-object mode emits for `props.X`. The one formula every live-read
package/src/relocate.ts CHANGED
@@ -15,7 +15,7 @@ import type { Scope, BindingKind, IRMetadata } from './types.ts'
15
15
  import { isVisibleIn } from './types.ts'
16
16
  import type { AnalyzerContext } from './analyzer-context.ts'
17
17
  import { PROPS_PARAM } from './ir-to-client-js/utils.ts'
18
- import { buildPropAliasMap } from './props-binding.ts'
18
+ import { buildPropAliasMap, isPropsAliasConst } from './props-binding.ts'
19
19
  import type {
20
20
  TemplatePrimitiveRegistry,
21
21
  TemplateCallAcceptor,
@@ -78,6 +78,15 @@ export interface RelocateEnv {
78
78
  * in `templatePrimitives`. Returning true marks the call as accepted.
79
79
  */
80
80
  acceptsTemplateCall?: TemplateCallAcceptor
81
+ /**
82
+ * Component-scope locals already classified as inlinable into template
83
+ * scope (#3513), filled in declaration order by `computeInlinability`. A
84
+ * method call on one (`text.toUpperCase()` with `const text = props.label
85
+ * ?? 'd'`) runs on the local's inlined value, so a broad
86
+ * `acceptsTemplateCall` can vouch for it even though the receiver is an
87
+ * init-local.
88
+ */
89
+ inlinableLocals?: ReadonlySet<string>
81
90
  /**
82
91
  * Lowering-registry matchers (#2057) bound to this component's metadata
83
92
  * (`prepareLoweringMatchers`), consulted by `isCallAcceptedByAdapter` as a
@@ -476,6 +485,24 @@ const REGISTRY_SAFE_BINDING_KINDS: ReadonlySet<BindingKind> = new Set([
476
485
  'module-local',
477
486
  ])
478
487
 
488
+ /**
489
+ * A method call on an inlinable local (`text.toUpperCase()`) runs on that
490
+ * local's value in template scope (#3513). Only the broad
491
+ * `acceptsTemplateCall` can vouch for it: the path-keyed registries name
492
+ * globals, which this receiver isn't. A bare call of the local itself is
493
+ * never accepted.
494
+ */
495
+ function isAcceptedMethodCallOnInlinableLocal(
496
+ originalPath: string,
497
+ leftmost: string | null,
498
+ resolvedLeftmost: string,
499
+ resolvedPath: string,
500
+ env: RelocateEnv,
501
+ ): boolean {
502
+ if (originalPath === leftmost || env.inlinableLocals?.has(resolvedLeftmost) !== true) return false
503
+ return env.acceptsTemplateCall?.(resolvedPath) === true
504
+ }
505
+
479
506
  /**
480
507
  * Whether `env`'s adapter promises it can render this call in template
481
508
  * scope. Three independent acceptance paths, any of which is sufficient:
@@ -540,7 +567,7 @@ function isCallAcceptedByAdapter(
540
567
  if (resolvedLeftmost !== null) {
541
568
  const kind = env.bindings.get(resolvedLeftmost)
542
569
  if (kind !== undefined && !REGISTRY_SAFE_BINDING_KINDS.has(kind)) {
543
- return false
570
+ return isAcceptedMethodCallOnInlinableLocal(originalPath, leftmost, resolvedLeftmost, resolvedPath, env)
544
571
  }
545
572
  }
546
573
 
@@ -791,6 +818,16 @@ export function buildRelocateEnvFromIR(
791
818
  return env
792
819
  }
793
820
 
821
+ /**
822
+ * Every name the component or its module binds, by kind: imports, module
823
+ * consts and functions, props, init locals, signals and memos (`classify`'s
824
+ * table). A free name absent from it, and bound by no enclosing loop or
825
+ * callback, is a JavaScript global.
826
+ */
827
+ export function componentBindings(metadata: IRMetadata): ReadonlyMap<string, BindingKind> {
828
+ return buildRelocateEnvFromFields(metadata).bindings
829
+ }
830
+
794
831
  interface EnvFields {
795
832
  imports: AnalyzerContext['imports']
796
833
  localFunctions: AnalyzerContext['localFunctions']
@@ -841,12 +878,7 @@ function buildRelocateEnvFromFields(src: EnvFields): RelocateEnv {
841
878
  const propsObjectName = src.propsObjectName
842
879
  for (const c of src.localConstants) {
843
880
  if (c.isModule) continue
844
- const isPureAlias =
845
- typeof c.value === 'string' &&
846
- propsObjectName !== null &&
847
- (c.value === `${propsObjectName}.${c.name}` ||
848
- c.value.startsWith(`${propsObjectName}.${c.name} ??`))
849
- bindings.set(c.name, isPureAlias ? 'prop' : 'init-local')
881
+ bindings.set(c.name, isPropsAliasConst(c, propsObjectName) ? 'prop' : 'init-local')
850
882
  }
851
883
 
852
884
  // Init-body local functions.
@@ -1,8 +1,11 @@
1
1
  import { describe, test, expect } from 'bun:test'
2
+ import ts from 'typescript'
2
3
  import {
3
4
  replaceInExprContexts,
4
5
  findInterpolationEnd,
5
6
  findTopLevelTemplateLiterals,
7
+ isTriviaKind,
8
+ iterateJsTokens,
6
9
  } from '../js-scanner'
7
10
 
8
11
  // ---------------------------------------------------------------------------
@@ -243,3 +246,37 @@ describe('findTopLevelTemplateLiterals', () => {
243
246
  expect(r).toEqual(['<a/>', '<b/>'])
244
247
  })
245
248
  })
249
+
250
+ describe('iterateJsTokens: division after a keyword used as a name (#3536)', () => {
251
+ const kinds = (text: string) =>
252
+ [...iterateJsTokens(text)].filter(t => !isTriviaKind(t.kind)).map(t => ts.SyntaxKind[t.kind])
253
+
254
+ test('a contextual-keyword binding is followed by division', () => {
255
+ expect(kinds('type / 2 + step / 3')).not.toContain('RegularExpressionLiteral')
256
+ })
257
+
258
+ test('a keyword-named member is followed by division', () => {
259
+ expect(kinds('obj.default / 2 + step / 3')).not.toContain('RegularExpressionLiteral')
260
+ expect(kinds('obj?.new / 2')).not.toContain('RegularExpressionLiteral')
261
+ })
262
+
263
+ test('`of` as a binding is followed by division; as the for-of separator, by a regex literal', () => {
264
+ expect(kinds('of / 2 + step / 3')).not.toContain('RegularExpressionLiteral')
265
+ expect(kinds('for (const hit of /"/.exec(x) || []) {}')).toContain('RegularExpressionLiteral')
266
+ expect(kinds('for (const [a, b] of /x/.exec(s)) {}')).toContain('RegularExpressionLiteral')
267
+ expect(kinds('for await (const hit of /x/.exec(s)) {}')).toContain('RegularExpressionLiteral')
268
+ expect(kinds('for (const type of /"/.exec(x) || []) {}')).toContain('RegularExpressionLiteral')
269
+ expect(kinds('for (const of of /x/.exec(s)) {}')).toContain('RegularExpressionLiteral')
270
+ })
271
+
272
+ test('`of` after a binding outside a for header is a name (ASI)', () => {
273
+ expect(kinds('let of = x\nof /= step\nreturn of')).not.toContain('RegularExpressionLiteral')
274
+ expect(kinds('f(x)\nof / 2 + step / 3')).not.toContain('RegularExpressionLiteral')
275
+ })
276
+
277
+ test('an operator keyword still starts a regex literal', () => {
278
+ expect(kinds('return /a/.test(x)')).toContain('RegularExpressionLiteral')
279
+ expect(kinds('typeof /a/')).toContain('RegularExpressionLiteral')
280
+ expect(kinds('await /a/.test(x)')).toContain('RegularExpressionLiteral')
281
+ })
282
+ })