@babel/parser(ts): literal computed property names in enums
See original GitHub issueBug Report
- I would like to work on a fix!
Current behavior Babel fails if computed property is provided as key of enum, this synatx should be allowed only for computed properties with string literal value or template literal without arguments.
Input Code
// should work
export enum Foo { ['baz'] }
export enum Foo { [`baz`] }
// should fail
export enum Foo { [foo] } // Computed property names are not allowed in enums
export enum Foo { [1] } // An enum member cannot have a numeric name.
export enum Foo { [`test${foo}`] } // Computed property names are not allowed in enums.
Expected behavior Babel should allow computed property or template literals
Note
In my opinion this syntax is a issue in typescript as Computed property names are not allowed in enums (1164)
, but as for now its parsed correctly and results in correct output
- Babel version(s): v7.12.0
- Node/npm version: 10-14
- OS: ----
- Monorepo: ----
- How you are using Babel: @babel/parser -> parse
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Object literals combining enums and computed property names
I have an enum enum Action { action1 = 'action1', action2 = 'action2' };. whose values I use as computed property names in...
Read more >babel/types
value : string (required). Aliases: Standardized , Expression , Pureish , Literal , Immutable ... memberExpression(object, property, computed, optional);.
Read more >@babel/plugin-transform-computed-properties | Yarn - Package ...
Fast, reliable, and secure dependency management.
Read more >@babel/plugin-transform-shorthand-properties - NPM Package ...
v7.18.6 (2022-06-27). :eyeglasses: Spec Compliance. babel-parser. #14650 [ts] Disallow property access after instantiation expression (@nicolo-ribaudo) ...
Read more >typescript.rs - source - Docs.rs
(self); // Computed property names are grammar errors in an enum, so accept just string // literal or identifier. let id = match...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Should I submit a PR for this?
@fedeci yes :>