Skip to content

@babel/parser(ts): literal computed property names in enums #12683

@armano2

Description

@armano2

Bug 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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions