Skip to content

Repository files navigation

acorn-globals

Detect global variables in JavaScript using acorn

Get supported acorn-globals with the Tidelift Subscription

Build StatusRolling VersionsNPM version

Installation

npm install acorn-globals

Usage

detect.js

varfs=require('fs');vardetect=require('acorn-globals');varsrc=fs.readFileSync(__dirname+'/input.js','utf8');varscope=detect(src);console.dir(scope);

input.js

varx=5;vary=3,z=2;w.foo();w=2;RAWR=444;RAWR.foo();BLARG=3;foo(function(){varBAR=3;process.nextTick(function(ZZZZZZZZZZZZ){console.log('beep boop');varxyz=4;x+=10;x.zzzzzz;ZZZ=6;});functiondoom(){}ZZZ.foo();});console.log(xyz);

output:

$ node example/detect.js
[ { name: 'BLARG', nodes: [ [Object] ] },
{ name: 'RAWR', nodes: [ [Object], [Object] ] },
{ name: 'ZZZ', nodes: [ [Object], [Object] ] },
{ name: 'console', nodes: [ [Object], [Object] ] },
{ name: 'foo', nodes: [ [Object] ] },
{ name: 'process', nodes: [ [Object] ] },
{ name: 'w', nodes: [ [Object], [Object] ] },
{ name: 'xyz', nodes: [ [Object] ] } ]

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

License

MIT

About

Use acorn to detect global variables in JavaScript

Resources

Stars

47 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages