Skip to content

Instantly share code, notes, and snippets.

@daybrush
Last active October 10, 2018 05:12
Show Gist options
  • Save daybrush/a68312a444fc8e7ccec0942c4a43e5ed to your computer and use it in GitHub Desktop.
Save daybrush/a68312a444fc8e7ccec0942c4a43e5ed to your computer and use it in GitHub Desktop.
import traverse from "@babel/traverse";
import t from "@babel/types";
traverse(ast, {
FunctionDeclaration: function (path) {
// path.node(FunctionDeclaration)
path.insertAfter(t.variableDeclaration("var", [
t.variableDeclarator(
t.identifier("__proto"),
t.memberExpression(t.identifier("Item"), t.identifier("prototype"))
)
]));
},
});
/*
function Item() {}
var __proto = Item.prototype;
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment