-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
84 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Node, Parent } from 'unist' | ||
|
||
export type Traverser = (node: Node, parent?: Parent) => void | ||
|
||
export interface TraverseOptions { | ||
enter: Traverser | ||
} | ||
|
||
export class Traverse { | ||
private _enter: Traverser | ||
|
||
constructor({ enter }: TraverseOptions) { | ||
this._enter = enter | ||
} | ||
|
||
traverse(node: Node, parent?: Parent) { | ||
if (!node) { | ||
return | ||
} | ||
|
||
this._enter(node, parent) | ||
|
||
if (node.children) { | ||
parent = node as Parent | ||
parent.children.forEach(child => this.traverse(child, parent)) | ||
} | ||
} | ||
} | ||
|
||
export const traverse = (root: Parent, options: TraverseOptions) => | ||
new Traverse(options).traverse(root) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
declare module 'eslint-utils' {} | ||
|
||
declare module 'espree' { | ||
import * as estree from 'estree' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters