-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
Description
The parsed JavaScript AST sometimes includes JSDoc in its trivia, and sometimes it doesn't. This seems to be a regression from TS 1.9ish to current tip of tree.
If you have an input file like
/** @a */
var a = 3;
/** @b */
function b() { }
and you parse this with TypeScript ts.createSourceFile
and reserialize it out via a recursive loop like:
function dump(node: ts.Node) {
let pos = node.getFullStart();
for (const child of node.getChildren()) {
dumpRange(pos, child.getFullStart());
dump(child);
pos = child.getEnd();
}
dumpRange(pos, node.getEnd());
function dumpRange(start: number, end: number) {
process.stdout.write(node.getSourceFile().text.slice(start, end));
}
}
The output is:
/** @a *//** @a */
var a = 3;
/** @b */
function b() { }
You'll see that one of the comments was duplicated, and the other wasn't.
I think this is because in the FunctionDeclaration
case, the trivia of the FunctionDeclaration
node stops at the JSDocComment
, but in the VariableStatement
case, the trivia of the VarKeyword
still includes the jsdoc despite it also having a JSDocComment
.
Metadata
Metadata
Assignees
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code