You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.8 KiB

  1. # acorn-globals
  2. Detect global variables in JavaScript using acorn
  3. [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)
  4. [![Build Status](https://img.shields.io/travis/ForbesLindesay/acorn-globals/master.svg)](https://travis-ci.org/ForbesLindesay/acorn-globals)
  5. [![Dependency Status](https://img.shields.io/david/ForbesLindesay/acorn-globals.svg)](https://david-dm.org/ForbesLindesay/acorn-globals)
  6. [![NPM version](https://img.shields.io/npm/v/acorn-globals.svg)](https://www.npmjs.org/package/acorn-globals)
  7. ## Installation
  8. npm install acorn-globals
  9. ## Usage
  10. detect.js
  11. ```js
  12. var fs = require('fs');
  13. var detect = require('acorn-globals');
  14. var src = fs.readFileSync(__dirname + '/input.js', 'utf8');
  15. var scope = detect(src);
  16. console.dir(scope);
  17. ```
  18. input.js
  19. ```js
  20. var x = 5;
  21. var y = 3, z = 2;
  22. w.foo();
  23. w = 2;
  24. RAWR=444;
  25. RAWR.foo();
  26. BLARG=3;
  27. foo(function () {
  28. var BAR = 3;
  29. process.nextTick(function (ZZZZZZZZZZZZ) {
  30. console.log('beep boop');
  31. var xyz = 4;
  32. x += 10;
  33. x.zzzzzz;
  34. ZZZ=6;
  35. });
  36. function doom () {
  37. }
  38. ZZZ.foo();
  39. });
  40. console.log(xyz);
  41. ```
  42. output:
  43. ```
  44. $ node example/detect.js
  45. [ { name: 'BLARG', nodes: [ [Object] ] },
  46. { name: 'RAWR', nodes: [ [Object], [Object] ] },
  47. { name: 'ZZZ', nodes: [ [Object], [Object] ] },
  48. { name: 'console', nodes: [ [Object], [Object] ] },
  49. { name: 'foo', nodes: [ [Object] ] },
  50. { name: 'process', nodes: [ [Object] ] },
  51. { name: 'w', nodes: [ [Object], [Object] ] },
  52. { name: 'xyz', nodes: [ [Object] ] } ]
  53. ```
  54. ## Security contact information
  55. To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
  56. ## License
  57. MIT