Skip to content

Commit

Permalink
Avoid unnecessary top level constructor (#1116)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericcornelissen authored Aug 4, 2024
1 parent 1523f08 commit a7e9566
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import type {Rule} from 'eslint';

const topLevelTypes = new Set([
const topLevelTypes = [
'ArrayExpression',
'AssignmentExpression',
'BinaryExpression',
Expand All @@ -18,7 +18,7 @@ const topLevelTypes = new Set([
'UnaryExpression',
'VariableDeclaration',
'VariableDeclarator'
]);
];

export function IsCommonJs(node: Rule.Node) {
while (node.type !== 'Program') {
Expand All @@ -29,7 +29,7 @@ export function IsCommonJs(node: Rule.Node) {

export function isTopLevel(node: Rule.Node) {
let scope = node.parent;
while (topLevelTypes.has(scope.type)) {
while (topLevelTypes.includes(scope.type)) {
scope = scope.parent;
}
return scope.type === 'Program';
Expand Down

0 comments on commit a7e9566

Please sign in to comment.