{"name":"scope-analyzer","description":"simple scope analysis for javascript ASTs","version":"2.0.2","author":{"name":"Renée Kooi","email":"renee@kooi.me"},"bugs":{"url":"https://github.com/goto-bus-stop/scope-analyzer/issues"},"dependencies":{"acorn":"^5.5.3","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":{"babel-core":"^6.26.0","babel-plugin-transform-es2015-template-literals":"^6.22.0","d3":"^4.13.0","has-template-literals":"^1.0.0","nanobench":"^2.1.0","standard":"^10.0.3","tape":"^4.8.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":"c7313ab006189fcc21c75ee96dfa5dfdd4a1ebb9","_id":"scope-analyzer@2.0.2","_npmVersion":"5.8.0","_nodeVersion":"9.11.1","_npmUser":{"name":"goto-bus-stop","email":"rene@kooi.me"},"dist":{"integrity":"sha512-972Ma6HzvRmz44TZn1b2Nqzcr6GU7f9Mi0S3OhusFJb+kbYXOIsqIdGY4rINFiTp0C3S4ak4xtyoaGvw4UcGbg==","shasum":"8b7b2c05a792193742262fa261da8d393b09af8f","tarball":"http://registry-npm.ywwl.com/scope-analyzer/download/scope-analyzer-2.0.2.tgz","fileCount":13,"unpackedSize":24504,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa2dSuCRA9TVsSAnZWagAAeRUP/jg1b1b+dc8Ui8qKP+0d\nTwnWt6eUMvUDKxe3RHLF/auVWoBkpPtZcufzUmyG41sKxd4yvP1oPlHpS93Y\njYYVeue7rFZ0CAl3w5LygryCoXzqnioxehROepwttuG3EzLfZdp1JgNuKSpK\nRKrCB5EqM7uHflKz/MqW80Tyk+NSQDAxh18tX89fmZnC9YeU2bbVNUVvHFNs\n0yjkCfwKmRNoIBNoegF2UQaV2fHsq63ztCKChpioZ2ZS39NZtzlCe+xyWe2s\n0tGsgapYzZGlyRbI+ezzTEQkocDXDMuOu8gR/KHzZ6s0KQusY7rML7wDaR1K\nNnuB3GDWMdbB4AMmSCmzq+emJU1Zr5PvcFaPPuboQou7MJaCc/f9DEn6H1H5\ncVcqF4OJT/U9l4E+hZ3X9hPpks1hwx5KXYsqpbhvRQ9Bf0bOUSzhTyB+e9HU\n1zCjnuh17khz3/LRgZKBlv1oNRLQIABjWEpEsq6rAjb7m99CXLbcBt8S1UPE\nYf9fCJ8dDQJ97pLtdIRIRGhvTiSWMr6E9uci8paGvqx561yMfNknvX9cDOpe\n2VyjlXgkJfhITQ0kLH512S9C6NW2S9OjJ11fF0nKPZ80VjQbfF6ZIbdrEesy\nrGrWjpe3lADC34pQC5v2N28corYWnE8N69VCjSDUNGfyfe8tc59kE/EaSie2\n+2YJ\r\n=W/KV\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHvGX65ppQg6poef4f1XSVffO2fzRZzy2V6xwIV39RvpAiEAoB8LjH8IodvYE97BxzmKS9VD1dLhObC5sDzGkxrL2CU="}],"size":7289,"noattachment":false,"key":"/scope-analyzer/-/scope-analyzer-2.0.2.tgz"},"maintainers":[{"name":"goto-bus-stop","email":"rene@kooi.me"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/scope-analyzer_2.0.2_1524225196874_0.1396570550144247"},"_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":1524225196962,"_cnpm_publish_time":1524225196962,"dist-tags":{"latest":"2.1.2"}}