Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var esprima = require("esprima");
var estraverse = require("estraverse");
var ast = esprima.parse(`
function level1() {
function level2() {
;
}
}
function level1_1() {
;
}
`);
estraverse.traverse(ast, {
enter: enter,
leave: leave
});
function enter(node) {
if (node.type === "FunctionDeclaration") {
console.log("enter function: ", node.id.name);
}
}
function leave(node) {
if (node.type === "FunctionDeclaration") {
console.log("leave function: ", node.id.name);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.