-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8010 from Microsoft/controlFlowTypes
Control flow based type analysis
- Loading branch information
Showing
198 changed files
with
8,050 additions
and
3,595 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//// [assignmentTypeNarrowing.ts] | ||
let x: string | number | boolean | RegExp; | ||
|
||
x = ""; | ||
x; // string | ||
|
||
[x] = [true]; | ||
x; // boolean | ||
|
||
[x = ""] = [1]; | ||
x; // string | number | ||
|
||
({x} = {x: true}); | ||
x; // boolean | ||
|
||
({y: x} = {y: 1}); | ||
x; // number | ||
|
||
({x = ""} = {x: true}); | ||
x; // string | boolean | ||
|
||
({y: x = /a/} = {y: 1}); | ||
x; // number | RegExp | ||
|
||
let a: string[]; | ||
|
||
for (x of a) { | ||
x; // string | ||
} | ||
|
||
|
||
//// [assignmentTypeNarrowing.js] | ||
var x; | ||
x = ""; | ||
x; // string | ||
x = [true][0]; | ||
x; // boolean | ||
_a = [1][0], x = _a === void 0 ? "" : _a; | ||
x; // string | number | ||
(_b = { x: true }, x = _b.x, _b); | ||
x; // boolean | ||
(_c = { y: 1 }, x = _c.y, _c); | ||
x; // number | ||
(_d = { x: true }, _e = _d.x, x = _e === void 0 ? "" : _e, _d); | ||
x; // string | boolean | ||
(_f = { y: 1 }, _g = _f.y, x = _g === void 0 ? /a/ : _g, _f); | ||
x; // number | RegExp | ||
var a; | ||
for (var _i = 0, a_1 = a; _i < a_1.length; _i++) { | ||
x = a_1[_i]; | ||
x; // string | ||
} | ||
var _a, _b, _c, _d, _e, _f, _g; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
=== tests/cases/conformance/expressions/assignmentOperator/assignmentTypeNarrowing.ts === | ||
let x: string | number | boolean | RegExp; | ||
>x : Symbol(x, Decl(assignmentTypeNarrowing.ts, 0, 3)) | ||
>RegExp : Symbol(RegExp, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) | ||
|
||
x = ""; | ||
>x : Symbol(x, Decl(assignmentTypeNarrowing.ts, 0, 3)) | ||
|
||
x; // string | ||
>x : Symbol(x, Decl(assignmentTypeNarrowing.ts, 0, 3)) | ||
|
||
[x] = [true]; | ||
>x : Symbol(x, Decl(assignmentTypeNarrowing.ts, 0, 3)) | ||
|
||
x; // boolean | ||
>x : Symbol(x, Decl(assignmentTypeNarrowing.ts, 0, 3)) | ||
|
||
[x = ""] = [1]; | ||
>x : Symbol(x, Decl(assignmentTypeNarrowing.ts, 0, 3)) | ||
|
||
x; // string | number | ||
>x : Symbol(x, Decl(assignmentTypeNarrowing.ts, 0, 3)) | ||
|
||
({x} = {x: true}); | ||
>x : Symbol(x, Decl(assignmentTypeNarrowing.ts, 11, 2)) | ||
>x : Symbol(x, Decl(assignmentTypeNarrowing.ts, 11, 8)) | ||
|
||
x; // boolean | ||
>x : Symbol(x, Decl(assignmentTypeNarrowing.ts, 0, 3)) | ||
|
||
({y: x} = {y: 1}); | ||
>y : Symbol(y, Decl(assignmentTypeNarrowing.ts, 14, 2)) | ||
>x : Symbol(x, Decl(assignmentTypeNarrowing.ts, 0, 3)) | ||
>y : Symbol(y, Decl(assignmentTypeNarrowing.ts, 14, 11)) | ||
|
||
x; // number | ||
>x : Symbol(x, Decl(assignmentTypeNarrowing.ts, 0, 3)) | ||
|
||
({x = ""} = {x: true}); | ||
>x : Symbol(x, Decl(assignmentTypeNarrowing.ts, 17, 2)) | ||
>x : Symbol(x, Decl(assignmentTypeNarrowing.ts, 17, 13)) | ||
|
||
x; // string | boolean | ||
>x : Symbol(x, Decl(assignmentTypeNarrowing.ts, 0, 3)) | ||
|
||
({y: x = /a/} = {y: 1}); | ||
>y : Symbol(y, Decl(assignmentTypeNarrowing.ts, 20, 2)) | ||
>x : Symbol(x, Decl(assignmentTypeNarrowing.ts, 0, 3)) | ||
>y : Symbol(y, Decl(assignmentTypeNarrowing.ts, 20, 17)) | ||
|
||
x; // number | RegExp | ||
>x : Symbol(x, Decl(assignmentTypeNarrowing.ts, 0, 3)) | ||
|
||
let a: string[]; | ||
>a : Symbol(a, Decl(assignmentTypeNarrowing.ts, 23, 3)) | ||
|
||
for (x of a) { | ||
>x : Symbol(x, Decl(assignmentTypeNarrowing.ts, 0, 3)) | ||
>a : Symbol(a, Decl(assignmentTypeNarrowing.ts, 23, 3)) | ||
|
||
x; // string | ||
>x : Symbol(x, Decl(assignmentTypeNarrowing.ts, 0, 3)) | ||
} | ||
|
Oops, something went wrong.