Skip to content
This repository was archived by the owner on May 29, 2018. It is now read-only.

sourcegraph/javascript-idents

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

javascript-idents

javascript-idents walks a JS abstract syntax tree (AST) and returns all identifiers the code uses.

It relies on Marijn Haverbeke's Acorn for AST walking, and should work with any ESTree-compliant JavaScript AST.

npm version build status dependency status dev dependency status BSD-licensed

Example

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

const acorn = require('acorn/dist/acorn');
const idents = require('javascript-idents');

acorn.parse(`
    const c = a.b[d];
    function f (w, x, y) {
        return z;
    }
`);

idents.inspect(ast, (identifier) => {
  console.log('identifier found:', identifier.name);
});
identifier found: a
identifier found: d
identifier found: c
identifier found: z
identifier found: f
identifier found: w
identifier found: x
identifier found: y

Running tests

Run npm test.

Contributors

About

Walks a JavaScript AST and collects Identifier nodes

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •