File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -228,13 +228,17 @@ class Stringifier {
228
228
}
229
229
return out ;
230
230
}
231
+ encounteredFragment = false ;
231
232
/**
232
233
* @returns {string } The header.
233
234
*/
234
235
getHeader ( ) {
235
236
if ( ! this . addReactImport ) {
236
237
return '' ;
237
238
}
239
+ if ( this . encounteredFragment ) {
240
+ return "import {createElement, Fragment} from 'react';\n" ;
241
+ }
238
242
return "import {createElement} from 'react';\n" ;
239
243
}
240
244
get parent ( ) {
@@ -1133,6 +1137,42 @@ class Stringifier {
1133
1137
out += ')' ;
1134
1138
return out ;
1135
1139
}
1140
+ /**
1141
+ * @param {import("@babel/types").JSXFragment } node - The Babel AST node.
1142
+ * @returns {string } Stringification of the node.
1143
+ */
1144
+ JSXFragment ( node ) {
1145
+ const { /*openingFragment, closingFragment,*/ children} = node ;
1146
+ this . encounteredFragment = true ;
1147
+ // console.log('JSXFragment', {openingFragment, closingFragment, children});
1148
+ let { spaces} = this ;
1149
+ let out = 'createElement(\n' ;
1150
+ this . numSpaces ++ ;
1151
+ spaces = this . spaces ;
1152
+ out += spaces ;
1153
+ out += 'Fragment,\n' ;
1154
+ out += spaces ;
1155
+ out += 'null' ;
1156
+ // Same code for children as in JSXElement
1157
+ if ( children . length ) {
1158
+ out += ',\n' ;
1159
+ for ( const child of children ) {
1160
+ const source = this . toSource ( child ) ;
1161
+ if ( ! source . length ) {
1162
+ continue ;
1163
+ }
1164
+ out += spaces ;
1165
+ out += source ;
1166
+ out += ',\n' ;
1167
+ }
1168
+ } else {
1169
+ out += '\n' ;
1170
+ }
1171
+ this . numSpaces -- ;
1172
+ out += this . spaces ;
1173
+ out += ')' ;
1174
+ return out ;
1175
+ }
1136
1176
/**
1137
1177
* @param {import("@babel/types").JSXIdentifier } node - The Babel AST node.
1138
1178
* @returns {string } Stringification of the node.
You can’t perform that action at this time.
0 commit comments