Skip to content

Commit 4c326b2

Browse files
author
Andy
authored
Simplify addJSDocComment (microsoft#25196)
* Simplify addJSDocComment * Add assert
1 parent 62e5541 commit 4c326b2

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/compiler/parser.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -864,13 +864,9 @@ namespace ts {
864864
}
865865

866866
function addJSDocComment<T extends HasJSDoc>(node: T): T {
867-
const comments = getJSDocCommentRanges(node, sourceFile.text);
868-
if (comments) {
869-
for (const comment of comments) {
870-
node.jsDoc = append<JSDoc>(node.jsDoc, JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos));
871-
}
872-
}
873-
867+
Debug.assert(!node.jsDoc); // Should only be called once per node
868+
const jsDoc = mapDefined(getJSDocCommentRanges(node, sourceFile.text), comment => JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos));
869+
if (jsDoc.length) node.jsDoc = jsDoc;
874870
return node;
875871
}
876872

0 commit comments

Comments
 (0)