@@ -191,15 +191,15 @@ describe('compiler AST emit architecture', () => {
191191 } ) ;
192192} ) ;
193193
194- // RFC tsrx-org/RFCs#1: `{style(expr)}` is resolved by the scope pre-pass
195- // (style-scopes.js) into the scope chain plus the value. By the time the
196- // emitters run — and compile.js's `resolveStyleExpr` fallback with them — no
197- // `style(...)` call is left on the AST, so the output never carries one .
194+ // RFC tsrx-org/RFCs#1: `{style(expr)}` in class position is resolved by the
195+ // scope pre-pass (style-scopes.js) into the scope chain plus the value. By
196+ // the time the emitters run — and compile.js's `resolveStyleExpr` fallback
197+ // with them — no class-position `style(...)` call is left on the AST.
198198describe ( 'scoped style pre-pass' , ( ) => {
199199 const SOURCE = `export function App(props) @{
200200 <>
201201 <style>.x { color: red; }</style>
202- <p class={style('x')}>{style('x y') }</p>
202+ <p class={style('x')}>{'x' }</p>
203203 <i class={style(props.cls)}>{'i'}</i>
204204 </>
205205}` ;
@@ -208,15 +208,39 @@ describe('scoped style pre-pass', () => {
208208 [ 'client' , { } ] ,
209209 [ 'client prod' , { hmr : false as const } ] ,
210210 [ 'server' , { mode : 'server' as const } ] ,
211- ] ) ( 'resolves every {style(...)} call before the emitters run — %s' , ( _label , options ) => {
212- const { code } = compile ( SOURCE , 'style-call.tsrx' , options ) ;
213- expect ( code ) . not . toMatch ( / \b s t y l e \( / ) ;
214- const hash = code . match ( / i n j e c t S t y l e \( " ( t s r x - [ 0 - 9 a - f ] + ) " / ) ! [ 1 ] ;
215- // Static values fold to a literal that opens with the scope chain…
216- expect ( code ) . toContain ( `${ hash } x` ) ;
217- expect ( code ) . toContain ( `${ hash } x y` ) ;
218- // …and a dynamic value concatenates after the chain at runtime.
219- expect ( code ) . toContain ( `"${ hash } " + props.cls` ) ;
211+ ] ) (
212+ 'resolves every class-position {style(...)} call before the emitters run — %s' ,
213+ ( _label , options ) => {
214+ const { code } = compile ( SOURCE , 'style-call.tsrx' , options ) ;
215+ expect ( code ) . not . toMatch ( / \b s t y l e \( / ) ;
216+ const hash = code . match ( / i n j e c t S t y l e \( " ( t s r x - [ 0 - 9 a - f ] + ) " / ) ! [ 1 ] ;
217+ // Static values fold to a literal that opens with the scope chain…
218+ expect ( code ) . toContain ( `${ hash } x` ) ;
219+ // …and a dynamic value concatenates after the chain at runtime.
220+ expect ( code ) . toContain ( `"${ hash } " + props.cls` ) ;
221+ } ,
222+ ) ;
223+
224+ it . each ( [
225+ [ 'client' , { } ] ,
226+ [ 'client prod' , { hmr : false as const } ] ,
227+ [ 'server' , { mode : 'server' as const } ] ,
228+ ] ) ( 'leaves a style() helper on the style prop alone — %s' , ( _label , options ) => {
229+ const { code } = compile (
230+ `function style(props) {
231+ return { color: props.color };
232+ }
233+ export function App(props) @{
234+ <>
235+ <style>.box { padding: 2px; }</style>
236+ <div class="box" style={style(props)}>{'x'}</div>
237+ </>
238+ }` ,
239+ 'style-prop-helper.tsrx' ,
240+ options ,
241+ ) ;
242+ expect ( code ) . toMatch ( / \b s t y l e \( p r o p s \) / ) ;
243+ expect ( code ) . not . toMatch ( / " [ ^ " ] * t s r x - [ 0 - 9 a - f ] + [ ^ " ] * " \s * \+ \s * p r o p s / ) ;
220244 } ) ;
221245
222246 it ( 'keeps the emitter fallback out of the shipped path (no cssHash-driven rewrite)' , ( ) => {
0 commit comments