()
| 428 | } |
| 429 | |
| 430 | func (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 | |
| 465 | func (p *Parser) finishSourceFile(result *ast.SourceFile, isDeclarationFile bool) { |
| 466 | result.CommentDirectives = p.scanner.CommentDirectives() |
no test coverage detected