-
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 for element access expressions (#31478)
* Control flow for element access expressions Draft version, just want to see how performance is * Add baselines * Fix cast lint * Cleanup to share code path * Fix errant diffs
- Loading branch information
Showing
5 changed files
with
147 additions
and
4 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
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,25 @@ | ||
//// [controlFlowElementAccess2.ts] | ||
declare const config: { | ||
[key: string]: boolean | { prop: string }; | ||
}; | ||
|
||
if (typeof config['works'] !== 'boolean') { | ||
config.works.prop = 'test'; // ok | ||
config['works'].prop = 'test'; // error, config['works']: boolean | { 'prop': string } | ||
} | ||
if (typeof config.works !== 'boolean') { | ||
config['works'].prop = 'test'; // error, config['works']: boolean | { 'prop': string } | ||
config.works.prop = 'test'; // ok | ||
} | ||
|
||
|
||
//// [controlFlowElementAccess2.js] | ||
"use strict"; | ||
if (typeof config['works'] !== 'boolean') { | ||
config.works.prop = 'test'; // ok | ||
config['works'].prop = 'test'; // error, config['works']: boolean | { 'prop': string } | ||
} | ||
if (typeof config.works !== 'boolean') { | ||
config['works'].prop = 'test'; // error, config['works']: boolean | { 'prop': string } | ||
config.works.prop = 'test'; // ok | ||
} |
37 changes: 37 additions & 0 deletions
37
tests/baselines/reference/controlFlowElementAccess2.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,37 @@ | ||
=== tests/cases/conformance/controlFlow/controlFlowElementAccess2.ts === | ||
declare const config: { | ||
>config : Symbol(config, Decl(controlFlowElementAccess2.ts, 0, 13)) | ||
|
||
[key: string]: boolean | { prop: string }; | ||
>key : Symbol(key, Decl(controlFlowElementAccess2.ts, 1, 5)) | ||
>prop : Symbol(prop, Decl(controlFlowElementAccess2.ts, 1, 30)) | ||
|
||
}; | ||
|
||
if (typeof config['works'] !== 'boolean') { | ||
>config : Symbol(config, Decl(controlFlowElementAccess2.ts, 0, 13)) | ||
|
||
config.works.prop = 'test'; // ok | ||
>config.works.prop : Symbol(prop, Decl(controlFlowElementAccess2.ts, 1, 30)) | ||
>config : Symbol(config, Decl(controlFlowElementAccess2.ts, 0, 13)) | ||
>prop : Symbol(prop, Decl(controlFlowElementAccess2.ts, 1, 30)) | ||
|
||
config['works'].prop = 'test'; // error, config['works']: boolean | { 'prop': string } | ||
>config['works'].prop : Symbol(prop, Decl(controlFlowElementAccess2.ts, 1, 30)) | ||
>config : Symbol(config, Decl(controlFlowElementAccess2.ts, 0, 13)) | ||
>prop : Symbol(prop, Decl(controlFlowElementAccess2.ts, 1, 30)) | ||
} | ||
if (typeof config.works !== 'boolean') { | ||
>config : Symbol(config, Decl(controlFlowElementAccess2.ts, 0, 13)) | ||
|
||
config['works'].prop = 'test'; // error, config['works']: boolean | { 'prop': string } | ||
>config['works'].prop : Symbol(prop, Decl(controlFlowElementAccess2.ts, 1, 30)) | ||
>config : Symbol(config, Decl(controlFlowElementAccess2.ts, 0, 13)) | ||
>prop : Symbol(prop, Decl(controlFlowElementAccess2.ts, 1, 30)) | ||
|
||
config.works.prop = 'test'; // ok | ||
>config.works.prop : Symbol(prop, Decl(controlFlowElementAccess2.ts, 1, 30)) | ||
>config : Symbol(config, Decl(controlFlowElementAccess2.ts, 0, 13)) | ||
>prop : Symbol(prop, Decl(controlFlowElementAccess2.ts, 1, 30)) | ||
} | ||
|
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,63 @@ | ||
=== tests/cases/conformance/controlFlow/controlFlowElementAccess2.ts === | ||
declare const config: { | ||
>config : { [key: string]: boolean | { prop: string; }; } | ||
|
||
[key: string]: boolean | { prop: string }; | ||
>key : string | ||
>prop : string | ||
|
||
}; | ||
|
||
if (typeof config['works'] !== 'boolean') { | ||
>typeof config['works'] !== 'boolean' : boolean | ||
>typeof config['works'] : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | ||
>config['works'] : boolean | { prop: string; } | ||
>config : { [key: string]: boolean | { prop: string; }; } | ||
>'works' : "works" | ||
>'boolean' : "boolean" | ||
|
||
config.works.prop = 'test'; // ok | ||
>config.works.prop = 'test' : "test" | ||
>config.works.prop : string | ||
>config.works : { prop: string; } | ||
>config : { [key: string]: boolean | { prop: string; }; } | ||
>works : { prop: string; } | ||
>prop : string | ||
>'test' : "test" | ||
|
||
config['works'].prop = 'test'; // error, config['works']: boolean | { 'prop': string } | ||
>config['works'].prop = 'test' : "test" | ||
>config['works'].prop : string | ||
>config['works'] : { prop: string; } | ||
>config : { [key: string]: boolean | { prop: string; }; } | ||
>'works' : "works" | ||
>prop : string | ||
>'test' : "test" | ||
} | ||
if (typeof config.works !== 'boolean') { | ||
>typeof config.works !== 'boolean' : boolean | ||
>typeof config.works : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | ||
>config.works : boolean | { prop: string; } | ||
>config : { [key: string]: boolean | { prop: string; }; } | ||
>works : boolean | { prop: string; } | ||
>'boolean' : "boolean" | ||
|
||
config['works'].prop = 'test'; // error, config['works']: boolean | { 'prop': string } | ||
>config['works'].prop = 'test' : "test" | ||
>config['works'].prop : string | ||
>config['works'] : { prop: string; } | ||
>config : { [key: string]: boolean | { prop: string; }; } | ||
>'works' : "works" | ||
>prop : string | ||
>'test' : "test" | ||
|
||
config.works.prop = 'test'; // ok | ||
>config.works.prop = 'test' : "test" | ||
>config.works.prop : string | ||
>config.works : { prop: string; } | ||
>config : { [key: string]: boolean | { prop: string; }; } | ||
>works : { prop: string; } | ||
>prop : string | ||
>'test' : "test" | ||
} | ||
|
13 changes: 13 additions & 0 deletions
13
tests/cases/conformance/controlFlow/controlFlowElementAccess2.ts
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,13 @@ | ||
// @strict: true | ||
declare const config: { | ||
[key: string]: boolean | { prop: string }; | ||
}; | ||
|
||
if (typeof config['works'] !== 'boolean') { | ||
config.works.prop = 'test'; // ok | ||
config['works'].prop = 'test'; // error, config['works']: boolean | { 'prop': string } | ||
} | ||
if (typeof config.works !== 'boolean') { | ||
config['works'].prop = 'test'; // error, config['works']: boolean | { 'prop': string } | ||
config.works.prop = 'test'; // ok | ||
} |