Reputation: 1062
I expected to be able to extract the default value of a JsDoc param but I'm actually unable to find the default value on the JsDoc node. For example, give this:
/** * @param [foo=42] This is foo! */
I'd like to extract '42' from the node. Yet I find no default value field on the ts node:
It exposes isBracketed
but I cannot find the 42
. Typescript does claim to support default JsDoc arguments:
https://github.com/Microsoft/TypeScript/wiki/JSDoc-support-in-JavaScript#param-and-returns
Yet I cannot seem to find the exposed in the AST... :<
Before I log a bug, I figured I'd ask around and see if anyone knows the secret handshake.
Upvotes: 3
Views: 500
Reputation: 106840
No, it's not currently in the AST. The parser currently skips over the expression without storing the return value anywhere.
// May have an optional default, e.g. '[foo = 42]'
if (parseOptionalToken(SyntaxKind.EqualsToken)) {
parseExpression();
}
Upvotes: 2