estools / estraverse

ECMAScript JS AST traversal functions
BSD 2-Clause "Simplified" License
936 stars 131 forks source link

backward traversal #39

Open drom opened 9 years ago

drom commented 9 years ago

First, thank you for very elegant, concise, and useful tool. I use both tools: estraverse and recently shift-traverse for my projects.

One thing that I am missing is backward AST traversal. IMHO It will be useful for the static code analysis algorithms like lazy SSA construction or definition search.

What do you think?

a-x- commented 8 years ago

Hey, @drom, I see, you're in theme, but I am a novice. do you know also, are there backward AST generation algorithms?

I build AST locally backward and forward from the point on target node in large (and possibly not correct at all) source code file.

e.g.:

var c conosle.log.bind(console); // far away mistaken statement
... // about 100 sloc
foo({ bar:1, baz: 2, qux: 42 });
//                        ^ Starts AST-generation here for ObjectExpression

I use acorn.parseExpressionAt and some heuristics for that.