Skip to content

fail to parse decorator with computed name in class #10978

@laysent

Description

@laysent

Bug Report

  • I would like to work on a fix!

Current Behavior

Babel is throwing syntax error (Unexpected token) when parsing decorator (legacy mode) with computed class property.

Input Code

class Example {
  @computed ['name'] = 1;
}

Expected behavior/code

Babel should parse the above code without throwing out syntax error.

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: babel.config.js
module.exports = env => ({
  "presets": [
    "@babel/preset-env",
    "@babel/preset-typescript",
    "@babel/preset-react"
  ],
  "plugins": [
    ["@babel/plugin-proposal-decorators", {
      "legacy": true
    }],
    ["@babel/plugin-proposal-class-properties", {
      "loose": true
    }],
  ],
  "sourceMaps": true
});

Environment

  • Babel version(s): v7.7.7
  • Node/npm version: Node v10.16.0 / npm 6.9.0
  • OS: OSX 10.14.6
  • Monorepo: no
  • How you are using Babel: cli, loader

It also fails on online demo (try here)

Possible Solution

Additional context/Screenshots
Add any other context about the problem here. If applicable, add screenshots to help explain.

Metadata

Metadata

Assignees

No one assigned

    Labels

    i: invalidoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions