Have ideas to improve npm?Join in the discussion! »

    acorn-globals

    6.0.0 • Public • Published

    acorn-globals

    Detect global variables in JavaScript using acorn

    Get supported acorn-globals with the Tidelift Subscription

    Build Status Dependency Status NPM version

    Installation

    npm install acorn-globals
    

    Usage

    detect.js

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

    input.js

    var x = 5;
    var y = 3, z = 2;
     
    w.foo();
    = 2;
     
    RAWR=444;
    RAWR.foo();
     
    BLARG=3;
     
    foo(function () {
        var BAR = 3;
        process.nextTick(function (ZZZZZZZZZZZZ) {
            console.log('beep boop');
            var xyz = 4;
            x += 10;
            x.zzzzzz;
            ZZZ=6;
        });
        function doom () {
        }
        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

    Install

    npm i acorn-globals

    DownloadsWeekly Downloads

    13,837,773

    Version

    6.0.0

    License

    MIT

    Unpacked Size

    9.1 kB

    Total Files

    5

    Last publish

    Collaborators

    • avatar
    • avatar