mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-16 05:58:32 -06:00
Fix extra slice in array with spread
This commit is contained in:
parent
0f9bccdf32
commit
63cf58bd09
@ -1467,7 +1467,7 @@ namespace ts {
|
||||
return createFunctionApply(
|
||||
visitNode(target, visitor, isExpression),
|
||||
visitNode(thisArg, visitor, isExpression),
|
||||
transformAndSpreadElements(node.arguments, /*needsUniqueCopy*/ false, /*multiLine*/ false)
|
||||
transformAndSpreadElements(node.arguments, /*needsUniqueCopy*/ false, /*multiLine*/ false, /*hasTrailingComma*/ false)
|
||||
);
|
||||
}
|
||||
else {
|
||||
@ -1510,7 +1510,7 @@ namespace ts {
|
||||
createFunctionApply(
|
||||
visitNode(target, visitor, isExpression),
|
||||
thisArg,
|
||||
transformAndSpreadElements(createNodeArray([createVoidZero(), ...node.arguments]), /*needsUniqueCopy*/ false, /*multiLine*/ false)
|
||||
transformAndSpreadElements(createNodeArray([createVoidZero(), ...node.arguments]), /*needsUniqueCopy*/ false, /*multiLine*/ false, /*hasTrailingComma*/ false)
|
||||
),
|
||||
[]
|
||||
);
|
||||
@ -1523,7 +1523,7 @@ namespace ts {
|
||||
* @param needsUniqueCopy A value indicating whether to ensure that the result is a fresh array.
|
||||
* @param multiLine A value indicating whether the result should be emitted on multiple lines.
|
||||
*/
|
||||
function transformAndSpreadElements(elements: NodeArray<Expression>, needsUniqueCopy: boolean, multiLine: boolean, hasTrailingComma?: boolean): Expression {
|
||||
function transformAndSpreadElements(elements: NodeArray<Expression>, needsUniqueCopy: boolean, multiLine: boolean, hasTrailingComma: boolean): Expression {
|
||||
// [source]
|
||||
// [a, ...b, c]
|
||||
//
|
||||
@ -1540,7 +1540,8 @@ namespace ts {
|
||||
);
|
||||
|
||||
if (segments.length === 1) {
|
||||
return needsUniqueCopy && isSpreadElementExpression(elements[0])
|
||||
const firstElement = elements[0];
|
||||
return needsUniqueCopy && isSpreadElementExpression(firstElement) && firstElement.expression.kind !== SyntaxKind.ArrayLiteralExpression
|
||||
? createArraySlice(segments[0])
|
||||
: segments[0];
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user