Just add a trailing call to visitNode instead of creating a new array when collecting outlining spans (#61987)

This commit is contained in:
Daniel Rosenwasser 2025-07-02 10:18:12 -07:00 committed by GitHub
parent 441655c270
commit fe698aef28
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -67,8 +67,7 @@ export function collectElements(sourceFile: SourceFile, cancellationToken: Cance
function addNodeOutliningSpans(sourceFile: SourceFile, cancellationToken: CancellationToken, out: OutliningSpan[]): void {
let depthRemaining = 40;
let current = 0;
// Includes the EOF Token so that comments which aren't attached to statements are included
const statements = [...sourceFile.statements, sourceFile.endOfFileToken];
const statements = sourceFile.statements;
const n = statements.length;
while (current < n) {
while (current < n && !isAnyImportSyntax(statements[current])) {
@ -87,6 +86,9 @@ function addNodeOutliningSpans(sourceFile: SourceFile, cancellationToken: Cancel
}
}
// Visit the EOF Token so that comments which aren't attached to statements are included.
visitNode(sourceFile.endOfFileToken);
function visitNode(n: Node) {
if (depthRemaining === 0) return;
cancellationToken.throwIfCancellationRequested();