Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions apps/oxlint/src-js/plugins/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,23 @@ export function initCompiledVisitor(): void {
enterExit.exit = null;
}
enterExitObjectCacheNextIndex = 0;

// Reset merged visitor type IDs from previous compilation
// These arrays must be cleared here in case the previous compilation failed
// before reaching the cleanup code in `finalizeCompiledVisitor`
mergedLeafVisitorTypeIds.length = 0;
mergedEnterVisitorTypeIds.length = 0;
mergedExitVisitorTypeIds.length = 0;

// Reset visit function array cache
// Empty all cached arrays and reset index
for (let i = 0; i < visitFnArrayCacheNextIndex; i++) {
visitFnArrayCache[i].length = 0;
}
visitFnArrayCacheNextIndex = 0;

// Reset hasActiveVisitors flag
hasActiveVisitors = false;
}

/**
Expand Down Expand Up @@ -409,6 +426,11 @@ export function finalizeCompiledVisitor() {
* @returns Function which calls all of `visitFns` in turn.
*/
function mergeVisitFns(visitFns: VisitFn[]): VisitFn {
// Validate that visitFns is actually an array
if (!isArray(visitFns)) {
throw new TypeError(`Expected visitFns to be an array, but got ${typeof visitFns}`);
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message uses template literal syntax but typeof on an array returns 'object', which isn't very helpful. Consider using Array.isArray() check result or providing the actual value type in a more descriptive way, e.g., Expected visitFns to be an array, but got ${visitFns === null ? 'null' : typeof visitFns}.

Suggested change
throw new TypeError(`Expected visitFns to be an array, but got ${typeof visitFns}`);
throw new TypeError(`Expected visitFns to be an array, but got ${visitFns === null ? 'null' : typeof visitFns}`);

Copilot uses AI. Check for mistakes.
}

const numVisitFns = visitFns.length;

// Get or create merger for merging `numVisitFns` functions
Expand Down
Loading