node-typescript-parser icon indicating copy to clipboard operation
node-typescript-parser copied to clipboard

Emit JSDoc-style comments

Open danmarshall opened this issue 7 years ago • 5 comments

Hello, thanks for this project 👍 One thing I would like to have is the JsDoc comments associated with a declaration:

/**
 * A meaningless declaration.
 */
const hello = "world";

current result:

VariableDeclaration {
       name: 'hello',
       isConst: true,
       isExported: false,
       type: undefined,
       start: 38,
       end: 60 }

desired result:

VariableDeclaration {
       comment: '/**\n * A meaningless declaration.\n */',
       name: 'hello',
       isConst: true,
       isExported: false,
       type: undefined,
       start: 38,
       end: 60 }

danmarshall avatar Nov 07 '18 22:11 danmarshall

Is it clear to decide which block do the comment belongs to? e.g. attached to variable, class, method, property, or standalone

beenotung avatar Dec 05 '18 03:12 beenotung

According to this page:

JSDoc comments should generally be placed immediately before the code being documented.

danmarshall avatar Dec 05 '18 03:12 danmarshall

Actually, I have to see if the ts compiler does provide this information...

buehler avatar Feb 11 '19 08:02 buehler

I checked the AST that is generated. Sadly, you have no clue, where comments are in the document. So the only option to add comments is to add them manually.

Therefore, this can't be implemented.

buehler avatar Mar 04 '19 13:03 buehler

Maybe I was too fast... https://stackoverflow.com/questions/47429792/is-it-possible-to-get-comments-as-nodes-in-the-ast-using-the-typescript-compiler

buehler avatar Mar 04 '19 13:03 buehler