flow-jsx-walk
v1.0.0
Published
Parse and walk through a Javascript/JSX code source
Downloads
2
Readme
flow-jsx-walk
A fork of acorn-jsx-walk that uses the flow parser to support ecmascript features like decorators and spread operators. Parse and walk through a Javascript JSX code source.
Install
npm install --save flow-jsx-walk
Example
import walk, { base } from 'flow-jsx-walk';
// base contains all the possible node walkers, see walk.js
// Program, BlockStatement, ExpressionStatement, SwitchStatement etc.
const source = `
const a = 2;
const f = (u) => {
const m = <div>Hey</div>;
return m;
}`;
walk(source, {
VariableDeclaration: (node) => { console.log(node.declarations.map(n => n.id.name)) },
});
/*
[ 'a' ]
[ 'm' ]
[ 'f' ]
*/
Note
It's using the walk
method of acorn
but extends it with the JSX addons.
It is shamelessly copied from
acorn code
source because it is not possible to import it in another project properly.