Skip to content

Commit 1c64943

Browse files
authored
Merge pull request #14956 from Microsoft/add-super-to-control-flow
Add super to control flow
2 parents 013d52a + b28975d commit 1c64943

File tree

6 files changed

+100
-0
lines changed

6 files changed

+100
-0
lines changed

src/compiler/binder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ namespace ts {
703703
function isNarrowableReference(expr: Expression): boolean {
704704
return expr.kind === SyntaxKind.Identifier ||
705705
expr.kind === SyntaxKind.ThisKeyword ||
706+
expr.kind === SyntaxKind.SuperKeyword ||
706707
expr.kind === SyntaxKind.PropertyAccessExpression && isNarrowableReference((<PropertyAccessExpression>expr).expression);
707708
}
708709

src/compiler/checker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10382,6 +10382,8 @@ namespace ts {
1038210382
getExportSymbolOfValueSymbolIfExported(getResolvedSymbol(<Identifier>source)) === getSymbolOfNode(target);
1038310383
case SyntaxKind.ThisKeyword:
1038410384
return target.kind === SyntaxKind.ThisKeyword;
10385+
case SyntaxKind.SuperKeyword:
10386+
return target.kind === SyntaxKind.SuperKeyword;
1038510387
case SyntaxKind.PropertyAccessExpression:
1038610388
return target.kind === SyntaxKind.PropertyAccessExpression &&
1038710389
(<PropertyAccessExpression>source).name.text === (<PropertyAccessExpression>target).name.text &&
@@ -11518,6 +11520,7 @@ namespace ts {
1151811520
switch (expr.kind) {
1151911521
case SyntaxKind.Identifier:
1152011522
case SyntaxKind.ThisKeyword:
11523+
case SyntaxKind.SuperKeyword:
1152111524
case SyntaxKind.PropertyAccessExpression:
1152211525
return narrowTypeByTruthiness(type, expr, assumeTrue);
1152311526
case SyntaxKind.CallExpression:
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//// [controlFlowSuperPropertyAccess.ts]
2+
class B {
3+
protected m?(): void;
4+
}
5+
class C extends B {
6+
body() {
7+
super.m && super.m();
8+
}
9+
}
10+
11+
12+
//// [controlFlowSuperPropertyAccess.js]
13+
var __extends = (this && this.__extends) || (function () {
14+
var extendStatics = Object.setPrototypeOf ||
15+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
16+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
17+
return function (d, b) {
18+
extendStatics(d, b);
19+
function __() { this.constructor = d; }
20+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
21+
};
22+
})();
23+
var B = (function () {
24+
function B() {
25+
}
26+
return B;
27+
}());
28+
var C = (function (_super) {
29+
__extends(C, _super);
30+
function C() {
31+
return _super !== null && _super.apply(this, arguments) || this;
32+
}
33+
C.prototype.body = function () {
34+
_super.prototype.m && _super.prototype.m.call(this);
35+
};
36+
return C;
37+
}(B));
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
=== tests/cases/conformance/controlFlow/controlFlowSuperPropertyAccess.ts ===
2+
class B {
3+
>B : Symbol(B, Decl(controlFlowSuperPropertyAccess.ts, 0, 0))
4+
5+
protected m?(): void;
6+
>m : Symbol(B.m, Decl(controlFlowSuperPropertyAccess.ts, 0, 9))
7+
}
8+
class C extends B {
9+
>C : Symbol(C, Decl(controlFlowSuperPropertyAccess.ts, 2, 1))
10+
>B : Symbol(B, Decl(controlFlowSuperPropertyAccess.ts, 0, 0))
11+
12+
body() {
13+
>body : Symbol(C.body, Decl(controlFlowSuperPropertyAccess.ts, 3, 19))
14+
15+
super.m && super.m();
16+
>super.m : Symbol(B.m, Decl(controlFlowSuperPropertyAccess.ts, 0, 9))
17+
>super : Symbol(B, Decl(controlFlowSuperPropertyAccess.ts, 0, 0))
18+
>m : Symbol(B.m, Decl(controlFlowSuperPropertyAccess.ts, 0, 9))
19+
>super.m : Symbol(B.m, Decl(controlFlowSuperPropertyAccess.ts, 0, 9))
20+
>super : Symbol(B, Decl(controlFlowSuperPropertyAccess.ts, 0, 0))
21+
>m : Symbol(B.m, Decl(controlFlowSuperPropertyAccess.ts, 0, 9))
22+
}
23+
}
24+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=== tests/cases/conformance/controlFlow/controlFlowSuperPropertyAccess.ts ===
2+
class B {
3+
>B : B
4+
5+
protected m?(): void;
6+
>m : (() => void) | undefined
7+
}
8+
class C extends B {
9+
>C : C
10+
>B : B
11+
12+
body() {
13+
>body : () => void
14+
15+
super.m && super.m();
16+
>super.m && super.m() : void | undefined
17+
>super.m : (() => void) | undefined
18+
>super : B
19+
>m : (() => void) | undefined
20+
>super.m() : void
21+
>super.m : () => void
22+
>super : B
23+
>m : () => void
24+
}
25+
}
26+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @strictNullChecks: true
2+
class B {
3+
protected m?(): void;
4+
}
5+
class C extends B {
6+
body() {
7+
super.m && super.m();
8+
}
9+
}

0 commit comments

Comments
 (0)