free-variables
Get a list of free variables used in a JS program. A free variable is one which is used but not declared.
Installation
With your favorite package manager:
-
packin:
packin add free-variables
-
component:
component install jkroso/free-variables
-
npm:
npm install free-variables
then in your app:
var free = require('free-variables')
API
free(ast)
Takes any standard JS AST and returns and Array
of String
's
var parse = require('esprima').parse
free(parse('console.log')) // => ['console']
free(parse('console[log]')) // => ['console', 'log']
free(parse('function b(){a}')) // => ['a']
free(parse('var a = 1; a + b')) // => ['b']
free(parse('a; var a')) // => []