es-lookup-scope
Version:
Look up the scoop of an estree compatible node
37 lines (33 loc) • 1.35 kB
Markdown
# es-lookup-scope
[](https://travis-ci.org/megawac/es-lookup-scope)
[](https://codeclimate.com/github/megawac/es-lookup-scope)
[](https://codeclimate.com/github/megawac/es-lookup-scope)
[](https://david-dm.org/megawac/es-lookup-scope)
[](https://david-dm.org/megawac/es-lookup-scope#info=devDependencies)
Using [escope](https://github.com/estools/escope) we find the scope of any estree compatible AST node.
```js
import {parse} from 'acorn';
import lookup from 'es-lookup-scope';
import {traverse} from 'estraverse'
let ast = parse(`
(function() {
const x = 2;
try {
const x = 1;
[1, 2, 3].map(x => x);
} catch(o_O) {}
console.log(x);
})();
module.exports = {
x() {
let y = this;
console.log(y);
}
}
`, { ecmaVersion: 6});
traverse(ast, {
enter(node) {
console.log(lookup(node));
}
});
```