fix(lint): don't recurse infinitely for large ASTs (#28265)

We previously failed to lint `./cli/tsc/00_typescript.js` with plugins,
because every "next" node would cause a new stack frame to be added.
This commit is contained in:
Luca Casonato 2025-02-24 02:51:30 -08:00 committed by GitHub
parent f373a20a6f
commit 55dc6f4b93
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1150,7 +1150,7 @@ export function runPluginsForFile(fileName, serializedAst) {
* @param {CancellationToken} cancellationToken
*/
function traverse(ctx, visitors, idx, cancellationToken) {
if (idx === AST_IDX_INVALID) return;
while (idx !== AST_IDX_INVALID) {
if (cancellationToken.isCancellationRequested()) return;
const { buf } = ctx;
@ -1195,9 +1195,7 @@ function traverse(ctx, visitors, idx, cancellationToken) {
}
}
const nextIdx = readNext(buf, idx);
if (nextIdx > AST_IDX_INVALID) {
traverse(ctx, visitors, nextIdx, cancellationToken);
idx = readNext(buf, idx);
}
}