@@ -78,30 +78,28 @@ const replaceDatagrid = (root, j) => {
7878
7979 // Replace Datagrid with DataTable
8080 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+ } ;
9293 } ) ;
9394
9495 return true ;
9596} ;
9697
9798const 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 ;
102100
103101 // rename the `rowStyle` attribute to `rowSx` if it exists
104- const rowSxRenamedAttributes = filtredAttributes . map ( attr => {
102+ const rowSxRenamedAttributes = initialAttributes . map ( attr => {
105103 if ( j . JSXAttribute . check ( attr ) && attr . name . name === 'rowStyle' ) {
106104 return j . jsxAttribute ( j . jsxIdentifier ( 'rowSx' ) , attr . value ) ;
107105 }
@@ -136,7 +134,12 @@ const cleanAttributes = (node, j) => {
136134 return attr ;
137135 } ) ;
138136
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 ;
140143} ;
141144
142145const transformChildren = ( root , j ) => {
0 commit comments