Skip to content

[parser] Disallow static fields named constructor#10461

Merged
nicolo-ribaudo merged 3 commits intobabel:masterfrom
guywaldman:guywald/disallow-constructor-static-field
Sep 17, 2019
Merged

[parser] Disallow static fields named constructor#10461
nicolo-ribaudo merged 3 commits intobabel:masterfrom
guywaldman:guywald/disallow-constructor-static-field

Conversation

@guywaldman
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator

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

@nicolo-ribaudo
Copy link
Copy Markdown
Member

Thanks!

Copy link
Copy Markdown
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
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Dec 18, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Dec 18, 2019
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