UNPKG

2.04 kBMarkdownView Raw
1# acorn-globals
2
3Detect 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
17detect.js
18
19```js
20var fs = require('fs');
21var detect = require('acorn-globals');
22
23var src = fs.readFileSync(__dirname + '/input.js', 'utf8');
24
25var scope = detect(src);
26console.dir(scope);
27```
28
29input.js
30
31```js
32var x = 5;
33var y = 3, z = 2;
34
35w.foo();
36w = 2;
37
38RAWR=444;
39RAWR.foo();
40
41BLARG=3;
42
43foo(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
58console.log(xyz);
59```
60
61output:
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
77To 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