Skip to content

Commit 376ad28

Browse files
committed
Skip outter expressions when checking for super keyword in binder
1 parent 9ece1a5 commit 376ad28

File tree

5 files changed

+187
-4
lines changed

5 files changed

+187
-4
lines changed

src/compiler/binder.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,14 +2742,13 @@ namespace ts {
27422742
function computeCallExpression(node: CallExpression, subtreeFlags: TransformFlags) {
27432743
let transformFlags = subtreeFlags;
27442744
const expression = node.expression;
2745-
const expressionKind = expression.kind;
27462745

27472746
if (node.typeArguments) {
27482747
transformFlags |= TransformFlags.AssertTypeScript;
27492748
}
27502749

27512750
if (subtreeFlags & TransformFlags.ContainsSpread
2752-
|| isSuperOrSuperProperty(expression, expressionKind)) {
2751+
|| isSuperOrSuperProperty(expression)) {
27532752
// If the this node contains a SpreadExpression, or is a super call, then it is an ES6
27542753
// node.
27552754
transformFlags |= TransformFlags.AssertES2015;
@@ -2769,8 +2768,9 @@ namespace ts {
27692768
return transformFlags & ~TransformFlags.ArrayLiteralOrCallOrNewExcludes;
27702769
}
27712770

2772-
function isSuperOrSuperProperty(node: Node, kind: SyntaxKind) {
2773-
switch (kind) {
2771+
function isSuperOrSuperProperty(node: Node) {
2772+
node = skipOuterExpressions(node);
2773+
switch (node.kind) {
27742774
case SyntaxKind.SuperKeyword:
27752775
return true;
27762776

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//// [superAccessCastedCall.ts]
2+
class Foo {
3+
bar(): void {}
4+
}
5+
6+
class Bar extends Foo {
7+
x: Number;
8+
9+
constructor() {
10+
super();
11+
this.x = 2;
12+
}
13+
14+
bar() {
15+
super.bar();
16+
(super.bar as any)();
17+
}
18+
}
19+
20+
let b = new Bar();
21+
b.bar()
22+
23+
//// [superAccessCastedCall.js]
24+
var __extends = (this && this.__extends) || (function () {
25+
var extendStatics = Object.setPrototypeOf ||
26+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
27+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
28+
return function (d, b) {
29+
extendStatics(d, b);
30+
function __() { this.constructor = d; }
31+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
32+
};
33+
})();
34+
var Foo = /** @class */ (function () {
35+
function Foo() {
36+
}
37+
Foo.prototype.bar = function () { };
38+
return Foo;
39+
}());
40+
var Bar = /** @class */ (function (_super) {
41+
__extends(Bar, _super);
42+
function Bar() {
43+
var _this = _super.call(this) || this;
44+
_this.x = 2;
45+
return _this;
46+
}
47+
Bar.prototype.bar = function () {
48+
_super.prototype.bar.call(this);
49+
_super.prototype.bar.call(this);
50+
};
51+
return Bar;
52+
}(Foo));
53+
var b = new Bar();
54+
b.bar();
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
=== tests/cases/compiler/superAccessCastedCall.ts ===
2+
class Foo {
3+
>Foo : Symbol(Foo, Decl(superAccessCastedCall.ts, 0, 0))
4+
5+
bar(): void {}
6+
>bar : Symbol(Foo.bar, Decl(superAccessCastedCall.ts, 0, 11))
7+
}
8+
9+
class Bar extends Foo {
10+
>Bar : Symbol(Bar, Decl(superAccessCastedCall.ts, 2, 1))
11+
>Foo : Symbol(Foo, Decl(superAccessCastedCall.ts, 0, 0))
12+
13+
x: Number;
14+
>x : Symbol(Bar.x, Decl(superAccessCastedCall.ts, 4, 23))
15+
>Number : Symbol(Number, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
16+
17+
constructor() {
18+
super();
19+
>super : Symbol(Foo, Decl(superAccessCastedCall.ts, 0, 0))
20+
21+
this.x = 2;
22+
>this.x : Symbol(Bar.x, Decl(superAccessCastedCall.ts, 4, 23))
23+
>this : Symbol(Bar, Decl(superAccessCastedCall.ts, 2, 1))
24+
>x : Symbol(Bar.x, Decl(superAccessCastedCall.ts, 4, 23))
25+
}
26+
27+
bar() {
28+
>bar : Symbol(Bar.bar, Decl(superAccessCastedCall.ts, 10, 5))
29+
30+
super.bar();
31+
>super.bar : Symbol(Foo.bar, Decl(superAccessCastedCall.ts, 0, 11))
32+
>super : Symbol(Foo, Decl(superAccessCastedCall.ts, 0, 0))
33+
>bar : Symbol(Foo.bar, Decl(superAccessCastedCall.ts, 0, 11))
34+
35+
(super.bar as any)();
36+
>super.bar : Symbol(Foo.bar, Decl(superAccessCastedCall.ts, 0, 11))
37+
>super : Symbol(Foo, Decl(superAccessCastedCall.ts, 0, 0))
38+
>bar : Symbol(Foo.bar, Decl(superAccessCastedCall.ts, 0, 11))
39+
}
40+
}
41+
42+
let b = new Bar();
43+
>b : Symbol(b, Decl(superAccessCastedCall.ts, 18, 3))
44+
>Bar : Symbol(Bar, Decl(superAccessCastedCall.ts, 2, 1))
45+
46+
b.bar()
47+
>b.bar : Symbol(Bar.bar, Decl(superAccessCastedCall.ts, 10, 5))
48+
>b : Symbol(b, Decl(superAccessCastedCall.ts, 18, 3))
49+
>bar : Symbol(Bar.bar, Decl(superAccessCastedCall.ts, 10, 5))
50+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
=== tests/cases/compiler/superAccessCastedCall.ts ===
2+
class Foo {
3+
>Foo : Foo
4+
5+
bar(): void {}
6+
>bar : () => void
7+
}
8+
9+
class Bar extends Foo {
10+
>Bar : Bar
11+
>Foo : Foo
12+
13+
x: Number;
14+
>x : Number
15+
>Number : Number
16+
17+
constructor() {
18+
super();
19+
>super() : void
20+
>super : typeof Foo
21+
22+
this.x = 2;
23+
>this.x = 2 : 2
24+
>this.x : Number
25+
>this : this
26+
>x : Number
27+
>2 : 2
28+
}
29+
30+
bar() {
31+
>bar : () => void
32+
33+
super.bar();
34+
>super.bar() : void
35+
>super.bar : () => void
36+
>super : Foo
37+
>bar : () => void
38+
39+
(super.bar as any)();
40+
>(super.bar as any)() : any
41+
>(super.bar as any) : any
42+
>super.bar as any : any
43+
>super.bar : () => void
44+
>super : Foo
45+
>bar : () => void
46+
}
47+
}
48+
49+
let b = new Bar();
50+
>b : Bar
51+
>new Bar() : Bar
52+
>Bar : typeof Bar
53+
54+
b.bar()
55+
>b.bar() : void
56+
>b.bar : () => void
57+
>b : Bar
58+
>bar : () => void
59+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Foo {
2+
bar(): void {}
3+
}
4+
5+
class Bar extends Foo {
6+
x: Number;
7+
8+
constructor() {
9+
super();
10+
this.x = 2;
11+
}
12+
13+
bar() {
14+
super.bar();
15+
(super.bar as any)();
16+
}
17+
}
18+
19+
let b = new Bar();
20+
b.bar()

0 commit comments

Comments
 (0)