Skip to content

Parenthesize non-simple decorator expression#14378

Merged
nicolo-ribaudo merged 4 commits intobabel:mainfrom
JLHwung:parenthesize-decorator-expression
Mar 22, 2022
Merged

Parenthesize non-simple decorator expression#14378
nicolo-ribaudo merged 4 commits intobabel:mainfrom
JLHwung:parenthesize-decorator-expression

Conversation

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

babel-bot commented Mar 21, 2022

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

@(foo + bar) method2() {}
} No newline at end of file

@(this.foo)(bar) method3() {}
Copy link
Copy Markdown
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
Copy Markdown
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.

4 participants