Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control flow based type analysis #8010

Merged
merged 70 commits into from
Apr 22, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
e67d15a
Initial implementation of control flow based type analysis
ahejlsberg Mar 22, 2016
afa1714
Add type annotations to suppress circularity errors
ahejlsberg Mar 22, 2016
7c45c7b
Fixing tests
ahejlsberg Mar 22, 2016
80c2e5e
Accepting new baselines
ahejlsberg Mar 22, 2016
33985b2
Adding a few optimizations
ahejlsberg Mar 24, 2016
ed5002c
Handle assignment of union types in getAssignmentReducedType
ahejlsberg Mar 25, 2016
6d25a42
Remove incorrect type predicate (could be true even when result is fa…
ahejlsberg Mar 25, 2016
bf78470
Fix overly aggressive optimization
ahejlsberg Mar 25, 2016
4f936c4
Add control flow tests
ivogabe Mar 25, 2016
7f02357
Merge pull request #7690 from ivogabe/controlFlowTypesTest
ahejlsberg Mar 25, 2016
9e965d4
Fix issues in analysis of do..while and for..in/for..of
ahejlsberg Mar 26, 2016
9de0a5d
Fix comment in test
ahejlsberg Mar 26, 2016
560bc3f
Accepting new baselines
ahejlsberg Mar 26, 2016
0820249
Fixing some tests
ahejlsberg Mar 26, 2016
5a5d89a
Accepting new baselines
ahejlsberg Mar 26, 2016
424074b
Use type {} for vacuous type guards / New getTypeWithFacts function
ahejlsberg Mar 30, 2016
c6f4de3
Remove unnecessary cast
ahejlsberg Mar 30, 2016
e53f390
Fix some tests
ahejlsberg Mar 30, 2016
a38d863
Accepting new baselines
ahejlsberg Mar 30, 2016
3d0fa31
Delete removeNullableKind, use getTypeWithFacts instead
ahejlsberg Mar 30, 2016
ce81ba5
Support unknown types (host object names) in typeof type guards
ahejlsberg Mar 31, 2016
354fd10
Separate error messages for 'null', 'undefined', or both.
ahejlsberg Apr 1, 2016
5179dd6
Flow analysis of &&, ||, and destructuring assignments
ahejlsberg Apr 8, 2016
019f5bd
Accepting new baselines
ahejlsberg Apr 8, 2016
f13c92f
Handle shorthand property assignments
ahejlsberg Apr 8, 2016
b03d087
Accepting new baselines
ahejlsberg Apr 8, 2016
7a32129
Support destructuring declarations in control flow analysis
ahejlsberg Apr 9, 2016
6fb9424
Accepting new baselines
ahejlsberg Apr 9, 2016
e45bac8
Adding test
ahejlsberg Apr 10, 2016
7dfcad6
Fixing fourslash tests
ahejlsberg Apr 10, 2016
92df029
Fixing tests
ahejlsberg Apr 10, 2016
32e6464
Accepting new baselines
ahejlsberg Apr 10, 2016
560e768
Fix linting errors
ahejlsberg Apr 10, 2016
b1e9f43
Merge branch 'master' into controlFlowTypes
ahejlsberg Apr 10, 2016
4c250d0
Accepting new baselines
ahejlsberg Apr 10, 2016
7c7a1c0
A few cosmetic changes
ahejlsberg Apr 12, 2016
df62fa0
Merge branch 'master' into controlFlowTypes
ahejlsberg Apr 12, 2016
586ac55
Fix finishFlow function and rename to finishFlowLabel
ahejlsberg Apr 12, 2016
cd88f1e
Adding regression test
ahejlsberg Apr 12, 2016
472ab7c
Accepting new baselines
ahejlsberg Apr 12, 2016
b689c07
Improving error reporting as suggested in code review
ahejlsberg Apr 13, 2016
1ed9871
Fix typo
ahejlsberg Apr 13, 2016
921efec
Improved handing of evolving types in iteration statements
ahejlsberg Apr 16, 2016
9aea708
Adding tests
ahejlsberg Apr 16, 2016
10889a0
Accepting new baselines
ahejlsberg Apr 16, 2016
2595f04
Removing unused properties
ahejlsberg Apr 17, 2016
b83dc88
Improve expression type caching to ensure consistent results
ahejlsberg Apr 18, 2016
538e22a
Adding tests
ahejlsberg Apr 18, 2016
b5104cb
Accepting new baselines
ahejlsberg Apr 18, 2016
87f55fa
Only evaluate assigned type when declared type is a union type
ahejlsberg Apr 18, 2016
9defdde
Accepting new baselines
ahejlsberg Apr 18, 2016
d28a4fe
typeof x === "function" type guards include Function interface
ahejlsberg Apr 18, 2016
d735b7a
Variables from different source files default to their declared type
ahejlsberg Apr 19, 2016
c8bf6d8
Variables from different module declarations default to their declare…
ahejlsberg Apr 19, 2016
ea96dfd
Support comma operator in type guards
ahejlsberg Apr 20, 2016
33e359f
Adding test
ahejlsberg Apr 20, 2016
bab8ef4
Accepting new baselines
ahejlsberg Apr 20, 2016
e9a7d3d
Removing unused logic
ahejlsberg Apr 20, 2016
a0101c0
Improve consistency of instanceof and user defined type guards
ahejlsberg Apr 21, 2016
729dfce
Fix incorrect user defined type guard function in compiler
ahejlsberg Apr 21, 2016
3045cf5
Add regression test
ahejlsberg Apr 21, 2016
06928b6
Accepting new baselines
ahejlsberg Apr 21, 2016
8a0bc3b
Support assignments in truthiness type guards
ahejlsberg Apr 21, 2016
d2b89be
Adding test
ahejlsberg Apr 21, 2016
ab4b039
Removing unused logic
ahejlsberg Apr 21, 2016
e12b2a7
Correct issue with exported variables in code flow analysis
ahejlsberg Apr 21, 2016
4fb31ac
Update fourslash test
ahejlsberg Apr 21, 2016
f06d3f6
Only narrow to {} in getNarrowedType when types are completely unrelated
ahejlsberg Apr 22, 2016
42e3fc4
Revert previous change
ahejlsberg Apr 22, 2016
0dee5ad
Accepting new baselines
ahejlsberg Apr 22, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding test
  • Loading branch information
ahejlsberg committed Apr 10, 2016
commit e45bac813954c72494ecd2cb5672ed51858c3a83
113 changes: 113 additions & 0 deletions tests/baselines/reference/controlFlowDestructuringDeclaration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
//// [controlFlowDestructuringDeclaration.ts]

function f1() {
let x: string | number = 1;
x;
let y: string | undefined = "";
y;
}

function f2() {
let [x]: [string | number] = [1];
x;
let [y]: [string | undefined] = [""];
y;
let [z = ""]: [string | undefined] = [undefined];
z;
}

function f3() {
let [x]: (string | number)[] = [1];
x;
let [y]: (string | undefined)[] = [""];
y;
let [z = ""]: (string | undefined)[] = [undefined];
z;
}

function f4() {
let { x }: { x: string | number } = { x: 1 };
x;
let { y }: { y: string | undefined } = { y: "" };
y;
let { z = "" }: { z: string | undefined } = { z: undefined };
z;
}

function f5() {
let { x }: { x?: string | number } = { x: 1 };
x;
let { y }: { y?: string | undefined } = { y: "" };
y;
let { z = "" }: { z?: string | undefined } = { z: undefined };
z;
}

function f6() {
let { x }: { x?: string | number } = {};
x;
let { y }: { y?: string | undefined } = {};
y;
let { z = "" }: { z?: string | undefined } = {};
z;
}

function f7() {
let o: { [x: string]: number } = { x: 1 };
let { x }: { [x: string]: string | number } = o;
x;
}


//// [controlFlowDestructuringDeclaration.js]
function f1() {
var x = 1;
x;
var y = "";
y;
}
function f2() {
var x = [1][0];
x;
var y = [""][0];
y;
var _a = [undefined][0], z = _a === void 0 ? "" : _a;
z;
}
function f3() {
var x = [1][0];
x;
var y = [""][0];
y;
var _a = [undefined][0], z = _a === void 0 ? "" : _a;
z;
}
function f4() {
var x = { x: 1 }.x;
x;
var y = { y: "" }.y;
y;
var _a = { z: undefined }.z, z = _a === void 0 ? "" : _a;
z;
}
function f5() {
var x = { x: 1 }.x;
x;
var y = { y: "" }.y;
y;
var _a = { z: undefined }.z, z = _a === void 0 ? "" : _a;
z;
}
function f6() {
var x = {}.x;
x;
var y = {}.y;
y;
var _a = {}.z, z = _a === void 0 ? "" : _a;
z;
}
function f7() {
var o = { x: 1 };
var x = o.x;
x;
}
164 changes: 164 additions & 0 deletions tests/baselines/reference/controlFlowDestructuringDeclaration.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
=== tests/cases/conformance/controlFlow/controlFlowDestructuringDeclaration.ts ===

function f1() {
>f1 : Symbol(f1, Decl(controlFlowDestructuringDeclaration.ts, 0, 0))

let x: string | number = 1;
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 2, 7))

