From 28a8d275a352336074e0fd281d8e8d5304fda71d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 18 Apr 2025 15:34:56 -0700 Subject: [PATCH] Remove possible allocation of `NodeList` by eliminating `IfElse`. --- internal/parser/jsdoc.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/parser/jsdoc.go b/internal/parser/jsdoc.go index 421b58f35f..8ff3c28980 100644 --- a/internal/parser/jsdoc.go +++ b/internal/parser/jsdoc.go @@ -502,22 +502,32 @@ loop: p.nextTokenJSDoc() } } + p.jsdocCommentsSpace = comments[:0] // Reuse this slice for further parses if commentsPos == -1 { commentsPos = p.scanner.TokenFullStart() } + trimmedComments := trimEnd(strings.Join(comments, "")) if len(trimmedComments) > 0 { jsdocText := p.factory.NewJSDocText(trimmedComments) p.finishNodeWithEnd(jsdocText, linkEnd, commentsPos) commentParts = append(commentParts, jsdocText) } + if len(commentParts) > 0 && len(tags) > 0 && commentsPos == -1 { panic("having parsed tags implies that the end of the comment span should be set") } + + var tagsNodeList *ast.NodeList + if tagsPos != -1 { + tagsNodeList = p.newNodeList(core.NewTextRange(tagsPos, tagsEnd), tags) + } + jsdocComment := p.factory.NewJSDoc( p.newNodeList(core.NewTextRange(start, commentsPos), commentParts), - core.IfElse(tagsPos != -1, p.newNodeList(core.NewTextRange(tagsPos, tagsEnd), tags), nil)) + tagsNodeList, + ) p.finishNodeWithEnd(jsdocComment, fullStart, end) return jsdocComment }