package
Extract AST nodes from a js string that define scope
npm install scopenodesGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 3 packages.
343.2 kB
Includes dependencies.
Find the AST nodes from a string of JavaScript that define scope. E.g. The outer Program scope and functions.
var scopenodes = require("scopenodes")
var fs = require("fs")
var filename = process.argv[2] || "./test/lib/nested.js"
var content = fs.readFileSync(filename).toString()
var out = scopenodes(content)
console.log(out)
/*
[ { type: 'Program',
body: [ [Object], [Object] ],
range: [ 0, 116 ],
loc: { start: [Object], end: [Object] },
path: [],
parent: null },
{ type: 'BlockStatement',
body: [ [Object] ],
range: [ 21, 69 ],
loc: { start: [Object], end: [Object] },
path: [ [Object] ],
parent:
{ type: 'FunctionDeclaration',
id: [Object],
params: [Object],
...
*/
scopenodes(jsString)Will return a list of nodes from an AST (Esprima) that define scoped blocks of the provided JavaScript string.
It will add some properties to each node:
Naming generally works like the following, and may change as we go:
new argument, call it "fnName() fn argument" where fnName is the function called.foo.on('exit', ...)) call it foo.on 'exit' listenerNaming nests with scope, so if you have code such as this:
function foo() {
function bar() {
// ...
}
}The two functions would be named foo and foo>bar denoting that this bar is the one defind in the scope of foo.
MIT