MCPcopy Create free account
hub / github.com/microsoft/typescript-go / parseJSDocCommentWorker

Method parseJSDocCommentWorker

internal/parser/jsdoc.go:193–378  ·  view source on GitHub ↗

** * @param offset - the offset in the containing file * @param indent - the number of spaces to consider as the margin (applies to non-first lines only) */

(start int, end int, fullStart int, indent int)

Source from the content-addressed store, hash-verified

191 * @param indent - the number of spaces to consider as the margin (applies to non-first lines only)
192 */
193func (p *Parser) parseJSDocCommentWorker(start int, end int, fullStart int, indent int) *ast.Node {
194 // Initially we can parse out a tag. We also have seen a starting asterisk.
195 // This is so that /** * @type */ doesn't parse.
196 tags := p.nodeSliceArena.NewSlice(1)[:0]
197 tagsPos := -1
198 tagsEnd := -1
199 state := jsdocStateSawAsterisk
200 backtickCount := 0
201 inFencedCodeBlock := false
202 commentParts := p.nodeSliceArena.NewSlice(1)[:0]
203 comments := p.jsdocCommentsSpace
204 commentsPos := -1
205 linkEnd := start
206 margin := -1
207 pushComment := func(text string) {
208 if margin == -1 {
209 margin = indent
210 }
211 comments = append(comments, text)
212 indent += len(text)
213 }
214
215 p.nextTokenJSDoc()
216 for p.parseOptionalJsdoc(ast.KindWhitespaceTrivia) {
217 }
218 if p.parseOptionalJsdoc(ast.KindNewLineTrivia) {
219 state = jsdocStateBeginningOfLine
220 indent = 0
221 }
222loop:
223 for {
224 // Detect fenced code blocks by counting consecutive backtick tokens.
225 // Three or more consecutive backticks toggle the fenced code block state.
226 if p.token != ast.KindBacktickToken && backtickCount > 0 {
227 if backtickCount >= 3 {
228 inFencedCodeBlock = !inFencedCodeBlock
229 }
230 backtickCount = 0
231 }
232 switch p.token {
233 case ast.KindAtToken:
234 if inFencedCodeBlock || !p.scanner.CanFollowJSDocAt() {
235 if inFencedCodeBlock {
236 state = jsdocStateSavingBackticks
237 } else {
238 state = jsdocStateSavingComments
239 }
240 pushComment(p.scanner.TokenText())
241 break
242 }
243 comments = removeTrailingWhitespace(comments)
244 if commentsPos == -1 {
245 commentsPos = p.nodePos()
246 }
247 tag := p.parseTag(tags, indent)
248 if tagsPos == -1 {
249 tagsPos = tag.Pos()
250 }

Callers 1

parseJSDocCommentMethod · 0.95

Calls 15

nextTokenJSDocMethod · 0.95
parseOptionalJsdocMethod · 0.95
nodePosMethod · 0.95
parseTagMethod · 0.95
parseJSDocLinkMethod · 0.95
finishNodeWithEndMethod · 0.95
newNodeListMethod · 0.95
NewTextRangeFunction · 0.92
lenFunction · 0.85
removeTrailingWhitespaceFunction · 0.85
panicFunction · 0.85

Tested by

no test coverage detected