Skip to content

Commit e26d5fd

Browse files
committed
refactor: enhance fallbackKeysFilter readability
1 parent 4e48327 commit e26d5fd

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/ast/traverse.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ export const KEYS = Evk.unionWith({
3232

3333
/**
3434
* Check that the given key should be traversed or not.
35-
* @this {Traversable}
3635
* @param key The key to check.
36+
* @param value The value of the key in the node.
3737
* @returns `true` if the key should be traversed.
3838
*/
39-
function fallbackKeysFilter(this: any, key: string): boolean {
40-
let value = null
39+
function fallbackKeysFilter(key: string, value: any = null): boolean {
4140
return (
4241
key !== "comments" &&
4342
key !== "leadingComments" &&
@@ -46,7 +45,7 @@ function fallbackKeysFilter(this: any, key: string): boolean {
4645
key !== "range" &&
4746
key !== "tokens" &&
4847
key !== "trailingComments" &&
49-
(value = this[key]) !== null &&
48+
value !== null &&
5049
typeof value === "object" &&
5150
(typeof value.type === "string" || Array.isArray(value))
5251
)
@@ -57,8 +56,10 @@ function fallbackKeysFilter(this: any, key: string): boolean {
5756
* @param node The node to get.
5857
* @returns The keys to traverse.
5958
*/
60-
function getFallbackKeys(node: Node): string[] {
61-
return Object.keys(node).filter(fallbackKeysFilter, node)
59+
export function getFallbackKeys(node: Node): string[] {
60+
return Object.keys(node).filter((key) =>
61+
fallbackKeysFilter(key, node[key as keyof Node]),
62+
)
6263
}
6364

6465
/**
@@ -119,5 +120,3 @@ export interface Visitor {
119120
export function traverseNodes(node: Node, visitor: Visitor): void {
120121
traverse(node, null, visitor)
121122
}
122-
123-
export { getFallbackKeys }

0 commit comments

Comments
 (0)