{"name":"scope-analyzer","description":"simple scope analysis for javascript ASTs","version":"2.0.6","author":{"name":"Renée Kooi","email":"renee@kooi.me"},"bugs":{"url":"https://github.com/goto-bus-stop/scope-analyzer/issues"},"dependencies":{"array-from":"^2.1.1","es6-map":"^0.1.5","es6-set":"^0.1.5","es6-symbol":"^3.1.1","estree-is-function":"^1.0.0","get-assigned-identifiers":"^1.1.0"},"devDependencies":{"acorn":"^6.2.0","babel-core":"^6.26.3","babel-plugin-transform-es2015-template-literals":"^6.22.0","d3":"^4.13.0","has-template-literals":"^1.0.0","nanobench":"^2.1.1","standard":"^13.0.0","tape":"^4.11.0","three":"^0.89.0"},"homepage":"https://github.com/goto-bus-stop/scope-analyzer","keywords":["analysis","ast","javascript","nodes","refactor","rename","scope"],"license":"Apache-2.0","main":"index.js","repository":{"type":"git","url":"git+https://github.com/goto-bus-stop/scope-analyzer.git"},"scripts":{"bench":"nanobench bench/*.js","test":"standard && tape -r ./test/_init.js test/index.js"},"gitHead":"6c45061205894461fd1e15d77ee6dc9d91522df6","_id":"scope-analyzer@2.0.6","_nodeVersion":"13.9.0","_npmVersion":"6.14.2","dist":{"integrity":"sha512-H6fei6NlOVJqH5VLPSCpJDWpzVp2iFYckjjZ3fdiHFbtCQUwIVKPLxhPF6LeopWKMstEG94RJPK8MebLZHw7nQ==","shasum":"c4c966833668353dde0bf6f27654b6b9097a12ff","tarball":"http://registry-npm.ywwl.com/scope-analyzer/download/scope-analyzer-2.0.6.tgz","fileCount":12,"unpackedSize":28401,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeYMXXCRA9TVsSAnZWagAAbDgQAIBMl2TDsFJMflBypZLA\nZDRiccbnnYwtAYpnh4NS6QUzm47yGGpvfsCvJBW7RWvoJweZt+pqmGJk39u6\nldzS5K50+0ctTpLt+Fb46pqnCUcxyyrwQXLfwE1MnBF255ZAHGzgQ6xpYBsX\n072i4uK0kZV4ZmrZ+9RY0UaSsxtwADZprB1nyJ4njXFga8qMMbOzpa1DIKam\nTin1Z9+WXlY26ueA63Pp7+oUa0YPDPjSwlO2zwN0zTx3iwqVgmo8VaRTETA/\nCfgisJFKMk1TA67eHSF3cZRpC9LmdwZiZ3INsq7Bg9DH3Q+ljHlofs3MTzDA\njuDhDgZTA42Gxy6oUxYh1klGnxSUxbDDdxpp0ZWI5uTXxXgNFGa2KJ7b9cGR\nmAYWDLIHX268LUxqzAMQaAfmgcmOM7gcV5pqaPctUCHrEIkBtC4gh9G3pX98\nKqQdR1vDWxz/FOSqsgz5Vun4VYnhKaMbhbjceu5SK59tGSqBtYVgslI6YS5k\nyjo9cxjJJBydNYzzC+s+1xUPF9wCxD6uQ9AnWLex+nS22JmB8bVC4zp0qL6o\nmKMcr7Ug4HYGkn6cBv7Ma4cS8ZG9F1p7JtBIY3iOkB0pvYACpvbdmraTgIak\n86XAKvJRR/qyy6NbAnlzGWZFgQfbQPjwWL5ufvQSjPbN9e3oJYpDwPWTLCWA\nZI1V\r\n=qFsW\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD3OYqDXxnXL1h+KwOUTEIPy32KBfbpXW5rYNuLbLqCugIhAN8PB6oFtm2uR9GfKZ434jDwAIzSYy4iYQW8KyYtCADX"}],"size":8070,"noattachment":false,"key":"/scope-analyzer/-/scope-analyzer-2.0.6.tgz"},"maintainers":[{"name":"goto-bus-stop","email":"rene@kooi.me"}],"_npmUser":{"name":"goto-bus-stop","email":"renee@kooi.me"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/scope-analyzer_2.0.6_1583400406796_0.6703941436889751"},"_hasShrinkwrap":false,"readme":"# scope-analyzer\n\nsimple scope analysis for javascript ASTs. tracks scopes and collects references to variables.\n\nCaveats and/or todos:\n\n - May be missing edge cases.\n - Things like `label:`s are not considered at all, but ideally in the future they will!\n\n[![stability][stability-image]][stability-url]\n[![npm][npm-image]][npm-url]\n[![travis][travis-image]][travis-url]\n[![standard][standard-image]][standard-url]\n\n[stability-image]: https://img.shields.io/badge/stability-experimental-orange.svg?style=flat-square\n[stability-url]: https://nodejs.org/api/documentation.html#documentation_stability_index\n[npm-image]: https://img.shields.io/npm/v/scope-analyzer.svg?style=flat-square\n[npm-url]: https://www.npmjs.com/package/scope-analyzer\n[travis-image]: https://img.shields.io/travis/goto-bus-stop/scope-analyzer.svg?style=flat-square\n[travis-url]: https://travis-ci.org/goto-bus-stop/scope-analyzer\n[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square\n[standard-url]: http://npm.im/standard\n\n## Install\n\n```\nnpm install scope-analyzer\n```\n\n## Usage\n\nNote: AST nodes passed to `scope-analyzer` functions are expected to reference the parent node on a `node.parent` property.\nNodes from [falafel](https://github.com/substack/node-falafel) or [transform-ast](https://github.com/goto-bus-stop/transform-ast) have a `.parent` property, but others may not. You can use [estree-assign-parent](https://github.com/goto-bus-stop/estree-assign-parent) to quickly assign a parent property to all nodes in an AST.\n\n```js\nvar scan = require('scope-analyzer')\n\nvar ast = parse('...')\n// Initialize node module variables\nscan.createScope(ast, ['module', 'exports', '__dirname', '__filename'])\nscan.crawl(ast)\n\nvar binding = scan.getBinding(ast, 'exports')\nbinding.getReferences().forEach(function (reference) {\n  // Assume for the sake of the example that all references to `exports` are assignments like\n  // `exports.xyz = abc`\n  console.log('found export:', reference.parent.property.name)\n})\n```\n\n## API\n\n### `crawl(ast)`\n\nWalk the ast and analyze all scopes. This will immediately allow you to use the `get*` methods on any node in the tree.\n\n### `clear(ast)`\n\nClear scope information in all nodes of the AST.\n\n### `visitScope(node)`\n\nVisit a node to check if it initialises any scopes.\nFor example, a function declaration will initialise a new scope to hold bindings for its parameters.\nUse this if you are already walking the AST manually, and if you don't need the scope information during this walk.\n\n### `visitBinding(node)`\n\nVisit a node to check if it is a reference to an existing binding.\nIf it is, the reference is added to the parent scope.\nUse this if you are already walking the AST manually.\n\n### `createScope(node, bindings)`\n\nInitialise a new scope at the given node. `bindings` is an array of variable names.\nThis can be useful to make the scope analyzer aware of preexisting global variables.\nIn that case, call `createScope` on the root node with the names of globals:\n\n```js\nvar ast = parse('xyz')\nscopeAnalyzer.createScope(ast, ['HTMLElement', 'Notification', ...])\n```\n\n### `deleteScope(node)`\n\nDelete the scope initialised by node.\n\n### `scope(node)`\n\nGet the [Scope](#scope) initialised by the given node.\n\n### `getBinding(node)`\n\nGet the [Binding](#binding) referenced by the `Identifier` `node`.\n\n### Scope\n\n#### `scope.has(name)`\n\nCheck if this scope defines `name`.\n\n#### `scope.getBinding(name)`\n\nGet the [Binding](#binding) named `name` that is declared by this scope.\n\n#### `scope.getReferences(name)`\n\nGet a list of all nodes referencing the `name` binding that is declared by this scope.\n\n#### `scope.getUndeclaredNames()`\n\nGet a list of all names that were used in this scope, but not defined anywhere in the AST.\n\n#### `scope.forEach(cb(binding, name))`\n\nLoop over all bindings declared by this scope.\n\n#### `scope.forEachAvailable(cb(binding, name))`\n\nLoop over all bindings available to this scope, declared in this scope or any parent scope.\n\n### Binding\n\n#### `binding.definition`\n\nThe node that defined this binding. If this binding was not declared in the AST, `binding.definition` will be undefined.\n\n#### `binding.getReferences()`\n\nReturn an array of nodes that reference this binding.\n\n#### `binding.isReferenced()`\n\nCheck if the binding is referenced, i.e., if there are any identifier Nodes (other than `binding.definition`) referencing this binding.\n\n#### `binding.remove(node)`\n\nRemove a reference to this binding. Use this when you are replacing the node referencing the binding with something else.\n\n## License\n\n[Apache-2.0](LICENSE.md)\n","publish_time":1583400406913,"_cnpm_publish_time":1583400406913,"dist-tags":{"latest":"2.1.2"}}