Morpher
JavaScript AST transformer and code generator, optimized for older engines.
Inspired by falafel (https://github.com/substack/node-falafel) and free-falafel (https://github.com/freethenation/node-falafel), but modified for performance in older JavaScript engines (eg. IE8.)
AST traversal is leaf-first (so child nodes are visited before their parents.)
Example
var code = 'var result = 1 + 2;';var ast = acorn;var transpiledCode = morpher;console; // Outputs `var result = postProcess(1 + 2);`
Use with a breadth-first callback
To process parent nodes before their children, you can pass a second callback to .morph(...)
:
var code = 'var result = 1 + 2; function test() { return 2 + 3; }';var ast = acorn;var transpiledCode = morpher;console; // Outputs `var result = 1 + 2; function test() { return postProcess(2 + 3); }`
Keeping up to date
- Follow me on Twitter for updates: https://twitter.com/@asmblah