Skip to content

Commit a7d97c0

Browse files
authored
Merge pull request microsoft#12280 from Microsoft/fix12262
Fix argument list for new containing yield
2 parents 73ada7a + e389e08 commit a7d97c0

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

Diff for: src/compiler/transformers/generators.ts

+20-8
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ namespace ts {
946946
* @param node The node to visit.
947947
*/
948948
function visitArrayLiteralExpression(node: ArrayLiteralExpression) {
949-
return visitElements(node.elements, node.multiLine);
949+
return visitElements(node.elements, /*leadingElement*/ undefined, /*location*/ undefined, node.multiLine);
950950
}
951951

952952
/**
@@ -956,7 +956,7 @@ namespace ts {
956956
* @param elements The elements to visit.
957957
* @param multiLine Whether array literals created should be emitted on multiple lines.
958958
*/
959-
function visitElements(elements: NodeArray<Expression>, _multiLine?: boolean) {
959+
function visitElements(elements: NodeArray<Expression>, leadingElement?: Expression, location?: TextRange, multiLine?: boolean) {
960960
// [source]
961961
// ar = [1, yield, 2];
962962
//
@@ -971,18 +971,22 @@ namespace ts {
971971
const temp = declareLocal();
972972
let hasAssignedTemp = false;
973973
if (numInitialElements > 0) {
974+
const initialElements = visitNodes(elements, visitor, isExpression, 0, numInitialElements);
974975
emitAssignment(temp,
975976
createArrayLiteral(
976-
visitNodes(elements, visitor, isExpression, 0, numInitialElements)
977+
leadingElement
978+
? [leadingElement, ...initialElements]
979+
: initialElements
977980
)
978981
);
982+
leadingElement = undefined;
979983
hasAssignedTemp = true;
980984
}
981985

982986
const expressions = reduceLeft(elements, reduceElement, <Expression[]>[], numInitialElements);
983987
return hasAssignedTemp
984-
? createArrayConcat(temp, [createArrayLiteral(expressions)])
985-
: createArrayLiteral(expressions);
988+
? createArrayConcat(temp, [createArrayLiteral(expressions, /*location*/ undefined, multiLine)])
989+
: createArrayLiteral(leadingElement ? [leadingElement, ...expressions] : expressions, location, multiLine);
986990

987991
function reduceElement(expressions: Expression[], element: Expression) {
988992
if (containsYield(element) && expressions.length > 0) {
@@ -991,11 +995,16 @@ namespace ts {
991995
hasAssignedTemp
992996
? createArrayConcat(
993997
temp,
994-
[createArrayLiteral(expressions)]
998+
[createArrayLiteral(expressions, /*location*/ undefined, multiLine)]
999+
)
1000+
: createArrayLiteral(
1001+
leadingElement ? [leadingElement, ...expressions] : expressions,
1002+
/*location*/ undefined,
1003+
multiLine
9951004
)
996-
: createArrayLiteral(expressions)
9971005
);
9981006
hasAssignedTemp = true;
1007+
leadingElement = undefined;
9991008
expressions = [];
10001009
}
10011010

@@ -1131,7 +1140,10 @@ namespace ts {
11311140
createFunctionApply(
11321141
cacheExpression(visitNode(target, visitor, isExpression)),
11331142
thisArg,
1134-
visitElements(node.arguments)
1143+
visitElements(
1144+
node.arguments,
1145+
/*leadingElement*/ createVoidZero()
1146+
)
11351147
),
11361148
/*typeArguments*/ undefined,
11371149
[],

Diff for: tests/baselines/reference/es5-asyncFunctionNewExpressions.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function newExpression2() {
119119
_a = x.bind;
120120
return [4 /*yield*/, y];
121121
case 1:
122-
new (_a.apply(x, [_c.sent(), z]))();
122+
new (_a.apply(x, [void 0, _c.sent(), z]))();
123123
return [2 /*return*/];
124124
}
125125
});
@@ -132,7 +132,7 @@ function newExpression3() {
132132
switch (_c.label) {
133133
case 0:
134134
_a = x.bind;
135-
_b = [y];
135+
_b = [void 0, y];
136136
return [4 /*yield*/, z];
137137
case 1:
138138
new (_a.apply(x, _b.concat([_c.sent()])))();
@@ -280,7 +280,7 @@ function newExpression13() {
280280
_b = (_a = x.a).bind;
281281
return [4 /*yield*/, y];
282282
case 1:
283-
new (_b.apply(_a, [_d.sent(), z]))();
283+
new (_b.apply(_a, [void 0, _d.sent(), z]))();
284284
return [2 /*return*/];
285285
}
286286
});
@@ -293,7 +293,7 @@ function newExpression14() {
293293
switch (_d.label) {
294294
case 0:
295295
_b = (_a = x.a).bind;
296-
_c = [y];
296+
_c = [void 0, y];
297297
return [4 /*yield*/, z];
298298
case 1:
299299
new (_b.apply(_a, _c.concat([_d.sent()])))();
@@ -362,7 +362,7 @@ function newExpression19() {
362362
_b = (_a = x[a]).bind;
363363
return [4 /*yield*/, y];
364364
case 1:
365-
new (_b.apply(_a, [_d.sent(), z]))();
365+
new (_b.apply(_a, [void 0, _d.sent(), z]))();
366366
return [2 /*return*/];
367367
}
368368
});
@@ -375,7 +375,7 @@ function newExpression20() {
375375
switch (_d.label) {
376376
case 0:
377377
_b = (_a = x[a]).bind;
378-
_c = [y];
378+
_c = [void 0, y];
379379
return [4 /*yield*/, z];
380380
case 1:
381381
new (_b.apply(_a, _c.concat([_d.sent()])))();

0 commit comments

Comments
 (0)