Previously we saw a bug that when we have nested if statements and an alternate then the generated code may confuse which if statement the alternate belongs to. e.g. ``` if (foo) if (bar) bar(); else baz(); ``` But this was handled by looking at the consequent and if it's an if we add a block. However we didn't handle situations where it's not an if but the last recursive statement is an if: ``` if (foo) while (bar) if (baz) baz(); else shoosh() ``` This handles it by recurring until we get the last statement.
babel-generator
Turns an AST into code.
Install
$ npm install babel-generator
Usage
import {parse} from 'babylon';
import generate from 'babel-generator';
const code = 'class Example {}';
const ast = parse(ast);
const output = generate(ast, { /* options */ }, code);