From 4c326b2b6cb7133d3e34835489de50a23b9a721f Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 25 Jun 2018 11:36:37 -0700 Subject: [PATCH] Simplify addJSDocComment (#25196) * Simplify addJSDocComment * Add assert --- src/compiler/parser.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 72b7fdc4850..c411a653cf0 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -864,13 +864,9 @@ namespace ts { } function addJSDocComment(node: T): T { - const comments = getJSDocCommentRanges(node, sourceFile.text); - if (comments) { - for (const comment of comments) { - node.jsDoc = append(node.jsDoc, JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos)); - } - } - + Debug.assert(!node.jsDoc); // Should only be called once per node + const jsDoc = mapDefined(getJSDocCommentRanges(node, sourceFile.text), comment => JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos)); + if (jsDoc.length) node.jsDoc = jsDoc; return node; }