-
Notifications
You must be signed in to change notification settings - Fork 12.8k
JSDoc param tag's default value parsing should support non-TS expressions #44932
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
Comments
Hi @sandersn , started converting to use the jsdoc compiler API and it worked great for isBracketed, thanks again. However the default value issue above is not quite working - the comment is still truncating part of the default value:
leads to:
|
Typescript's jsdoc parser doesn't support default values, only types. In addition, the value syntax of default values isn't the same as TS's value syntax -- the string isn't quoted, for example. One heavy-weight workaround is to get the text of the entire node and parse it yourself -- I can't remember the best API to get the text of a node, but in scripts I've used Edit: I looked at the code. It actually does parse default values, but it uses |
Thank you very much for the lead, I was able to somewhat work around -
and with re extract the default value like:
I can also fix the comment to remove the starting default value remains after the space: Do you think it also makes sense to remove the starting '-' hyphen from the comment? Btw - can you please give me a working example of default value working with a typescript expression, I was unable to come up with one. |
This works for me: https://ts-ast-viewer.com/#code/PQKhAIAEAcEMCdYFtwG0AeBeAjAXXACYAshysA5gKbgjABQAZgK4B2AxgC4CWA9i+EgAU6cJnDYAlOADe4AL50gA It's hard to tell because the tag doesn't save the default value. It just parses it and moves on. That's a separate, but prerequisite, problem to your original one. I assume that you'd like the default value present in the param tag?
I don't have a strong opinion, although I prefer to avoid processing comment text without a compelling reason. You could create another issue and try to get a discussion going among people who work with editors more. |
Got, it - I was trying to make it work with pure jsdoc, ie:
I understand and will create a new suggestion, as it seems the |
Suggestion
probably related to #44930 but a different use case. default values on
@param
: https://jsdoc.app/tags-param.html🔍 Search Terms
jsdoc param default value
⭐ Suggestion
Please allow for default value params parsing
currently parses to tags:
possibly add a new node
and clean up the description from
to
p.s. it mighy also be worth in general to clean up parameter descriptions
text
from the leading hyphenThe text was updated successfully, but these errors were encountered: