-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Triple-slash comments for JSDoc #39930
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
With two testsa, one of which shows that line-joining and current-tag maintenance isn't done yet.
In C# there's an expectation that these comments parse XML tags within them, like Other than that, I don't see much of a reason to bother, since it's not like any other JS tools interpret comments like this? Like, I get that there's probably not much harm done by it (expect potentially confusing future SO questions asking why doc tool X doesn't read "doc comments")... But... Eh? |
Oh, also, re: converting types of comments. In |
This seems pretty neat! For the tooling / editor side of things, I have a few questions:
|
@JacksonKearl What do you want to place after the doc comment? /// Does something
function foo() {
} |
Never mind, I'm assuming the declaration is already written 😄 |
@sandersn curious, does this mean that when you use |
Yes, but fourslash just uses source file text; it doesn't care about any AST. (As far as I know -- I could be wrong.) Same for any other tool that wants to use |
Having a "toggle doc comment" feature in VScode would be the killer feature here. I don't hate the triple slash syntax, but I don't see it being widely adopted. I'm not sure I'd use it personally. Feels like it'll just become a 'quirky' TypeScript thing down the line (that you then have to support forever). |
For a proposal to revamp JavaScript's established doc comment syntax, the 3 motivations above don't seem super compelling. In particular, the Markdown spacing ambiguity is probably a non-issue in practice. For example:
But microsoft/tsdoc#160 (comment) brings up a different motivation that maybe would justify a move to /**
* Strips the comments from an input string:
*
* @example
* ```ts
* // prints " some text":
* console.log(stripComments("/* a comment */ some text"); 👈 SYNTAX ERROR
* ```
*/
function stripComments(code: string): string; Nesting @sandersn this PR raises some other interesting design questions as well:
Some test cases for that last question: /// <!--
/// <reference types="node" />
/// --> /// ```
/// <reference types="node" />
/// ``` /// \<reference types="node" /> |
push : ) |
This experiment is pretty old, so I'm going to close it to reduce the number of open PRs. |
This PR adds a new triple-slash format for JSDoc comments. It's the same as the C#, Rust and Swift syntax for doc comments.
Motivation
Triple-slash comments have several advantages over multi-line doc comments:
into triple-slash comments is much easier than the conversion to multi-line comments. Turning one-line to multi-line is actually reasonable, unlike with JSDoc:
Triple-slash comments require a leading
///
on each line, and span only from after the///
to the end of the line:This is just a draft right now. I intend to talk to authors of other tools to see if they are interested in supporting this syntax.
Implementation
The current implementation has quite a bit of duplication. It also has a number of minor fixes that need to happen:
*
as in/// * markdown bullet point
.