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
Proposal: Add Closure Compiler Syntax Plugin #7661
Comments
Hey @arv! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
I'll probably write this in my own repo to start with but my end goal is to have this work with @babel/standalone |
Yeah basically I see two options for us, if we actually wanted to support this:
I go back and forth on it. The I'd probably be open to |
I'd be interested in writing a PR to add |
For reference, luaparse's solution to this problem is to add "inParens" properties to every node, rather than adding a new node type. |
@suchipi Out of curiosity, is your usecase also ClosureCompiler, or something else? |
Doesn't Babylon already add |
I'm a maintainer of prettier, and we could use paren information in the AST to ensure we reprint closure compiler and flowtype comments correctly. Currently we would have to check the source text. But I work with Babylon a lot in general (babel plugins, codemods, etc) and have found a lack of paren information in the AST understandable but occasionally inconvenient. |
@nicolo-ribaudo if it does, that's great news- I can use that |
It totally does, I can't believe I never noticed 😅 thanks! |
I guess Babylon adds Are there any advantages to adding |
Having an AST node for it ensures that transformers do not accidentally strip parens. We used ParenExpression in Traceur and it was never an issue there. |
Choose one: Feature request
Input Code
The parentheses are important to Closure Compiler and it defines a Cast expression
https://github.com/google/closure-compiler/wiki/Types-in-the-Closure-Type-System#type-casts
https://github.com/google/closure-compiler/blob/79deb15554ae0903b21fa9dc94746a879ae8ef12/src/com/google/javascript/jscomp/parsing/IRFactory.java#L783-L788
Expected Behavior
Keep the parens on a paren expression after a JSDoc comment.
Current Behavior
The ParenExpression is "transformed" to an Expression. (Not really transformed but Babel does not output unnecessary parens).
Possible Solution
Introduce a syntax plugin that detects the case where we have a paren expression preceded by a JSDoc comment with
@type
in it and create aCcCastExpression
instead. Have the generator for theCcCastExpression
output the comment, parens and the expression.Context
Cannot use Babel to do JSX transformation because we use Closure Compiler for type checking and minimization.
At this time I'm not suggesting adding any other Closure Compiler features. I was not planning on parsing the actual type in the JSDoc but future improvements to this plugin could do that.
The text was updated successfully, but these errors were encountered: