Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lexical-scope

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lexical-scope

detect global and local lexical identifiers from javascript source code

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
193K
increased by97.14%
Maintainers
1
Weekly downloads
 
Created
Source

lexical-scope

detect global and local lexical identifiers from javascript source code

browser support

build status

example

var detect = require('lexical-scope');
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/src.js');

var scope = detect(src);
console.dir(scope);

input:

var x = 5;
var y = 3, z = 2;

w.foo();
w = 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
{ locals: 
   { '': [ 'x', 'y', 'z' ],
     'body.7.arguments.0': [ 'BAR', 'doom' ],
     'body.7.arguments.0.body.1.arguments.0': [ 'xyz' ],
     'body.7.arguments.0.body.2': [] },
  globals: 
   { implicit: [ 'w', 'foo', 'process', 'console', 'xyz' ],
     exported: [ 'w', 'RAWR', 'BLARG', 'ZZZ' ] } }

live demo

If you are using a modern browser, you can go to http://lexical-scope.forbeslindesay.co.uk/ for a live demo.

methods

var detect = require('lexical-scope')

var scope = detect(src)

Return a scope structure from a javascript source string src.

scope.locals maps scope name keys to an array of local variable names declared with var. The key name '' refers to the top-level scope.

scope.globals.implicit contains the global variable names that are expected to already exist in the environment by the script.

scope.globals.explicit contains the global variable names that are exported by the script.

install

With npm do:

npm install lexical-scope

license

MIT

Keywords

FAQs

Package last updated on 05 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc