node package manager


Walks a JavaScript AST and collects Identifier nodes


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

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) {
// output: 
// Ident: c 
// Ident: a 
// Ident: b 
// Ident: d 
// Ident: f 
// Ident: w 
// Ident: x 
// Ident: y 
// Ident: z 

Running tests

Run npm test.