Skip to content

Remove possible allocation of NodeList by eliminating IfElse. #808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion internal/parser/jsdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down