README.md
1# acorn-globals
2
3Detect global variables in JavaScript using acorn
4
5[](https://travis-ci.org/ForbesLindesay/acorn-globals)
6[](https://david-dm.org/ForbesLindesay/acorn-globals)
7[](https://www.npmjs.org/package/acorn-globals)
8
9## Installation
10
11 npm install acorn-globals
12
13## Usage
14
15detect.js
16
17```js
18var fs = require('fs');
19var detect = require('acorn-globals');
20
21var src = fs.readFileSync(__dirname + '/input.js', 'utf8');
22
23var scope = detect(src);
24console.dir(scope);
25```
26
27input.js
28
29```js
30var x = 5;
31var y = 3, z = 2;
32
33w.foo();
34w = 2;
35
36RAWR=444;
37RAWR.foo();
38
39BLARG=3;
40
41foo(function () {
42 var BAR = 3;
43 process.nextTick(function (ZZZZZZZZZZZZ) {
44 console.log('beep boop');
45 var xyz = 4;
46 x += 10;
47 x.zzzzzz;
48 ZZZ=6;
49 });
50 function doom () {
51 }
52 ZZZ.foo();
53
54});
55
56console.log(xyz);
57```
58
59output:
60
61```
62$ node example/detect.js
63[ { name: 'BLARG', nodes: [ [Object] ] },
64 { name: 'RAWR', nodes: [ [Object], [Object] ] },
65 { name: 'ZZZ', nodes: [ [Object], [Object] ] },
66 { name: 'console', nodes: [ [Object], [Object] ] },
67 { name: 'foo', nodes: [ [Object] ] },
68 { name: 'process', nodes: [ [Object] ] },
69 { name: 'w', nodes: [ [Object], [Object] ] },
70 { name: 'xyz', nodes: [ [Object] ] } ]
71```
72
73
74## License
75
76 MIT
77