Nick -
Dimitris has been working on removing the hacky support for JSDoc from the Rhino parser with something much more robust. This work is a great improvement, but we have come to a bit of an impasse and are hoping you can break the tie.
Traditionally, we have always said that JSDoc "cast" were formed by a @type express attached to a parenthese expression:
/** @type {type} */( expr )
So far so good. Dimitris and I have agreed that a CAST is a @type expression attach to a parenthese expression.
Were we have a disagreement is the rule for attaching the JSDoc to the parenthese. From the parsers point of view it is consistent to always attach the JSDoc using simple precedence rules:
/** attach */ (x).prop --> attaches to GETPROP not the LP (which we would make a CAST)
/** attach */ x.prop --> attaches to the GETPROP not the NAME
/** attach */ x + y --> attaches to the NAME X not the operator
For the first case, would need an extra set of parenthese to create the cast:
(/** @type {foo} */ (x)).prop
I would prefer that we treat the cast as an operator:
/** @type {foo} */(x).prop
To do this properly without changing the parser to recognize @type JSDoc is a bit tricky we don't really want to attach other JSDoc to the parenthese. But we can do it in the IRFactory when we convert to our internal AST, without changing how the attach JSDOC in general:
When we see a node with a JSDoc attached, and it is a @type expression we look down the lhs of the tree for a parenthesized expression and if found insert a CAST node and attach it the JSDoc there.
I prefer this "extra work" as I think of the @type JSDoc and the parenthese as a single entity that we are trying to reconstructed while Dimitris finds the special handling odd and confusing.
Thoughts?