(sourceFile *ast.SourceFile)
| 516 | } |
| 517 | |
| 518 | func (p *Parser) reparseTopLevelAwait(sourceFile *ast.SourceFile) *ast.Node { |
| 519 | if len(p.possibleAwaitSpans)%2 == 1 { |
| 520 | panic("possibleAwaitSpans malformed: odd number of indices, not paired into spans.") |
| 521 | } |
| 522 | statements := []*ast.Statement{} |
| 523 | savedParseDiagnostics := p.diagnostics |
| 524 | p.diagnostics = []*ast.Diagnostic{} |
| 525 | |
| 526 | afterAwaitStatement := 0 |
| 527 | for i := 0; i < len(p.possibleAwaitSpans); i += 2 { |
| 528 | nextAwaitStatement := p.possibleAwaitSpans[i] |
| 529 | // append all non-await statements between afterAwaitStatement and nextAwaitStatement |
| 530 | prevStatement := sourceFile.Statements.Nodes[afterAwaitStatement] |
| 531 | nextStatement := sourceFile.Statements.Nodes[nextAwaitStatement] |
| 532 | statements = append(statements, sourceFile.Statements.Nodes[afterAwaitStatement:nextAwaitStatement]...) |
| 533 | |
| 534 | // append all diagnostics associated with the copied range |
| 535 | diagnosticStart := core.FindIndex(savedParseDiagnostics, func(diagnostic *ast.Diagnostic) bool { |
| 536 | return diagnostic.Pos() >= prevStatement.Pos() |
| 537 | }) |
| 538 | var diagnosticEnd int |
| 539 | if diagnosticStart >= 0 { |
| 540 | diagnosticEnd = core.FindIndex(savedParseDiagnostics[diagnosticStart:], func(diagnostic *ast.Diagnostic) bool { |
| 541 | return diagnostic.Pos() >= nextStatement.Pos() |
| 542 | }) |
| 543 | } else { |
| 544 | diagnosticEnd = -1 |
| 545 | } |
| 546 | if diagnosticStart >= 0 { |
| 547 | var slice []*ast.Diagnostic |
| 548 | if diagnosticEnd >= 0 { |
| 549 | slice = savedParseDiagnostics[diagnosticStart : diagnosticStart+diagnosticEnd] |
| 550 | } else { |
| 551 | slice = savedParseDiagnostics[diagnosticStart:] |
| 552 | } |
| 553 | p.diagnostics = append(p.diagnostics, slice...) |
| 554 | } |
| 555 | |
| 556 | state := p.mark() |
| 557 | // reparse all statements between start and pos. We skip existing diagnostics for the same range and allow the parser to generate new ones. |
| 558 | p.contextFlags |= ast.NodeFlagsAwaitContext |
| 559 | p.scanner.ResetPos(nextStatement.Pos()) |
| 560 | p.nextToken() |
| 561 | |
| 562 | afterAwaitStatement = p.possibleAwaitSpans[i+1] |
| 563 | for p.token != ast.KindEndOfFile { |
| 564 | startPos := p.scanner.TokenFullStart() |
| 565 | statement := p.parseStatement() |
| 566 | statements = append(statements, statement) |
| 567 | if startPos == p.scanner.TokenFullStart() { |
| 568 | p.nextToken() |
| 569 | } |
| 570 | if afterAwaitStatement < len(sourceFile.Statements.Nodes) { |
| 571 | lastAwaitStatement := sourceFile.Statements.Nodes[afterAwaitStatement-1] |
| 572 | if statement.End() == lastAwaitStatement.End() { |
| 573 | // done reparsing this section |
| 574 | break |
| 575 | } |
no test coverage detected