-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Ensure enum members syntactically determinable to be strings do not get reverse mappings #57686
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
Merged
andrewbranch
merged 6 commits into
microsoft:main
from
andrewbranch:no-reverse-mapping-string-enum-members
Mar 13, 2024
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a50acaf
Ensure enum members syntactically determinable to be strings do not g…
andrewbranch 46e5856
Update tests
andrewbranch 604d9a4
Fix typo
andrewbranch e3633bb
Update baselines
andrewbranch 8c0f48a
Skip all outer expressions
andrewbranch 086e13e
Lint
andrewbranch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
16 changes: 16 additions & 0 deletions
16
...selines/reference/computedEnumMemberSyntacticallyString(isolatedmodules=false).errors.txt
This file contains hidden or 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,16 @@ | ||
computedEnumMemberSyntacticallyString.ts(4,9): error TS18033: Type 'string' is not assignable to type 'number' as required for computed enum member values. | ||
computedEnumMemberSyntacticallyString.ts(5,9): error TS18033: Type 'string' is not assignable to type 'number' as required for computed enum member values. | ||
|
||
|
||
==== computedEnumMemberSyntacticallyString.ts (2 errors) ==== | ||
const BAR = 2..toFixed(0); | ||
|
||
enum Foo { | ||
A = `${BAR}`, | ||
~~~~~~~~ | ||
!!! error TS18033: Type 'string' is not assignable to type 'number' as required for computed enum member values. | ||
B = "2" + BAR, | ||
~~~~~~~~~ | ||
!!! error TS18033: Type 'string' is not assignable to type 'number' as required for computed enum member values. | ||
} | ||
|
18 changes: 18 additions & 0 deletions
18
tests/baselines/reference/computedEnumMemberSyntacticallyString(isolatedmodules=false).js
This file contains hidden or 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,18 @@ | ||
//// [tests/cases/compiler/computedEnumMemberSyntacticallyString.ts] //// | ||
|
||
//// [computedEnumMemberSyntacticallyString.ts] | ||
const BAR = 2..toFixed(0); | ||
|
||
enum Foo { | ||
A = `${BAR}`, | ||
B = "2" + BAR, | ||
} | ||
|
||
|
||
//// [computedEnumMemberSyntacticallyString.js] | ||
const BAR = 2..toFixed(0); | ||
var Foo; | ||
(function (Foo) { | ||
Foo["A"] = `${BAR}`; | ||
Foo["B"] = "2" + BAR; | ||
})(Foo || (Foo = {})); |
16 changes: 16 additions & 0 deletions
16
...aselines/reference/computedEnumMemberSyntacticallyString(isolatedmodules=true).errors.txt
This file contains hidden or 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,16 @@ | ||
computedEnumMemberSyntacticallyString.ts(4,9): error TS18033: Type 'string' is not assignable to type 'number' as required for computed enum member values. | ||
computedEnumMemberSyntacticallyString.ts(5,9): error TS18033: Type 'string' is not assignable to type 'number' as required for computed enum member values. | ||
|
||
|
||
==== computedEnumMemberSyntacticallyString.ts (2 errors) ==== | ||
const BAR = 2..toFixed(0); | ||
|
||
enum Foo { | ||
A = `${BAR}`, | ||
~~~~~~~~ | ||
!!! error TS18033: Type 'string' is not assignable to type 'number' as required for computed enum member values. | ||
B = "2" + BAR, | ||
~~~~~~~~~ | ||
!!! error TS18033: Type 'string' is not assignable to type 'number' as required for computed enum member values. | ||
} | ||
|
18 changes: 18 additions & 0 deletions
18
tests/baselines/reference/computedEnumMemberSyntacticallyString(isolatedmodules=true).js
This file contains hidden or 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,18 @@ | ||
//// [tests/cases/compiler/computedEnumMemberSyntacticallyString.ts] //// | ||
|
||
//// [computedEnumMemberSyntacticallyString.ts] | ||
const BAR = 2..toFixed(0); | ||
|
||
enum Foo { | ||
A = `${BAR}`, | ||
B = "2" + BAR, | ||
} | ||
|
||
|
||
//// [computedEnumMemberSyntacticallyString.js] | ||
const BAR = 2..toFixed(0); | ||
var Foo; | ||
(function (Foo) { | ||
Foo["A"] = `${BAR}`; | ||
Foo["B"] = "2" + BAR; | ||
})(Foo || (Foo = {})); |
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/computedEnumMemberSyntacticallyString2(isolatedmodules=false).js
This file contains hidden or 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,17 @@ | ||
//// [tests/cases/compiler/computedEnumMemberSyntacticallyString2.ts] //// | ||
|
||
//// [foo.ts] | ||
import { BAR } from './bar'; | ||
enum Foo { A = `${BAR}` } | ||
|
||
//// [bar.ts] | ||
export const BAR = 'bar'; | ||
|
||
//// [bar.js] | ||
export const BAR = 'bar'; | ||
//// [foo.js] | ||
import { BAR } from './bar'; | ||
var Foo; | ||
(function (Foo) { | ||
Foo["A"] = "bar"; | ||
})(Foo || (Foo = {})); |
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/computedEnumMemberSyntacticallyString2(isolatedmodules=true).js
This file contains hidden or 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,17 @@ | ||
//// [tests/cases/compiler/computedEnumMemberSyntacticallyString2.ts] //// | ||
|
||
//// [foo.ts] | ||
import { BAR } from './bar'; | ||
enum Foo { A = `${BAR}` } | ||
|
||
//// [bar.ts] | ||
export const BAR = 'bar'; | ||
|
||
//// [bar.js] | ||
export const BAR = 'bar'; | ||
//// [foo.js] | ||
import { BAR } from './bar'; | ||
var Foo; | ||
(function (Foo) { | ||
Foo["A"] = "bar"; | ||
})(Foo || (Foo = {})); |
6 changes: 6 additions & 0 deletions
6
...spile/Syntactically string but non-evaluatable enum members do not get reverse mapping.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
...ically string but non-evaluatable enum members do not get reverse mapping.oldTranspile.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
tests/cases/compiler/computedEnumMemberSyntacticallyString.ts
This file contains hidden or 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,10 @@ | ||
// @isolatedModules: true,false | ||
// @noTypesAndSymbols: true | ||
// @target: esnext | ||
|
||
const BAR = 2..toFixed(0); | ||
|
||
enum Foo { | ||
A = `${BAR}`, | ||
B = "2" + BAR, | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/cases/compiler/computedEnumMemberSyntacticallyString2.ts
This file contains hidden or 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,10 @@ | ||
// @isolatedModules: true,false | ||
// @noTypesAndSymbols: true | ||
// @target: esnext | ||
|
||
// @filename: ./foo.ts | ||
import { BAR } from './bar'; | ||
enum Foo { A = `${BAR}` } | ||
|
||
// @filename: ./bar.ts | ||
export const BAR = 'bar'; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.