mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 11:24:29 -05:00
Adds an always emit of pair of parens in spread syntax in new expression in ES5
This commit is contained in:
@@ -1853,12 +1853,6 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
emitListWithSpread(node.arguments, /*alwaysCopy*/ false, /*multiLine*/ false, /*trailingComma*/ false);
|
||||
write(")");
|
||||
}
|
||||
|
||||
function emitBracedEnclosedCommaList(nodes: Node[]) {
|
||||
write("(");
|
||||
emitCommaList(nodes);
|
||||
write(")");
|
||||
}
|
||||
|
||||
function emitCallExpression(node: CallExpression) {
|
||||
if (languageVersion < ScriptTarget.ES6 && hasSpreadElement(node.arguments)) {
|
||||
@@ -1871,14 +1865,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
superCall = true;
|
||||
}
|
||||
else {
|
||||
if (node.expression.kind === SyntaxKind.NewExpression) {
|
||||
emitNewExpression(<NewExpression>node.expression, /*emitCallHelper*/true);
|
||||
emitBracedEnclosedCommaList(node.arguments);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
emit(node.expression);
|
||||
}
|
||||
emit(node.expression);
|
||||
superCall = node.expression.kind === SyntaxKind.PropertyAccessExpression && (<PropertyAccessExpression>node.expression).expression.kind === SyntaxKind.SuperKeyword;
|
||||
}
|
||||
if (superCall && languageVersion < ScriptTarget.ES6) {
|
||||
@@ -1891,27 +1878,13 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
write(")");
|
||||
}
|
||||
else {
|
||||
emitBracedEnclosedCommaList(node.arguments);
|
||||
write("(");
|
||||
emitCommaList(node.arguments);
|
||||
write(")");
|
||||
}
|
||||
}
|
||||
|
||||
/** Emit a new expression.
|
||||
*
|
||||
* Emit call helper:
|
||||
* When we are emitting a call expression from a new expressions with spread syntax in ES5
|
||||
* we need an argument to help this function decide whether it should emit a pair of extra
|
||||
* braces "()" at the end. These extra braces are there to help the expression to not be
|
||||
* consumed by the new expression directly.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* new Array(...arguments)();
|
||||
*
|
||||
* Should be transpiled into ES5:
|
||||
*
|
||||
* new (Array.bind.apply(Array, [void 0].concat(arguments)))()()
|
||||
*/
|
||||
function emitNewExpression(node: NewExpression, emitCallHelper = false) {
|
||||
|
||||
function emitNewExpression(node: NewExpression) {
|
||||
write("new ");
|
||||
|
||||
// Spread operator logic can be supported in new expressions in ES5 using a combination
|
||||
@@ -1942,9 +1915,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
write(", [void 0].concat(");
|
||||
emitListWithSpread(node.arguments, /*multiline*/false, /*trailingComma*/false);
|
||||
write(")))");
|
||||
if (emitCallHelper) {
|
||||
write("()");
|
||||
}
|
||||
write("()");
|
||||
}
|
||||
else {
|
||||
emit(node.expression);
|
||||
|
||||
Reference in New Issue
Block a user