Skip to content

Instantly share code, notes, and snippets.

@marcioj
Created December 24, 2015 19:08
Show Gist options
  • Save marcioj/484723142d26e72c6754 to your computer and use it in GitHub Desktop.
Save marcioj/484723142d26e72c6754 to your computer and use it in GitHub Desktop.
Print AST to code in Babel 5.x
import generate from 'babel-core/lib/generation';
let file;
function print(ast) {
// duck type NodePath
if (ast.node) {
ast = ast.node;
}
console.log(generate(ast, file.opts, file.code).code);
}
export default function ({ Plugin, types: t }) {
return new Plugin('angular-annotate', {
visitor: {
Program: {
enter(node, parent, scope, _file) {
file = _file;
}
},
MemberExpression() {
print(this);
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment