@@ -21,33 +21,29 @@ fn extract_base_tag_and_class_name<'a>(
2121 input : & Expression < ' a > ,
2222 imports : & HashMap < String , ExportVariableKind > ,
2323) -> ( Option < String > , Option < Vec < ExtractStyleValue > > ) {
24- match input {
25- Expression :: StaticMemberExpression ( member) => {
26- ( Some ( member. property . name . to_string ( ) ) , None )
27- }
28- Expression :: CallExpression ( call) => {
29- if call. arguments . len ( ) == 1 {
30- // styled("div") or styled(Component)
31- if let Argument :: StringLiteral ( lit) = & call. arguments [ 0 ] {
32- ( Some ( lit. value . to_string ( ) ) , None )
33- } else if let Argument :: Identifier ( ident) = & call. arguments [ 0 ] {
34- if let Some ( export_variable_kind) = imports. get ( ident. name . as_str ( ) ) {
35- (
36- Some ( export_variable_kind. to_tag ( ) . to_string ( ) ) ,
37- Some ( export_variable_kind. extract ( ) ) ,
38- )
39- } else {
40- ( Some ( ident. name . to_string ( ) ) , None )
41- }
42- } else {
43- // Component reference - we'll handle this later
44- ( None , None )
45- }
24+ if let Expression :: StaticMemberExpression ( member) = input {
25+ ( Some ( member. property . name . to_string ( ) ) , None )
26+ } else if let Expression :: CallExpression ( call) = input
27+ && call. arguments . len ( ) == 1
28+ {
29+ // styled("div") or styled(Component)
30+ if let Argument :: StringLiteral ( lit) = & call. arguments [ 0 ] {
31+ ( Some ( lit. value . to_string ( ) ) , None )
32+ } else if let Argument :: Identifier ( ident) = & call. arguments [ 0 ] {
33+ if let Some ( export_variable_kind) = imports. get ( ident. name . as_str ( ) ) {
34+ (
35+ Some ( export_variable_kind. to_tag ( ) . to_string ( ) ) ,
36+ Some ( export_variable_kind. extract ( ) ) ,
37+ )
4638 } else {
47- ( None , None )
39+ ( Some ( ident . name . to_string ( ) ) , None )
4840 }
41+ } else {
42+ // Component reference - we'll handle this later
43+ ( None , None )
4944 }
50- _ => ( None , None ) ,
45+ } else {
46+ ( None , None )
5147 }
5248}
5349
@@ -169,14 +165,15 @@ fn create_styled_component<'a>(
169165 SPAN ,
170166 FormalParameterKind :: ArrowFormalParameters ,
171167 oxc_allocator:: Vec :: from_iter_in (
172- vec ! [ ast_builder. formal_parameter(
173- SPAN ,
174- oxc_allocator:: Vec :: from_iter_in( vec![ ] , ast_builder. allocator) ,
175- ast_builder. binding_pattern(
176- ast_builder. binding_pattern_kind_object_pattern(
177- SPAN ,
178- oxc_allocator:: Vec :: from_iter_in(
179- vec![
168+ vec ! [
169+ ast_builder. formal_parameter(
170+ SPAN ,
171+ oxc_allocator:: Vec :: from_iter_in( vec![ ] , ast_builder. allocator) ,
172+ ast_builder. binding_pattern(
173+ ast_builder. binding_pattern_kind_object_pattern(
174+ SPAN ,
175+ oxc_allocator:: Vec :: from_iter_in(
176+ vec![
180177 ast_builder. binding_property(
181178 SPAN ,
182179 ast_builder. property_key_static_identifier( SPAN , "style" ) ,
@@ -214,27 +211,28 @@ fn create_styled_component<'a>(
214211 false ,
215212 ) ,
216213 ] ,
217- ast_builder. allocator,
218- ) ,
219- Some ( ast_builder. binding_rest_element(
220- SPAN ,
221- ast_builder. binding_pattern(
222- ast_builder. binding_pattern_kind_binding_identifier(
223- SPAN ,
224- ast_builder. atom( "rest" ) ,
225- ) ,
226- None :: <oxc_allocator:: Box <oxc_ast:: ast:: TSTypeAnnotation <' a>>>,
227- false ,
214+ ast_builder. allocator,
228215 ) ,
229- ) ) ,
216+ Some ( ast_builder. binding_rest_element(
217+ SPAN ,
218+ ast_builder. binding_pattern(
219+ ast_builder. binding_pattern_kind_binding_identifier(
220+ SPAN ,
221+ ast_builder. atom( "rest" ) ,
222+ ) ,
223+ None :: <oxc_allocator:: Box <oxc_ast:: ast:: TSTypeAnnotation <' a>>>,
224+ false ,
225+ ) ,
226+ ) ) ,
227+ ) ,
228+ None :: <oxc_allocator:: Box <oxc_ast:: ast:: TSTypeAnnotation <' a>>>,
229+ false ,
230230 ) ,
231- None :: <oxc_allocator:: Box <oxc_ast:: ast:: TSTypeAnnotation <' a>>>,
231+ None ,
232+ false ,
232233 false ,
233234 ) ,
234- None ,
235- false ,
236- false ,
237- ) ] ,
235+ ] ,
238236 ast_builder. allocator ,
239237 ) ,
240238 None :: < oxc_allocator:: Box < oxc_ast:: ast:: BindingRestElement < ' a > > > ,
@@ -243,16 +241,20 @@ fn create_styled_component<'a>(
243241 SPAN ,
244242 oxc_allocator:: Vec :: from_iter_in ( vec ! [ ] , ast_builder. allocator ) ,
245243 oxc_allocator:: Vec :: from_iter_in (
246- vec ! [ ast_builder. statement_expression(
247- SPAN ,
248- ast_builder. expression_jsx_element(
244+ vec ! [
245+ ast_builder. statement_expression(
249246 SPAN ,
250- ast_builder. alloc_jsx_opening_element (
247+ ast_builder. expression_jsx_element (
251248 SPAN ,
252- ast_builder. jsx_element_name_identifier( SPAN , ast_builder. atom( tag_name) ) ,
253- None :: <oxc_allocator:: Box <oxc_ast:: ast:: TSTypeParameterInstantiation <' a>>>,
254- oxc_allocator:: Vec :: from_iter_in(
255- vec![
249+ ast_builder. alloc_jsx_opening_element(
250+ SPAN ,
251+ ast_builder
252+ . jsx_element_name_identifier( SPAN , ast_builder. atom( tag_name) ) ,
253+ None :: <
254+ oxc_allocator:: Box <oxc_ast:: ast:: TSTypeParameterInstantiation <' a>>,
255+ >,
256+ oxc_allocator:: Vec :: from_iter_in(
257+ vec![
256258 ast_builder. jsx_attribute_item_spread_attribute(
257259 SPAN ,
258260 ast_builder
@@ -331,13 +333,14 @@ fn create_styled_component<'a>(
331333 ) ,
332334 ) ,
333335 ] ,
334- ast_builder. allocator,
336+ ast_builder. allocator,
337+ ) ,
335338 ) ,
339+ oxc_allocator:: Vec :: from_iter_in( vec![ ] , ast_builder. allocator) ,
340+ None :: <oxc_allocator:: Box <oxc_ast:: ast:: JSXClosingElement <' a>>>,
336341 ) ,
337- oxc_allocator:: Vec :: from_iter_in( vec![ ] , ast_builder. allocator) ,
338- None :: <oxc_allocator:: Box <oxc_ast:: ast:: JSXClosingElement <' a>>>,
339342 ) ,
340- ) ] ,
343+ ] ,
341344 ast_builder. allocator ,
342345 ) ,
343346 ) ;
0 commit comments