@@ -3522,7 +3522,7 @@ namespace ts {
3522
3522
function visitArrayLiteralExpression ( node : ArrayLiteralExpression ) : Expression {
3523
3523
if ( some ( node . elements , isSpreadElement ) ) {
3524
3524
// We are here because we contain a SpreadElementExpression.
3525
- return transformAndSpreadElements ( node . elements , /*needsUniqueCopy*/ true , ! ! node . multiLine , /*hasTrailingComma*/ ! ! node . elements . hasTrailingComma ) ;
3525
+ return transformAndSpreadElements ( node . elements , ! ! node . multiLine , /*hasTrailingComma*/ ! ! node . elements . hasTrailingComma ) ;
3526
3526
}
3527
3527
return visitEachChild ( node , visitor , context ) ;
3528
3528
}
@@ -3737,7 +3737,7 @@ namespace ts {
3737
3737
resultingCall = createFunctionApply (
3738
3738
visitNode ( target , callExpressionVisitor , isExpression ) ,
3739
3739
node . expression . kind === SyntaxKind . SuperKeyword ? thisArg : visitNode ( thisArg , visitor , isExpression ) ,
3740
- transformAndSpreadElements ( node . arguments , /*needsUniqueCopy*/ false , /* multiLine*/ false , /*hasTrailingComma*/ false )
3740
+ transformAndSpreadElements ( node . arguments , /*multiLine*/ false , /*hasTrailingComma*/ false )
3741
3741
) ;
3742
3742
}
3743
3743
else {
@@ -3793,7 +3793,7 @@ namespace ts {
3793
3793
createFunctionApply (
3794
3794
visitNode ( target , visitor , isExpression ) ,
3795
3795
thisArg ,
3796
- transformAndSpreadElements ( createNodeArray ( [ createVoidZero ( ) , ...node . arguments ! ] ) , /*needsUniqueCopy*/ false , /* multiLine*/ false , /*hasTrailingComma*/ false )
3796
+ transformAndSpreadElements ( createNodeArray ( [ createVoidZero ( ) , ...node . arguments ! ] ) , /*multiLine*/ false , /*hasTrailingComma*/ false )
3797
3797
) ,
3798
3798
/*typeArguments*/ undefined ,
3799
3799
[ ]
@@ -3806,15 +3806,17 @@ namespace ts {
3806
3806
* Transforms an array of Expression nodes that contains a SpreadExpression.
3807
3807
*
3808
3808
* @param elements The array of Expression nodes.
3809
- * @param needsUniqueCopy A value indicating whether to ensure that the result is a fresh array.
3810
3809
* @param multiLine A value indicating whether the result should be emitted on multiple lines.
3811
3810
*/
3812
- function transformAndSpreadElements ( elements : NodeArray < Expression > , needsUniqueCopy : boolean , multiLine : boolean , hasTrailingComma : boolean ) : Expression {
3811
+ function transformAndSpreadElements ( elements : NodeArray < Expression > , multiLine : boolean , hasTrailingComma : boolean ) : Expression {
3813
3812
// [source]
3814
3813
// [a, ...b, c]
3815
3814
//
3815
+ // [output (downlevelIteration)]
3816
+ // __spread([a], b, [c])
3817
+ //
3816
3818
// [output]
3817
- // [a].concat( b, [c])
3819
+ // __spreadArrays( [a], b, [c])
3818
3820
3819
3821
// Map spans of spread expressions into their expressions and spans of other
3820
3822
// expressions into an array literal.
@@ -3840,14 +3842,16 @@ namespace ts {
3840
3842
}
3841
3843
else {
3842
3844
if ( segments . length === 1 ) {
3843
- const firstElement = elements [ 0 ] ;
3844
- return needsUniqueCopy && isSpreadElement ( firstElement ) && firstElement . expression . kind !== SyntaxKind . ArrayLiteralExpression
3845
- ? createArraySlice ( segments [ 0 ] )
3846
- : segments [ 0 ] ;
3845
+ const firstSegment = segments [ 0 ] ;
3846
+ if ( isCallExpression ( firstSegment )
3847
+ && isIdentifier ( firstSegment . expression )
3848
+ && ( getEmitFlags ( firstSegment . expression ) & EmitFlags . HelperName )
3849
+ && firstSegment . expression . escapedText === "___spreadArrays" ) {
3850
+ return segments [ 0 ] ;
3851
+ }
3847
3852
}
3848
3853
3849
- // Rewrite using the pattern <segment0>.concat(<segment1>, <segment2>, ...)
3850
- return createArrayConcat ( segments . shift ( ) ! , segments ) ;
3854
+ return createSpreadArraysHelper ( context , segments ) ;
3851
3855
}
3852
3856
}
3853
3857
0 commit comments