@@ -71,35 +71,31 @@ namespace ts {
71
71
function visitJsxOpeningLikeElement ( node : JsxOpeningLikeElement , children : JsxChild [ ] ) {
72
72
const tagName = getTagName ( node ) ;
73
73
let objectProperties : Expression ;
74
- if ( node . attributes . length === 0 ) {
74
+ const attrs = node . attributes ;
75
+ if ( attrs . length === 0 ) {
75
76
// When there are no attributes, React wants "null"
76
77
objectProperties = createNull ( ) ;
77
78
}
78
79
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
+
79
95
// Either emit one big object literal (no spread attribs), or
80
96
// 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
AAE2
- // 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 ) ;
103
99
}
104
100
105
101
return createJsxCreateElement (
0 commit comments