Skip to content

Instantly share code, notes, and snippets.

@smileboywtu
Created April 30, 2019 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smileboywtu/bdf1a0f1448cd8c0e4e09eb066b0bf7e to your computer and use it in GitHub Desktop.
Save smileboywtu/bdf1a0f1448cd8c0e4e09eb066b0bf7e to your computer and use it in GitHub Desktop.
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