Skip to content

mkx419/tsestree-walker

Repository files navigation

tsestree-walker

Simple utility for walking an AST in the TSESTree format.

This is a ported and feature-reduced version of estree-walker.

Installation

npm

npm i @mkx419/tsestree-walker

pnpm

pnpm add @mkx419/tsestree-walker

Usage

walk

import { walk } from "@mkx419/tsestree-walker";
import { parse } from "@typescript-eslint/typescript-estree";

const ast = parse(sourceCode);

walk(ast, {
  enter(node) {
    //
  },
  leave(node) {
    //
  },
});

WalkerBase

import { WalkerBase } from "@mkx419/tsestree-walker";
import { parse } from "@typescript-eslint/typescript-estree";

class CustomWalker extends WalkerBase {
  constructor() {
    super();
  }

  enter(node) {
    //
  }

  leave(node) {
    //
  }

  start(ast) {
    super.start(ast);
  }
}

const ast = parse(sourceCode);

new CustomWalker().start(ast);