-
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.
Control flow analysis for element access with variable index (#57847)
- Loading branch information
1 parent
316f180
commit a22aaf0
Showing
7 changed files
with
367 additions
and
14 deletions.
There are no files selected for viewing
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
134 changes: 134 additions & 0 deletions
134
tests/baselines/reference/controlFlowComputedPropertyNames.symbols
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,134 @@ | ||
//// [tests/cases/conformance/controlFlow/controlFlowComputedPropertyNames.ts] //// | ||
|
||
=== controlFlowComputedPropertyNames.ts === | ||
function f1(obj: Record<string, unknown>, key: string) { | ||
>f1 : Symbol(f1, Decl(controlFlowComputedPropertyNames.ts, 0, 0)) | ||
>obj : Symbol(obj, Decl(controlFlowComputedPropertyNames.ts, 0, 12)) | ||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) | ||
>key : Symbol(key, Decl(controlFlowComputedPropertyNames.ts, 0, 41)) | ||
|
||
if (typeof obj[key] === "string") { | ||
>obj : Symbol(obj, Decl(controlFlowComputedPropertyNames.ts, 0, 12)) | ||
>key : Symbol(key, Decl(controlFlowComputedPropertyNames.ts, 0, 41)) | ||
|
||
obj[key].toUpperCase(); | ||
>obj[key].toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) | ||
>obj : Symbol(obj, Decl(controlFlowComputedPropertyNames.ts, 0, 12)) | ||
>key : Symbol(key, Decl(controlFlowComputedPropertyNames.ts, 0, 41)) | ||
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) | ||
} | ||
} | ||
|
||
function f2(obj: Record<string, string | undefined>, key: string) { | ||
>f2 : Symbol(f2, Decl(controlFlowComputedPropertyNames.ts, 4, 1)) | ||
>obj : Symbol(obj, Decl(controlFlowComputedPropertyNames.ts, 6, 12)) | ||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) | ||
>key : Symbol(key, Decl(controlFlowComputedPropertyNames.ts, 6, 52)) | ||
|
||
if (obj[key] !== undefined) { | ||
>obj : Symbol(obj, Decl(controlFlowComputedPropertyNames.ts, 6, 12)) | ||
>key : Symbol(key, Decl(controlFlowComputedPropertyNames.ts, 6, 52)) | ||
>undefined : Symbol(undefined) | ||
|
||
obj[key].toUpperCase(); | ||
>obj[key].toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) | ||
>obj : Symbol(obj, Decl(controlFlowComputedPropertyNames.ts, 6, 12)) | ||
>key : Symbol(key, Decl(controlFlowComputedPropertyNames.ts, 6, 52)) | ||
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) | ||
} | ||
let key2 = key + key; | ||
>key2 : Symbol(key2, Decl(controlFlowComputedPropertyNames.ts, 10, 7)) | ||
>key : Symbol(key, Decl(controlFlowComputedPropertyNames.ts, 6, 52)) | ||
>key : Symbol(key, Decl(controlFlowComputedPropertyNames.ts, 6, 52)) | ||
|
||
if (obj[key2] !== undefined) { | ||
>obj : Symbol(obj, Decl(controlFlowComputedPropertyNames.ts, 6, 12)) | ||
>key2 : Symbol(key2, Decl(controlFlowComputedPropertyNames.ts, 10, 7)) | ||
>undefined : Symbol(undefined) | ||
|
||
obj[key2].toUpperCase(); | ||
>obj[key2].toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) | ||
>obj : Symbol(obj, Decl(controlFlowComputedPropertyNames.ts, 6, 12)) | ||
>key2 : Symbol(key2, Decl(controlFlowComputedPropertyNames.ts, 10, 7)) | ||
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) | ||
} | ||
const key3 = key + key; | ||
>key3 : Symbol(key3, Decl(controlFlowComputedPropertyNames.ts, 14, 9)) | ||
>key : Symbol(key, Decl(controlFlowComputedPropertyNames.ts, 6, 52)) | ||
>key : Symbol(key, Decl(controlFlowComputedPropertyNames.ts, 6, 52)) | ||
|
||
if (obj[key3] !== undefined) { | ||
>obj : Symbol(obj, Decl(controlFlowComputedPropertyNames.ts, 6, 12)) | ||
>key3 : Symbol(key3, Decl(controlFlowComputedPropertyNames.ts, 14, 9)) | ||
>undefined : Symbol(undefined) | ||
|
||
obj[key3].toUpperCase(); | ||
>obj[key3].toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) | ||
>obj : Symbol(obj, Decl(controlFlowComputedPropertyNames.ts, 6, 12)) | ||
>key3 : Symbol(key3, Decl(controlFlowComputedPropertyNames.ts, 14, 9)) | ||
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) | ||
} | ||
} | ||
|
||
type Thing = { a?: string, b?: number, c?: number }; | ||
>Thing : Symbol(Thing, Decl(controlFlowComputedPropertyNames.ts, 18, 1)) | ||
>a : Symbol(a, Decl(controlFlowComputedPropertyNames.ts, 20, 14)) | ||
>b : Symbol(b, Decl(controlFlowComputedPropertyNames.ts, 20, 26)) | ||
>c : Symbol(c, Decl(controlFlowComputedPropertyNames.ts, 20, 38)) | ||
|
||
function f3(obj: Thing, key: keyof Thing) { | ||
>f3 : Symbol(f3, Decl(controlFlowComputedPropertyNames.ts, 20, 52)) | ||
>obj : Symbol(obj, Decl(controlFlowComputedPropertyNames.ts, 22, 12)) | ||
>Thing : Symbol(Thing, Decl(controlFlowComputedPropertyNames.ts, 18, 1)) | ||
>key : Symbol(key, Decl(controlFlowComputedPropertyNames.ts, 22, 23)) | ||
>Thing : Symbol(Thing, Decl(controlFlowComputedPropertyNames.ts, 18, 1)) | ||
|
||
if (obj[key] !== undefined) { | ||
>obj : Symbol(obj, Decl(controlFlowComputedPropertyNames.ts, 22, 12)) | ||
>key : Symbol(key, Decl(controlFlowComputedPropertyNames.ts, 22, 23)) | ||
>undefined : Symbol(undefined) | ||
|
||
if (typeof obj[key] === "string") { | ||
>obj : Symbol(obj, Decl(controlFlowComputedPropertyNames.ts, 22, 12)) | ||
>key : Symbol(key, Decl(controlFlowComputedPropertyNames.ts, 22, 23)) | ||
|
||
obj[key].toUpperCase(); | ||
>obj[key].toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) | ||
>obj : Symbol(obj, Decl(controlFlowComputedPropertyNames.ts, 22, 12)) | ||
>key : Symbol(key, Decl(controlFlowComputedPropertyNames.ts, 22, 23)) | ||
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) | ||
} | ||
if (typeof obj[key] === "number") { | ||
>obj : Symbol(obj, Decl(controlFlowComputedPropertyNames.ts, 22, 12)) | ||
>key : Symbol(key, Decl(controlFlowComputedPropertyNames.ts, 22, 23)) | ||
|
||
obj[key].toFixed(); | ||
>obj[key].toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --)) | ||
>obj : Symbol(obj, Decl(controlFlowComputedPropertyNames.ts, 22, 12)) | ||
>key : Symbol(key, Decl(controlFlowComputedPropertyNames.ts, 22, 23)) | ||
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --)) | ||
} | ||
} | ||
} | ||
|
||
function f4<K extends string>(obj: Record<K, string | undefined>, key: K) { | ||
>f4 : Symbol(f4, Decl(controlFlowComputedPropertyNames.ts, 31, 1)) | ||
>K : Symbol(K, Decl(controlFlowComputedPropertyNames.ts, 33, 12)) | ||
>obj : Symbol(obj, Decl(controlFlowComputedPropertyNames.ts, 33, 30)) | ||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) | ||
>K : Symbol(K, Decl(controlFlowComputedPropertyNames.ts, 33, 12)) | ||
>key : Symbol(key, Decl(controlFlowComputedPropertyNames.ts, 33, 65)) | ||
>K : Symbol(K, Decl(controlFlowComputedPropertyNames.ts, 33, 12)) | ||
|
||
if (obj[key]) { | ||
>obj : Symbol(obj, Decl(controlFlowComputedPropertyNames.ts, 33, 30)) | ||
>key : Symbol(key, Decl(controlFlowComputedPropertyNames.ts, 33, 65)) | ||
|
||
obj[key].toUpperCase(); | ||
>obj[key].toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) | ||
>obj : Symbol(obj, Decl(controlFlowComputedPropertyNames.ts, 33, 30)) | ||
>key : Symbol(key, Decl(controlFlowComputedPropertyNames.ts, 33, 65)) | ||
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) | ||
} | ||
} | ||
|
163 changes: 163 additions & 0 deletions
163
tests/baselines/reference/controlFlowComputedPropertyNames.types
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,163 @@ | ||
//// [tests/cases/conformance/controlFlow/controlFlowComputedPropertyNames.ts] //// | ||
|
||
=== controlFlowComputedPropertyNames.ts === | ||
function f1(obj: Record<string, unknown>, key: string) { | ||
>f1 : (obj: Record<string, unknown>, key: string) => void | ||
>obj : Record<string, unknown> | ||
>key : string | ||
|
||
if (typeof obj[key] === "string") { | ||
>typeof obj[key] === "string" : boolean | ||
>typeof obj[key] : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | ||
>obj[key] : unknown | ||
>obj : Record<string, unknown> | ||
>key : string | ||
>"string" : "string" | ||
|
||
obj[key].toUpperCase(); | ||
>obj[key].toUpperCase() : string | ||
>obj[key].toUpperCase : () => string | ||
>obj[key] : string | ||
>obj : Record<string, unknown> | ||
>key : string | ||
>toUpperCase : () => string | ||
} | ||
} | ||
|
||
function f2(obj: Record<string, string | undefined>, key: string) { | ||
>f2 : (obj: Record<string, string | undefined>, key: string) => void | ||
>obj : Record<string, string | undefined> | ||
>key : string | ||
|
||
if (obj[key] !== undefined) { | ||
>obj[key] !== undefined : boolean | ||
>obj[key] : string | undefined | ||
>obj : Record<string, string | undefined> | ||
>key : string | ||
>undefined : undefined | ||
|
||
obj[key].toUpperCase(); | ||
>obj[key].toUpperCase() : string | ||
>obj[key].toUpperCase : () => string | ||
>obj[key] : string | ||
>obj : Record<string, string | undefined> | ||
>key : string | ||
>toUpperCase : () => string | ||
} | ||
let key2 = key + key; | ||
>key2 : string | ||
>key + key : string | ||
>key : string | ||
>key : string | ||
|
||
if (obj[key2] !== undefined) { | ||
>obj[key2] !== undefined : boolean | ||
>obj[key2] : string | undefined | ||
>obj : Record<string, string | undefined> | ||
>key2 : string | ||
>undefined : undefined | ||
|
||
obj[key2].toUpperCase(); | ||
>obj[key2].toUpperCase() : string | ||
>obj[key2].toUpperCase : () => string | ||
>obj[key2] : string | ||
>obj : Record<string, string | undefined> | ||
>key2 : string | ||
>toUpperCase : () => string | ||
} | ||
const key3 = key + key; | ||
>key3 : string | ||
>key + key : string | ||
>key : string | ||
>key : string | ||
|
||
if (obj[key3] !== undefined) { | ||
>obj[key3] !== undefined : boolean | ||
>obj[key3] : string | undefined | ||
>obj : Record<string, string | undefined> | ||
>key3 : string | ||
>undefined : undefined | ||
|
||
obj[key3].toUpperCase(); | ||
>obj[key3].toUpperCase() : string | ||
>obj[key3].toUpperCase : () => string | ||
>obj[key3] : string | ||
>obj : Record<string, string | undefined> | ||
>key3 : string | ||
>toUpperCase : () => string | ||
} | ||
} | ||
|
||
type Thing = { a?: string, b?: number, c?: number }; | ||
>Thing : { a?: string | undefined; b?: number | undefined; c?: number | undefined; } | ||
>a : string | undefined | ||
>b : number | undefined | ||
>c : number | undefined | ||
|
||
function f3(obj: Thing, key: keyof Thing) { | ||
>f3 : (obj: Thing, key: keyof Thing) => void | ||
>obj : Thing | ||
>key : keyof Thing | ||
|
||
if (obj[key] !== undefined) { | ||
>obj[key] !== undefined : boolean | ||
>obj[key] : string | number | undefined | ||
>obj : Thing | ||
>key : keyof Thing | ||
>undefined : undefined | ||
|
||
if (typeof obj[key] === "string") { | ||
>typeof obj[key] === "string" : boolean | ||
>typeof obj[key] : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | ||
>obj[key] : string | number | ||
>obj : Thing | ||
>key : keyof Thing | ||
>"string" : "string" | ||
|
||
obj[key].toUpperCase(); | ||
>obj[key].toUpperCase() : string | ||
>obj[key].toUpperCase : () => string | ||
>obj[key] : string | ||
>obj : Thing | ||
>key : keyof Thing | ||
>toUpperCase : () => string | ||
} | ||
if (typeof obj[key] === "number") { | ||
>typeof obj[key] === "number" : boolean | ||
>typeof obj[key] : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | ||
>obj[key] : string | number | ||
>obj : Thing | ||
>key : keyof Thing | ||
>"number" : "number" | ||
|
||
obj[key].toFixed(); | ||
>obj[key].toFixed() : string | ||
>obj[key].toFixed : (fractionDigits?: number | undefined) => string | ||
>obj[key] : number | ||
>obj : Thing | ||
>key : keyof Thing | ||
>toFixed : (fractionDigits?: number | undefined) => string | ||
} | ||
} | ||
} | ||
|
||
function f4<K extends string>(obj: Record<K, string | undefined>, key: K) { | ||
>f4 : <K extends string>(obj: Record<K, string | undefined>, key: K) => void | ||
>obj : Record<K, string | undefined> | ||
>key : K | ||
|
||
if (obj[key]) { | ||
>obj[key] : Record<K, string | undefined>[K] | ||
>obj : Record<K, string | undefined> | ||
>key : K | ||
|
||
obj[key].toUpperCase(); | ||
>obj[key].toUpperCase() : string | ||
>obj[key].toUpperCase : () => string | ||
>obj[key] : string | ||
>obj : Record<K, string | undefined> | ||
>key : K | ||
>toUpperCase : () => string | ||
} | ||
} | ||
|
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
Oops, something went wrong.