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

[parser] Disallow static fields named constructor #10461

Conversation

guywaldman
Copy link
Contributor

Q                       A
Fixed Issues? Fixes #10459
Patch: Bug Fix? 👍
Major: Breaking Change? 👍
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Main Changes

  • Disallowed static fields named constructor in a class (previously only non-static were disallowed)
  • Updated the text for the error for one consolidated warning, for both static and non-static fields
  • Added a test with a static constructor field
  • Updated an existing test in the flow test suite of the parser to reflect the parse error (see note below)

Note for reviewers:

I updated an existing test in the flow test suite of the parser (constructor-override-with-class-prop-plugin) to reflect the parse error. Strangely, the test used to pass and started failing when inlining the isNonstaticConstructor method, without any changes.
In that test, constructor was a field, so in theory it should never have passed.
The test relies on the jsx (which is probably unrelated), flow and classProperties plugins.
So would appreciate some feedback on this, as I'm not 100% sure if this is somehow related to Flow.

    - Disallowed static fields named `constructor` in a class (previously only non-static were disallowed)
    - Updated the text for the error for one consolidated warning, for both static and non-static fields
    - Added a test
    - Updated an existing test in the `flow` test suite of the parser to reflect the parse error.
  Strangely, the test used to pass and started failing when inlining the `isNonstaticConstructor` method, without any changes.
  In that test, `constructor` was a field, so in theory it should never have passed.
  Would appreciate some feedback on this, as I'm not 100% sure if this is somehow related to Flow
@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories PR: Spec Compliance 👓 A type of pull request used for our changelog categories Spec: Class Fields and removed PR: Bug Fix 🐛 A type of pull request used for our changelog categories labels Sep 17, 2019
@babel-bot
Copy link
Collaborator

babel-bot commented Sep 17, 2019

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/11604/

@babel-bot
Copy link
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/11602/

@nicolo-ribaudo
Copy link
Member

Thanks!

Copy link
Member

@existentialism existentialism left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @guywaldman!

@nicolo-ribaudo nicolo-ribaudo merged commit 9c1ad0a into babel:master Sep 17, 2019
@guywaldman guywaldman deleted the guywald/disallow-constructor-static-field branch September 18, 2019 21:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Spec Compliance 👓 A type of pull request used for our changelog categories Spec: Class Fields
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Static fields named "constructor" should be a parser error
4 participants