📄 simple-traverse¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 4 |
| 🧱 Classes | 1 |
| 📦 Imports | 3 |
| 📑 Type Aliases | 1 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/typescript-estree/src/simple-traverse.ts
📦 Imports¶
| Name | Source |
|---|---|
VisitorKeys |
@typescript-eslint/visitor-keys |
visitorKeys |
@typescript-eslint/visitor-keys |
TSESTree |
./ts-estree |
Functions¶
simpleTraverse(startingNode: TSESTree.Node, options: SimpleTraverseOptions, setParentPointers: boolean): void¶
Parameters:
startingNodeTSESTree.NodeoptionsSimpleTraverseOptionssetParentPointersboolean
Returns: void
Calls:
new SimpleTraverser(options, setParentPointers).traverse
Code
isValidNode(x: unknown): x is TSESTree.Node¶
Parameters:
xunknown
Returns: x is TSESTree.Node
Code
getVisitorKeysForNode(allVisitorKeys: typeof visitorKeys, node: TSESTree.Node): readonly (keyof TSESTree.Node)[]¶
Parameters:
allVisitorKeystypeof visitorKeysnodeTSESTree.Node
Returns: readonly (keyof TSESTree.Node)[]
Code
SimpleTraverser.traverse(node: unknown, parent: TSESTree.Node | undefined): void¶
Parameters:
nodeunknownparentTSESTree.Node | undefined
Returns: void
Calls:
isValidNodethis.selectors.entercomplex_call_1689getVisitorKeysForNodeArray.isArraythis.traverse
Code
traverse(node: unknown, parent: TSESTree.Node | undefined): void {
if (!isValidNode(node)) {
return;
}
if (this.setParentPointers) {
node.parent = parent;
}
if ('enter' in this.selectors) {
this.selectors.enter(node, parent);
} else if (node.type in this.selectors.visitors) {
this.selectors.visitors[node.type](node, parent);
}
const keys = getVisitorKeysForNode(this.allVisitorKeys, node);
if (keys.length < 1) {
return;
}
for (const key of keys) {
const childOrChildren = node[key];
if (Array.isArray(childOrChildren)) {
for (const child of childOrChildren) {
this.traverse(child, node);
}
} else {
this.traverse(childOrChildren, node);
}
}
}
Classes¶
SimpleTraverser¶
Class Code
class SimpleTraverser {
private readonly allVisitorKeys: Readonly<VisitorKeys> = visitorKeys;
private readonly selectors: SimpleTraverseOptions;
private readonly setParentPointers: boolean;
constructor(selectors: SimpleTraverseOptions, setParentPointers = false) {
this.selectors = selectors;
this.setParentPointers = setParentPointers;
if (selectors.visitorKeys) {
this.allVisitorKeys = selectors.visitorKeys;
}
}
traverse(node: unknown, parent: TSESTree.Node | undefined): void {
if (!isValidNode(node)) {
return;
}
if (this.setParentPointers) {
node.parent = parent;
}
if ('enter' in this.selectors) {
this.selectors.enter(node, parent);
} else if (node.type in this.selectors.visitors) {
this.selectors.visitors[node.type](node, parent);
}
const keys = getVisitorKeysForNode(this.allVisitorKeys, node);
if (keys.length < 1) {
return;
}
for (const key of keys) {
const childOrChildren = node[key];
if (Array.isArray(childOrChildren)) {
for (const child of childOrChildren) {
this.traverse(child, node);
}
} else {
this.traverse(childOrChildren, node);
}
}
}
}
Methods (1) — full entries under Functions
| Method | Signature |
|---|---|
traverse |
(node: unknown, parent: TSESTree.Node \| undefined): void |
Type Aliases¶
SimpleTraverseOptions¶
type SimpleTraverseOptions = Readonly<
| {
enter: (node: TSESTree.Node, parent: TSESTree.Node | undefined) => void;
visitorKeys?: Readonly<VisitorKeys>;
}
| {
visitorKeys?: Readonly<VisitorKeys>;
visitors: Record<
string,
(node: TSESTree.Node, parent: TSESTree.Node | undefined) => void
>;
}
>;
Generated by Syntax Scribe