npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

episcope

v0.0.1

Published

ECMAScript scope analyzer

Downloads

4

Readme

episcope

Build Status

ECMAScript scope analyzer. Library provides set of functions that perform analyzes on the nodes of the AST in the de facto syntax tree format. All the API function take AST nodes denoting a lexical scope and performed static analyzes at the given scope level.

API

references

Returns array of Identifier nodes for all the free references with in the given scope that are not part of declarations or members access identifiers.

var esprima = require("esprima")
var references = require("episcope/references")
var ast = esprima.parse("console.log('>>>', error)")
references(ast)
// =>  [{ type: "Identifier", name: "console" }, { type: "Identifier", name: "error" }]

bindings

Returns array of Identifier nodes for all the declared bindings available to the given scope, including named arguments if given scope is a function form.

var esprima = require("esprima")
var bindings = require("episcope/bindings")
var ast = esprima.parse("function foo(a, b) { var c = a + b; return c * c }")
ast.body[0].id
// => { type: 'Identifier', name: 'foo' }
bindings(ast.body[0])
// =>  [ { type: 'Identifier', name: 'a' },
//       { type: 'Identifier', name: 'b' },
//       { type: 'Identifier', name: 'c' } ]

scopes

Returns array of nested scope forms for the given one. Note the nested scopes of those nested scopes are not included, but this function can be used to do the walk through them too.

var esprima = require("esprima")
var scopes = require("episcope/scopes")
var ast = esprima.parse(String(function root() {
  function nested() { /***/ }
  try { /***/ } catch(error) { /***/ }
}))
ast.body[0].id
// => { type: 'Identifier', name: 'foo' }

scopes(ast.body[0])
// => [
//  { 
//    type: 'FunctionDeclaration',
//    id: { type: 'Identifier', name: 'nested' },
//    // ...
//  },
//  {
//    type: 'CatchClause',
//    param: { type: 'Identifier', name: 'error' },
//    body: { type: 'BlockStatement', body: [] }
//  }
//]

properties

Returns array of Identifier nodes for all the property references within the given scope. Mainly used internally to filter out references to free variables.

var esprima = require("esprima")
var properties = require("episcope/properties")
var ast = esprima.parse("document.body.appendChild(node)")

properties(ast)
// => [ { type: 'Identifier', name: 'appendChild' },
//      { type: 'Identifier', name: 'body' } ]

Install

npm install episcope