@@ -19,30 +19,29 @@ pub fn modify_prop_object<'a>(
1919 let mut class_name_prop = None ;
2020 let mut style_prop = None ;
2121
22- for idx in 0 ..props. len ( ) {
23- if let ObjectPropertyKind :: ObjectProperty ( attr) = & props[ idx] {
22+ for idx in ( 0 ..props. len ( ) ) . rev ( ) {
23+ if let ObjectPropertyKind :: ObjectProperty ( attr) = props. remove ( idx) {
2424 if let PropertyKey :: StaticIdentifier ( ident) = & attr. key {
2525 if ident. name == "className" {
26- if let ObjectPropertyKind :: ObjectProperty ( attr) = props. remove ( idx) {
27- class_name_prop = Some ( attr) ;
28- }
26+ class_name_prop = Some ( attr) ;
27+ continue ;
2928 } else if ident. name == "style" {
30- if let ObjectPropertyKind :: ObjectProperty ( attr) = props. remove ( idx) {
31- style_prop = Some ( attr) ;
32- }
29+ style_prop = Some ( attr) ;
30+ continue ;
3331 }
3432 }
33+ props. insert ( idx, ObjectPropertyKind :: ObjectProperty ( attr) ) ;
3534 }
3635 }
3736
3837 // should modify class name prop
3938 if let Some ( ex) = gen_class_names ( ast_builder, & styles) {
4039 if let Some ( pr) = if let Some ( class_name_prop) = class_name_prop {
41- let res = merge_expression_for_class_name (
40+ merge_expression_for_class_name (
4241 ast_builder,
4342 vec ! [ class_name_prop. value. clone_in( ast_builder. allocator) , ex] ,
44- ) ;
45- res . map ( |res| {
43+ )
44+ . map ( |res| {
4645 ast_builder. alloc_object_property (
4746 SPAN ,
4847 PropertyKind :: Init ,
@@ -75,41 +74,37 @@ pub fn modify_prop_object<'a>(
7574
7675 // should modify style prop
7776 if let Some ( mut ex) = gen_styles ( ast_builder, & styles) {
78- if let Some ( style_prop) = style_prop {
79- props. push ( ObjectPropertyKind :: ObjectProperty (
80- ast_builder. alloc_object_property (
81- SPAN ,
82- PropertyKind :: Init ,
83- PropertyKey :: StaticIdentifier ( ast_builder. alloc_identifier_name ( SPAN , "style" ) ) ,
84- if ex. properties . is_empty ( ) {
85- Expression :: ObjectExpression ( ast_builder. alloc ( ex) )
86- } else {
87- ex. properties . push ( ObjectPropertyKind :: SpreadProperty (
88- ast_builder. alloc_spread_element (
89- SPAN ,
90- style_prop. value . clone_in ( ast_builder. allocator ) ,
91- ) ,
92- ) ) ;
93- Expression :: ObjectExpression ( ast_builder. alloc ( ex) )
94- } ,
95- false ,
96- false ,
97- false ,
98- ) ,
99- ) ) ;
77+ props. push ( if let Some ( style_prop) = style_prop {
78+ ObjectPropertyKind :: ObjectProperty ( ast_builder. alloc_object_property (
79+ SPAN ,
80+ PropertyKind :: Init ,
81+ PropertyKey :: StaticIdentifier ( ast_builder. alloc_identifier_name ( SPAN , "style" ) ) ,
82+ if ex. properties . is_empty ( ) {
83+ Expression :: ObjectExpression ( ast_builder. alloc ( ex) )
84+ } else {
85+ ex. properties . push ( ObjectPropertyKind :: SpreadProperty (
86+ ast_builder. alloc_spread_element (
87+ SPAN ,
88+ style_prop. value . clone_in ( ast_builder. allocator ) ,
89+ ) ,
90+ ) ) ;
91+ Expression :: ObjectExpression ( ast_builder. alloc ( ex) )
92+ } ,
93+ false ,
94+ false ,
95+ false ,
96+ ) )
10097 } else {
101- props. push ( ObjectPropertyKind :: ObjectProperty (
102- ast_builder. alloc_object_property (
103- SPAN ,
104- PropertyKind :: Init ,
105- PropertyKey :: StaticIdentifier ( ast_builder. alloc_identifier_name ( SPAN , "style" ) ) ,
106- Expression :: ObjectExpression ( ast_builder. alloc ( ex) ) ,
107- false ,
108- false ,
109- false ,
110- ) ,
111- ) ) ;
112- } ;
98+ ObjectPropertyKind :: ObjectProperty ( ast_builder. alloc_object_property (
99+ SPAN ,
100+ PropertyKind :: Init ,
101+ PropertyKey :: StaticIdentifier ( ast_builder. alloc_identifier_name ( SPAN , "style" ) ) ,
102+ Expression :: ObjectExpression ( ast_builder. alloc ( ex) ) ,
103+ false ,
104+ false ,
105+ false ,
106+ ) )
107+ } ) ;
113108 } else if let Some ( style_prop) = style_prop {
114109 // re add class name prop if not modified
115110 props. push ( ObjectPropertyKind :: ObjectProperty ( style_prop) )
@@ -124,19 +119,18 @@ pub fn modify_props<'a>(
124119 let mut class_name_prop = None ;
125120 let mut style_prop = None ;
126121
127- for idx in 0 ..props. len ( ) {
128- if let Attribute ( attr) = & props[ idx] {
122+ for idx in ( 0 ..props. len ( ) ) . rev ( ) {
123+ if let Attribute ( attr) = props. remove ( idx) {
129124 if let Identifier ( ident) = & attr. name {
130125 if ident. name == "className" {
131- if let Attribute ( attr) = props. remove ( idx) {
132- class_name_prop = Some ( attr) ;
133- }
126+ class_name_prop = Some ( attr) ;
127+ continue ;
134128 } else if ident. name == "style" {
135- if let Attribute ( attr) = props. remove ( idx) {
136- style_prop = Some ( attr) ;
137- }
129+ style_prop = Some ( attr) ;
130+ continue ;
138131 }
139132 }
133+ props. insert ( idx, Attribute ( attr) ) ;
140134 }
141135 }
142136
0 commit comments