MCPcopy Index your code
hub / github.com/microsoft/typescript-go / parseSourceFileWorker

Method parseSourceFileWorker

internal/parser/parser.go:430–463  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

428}
429
430func (p *Parser) parseSourceFileWorker() *ast.SourceFile {
431 isDeclarationFile := tspath.IsDeclarationFileName(p.opts.FileName)
432 if isDeclarationFile {
433 p.contextFlags |= ast.NodeFlagsAmbient
434 }
435 pos := p.nodePos()
436 statements := p.parseListIndex(PCSourceElements, (*Parser).parseToplevelStatement)
437 end := p.nodePos()
438 endJSDoc := p.jsdocScannerInfo()
439 eof := p.parseTokenNode()
440 p.withJSDoc(eof, endJSDoc)
441 if eof.Kind != ast.KindEndOfFile {
442 panic("Expected end of file token from scanner.")
443 }
444 if len(p.reparseList) != 0 {
445 statements = append(statements, p.reparseList...)
446 p.reparseList = nil
447 }
448 node := p.finishNode(p.factory.NewSourceFile(p.opts, p.sourceText, p.newNodeList(core.NewTextRange(pos, end), statements), eof), pos)
449 result := node.AsSourceFile()
450 p.finishSourceFile(result, isDeclarationFile)
451 if !result.IsDeclarationFile && result.ExternalModuleIndicator != nil && len(p.possibleAwaitSpans) > 0 {
452 reparse := p.finishNode(p.reparseTopLevelAwait(result), pos)
453 if node != reparse {
454 result = reparse.AsSourceFile()
455 p.finishSourceFile(result, isDeclarationFile)
456 }
457 }
458 collectExternalModuleReferences(result)
459 if ast.IsInJSFile(node) {
460 result.SetJSDiagnostics(attachFileToDiagnostics(p.jsDiagnostics, result))
461 }
462 return result
463}
464
465func (p *Parser) finishSourceFile(result *ast.SourceFile, isDeclarationFile bool) {
466 result.CommentDirectives = p.scanner.CommentDirectives()

Callers 1

ParseSourceFileFunction · 0.80

Calls 15

nodePosMethod · 0.95
parseListIndexMethod · 0.95
jsdocScannerInfoMethod · 0.95
parseTokenNodeMethod · 0.95
withJSDocMethod · 0.95
finishNodeMethod · 0.95
newNodeListMethod · 0.95
finishSourceFileMethod · 0.95
reparseTopLevelAwaitMethod · 0.95
IsDeclarationFileNameFunction · 0.92
NewTextRangeFunction · 0.92
IsInJSFileFunction · 0.92

Tested by

no test coverage detected