estree-to-js
Parser / JSON + visitor generator of the markdown estree spec;
Usage
npdejs API
estree-to-js interface:
var estree = ;var visitorSource = estree
Visitors
Creation of visitor:
var visitor;visitorSource ;
Print path example
visitors have an accept(node, state, path)
method and visitNodeType methods
like visitVariableDeclaration(node, state, path)
. You can customize it to
your needs, for example:
var lang = ast = ;visitoraccept = langfun;var state = ;visitoracceptast state ;console; // => // - Program // body.0 - VariableDeclaration // body.0.declarations.0 - VariableDeclarator // ...
Rewriting example
var langobjvar visitor = ;visitoraccept = langfun;var rewritten = visitoracceptast null ;ast; // => var foo_x = 1 + 3;
command line
--out file output file to write
--generate-json-spec fetch and parse markdown source and generate JSON spec from it (default)
--generate-visitor generate source code for AST visitor class
--json-spec file to json spec. If specified it is used instead of fetching + parsing
Examples:
./bin/estree-to-js.js es6
prints JSON spec of es6 estree./bin/estree-to-js.js es6 --generate-visitor
prints JS source es6 estree visitor class