Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Walks a JavaScript AST and collects Identifier nodes
JavaScript
branch: master
Failed to load latest commit information.
.gitignore Version 0.0.1: idents.inspect and idents.all
LICENSE Version 0.0.1: idents.inspect and idents.all
README.md Add badges
idents.js
package.json
test.js

README.md

javascript-idents

xrefs funcs top func library users status

javascript-idents walks a JavaScript AST and collects all Identifier AST nodes. It relies on Marijn Haverbeke's acorn.js for AST walking, and it should be compatible with any SpiderMonkey Parser API-compliant JavaScript AST.

It is intended for use in node.js but can be adapted to work in other JavaScript environments.

Documentation: javascript-idents on Sourcegraph

Example

The following example prints the name of each Identifier AST node to the console.

var acorn = require('acorn'), idents = require('javascript-idents');

var src = 'var c = a.b[d]; function f(w, x, y) { return z; }';
var astNode = acorn.parse(src);
idents.inspect(astNode, function(ident) {
  console.log('Ident:', ident.name);
});

// output:
// Ident: c
// Ident: a
// Ident: b
// Ident: d
// Ident: f
// Ident: w
// Ident: x
// Ident: y
// Ident: z

Running tests

Run npm test.

Contributors

Something went wrong with that request. Please try again.