Skip to content

Commit e90742f

Browse files
authored
Merge pull request #13040 from Microsoft/es2015-cleanup
Clean up for ES2015 transforms
2 parents a71befe + fa53eb1 commit e90742f

10 files changed

+597
-411
lines changed

src/compiler/factory.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,23 @@ namespace ts {
17551755

17561756
// Utilities
17571757

1758+
export function restoreEnclosingLabel(node: Statement, outermostLabeledStatement: LabeledStatement, afterRestoreLabelCallback?: (node: LabeledStatement) => void): Statement {
1759+
if (!outermostLabeledStatement) {
1760+
return node;
1761+
}
1762+
const updated = updateLabel(
1763+
outermostLabeledStatement,
1764+
outermostLabeledStatement.label,
1765+
outermostLabeledStatement.statement.kind === SyntaxKind.LabeledStatement
1766+
? restoreEnclosingLabel(node, <LabeledStatement>outermostLabeledStatement.statement)
1767+
: node
1768+
);
1769+
if (afterRestoreLabelCallback) {
1770+
afterRestoreLabelCallback(outermostLabeledStatement);
1771+
}
1772+
return updated;
1773+
}
1774+
17581775
export interface CallBinding {
17591776
target: LeftHandSideExpression;
17601777
thisArg: Expression;

src/compiler/transformers/es2015.ts

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

src/compiler/utilities.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,17 @@ namespace ts {
914914
return false;
915915
}
916916

917+
export function unwrapInnermostStatmentOfLabel(node: LabeledStatement, beforeUnwrapLabelCallback?: (node: LabeledStatement) => void) {
918+
while (true) {
919+
if (beforeUnwrapLabelCallback) {
920+
beforeUnwrapLabelCallback(node);
921+
}
922+
if (node.statement.kind !== SyntaxKind.LabeledStatement) {
923+
return node.statement;
924+
}
925+
node = <LabeledStatement>node.statement;
926+
}
927+
}
917928

918929
export function isFunctionBlock(node: Node) {
919930
return node && node.kind === SyntaxKind.Block && isFunctionLike(node.parent);

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;

tests/baselines/reference/super_inside-object-literal-getters-and-setters.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ var ObjectLiteral;
3838
var ThisInObjectLiteral = {
3939
_foo: '1',
4040
get foo() {
41-
return _super.prototype._foo;
41+
return _super._foo;
4242
},
4343
set foo(value) {
44-
_super.prototype._foo = value;
44+
_super._foo = value;
4545
},
4646
test: function () {
4747
return _super._foo;
@@ -62,7 +62,7 @@ var SuperObjectTest = (function (_super) {
6262
SuperObjectTest.prototype.testing = function () {
6363
var test = {
6464
get F() {
65-
return _super.prototype.test.call(this);
65+
return _super.test.call(this);
6666
}
6767
};
6868
};

0 commit comments

Comments
 (0)