@@ -26,12 +26,12 @@ namespace ts {
26
26
return currentFileState . filenameDeclaration . name ;
27
27
}
28
28
29
- function getJsxFactoryCalleePrimitive ( childrenLength : number ) : "jsx" | "jsxs" | "jsxDEV" {
30
- return compilerOptions . jsx === JsxEmit . ReactJSXDev ? "jsxDEV" : childrenLength > 1 ? "jsxs" : "jsx" ;
29
+ function getJsxFactoryCalleePrimitive ( isStaticChildren : boolean ) : "jsx" | "jsxs" | "jsxDEV" {
30
+ return compilerOptions . jsx === JsxEmit . ReactJSXDev ? "jsxDEV" : isStaticChildren ? "jsxs" : "jsx" ;
31
31
}
32
32
33
- function getJsxFactoryCallee ( childrenLength : number ) {
34
- const type = getJsxFactoryCalleePrimitive ( childrenLength ) ;
33
+ function getJsxFactoryCallee ( isStaticChildren : boolean ) {
34
+ const type = getJsxFactoryCalleePrimitive ( isStaticChildren ) ;
35
35
return getImplicitImportForName ( type ) ;
36
36
}
37
37
@@ -206,7 +206,7 @@ namespace ts {
206
206
207
207
function convertJsxChildrenToChildrenPropAssignment ( children : readonly JsxChild [ ] ) {
208
208
const nonWhitespaceChildren = getSemanticJsxChildren ( children ) ;
209
- if ( length ( nonWhitespaceChildren ) === 1 ) {
209
+ if ( length ( nonWhitespaceChildren ) === 1 && ! ( nonWhitespaceChildren [ 0 ] as JsxExpression ) . dotDotDotToken ) {
210
210
const result = transformJsxChildToExpression ( nonWhitespaceChildren [ 0 ] ) ;
211
211
return result && factory . createPropertyAssignment ( "children" , result ) ;
212
212
}
@@ -221,16 +221,33 @@ namespace ts {
221
221
const attrs = keyAttr ? filter ( node . attributes . properties , p => p !== keyAttr ) : node . attributes . properties ;
222
222
const objectProperties = length ( attrs ) ? transformJsxAttributesToObjectProps ( attrs , childrenProp ) :
223
223
factory . createObjectLiteralExpression ( childrenProp ? [ childrenProp ] : emptyArray ) ; // When there are no attributes, React wants {}
224
- return visitJsxOpeningLikeElementOrFragmentJSX ( tagName , objectProperties , keyAttr , length ( getSemanticJsxChildren ( children || emptyArray ) ) , isChild , location ) ;
224
+ return visitJsxOpeningLikeElementOrFragmentJSX (
225
+ tagName ,
226
+ objectProperties ,
227
+ keyAttr ,
228
+ children || emptyArray ,
229
+ isChild ,
230
+ location
231
+ ) ;
225
232
}
226
233
227
- function visitJsxOpeningLikeElementOrFragmentJSX ( tagName : Expression , objectProperties : Expression , keyAttr : JsxAttribute | undefined , childrenLength : number , isChild : boolean , location : TextRange ) {
234
+ function visitJsxOpeningLikeElementOrFragmentJSX (
235
+ tagName : Expression ,
236
+ objectProperties : Expression ,
237
+ keyAttr : JsxAttribute | undefined ,
238
+ children : readonly JsxChild [ ] ,
239
+ isChild : boolean ,
240
+ location : TextRange
241
+ ) {
242
+ const nonWhitespaceChildren = getSemanticJsxChildren ( children ) ;
243
+ const isStaticChildren =
244
+ length ( nonWhitespaceChildren ) > 1 || ! ! ( nonWhitespaceChildren [ 0 ] as JsxExpression ) ?. dotDotDotToken ;
228
245
const args : Expression [ ] = [ tagName , objectProperties , ! keyAttr ? factory . createVoidZero ( ) : transformJsxAttributeInitializer ( keyAttr . initializer ) ] ;
229
246
if ( compilerOptions . jsx === JsxEmit . ReactJSXDev ) {
230
247
const originalFile = getOriginalNode ( currentSourceFile ) ;
231
248
if ( originalFile && isSourceFile ( originalFile ) ) {
232
249
// isStaticChildren development flag
233
- args . push ( childrenLength > 1 ? factory . createTrue ( ) : factory . createFalse ( ) ) ;
250
+ args . push ( isStaticChildren ? factory . createTrue ( ) : factory . createFalse ( ) ) ;
234
251
// __source development flag
235
252
const lineCol = getLineAndCharacterOfPosition ( originalFile , location . pos ) ;
236
253
args . push ( factory . createObjectLiteralExpression ( [
@@ -242,7 +259,10 @@ namespace ts {
242
259
args . push ( factory . createThis ( ) ) ;
243
260
}
244
261
}
245
- const element = setTextRange ( factory . createCallExpression ( getJsxFactoryCallee ( childrenLength ) , /*typeArguments*/ undefined , args ) , location ) ;
262
+ const element = setTextRange (
263
+ factory . createCallExpression ( getJsxFactoryCallee ( isStaticChildren ) , /*typeArguments*/ undefined , args ) ,
264
+ location
265
+ ) ;
246
266
247
267
if ( isChild ) {
248
268
startOnNewLine ( element ) ;
@@ -294,7 +314,7 @@ namespace ts {
294
314
getImplicitJsxFragmentReference ( ) ,
295
315
childrenProps || factory . createObjectLiteralExpression ( [ ] ) ,
296
316
/*keyAttr*/ undefined ,
297
- length ( getSemanticJsxChildren ( children ) ) ,
317
+ children ,
298
318
isChild ,
299
319
location
300
320
) ;
0 commit comments