Traversers
→ LCE traversers are implemented as a modified visitor pattern
- The abstract
Traverserbase class provides the implementation that orchestrates the execution of the other components- only the
traverseChildrenmethod that delegates the traversal of potential child nodes to other traversers is abstract and has to be implemented by sub types
- only the
- for each AST node type (provided via
@typescript-eslint/utils) that should be processed, a separateTraverserimplementation has to be provided- note that skipping nodes in the ESLint AST through a simplified
Traverserimplementation (e.g. via nested node access:runTraverserForNodes(node.body.body, ...)) must be avoided as it leads to an incorrectly setparentproperty on the traversed child nodes
- note that skipping nodes in the ESLint AST through a simplified
- all traverser implementations are located under
typescript/src/core/traversers- all files end with
.traverser.ts - may export one or more traverser classes each
- all files end with
Notes for creating new traversers:
- each traverser class must inherit from
Traverser - all traversers need to be registered in the
TRAVERSERSfeature collection infeatures.ts- before implementing a new traverser check if there already exists one in the collection
- existing traversers may not trigger the traversal for all their child nodes: expand where needed
- for nodes that don’t have any children that should be traversed the
SimpleTraverserdefault implementation can be specified inTRAVERSERSfor the corresponding node type
- use
runTraverserForNode(s) utility function to easily delegate the traversal process - parent property names should be declared as
public static readonlymembers of the implementing class