@@ -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
@@ -221,24 +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
- const nonWhitespaceChildren = getSemanticJsxChildren ( children || emptyArray ) ;
225
224
return visitJsxOpeningLikeElementOrFragmentJSX (
226
225
tagName ,
227
226
objectProperties ,
228
227
keyAttr ,
229
- ( nonWhitespaceChildren [ 0 ] as JsxExpression ) ?. dotDotDotToken ? 2 : length ( nonWhitespaceChildren ) ,
228
+ children || emptyArray ,
230
229
isChild ,
231
230
location
232
231
) ;
233
232
}
234
233
235
- 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 ;
236
245
const args : Expression [ ] = [ tagName , objectProperties , ! keyAttr ? factory . createVoidZero ( ) : transformJsxAttributeInitializer ( keyAttr . initializer ) ] ;
237
246
if ( compilerOptions . jsx === JsxEmit . ReactJSXDev ) {
238
247
const originalFile = getOriginalNode ( currentSourceFile ) ;
239
248
if ( originalFile && isSourceFile ( originalFile ) ) {
240
249
// isStaticChildren development flag
241
- args . push ( childrenLength > 1 ? factory . createTrue ( ) : factory . createFalse ( ) ) ;
250
+ args . push ( isStaticChildren ? factory . createTrue ( ) : factory . createFalse ( ) ) ;
242
251
// __source development flag
243
252
const lineCol = getLineAndCharacterOfPosition ( originalFile , location . pos ) ;
244
253
args . push ( factory . createObjectLiteralExpression ( [
@@ -250,7 +259,10 @@ namespace ts {
250
259
args . push ( factory . createThis ( ) ) ;
251
260
}
252
261
}
253
- 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
+ ) ;
254
266
255
267
if ( isChild ) {
256
268
startOnNewLine ( element ) ;
@@ -298,12 +310,11 @@ namespace ts {
298
310
childrenProps = result ;
299
311
}
300
312
}
301
- const nonWhitespaceChildren = getSemanticJsxChildren ( children ) ;
302
313
return visitJsxOpeningLikeElementOrFragmentJSX (
303
314
getImplicitJsxFragmentReference ( ) ,
304
315
childrenProps || factory . createObjectLiteralExpression ( [ ] ) ,
305
316
/*keyAttr*/ undefined ,
306
- ( nonWhitespaceChildren [ 0 ] as JsxExpression ) ?. dotDotDotToken ? 2 : length ( nonWhitespaceChildren ) ,
317
+ children ,
307
318
isChild ,
308
319
location
309
320
) ;
0 commit comments