@@ -71,35 +71,31 @@ namespace ts {
7171 function visitJsxOpeningLikeElement ( node : JsxOpeningLikeElement , children : JsxChild [ ] ) {
7272 const tagName = getTagName ( node ) ;
7373 let objectProperties : Expression ;
74- if ( node . attributes . length === 0 ) {
74+ const attrs = node . attributes ;
75+ if ( attrs . length === 0 ) {
7576 // When there are no attributes, React wants "null"
7677 objectProperties = createNull ( ) ;
7778 }
7879 else {
80+ // Map spans of JsxAttribute nodes into object literals and spans
81+ // of JsxSpreadAttribute nodes into expressions.
82+ const segments = flatten (
83+ spanMap ( attrs , isJsxSpreadAttribute , ( attrs , isSpread ) => isSpread
84+ ? map ( attrs , transformJsxSpreadAttributeToExpression )
85+ : createObjectLiteral ( map ( attrs , transformJsxAttributeToObjectLiteralElement ) )
86+ )
87+ ) ;
88+
89+ if ( isJsxSpreadAttribute ( attrs [ 0 ] ) ) {
90+ // We must always emit at least one object literal before a spread
91+ // argument.
92+ segments . unshift ( createObjectLiteral ( ) ) ;
93+ }
94+
7995 // Either emit one big object literal (no spread attribs), or
8096 // a call to React.__spread
81- const attrs = node . attributes ;
82- if ( ! forEach ( attrs , isJsxSpreadAttribute ) ) {
83- objectProperties = createObjectLiteral ( map ( node . attributes , transformJsxAttributeToObjectLiteralElement ) ) ;
84- }
85- else {
86- objectProperties = createJsxSpread ( compilerOptions . reactNamespace ,
87- concatenate (
88- // We must always emit at least one object literal before a spread
89- // argument.
90- isJsxSpreadAttribute ( attrs [ 0 ] ) ? [ createObjectLiteral ( ) ] : undefined ,
91-
92- // Map spans of JsxAttribute nodes into object literals and spans
93- // of JsxSpreadAttribute nodes into expressions.
94- flatten (
95- spanMap ( attrs , isJsxSpreadAttribute , ( attrs , isSpread ) => isSpread
96- ? map ( attrs , transformJsxSpreadAttributeToExpression )
97- : createObjectLiteral ( map ( attrs , transformJsxAttributeToObjectLiteralElement ) )
98- )
99- )
100- )
101- ) ;
102- }
97+ objectProperties = singleOrUndefined ( segments )
98+ || createJsxSpread ( compilerOptions . reactNamespace , segments ) ;
10399 }
104100
105101 return createJsxCreateElement (
0 commit comments