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

Parenthesize non-simple decorator expression #14378

Merged
merged 4 commits into from Mar 22, 2022

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Mar 21, 2022

Q                       A
Fixed Issues? @babel/generator generates incorrect code @this[bar] from @(this[bar])
Patch: Bug Fix? Y
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

In this PR we ensure that @babel/generator generates correct codes for non-simple decorator expressions such as @(this.foo().bar). In the first commit we mark all these non-simple expressions as "parenthesized", so that we generate correct AST for cases like @(this).bar. The second commit fixes the generator issue.

The current decorator spec ("2022-03") share the same decorator expression grammar production with "2021-12" and "2018-09".

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: generator Spec: Decorators labels Mar 21, 2022
@babel-bot
Copy link
Collaborator

babel-bot commented Mar 21, 2022

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


@(this.foo)(bar) method3() {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a new parser test case here.

nicolo-ribaudo
nicolo-ribaudo previously approved these changes Mar 22, 2022
{
"plugins": [["decorators", { "decoratorsBeforeExport": false }]],
"decoratorsBeforeExport": true,
"parserOpts": { "createParenthesizedExpressions": true }
Copy link
Member

Choose a reason for hiding this comment

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

We should also add a parser test with "createParenthesizedExpressions": true

@nicolo-ribaudo nicolo-ribaudo dismissed their stale review March 22, 2022 17:03

Whops, I approved after reviewing only the generator changes

@nicolo-ribaudo nicolo-ribaudo merged commit c79709a into babel:main Mar 22, 2022
@nicolo-ribaudo nicolo-ribaudo deleted the parenthesize-decorator-expression branch March 22, 2022 18:52
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jun 22, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 22, 2022
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 pkg: generator PR: Bug Fix 🐛 A type of pull request used for our changelog categories Spec: Decorators
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants