Skip to content

hkasemir/flow-jsx-walk

 
 

Repository files navigation

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.

About

Walk through a es6+jsx parsed program source

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%