Skip to content

Commit

Permalink
Merge pull request #12280 from Microsoft/fix12262
Browse files Browse the repository at this point in the history
Fix argument list for new containing yield
  • Loading branch information
rbuckton authored Nov 15, 2016
2 parents 73ada7a + e389e08 commit a7d97c0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
28 changes: 20 additions & 8 deletions src/compiler/transformers/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ namespace ts {
* @param node The node to visit.
*/
function visitArrayLiteralExpression(node: ArrayLiteralExpression) {
return visitElements(node.elements, node.multiLine);
return visitElements(node.elements, /*leadingElement*/ undefined, /*location*/ undefined, node.multiLine);
}

/**
Expand All @@ -956,7 +956,7 @@ namespace ts {
* @param elements The elements to visit.
* @param multiLine Whether array literals created should be emitted on multiple lines.
*/
function visitElements(elements: NodeArray<Expression>, _multiLine?: boolean) {
function visitElements(elements: NodeArray<Expression>, leadingElement?: Expression, location?: TextRange, multiLine?: boolean) {
// [source]
// ar = [1, yield, 2];
//
Expand All @@ -971,18 +971,22 @@ namespace ts {
const temp = declareLocal();
let hasAssignedTemp = false;
if (numInitialElements > 0) {
const initialElements = visitNodes(elements, visitor, isExpression, 0, numInitialElements);
emitAssignment(temp,
createArrayLiteral(
visitNodes(elements, visitor, isExpression, 0, numInitialElements)
leadingElement
? [leadingElement, ...initialElements]
: initialElements
)
);
leadingElement = undefined;
hasAssignedTemp = true;
}

const expressions = reduceLeft(elements, reduceElement, <Expression[]>[], numInitialElements);
return hasAssignedTemp
? createArrayConcat(temp, [createArrayLiteral(expressions)])
: createArrayLiteral(expressions);
? createArrayConcat(temp, [createArrayLiteral(expressions, /*location*/ undefined, multiLine)])
: createArrayLiteral(leadingElement ? [leadingElement, ...expressions] : expressions, location, multiLine);

function reduceElement(expressions: Expression[], element: Expression) {
if (containsYield(element) && expressions.length > 0) {
Expand All @@ -991,11 +995,16 @@ namespace ts {
hasAssignedTemp
? createArrayConcat(
temp,
[createArrayLiteral(expressions)]
[createArrayLiteral(expressions, /*location*/ undefined, multiLine)]
)
: createArrayLiteral(
leadingElement ? [leadingElement, ...expressions] : expressions,
/*location*/ undefined,
multiLine
)
: createArrayLiteral(expressions)
);
hasAssignedTemp = true;
leadingElement = undefined;
expressions = [];
}

Expand Down Expand Up @@ -1131,7 +1140,10 @@ namespace ts {
createFunctionApply(
cacheExpression(visitNode(target, visitor, isExpression)),
thisArg,
visitElements(node.arguments)
visitElements(
node.arguments,
/*leadingElement*/ createVoidZero()
)
),
/*typeArguments*/ undefined,
[],
Expand Down
12 changes: 6 additions & 6 deletions tests/baselines/reference/es5-asyncFunctionNewExpressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function newExpression2() {
_a = x.bind;
return [4 /*yield*/, y];
case 1:
new (_a.apply(x, [_c.sent(), z]))();
new (_a.apply(x, [void 0, _c.sent(), z]))();
return [2 /*return*/];
}
});
Expand All @@ -132,7 +132,7 @@ function newExpression3() {
switch (_c.label) {
case 0:
_a = x.bind;
_b = [y];
_b = [void 0, y];
return [4 /*yield*/, z];
case 1:
new (_a.apply(x, _b.concat([_c.sent()])))();
Expand Down Expand Up @@ -280,7 +280,7 @@ function newExpression13() {
_b = (_a = x.a).bind;
return [4 /*yield*/, y];
case 1:
new (_b.apply(_a, [_d.sent(), z]))();
new (_b.apply(_a, [void 0, _d.sent(), z]))();
return [2 /*return*/];
}
});
Expand All @@ -293,7 +293,7 @@ function newExpression14() {
switch (_d.label) {
case 0:
_b = (_a = x.a).bind;
_c = [y];
_c = [void 0, y];
return [4 /*yield*/, z];
case 1:
new (_b.apply(_a, _c.concat([_d.sent()])))();
Expand Down Expand Up @@ -362,7 +362,7 @@ function newExpression19() {
_b = (_a = x[a]).bind;
return [4 /*yield*/, y];
case 1:
new (_b.apply(_a, [_d.sent(), z]))();
new (_b.apply(_a, [void 0, _d.sent(), z]))();
return [2 /*return*/];
}
});
Expand All @@ -375,7 +375,7 @@ function newExpression20() {
switch (_d.label) {
case 0:
_b = (_a = x[a]).bind;
_c = [y];
_c = [void 0, y];
return [4 /*yield*/, z];
case 1:
new (_b.apply(_a, _c.concat([_d.sent()])))();
Expand Down

0 comments on commit a7d97c0

Please sign in to comment.