1 | # acorn-globals
|
2 |
|
3 | Detect global variables in JavaScript using acorn
|
4 |
|
5 | [Get supported acorn-globals with the Tidelift Subscription](https://tidelift.com/subscription/pkg/npm-acorn_globals?utm_source=npm-acorn-globals&utm_medium=referral&utm_campaign=readme)
|
6 |
|
7 | [![Build Status](https://img.shields.io/github/workflow/status/ForbesLindesay/acorn-globals/Publish%20Canary/master?style=for-the-badge)](https://github.com/ForbesLindesay/acorn-globals/actions?query=workflow%3APublish%20Canary+branch%3Amaster)
|
8 | [![Rolling Versions](https://img.shields.io/badge/Rolling%20Versions-Enabled-brightgreen?style=for-the-badge)](https://rollingversions.com/ForbesLindesay/acorn-globals)
|
9 | [![NPM version](https://img.shields.io/npm/v/acorn-globals?style=for-the-badge)](https://www.npmjs.com/package/acorn-globals)
|
10 |
|
11 | ## Installation
|
12 |
|
13 | npm install acorn-globals
|
14 |
|
15 | ## Usage
|
16 |
|
17 | detect.js
|
18 |
|
19 | ```js
|
20 | var fs = require('fs');
|
21 | var detect = require('acorn-globals');
|
22 |
|
23 | var src = fs.readFileSync(__dirname + '/input.js', 'utf8');
|
24 |
|
25 | var scope = detect(src);
|
26 | console.dir(scope);
|
27 | ```
|
28 |
|
29 | input.js
|
30 |
|
31 | ```js
|
32 | var x = 5;
|
33 | var y = 3, z = 2;
|
34 |
|
35 | w.foo();
|
36 | w = 2;
|
37 |
|
38 | RAWR=444;
|
39 | RAWR.foo();
|
40 |
|
41 | BLARG=3;
|
42 |
|
43 | foo(function () {
|
44 | var BAR = 3;
|
45 | process.nextTick(function (ZZZZZZZZZZZZ) {
|
46 | console.log('beep boop');
|
47 | var xyz = 4;
|
48 | x += 10;
|
49 | x.zzzzzz;
|
50 | ZZZ=6;
|
51 | });
|
52 | function doom () {
|
53 | }
|
54 | ZZZ.foo();
|
55 |
|
56 | });
|
57 |
|
58 | console.log(xyz);
|
59 | ```
|
60 |
|
61 | output:
|
62 |
|
63 | ```
|
64 | $ node example/detect.js
|
65 | [ { name: 'BLARG', nodes: [ [Object] ] },
|
66 | { name: 'RAWR', nodes: [ [Object], [Object] ] },
|
67 | { name: 'ZZZ', nodes: [ [Object], [Object] ] },
|
68 | { name: 'console', nodes: [ [Object], [Object] ] },
|
69 | { name: 'foo', nodes: [ [Object] ] },
|
70 | { name: 'process', nodes: [ [Object] ] },
|
71 | { name: 'w', nodes: [ [Object], [Object] ] },
|
72 | { name: 'xyz', nodes: [ [Object] ] } ]
|
73 | ```
|
74 |
|
75 | ## Security contact information
|
76 |
|
77 | To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
|
78 |
|
79 | ## License
|
80 |
|
81 | MIT
|