Skip to content

Commit e2a0997

Browse files
committed
perf(linter/plugins): recycle empty visitor object in ESLint compat mode (#15693)
Small perf optimization. In ESLint compat mode, `create` returns an empty visitor object when `before` hook returns `false`. Reuse the same object, instead of creating a new one each time.
1 parent 2eec3f5 commit e2a0997

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

apps/oxlint/src-js/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ const {
5151
assign: ObjectAssign,
5252
} = Object;
5353

54+
// Empty visitor object, returned by `create` when `before` hook returns `false`.
55+
const EMPTY_VISITOR: Visitor = {};
56+
5457
/**
5558
* Define a plugin.
5659
*
@@ -124,7 +127,7 @@ export function defineRule(rule: Rule): Rule {
124127
// If `before` hook returns `false`, skip traversal by returning an empty object as visitor
125128
if (beforeHook !== null) {
126129
const shouldRun = beforeHook();
127-
if (shouldRun === false) return {};
130+
if (shouldRun === false) return EMPTY_VISITOR;
128131
}
129132

130133
// Return same visitor each time

0 commit comments

Comments
 (0)