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

Class Property without initializer parsed when classProperties plugin is not enabled #6710

Closed
babel-bot opened this issue Nov 29, 2016 · 4 comments
Labels
i: bug imported outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser

Comments

@babel-bot
Copy link
Collaborator

Issue originally reported by @DrewML in babel/babylon#242

Input Code

class Bar {
   abc; 
}

Babylon/Babel Configuration

Calling babylon.parse() without a plugins []

Expected Behavior

Unexpected token error

Current Behavior

Class Property is parsed

Your Environment

software version
Babylon 6.14.1
node All
npm All
Operating System All

The only check for the classProperties plugin is currently in pp.parseClassProperty in statement.js:

pp.parseClassProperty = function (node) {
  if (this.match(tt.eq)) {
    if (!this.hasPlugin("classProperties")) this.unexpected();
    this.next();
    node.value = this.parseMaybeAssign();
  } else {
    node.value = null;
  }
  this.semicolon();
  return this.finishNode(node, "ClassProperty");
};

If an initializer is not provided, it drops passed the branch that has the plugin check. I think we can just fix this by moving the plugin check to the top of parseClassProperty, since we've already done a check prior (in pp.parseClassBody) to verify we're dealing with a class prop.

@babel-bot
Copy link
Collaborator Author

Comment originally made by @loganfsmyth

This does indeed seem like a bug. Just a general note, any fix for this needs to take https://github.com/babel/babylon/blob/48873f886aa91c4d250ccce0c5e220c82f538f11/src/plugins/flow.js#L1050 into account. If I had to guess, that's the motivation for the current behavior.

You can do

class Foo {
    prop: string;
}

with only flow turned on, without classProperties.

@babel-bot
Copy link
Collaborator Author

Comment originally made by @DrewML

Good call on the flow stuff, hadn't considered that. Will keep in mind. I plan on addressing this, just trying to get through work on the Private Class Fields proposal first.

@babel-bot
Copy link
Collaborator Author

Comment originally made by @bakkot

I believe this was fixed by #300.

@hzoo
Copy link
Member

hzoo commented Nov 6, 2017

Fixed by babel/babylon#300

@hzoo hzoo closed this as completed Nov 6, 2017
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 4, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug imported outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser
Projects
None yet
Development

No branches or pull requests

2 participants