@@ -78,30 +78,28 @@ const replaceDatagrid = (root, j) => {
78
78
79
79
// Replace Datagrid with DataTable
80
80
datagridComponents . replaceWith ( ( { node } ) => {
81
- const attributes = cleanAttributes ( node , j ) ;
82
-
83
- const openingElement = j . jsxOpeningElement (
84
- j . jsxIdentifier ( 'DataTable' ) ,
85
- attributes ,
86
- false
87
- ) ;
88
- const closingElement = j . jsxClosingElement (
89
- j . jsxIdentifier ( 'DataTable' )
90
- ) ;
91
- return j . jsxElement ( openingElement , closingElement , node . children ) ;
81
+ return {
82
+ ...node ,
83
+ openingElement : {
84
+ ...node . openingElement ,
85
+ name : j . jsxIdentifier ( 'DataTable' ) ,
86
+ attributes : cleanAttributes ( node , j ) ,
87
+ } ,
88
+ closingElement : {
89
+ ...node . closingElement ,
90
+ name : j . jsxIdentifier ( 'DataTable' ) ,
91
+ } ,
92
+ } ;
92
93
} ) ;
93
94
94
95
return true ;
95
96
} ;
96
97
97
98
const cleanAttributes = ( node , j ) => {
98
- // remove the `optimized` attribute if it exists
99
- const filtredAttributes = node . openingElement . attributes . filter (
100
- attr => ! ( j . JSXAttribute . check ( attr ) && attr . name . name === 'optimized' )
101
- ) ;
99
+ const initialAttributes = node . openingElement . attributes ;
102
100
103
101
// rename the `rowStyle` attribute to `rowSx` if it exists
104
- const rowSxRenamedAttributes = filtredAttributes . map ( attr => {
102
+ const rowSxRenamedAttributes = initialAttributes . map ( attr => {
105
103
if ( j . JSXAttribute . check ( attr ) && attr . name . name === 'rowStyle' ) {
106
104
return j . jsxAttribute ( j . jsxIdentifier ( 'rowSx' ) , attr . value ) ;
107
105
}
@@ -136,7 +134,12 @@ const cleanAttributes = (node, j) => {
136
134
return attr ;
137
135
} ) ;
138
136
139
- return sxRenamedAttributes ;
137
+ // remove the `optimized` attribute if it exists
138
+ const finalAttributes = sxRenamedAttributes . filter (
139
+ attr => ! ( j . JSXAttribute . check ( attr ) && attr . name . name === 'optimized' )
140
+ ) ;
141
+
142
+ return finalAttributes ;
140
143
} ;
141
144
142
145
const transformChildren = ( root , j ) => {
0 commit comments