Skip to content

Commit b0faa92

Browse files
committed
Merge branch 'es2015-cleanup' into asyncGenerators
2 parents 87eeb57 + fa53eb1 commit b0faa92

11 files changed

+602
-471
lines changed

src/compiler/factory.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,19 +1862,6 @@ namespace ts {
18621862

18631863
// Utilities
18641864

1865-
export function restoreEnclosingLabels(node: Statement, enclosingLabeledStatements: LabeledStatement[]) {
1866-
if (enclosingLabeledStatements) {
1867-
for (const labeledStatement of enclosingLabeledStatements) {
1868-
node = updateLabel(
1869-
labeledStatement,
1870-
labeledStatement.label,
1871-
node
1872-
);
1873-
}
1874-
}
1875-
return node;
1876-
}
1877-
18781865
export function createForOfBindingStatement(node: ForInitializer, boundValue: Expression): Statement {
18791866
if (isVariableDeclarationList(node)) {
18801867
const firstDeclaration = firstOrUndefined(node.declarations);
@@ -1906,6 +1893,23 @@ namespace ts {
19061893
}
19071894
}
19081895

1896+
export function restoreEnclosingLabel(node: Statement, outermostLabeledStatement: LabeledStatement, afterRestoreLabelCallback?: (node: LabeledStatement) => void): Statement {
1897+
if (!outermostLabeledStatement) {
1898+
return node;
1899+
}
1900+
const updated = updateLabel(
1901+
outermostLabeledStatement,
1902+
outermostLabeledStatement.label,
1903+
outermostLabeledStatement.statement.kind === SyntaxKind.LabeledStatement
1904+
? restoreEnclosingLabel(node, <LabeledStatement>outermostLabeledStatement.statement)
1905+
: node
1906+
);
1907+
if (afterRestoreLabelCallback) {
1908+
afterRestoreLabelCallback(outermostLabeledStatement);
1909+
}
1910+
return updated;
1911+
}
1912+
19091913
export interface CallBinding {
19101914
target: LeftHandSideExpression;
19111915
thisArg: Expression;

src/compiler/transformers/es2015.ts

Lines changed: 553 additions & 424 deletions
Large diffs are not rendered by default.

src/compiler/transformers/es2017.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,16 @@ namespace ts {
156156
}
157157

158158
function visitLabeledStatement(node: LabeledStatement): VisitResult<Statement> {
159-
const enclosedStatement = getEnclosedStatement(node);
160-
if (enclosedStatement.statement.kind === SyntaxKind.ForOfStatement &&
161-
(<ForOfStatement>enclosedStatement.statement).awaitModifier) {
162-
return visitForOfStatement(<ForOfStatement>node.statement, enclosedStatement.enclosingLabeledStatements);
159+
const statement = unwrapInnermostStatmentOfLabel(node);
160+
if (statement.kind === SyntaxKind.ForOfStatement &&
161+
(<ForOfStatement>statement).awaitModifier) {
162+
return visitForOfStatement(<ForOfStatement>statement, node);
163163
}
164164

165-
return restoreEnclosingLabels(visitEachChild(node, visitor, context), enclosedStatement.enclosingLabeledStatements);
165+
return restoreEnclosingLabel(visitEachChild(node, visitor, context), node);
166166
}
167167

168-
function visitForOfStatement(node: ForOfStatement, enclosingLabeledStatements: LabeledStatement[]): VisitResult<Statement> {
168+
function visitForOfStatement(node: ForOfStatement, outermostLabeledStatement: LabeledStatement): VisitResult<Statement> {
169169
if (!node.awaitModifier) return visitEachChild(node, visitor, context);
170170

171171
let bodyLocation: TextRange;
@@ -247,7 +247,7 @@ namespace ts {
247247
EmitFlags.NoTokenTrailingSourceMaps
248248
);
249249

250-
outerStatement = restoreEnclosingLabels(outerStatement, enclosingLabeledStatements);
250+
outerStatement = restoreEnclosingLabel(outerStatement, outermostLabeledStatement);
251251
return closeAsyncIterator(outerStatement, iteratorRecord);
252252
}
253253

src/compiler/utilities.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -900,20 +900,18 @@ namespace ts {
900900
return false;
901901
}
902902

903-
export function getEnclosedStatement(node: LabeledStatement): { statement: Statement; enclosingLabeledStatements: LabeledStatement[]; } {
904-
switch (node.statement.kind) {
905-
case SyntaxKind.LabeledStatement:
906-
const result = getEnclosedStatement(<LabeledStatement>node.statement);
907-
if (result) {
908-
result.enclosingLabeledStatements.push(node);
909-
}
910-
return result;
911-
default:
912-
return { statement: <IterationStatement>node.statement, enclosingLabeledStatements: [node] };
903+
export function unwrapInnermostStatmentOfLabel(node: LabeledStatement, beforeUnwrapLabelCallback?: (node: LabeledStatement) => void) {
904+
while (true) {
905+
if (beforeUnwrapLabelCallback) {
906+
beforeUnwrapLabelCallback(node);
907+
}
908+
if (node.statement.kind !== SyntaxKind.LabeledStatement) {
909+
return node.statement;
910+
}
911+
node = <LabeledStatement>node.statement;
913912
}
914913
}
915914

916-
917915
export function isFunctionBlock(node: Node) {
918916
return node && node.kind === SyntaxKind.Block && isFunctionLike(node.parent);
919917
}

tests/baselines/reference/captureSuperPropertyAccessInSuperCall01.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var A = (function () {
2626
var B = (function (_super) {
2727
__extends(B, _super);
2828
function B() {
29-
var _this = _super.call(this, function () { return _super.blah.call(_this); }) || this;
29+
var _this = _super.call(this, function () { return _super.prototype.blah.call(_this); }) || this;
3030
return _this;
3131
}
3232
return B;

tests/baselines/reference/superAccess2.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ var Q = (function (_super) {
4141
__extends(Q, _super);
4242
// Super is not allowed in constructor args
4343
function Q(z, zz, zzz) {
44-
if (z === void 0) { z = _super.; }
45-
if (zz === void 0) { zz = _super.; }
46-
if (zzz === void 0) { zzz = function () { return _super.; }; }
44+
if (z === void 0) { z = _super.prototype.; }
45+
if (zz === void 0) { zz = _super.prototype.; }
46+
if (zzz === void 0) { zzz = function () { return _super.prototype.; }; }
4747
var _this = _super.call(this) || this;
4848
_this.z = z;
4949
_this.xx = _super.prototype.;

tests/baselines/reference/superInConstructorParam1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var B = (function () {
2727
var C = (function (_super) {
2828
__extends(C, _super);
2929
function C(a) {
30-
if (a === void 0) { a = _super.foo.call(_this); }
30+
if (a === void 0) { a = _super.prototype.foo.call(_this); }
3131
var _this;
3232
return _this;
3333
}

tests/baselines/reference/superInObjectLiterals_ES5.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ var obj = {
7272
}
7373
},
7474
method: function () {
75-
_super.prototype.method.call(this);
75+
_super.method.call(this);
7676
},
7777
get prop() {
78-
_super.prototype.method.call(this);
78+
_super.method.call(this);
7979
return 10;
8080
},
8181
set prop(value) {
82-
_super.prototype.method.call(this);
82+
_super.method.call(this);
8383
},
8484
p1: function () {
8585
_super.method.call(this);
@@ -110,14 +110,14 @@ var B = (function (_super) {
110110
}
111111
},
112112
method: function () {
113-
_super.prototype.method.call(this);
113+
_super.method.call(this);
114114
},
115115
get prop() {
116-
_super.prototype.method.call(this);
116+
_super.method.call(this);
117117
return 10;
118118
},
119119
set prop(value) {
120-
_super.prototype.method.call(this);
120+
_super.method.call(this);
121121
},
122122
p1: function () {
123123
_super.method.call(this);

tests/baselines/reference/superPropertyAccessInSuperCall01.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var A = (function () {
2626
var B = (function (_super) {
2727
__extends(B, _super);
2828
function B() {
29-
var _this = _super.call(this, _super.blah.call(_this)) || this;
29+
var _this = _super.call(this, _super.prototype.blah.call(_this)) || this;
3030
return _this;
3131
}
3232
return B;

tests/baselines/reference/superPropertyInConstructorBeforeSuperCall.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var C1 = (function (_super) {
4040
var C2 = (function (_super) {
4141
__extends(C2, _super);
4242
function C2() {
43-
var _this = _super.call(this, _super.x.call(_this)) || this;
43+
var _this = _super.call(this, _super.prototype.x.call(_this)) || this;
4444
return _this;
4545
}
4646
return C2;

0 commit comments

Comments
 (0)