Created
April 30, 2019 03:35
-
-
Save smileboywtu/bdf1a0f1448cd8c0e4e09eb066b0bf7e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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