Skip to content
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

Babel 7 decorators (legacy) break on string literal class properties #10059

mnzaki opened this issue Jun 5, 2019 · 1 comment


None yet
2 participants
Copy link

commented Jun 5, 2019

Bug Report

Current Behavior
Using a decorator on a class property name that is wrapped in quotes causes the proposal-decorators plugin with { legacy: true } to choke on the StringLiteral

TypeError: Property value expected type of string but got null
    at Object.validate ([...]/node_modules/@babel/types/lib/definitions/utils.js:161:13)
    at validate ([...]/node_modules/@babel/types/lib/validators/validate.js:17:9)
    at builder ([...]/node_modules/@babel/types/lib/builders/builder.js:46:27)
    at Object.StringLiteral ([...]/node_modules/@babel/types/lib/builders/generated/index.js:335:31)
    at PluginPass.AssignmentExpression ([...]/node_modules/@babel/plugin-proposal-decorators/lib/transformer-legacy.js:167:167)
    at newFn ([...]/node_modules/@babel/traverse/lib/visitors.js:193:21)
    at NodePath._call ([...]/node_modules/@babel/traverse/lib/path/context.js:53:20)
    at ([...]/node_modules/@babel/traverse/lib/path/context.js:40:17)
    at NodePath.visit ([...]/node_modules/@babel/traverse/lib/path/context.js:88:12)
    at TraversalContext.visitQueue ([...]/node_modules/@babel/traverse/lib/context.js:118:16)

Input Code

function propDec(o, n) {
  return o

export class Test {

Expected behavior/code
Should compile

Babel Configuration (babel.config.js)

// babel.config.js
module.exports = {
  "plugins": [
    ["@babel/plugin-proposal-decorators", {
      "legacy": true
    ["@babel/plugin-proposal-class-properties", {
      "loose": true


  • Babel version(s): 7.4.4
  • Node/npm version: Node 11 / yarn 1.16
  • OS: Linux
  • Monorepo: no
  • How you are using Babel: cli

Possible Solution

if it's a StringLiteral then it should probably get node.value in this line

I have tested with changing that line to:

t.stringLiteral(path.get("") || path.get("").node.value),

and it seems to work


This comment has been minimized.

Copy link

commented Jun 5, 2019

Hey @mnzaki! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
that typically always has someone willing to help. You can sign-up here
for an invite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.