x;
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 2, 7))

let y: string | undefined = "";
>y : Symbol(y, Decl(controlFlowDestructuringDeclaration.ts, 4, 7))

y;
>y : Symbol(y, Decl(controlFlowDestructuringDeclaration.ts, 4, 7))
}

function f2() {
>f2 : Symbol(f2, Decl(controlFlowDestructuringDeclaration.ts, 6, 1))

let [x]: [string | number] = [1];
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 9, 9))

x;
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 9, 9))

let [y]: [string | undefined] = [""];
>y : Symbol(y, Decl(controlFlowDestructuringDeclaration.ts, 11, 9))

y;
>y : Symbol(y, Decl(controlFlowDestructuringDeclaration.ts, 11, 9))

let [z = ""]: [string | undefined] = [undefined];
>z : Symbol(z, Decl(controlFlowDestructuringDeclaration.ts, 13, 9))
>undefined : Symbol(undefined)

z;
>z : Symbol(z, Decl(controlFlowDestructuringDeclaration.ts, 13, 9))
}

function f3() {
>f3 : Symbol(f3, Decl(controlFlowDestructuringDeclaration.ts, 15, 1))

let [x]: (string | number)[] = [1];
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 18, 9))

x;
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 18, 9))

let [y]: (string | undefined)[] = [""];
>y : Symbol(y, Decl(controlFlowDestructuringDeclaration.ts, 20, 9))

y;
>y : Symbol(y, Decl(controlFlowDestructuringDeclaration.ts, 20, 9))

let [z = ""]: (string | undefined)[] = [undefined];
>z : Symbol(z, Decl(controlFlowDestructuringDeclaration.ts, 22, 9))
>undefined : Symbol(undefined)

z;
>z : Symbol(z, Decl(controlFlowDestructuringDeclaration.ts, 22, 9))
}

function f4() {
>f4 : Symbol(f4, Decl(controlFlowDestructuringDeclaration.ts, 24, 1))

let { x }: { x: string | number } = { x: 1 };
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 27, 9))
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 27, 16))
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 27, 41))

x;
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 27, 9))

let { y }: { y: string | undefined } = { y: "" };
>y : Symbol(y, Decl(controlFlowDestructuringDeclaration.ts, 29, 9))
>y : Symbol(y, Decl(controlFlowDestructuringDeclaration.ts, 29, 16))
>y : Symbol(y, Decl(controlFlowDestructuringDeclaration.ts, 29, 44))

y;
>y : Symbol(y, Decl(controlFlowDestructuringDeclaration.ts, 29, 9))

let { z = "" }: { z: string | undefined } = { z: undefined };
>z : Symbol(z, Decl(controlFlowDestructuringDeclaration.ts, 31, 9))
>z : Symbol(z, Decl(controlFlowDestructuringDeclaration.ts, 31, 21))
>z : Symbol(z, Decl(controlFlowDestructuringDeclaration.ts, 31, 49))
>undefined : Symbol(undefined)

z;
>z : Symbol(z, Decl(controlFlowDestructuringDeclaration.ts, 31, 9))
}

function f5() {
>f5 : Symbol(f5, Decl(controlFlowDestructuringDeclaration.ts, 33, 1))

let { x }: { x?: string | number } = { x: 1 };
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 36, 9))
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 36, 16))
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 36, 42))

x;
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 36, 9))

let { y }: { y?: string | undefined } = { y: "" };
>y : Symbol(y, Decl(controlFlowDestructuringDeclaration.ts, 38, 9))
>y : Symbol(y, Decl(controlFlowDestructuringDeclaration.ts, 38, 16))
>y : Symbol(y, Decl(controlFlowDestructuringDeclaration.ts, 38, 45))

y;
>y : Symbol(y, Decl(controlFlowDestructuringDeclaration.ts, 38, 9))

let { z = "" }: { z?: string | undefined } = { z: undefined };
>z : Symbol(z, Decl(controlFlowDestructuringDeclaration.ts, 40, 9))
>z : Symbol(z, Decl(controlFlowDestructuringDeclaration.ts, 40, 21))
>z : Symbol(z, Decl(controlFlowDestructuringDeclaration.ts, 40, 50))
>undefined : Symbol(undefined)

z;
>z : Symbol(z, Decl(controlFlowDestructuringDeclaration.ts, 40, 9))
}

function f6() {
>f6 : Symbol(f6, Decl(controlFlowDestructuringDeclaration.ts, 42, 1))

let { x }: { x?: string | number } = {};
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 45, 9))
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 45, 16))

x;
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 45, 9))

let { y }: { y?: string | undefined } = {};
>y : Symbol(y, Decl(controlFlowDestructuringDeclaration.ts, 47, 9))
>y : Symbol(y, Decl(controlFlowDestructuringDeclaration.ts, 47, 16))

y;
>y : Symbol(y, Decl(controlFlowDestructuringDeclaration.ts, 47, 9))

let { z = "" }: { z?: string | undefined } = {};
>z : Symbol(z, Decl(controlFlowDestructuringDeclaration.ts, 49, 9))
>z : Symbol(z, Decl(controlFlowDestructuringDeclaration.ts, 49, 21))

z;
>z : Symbol(z, Decl(controlFlowDestructuringDeclaration.ts, 49, 9))
}

function f7() {
>f7 : Symbol(f7, Decl(controlFlowDestructuringDeclaration.ts, 51, 1))

let o: { [x: string]: number } = { x: 1 };
>o : Symbol(o, Decl(controlFlowDestructuringDeclaration.ts, 54, 7))
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 54, 14))
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 54, 38))

let { x }: { [x: string]: string | number } = o;
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 55, 9))
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 55, 18))
>o : Symbol(o, Decl(controlFlowDestructuringDeclaration.ts, 54, 7))

x;
>x : Symbol(x, Decl(controlFlowDestructuringDeclaration.ts, 55, 9))
}

Loading