print-highlighted-ast
print a babel AST with specific nodes highlighted, for debugging codemods
Example
Script
traverseast, console.logprintHighlightedAstcode,
Output
const foo = () => 2
const bar = 500 + 600
APIYou can pass the source code or a parsed AST as the first argument. If you pass an AST it will be
converted to code with @babel/generator
.
Each element of highlights
is a tuple of [0]
path you want to highlight, [1]
highlighting function.
You can pass options to @babel/parser
and @babel/generator
as shown below.
The code will be parsed with @babel/parser
to determine the source range of the paths you want to
highlight. If you're using language extensions like Flow, Typescript, or JSX, you'll need to pass
those plugins in parseOptions
.