MCPcopy Index your code
hub / github.com/nodejs/node / reparseTopLevelAwait

Function reparseTopLevelAwait

test/fixtures/snapshot/typescript.js:31722–31815  ·  view source on GitHub ↗
(sourceFile)

Source from the content-addressed store, hash-verified

31720 return node;
31721 }
31722 function reparseTopLevelAwait(sourceFile) {
31723 var savedSyntaxCursor = syntaxCursor;
31724 var baseSyntaxCursor = IncrementalParser.createSyntaxCursor(sourceFile);
31725 syntaxCursor = { currentNode: currentNode };
31726 var statements = [];
31727 var savedParseDiagnostics = parseDiagnostics;
31728 parseDiagnostics = [];
31729 var pos = 0;
31730 var start = findNextStatementWithAwait(sourceFile.statements, 0);
31731 var _loop_3 = function () {
31732 // append all statements between pos and start
31733 var prevStatement = sourceFile.statements[pos];
31734 var nextStatement = sourceFile.statements[start];
31735 ts.addRange(statements, sourceFile.statements, pos, start);
31736 pos = findNextStatementWithoutAwait(sourceFile.statements, start);
31737 // append all diagnostics associated with the copied range
31738 var diagnosticStart = ts.findIndex(savedParseDiagnostics, function (diagnostic) { return diagnostic.start >= prevStatement.pos; });
31739 var diagnosticEnd = diagnosticStart >= 0 ? ts.findIndex(savedParseDiagnostics, function (diagnostic) { return diagnostic.start >= nextStatement.pos; }, diagnosticStart) : -1;
31740 if (diagnosticStart >= 0) {
31741 ts.addRange(parseDiagnostics, savedParseDiagnostics, diagnosticStart, diagnosticEnd >= 0 ? diagnosticEnd : undefined);
31742 }
31743 // reparse all statements between start and pos. We skip existing diagnostics for the same range and allow the parser to generate new ones.
31744 speculationHelper(function () {
31745 var savedContextFlags = contextFlags;
31746 contextFlags |= 32768 /* NodeFlags.AwaitContext */;
31747 scanner.setTextPos(nextStatement.pos);
31748 nextToken();
31749 while (token() !== 1 /* SyntaxKind.EndOfFileToken */) {
31750 var startPos = scanner.getStartPos();
31751 var statement = parseListElement(0 /* ParsingContext.SourceElements */, parseStatement);
31752 statements.push(statement);
31753 if (startPos === scanner.getStartPos()) {
31754 nextToken();
31755 }
31756 if (pos >= 0) {
31757 var nonAwaitStatement = sourceFile.statements[pos];
31758 if (statement.end === nonAwaitStatement.pos) {
31759 // done reparsing this section
31760 break;
31761 }
31762 if (statement.end > nonAwaitStatement.pos) {
31763 // we ate into the next statement, so we must reparse it.
31764 pos = findNextStatementWithoutAwait(sourceFile.statements, pos + 1);
31765 }
31766 }
31767 }
31768 contextFlags = savedContextFlags;
31769 }, 2 /* SpeculationKind.Reparse */);
31770 // find the next statement containing an `await`
31771 start = pos >= 0 ? findNextStatementWithAwait(sourceFile.statements, pos) : -1;
31772 };
31773 while (start !== -1) {
31774 _loop_3();
31775 }
31776 // append all statements between pos and the end of the list
31777 if (pos >= 0) {
31778 var prevStatement_1 = sourceFile.statements[pos];
31779 ts.addRange(statements, sourceFile.statements, pos);

Callers 1

createSourceFileFunction · 0.85

Calls 3

_loop_3Function · 0.85
addRangeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…