-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Description
Choose one: Feature request
Input Code
// Closure Compiler input/output
/** @return {T} */
function f() {
return /** @type {T} */ (someExpression);
}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
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 a CcCastExpression instead. Have the generator for the CcCastExpression 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.