11use crate :: { ExtractStyleProp , StyleProperty } ;
22use oxc_allocator:: CloneIn ;
33use oxc_ast:: AstBuilder ;
4- use oxc_ast:: ast:: {
5- Expression , JSXAttribute , JSXAttributeValue , JSXExpression , ObjectExpression ,
6- ObjectPropertyKind , PropertyKey , PropertyKind ,
7- } ;
4+ use oxc_ast:: ast:: { Expression , ObjectPropertyKind , PropertyKey , PropertyKind } ;
85use oxc_span:: SPAN ;
96use std:: collections:: BTreeMap ;
107pub fn gen_styles < ' a > (
118 ast_builder : & AstBuilder < ' a > ,
129 style_props : & [ ExtractStyleProp < ' a > ] ,
13- ) -> Option < ObjectExpression < ' a > > {
10+ ) -> Option < Expression < ' a > > {
1411 if style_props. is_empty ( ) {
1512 return None ;
1613 }
@@ -22,9 +19,11 @@ pub fn gen_styles<'a>(
2219 if properties. is_empty ( ) {
2320 return None ;
2421 }
25- Some ( ast_builder. object_expression (
26- SPAN ,
27- oxc_allocator:: Vec :: from_iter_in ( properties, ast_builder. allocator ) ,
22+ Some ( Expression :: ObjectExpression (
23+ ast_builder. alloc_object_expression (
24+ SPAN ,
25+ oxc_allocator:: Vec :: from_iter_in ( properties, ast_builder. allocator ) ,
26+ ) ,
2827 ) )
2928}
3029fn gen_style < ' a > (
@@ -345,39 +344,3 @@ fn gen_style<'a>(
345344 properties. reverse ( ) ;
346345 properties
347346}
348-
349- pub fn apply_style_attribute < ' a > (
350- ast_builder : & AstBuilder < ' a > ,
351- style_prop : & mut JSXAttribute < ' a > ,
352- // must be an object expression
353- mut expression : ObjectExpression < ' a > ,
354- ) {
355- if let Some ( ref mut value) = style_prop. value {
356- if let JSXAttributeValue :: ExpressionContainer ( container) = value {
357- if let Some ( spread_property) = match & container. expression {
358- JSXExpression :: ObjectExpression ( obj) => Some ( Expression :: ObjectExpression (
359- obj. clone_in ( ast_builder. allocator ) ,
360- ) ) ,
361- JSXExpression :: Identifier ( ident) => Some ( Expression :: Identifier (
362- ident. clone_in ( ast_builder. allocator ) ,
363- ) ) ,
364- _ => None ,
365- } {
366- expression. properties . insert (
367- 0 ,
368- ObjectPropertyKind :: SpreadProperty (
369- ast_builder. alloc_spread_element ( SPAN , spread_property) ,
370- ) ,
371- ) ;
372- }
373- container. expression = JSXExpression :: ObjectExpression ( ast_builder. alloc ( expression) ) ;
374- }
375- } else {
376- style_prop. value = Some ( JSXAttributeValue :: ExpressionContainer (
377- ast_builder. alloc_jsx_expression_container (
378- SPAN ,
379- JSXExpression :: ObjectExpression ( ast_builder. alloc ( expression) ) ,
380- ) ,
381- ) ) ;
382- } ;
383- }
0 commit comments