Add retainExtraParens option into babel-generator#7015
Add retainExtraParens option into babel-generator#7015koba04 wants to merge 6 commits intobabel:masterfrom
Conversation
|
This is the blocker to use Babel in our project. |
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/6314/ |
|
My concern with this any time is comes up is that to define an API that we can confidently maintain, we need to know what we are guaranteeing. If a random plugin decides to clear For example if a user does and we transform that to the |
|
@loganfsmyth Thank you for your feedback! I thought |
|
The issue with emulating comments is that we already don't make any guarantees about comments. Babel is only defined to make a best effort at preserving comments, because comments have no functional affect on runtime code, and people already run into issues with that. They'd likely have the same issues with this, so we'd be introducing a new thing for people to trip on. |
|
To do this "right" given our current structure, we'd have to have an actual AST node for parenthesized expressions, and then every single transform we and anyone else writes would have to make sure to handle it, which would be a mountain of work for everyone involved. |
|
@loganfsmyth I think it's hard to guarantee to work this well against any AST operations. Is having an actual AST node for Parens( |
2d2750e to
b7c7353
Compare
b7c7353 to
9af3ce7
Compare
|
I've updated this to remove the option from |
|
I'm running into this as well. Removing the parens should really be up to babel/minify. |
|
I believe retaining the parens through the transformation passes is always the right thing to do. Maybe the option should be called |
|
I want us to make progress on this. Here is my proposal:
@koba04 @loganfsmyth WDYT? |
If the original expression had parens then add parens around the new expression too, Based on babel#7015 Co-authored-by: Toru Kobayashi <koba0004@gmail.com>
If the original expression had parens then add parens around the new expression too, Based on babel#7015 Co-authored-by: Toru Kobayashi <koba0004@gmail.com>
This PR is to add a new option
retainParents, which is to retain parens even if they are meaningless for parsers.I know this feature is useless for many cases but it's useful for some cases.
(Parens are in there for a reason)
I think this option shouldn't enable by default, but it makes sense to able to enable it by optional.
Thanks!