{"name":"scope-analyzer","description":"simple scope analysis for javascript ASTs","version":"2.1.0","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":"^14.3.1","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":"d6fdc4e5c67aaf56666f23f3cb2bfb5cb9dad738","_id":"scope-analyzer@2.1.0","_nodeVersion":"13.9.0","_npmVersion":"6.14.2","dist":{"integrity":"sha512-qSb5aiwHsaH2Nc9GqpFn1u9YZMLoZibuSXX9vSAPzrvBAcCpLENhB/BPK0nAs9n3M9K/bnnDUULaHD9TZaCO0A==","shasum":"4fb281ec3f3f349fa6cb42cbcbb7e57bd0a0ee5a","tarball":"http://registry-npm.ywwl.com/scope-analyzer/download/scope-analyzer-2.1.0.tgz","fileCount":12,"unpackedSize":29581,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeYh/ICRA9TVsSAnZWagAA+twP/2j6rR35bXy5agDQDKmh\nOUaDIJSq+k+fb5I2ITwrTzU7ErWnHZpyVnPw2VMyOHld8LDC2VQADIvtGBOq\nUa78INhktMQnYqifBtTBwY1iCKNtnITYsR8s5gsxa/K/RuC9SDwVhoT/9di3\nj0HxM+xwE5O9gk0fPcDEaAntCc6RKieVbYZz6BSGYGzyFgwljpEFmeauI9Rk\noA83V5QWKNS1O+fTNcz7FLtyk8/TdIlE10HSiiqJigp7qULyVXdRcrL9+d0K\nremAL40RbgKxteyTnJHaJltKb4MSvTdSsJQOgmZBDdqQh2BMyunvVS0TuC6l\nO/0ZW6J49yxX8+K+Uz1fQkC0QUB3hk20CAWmHke9WSTLMlKgghHW1/7h88lD\nctG9oupXvSxnS76PU7kRAROPCJyJ+9znQpgNdgLCudBjH5+40fTfH5d7JkBP\ndzAzE3VAjVfrVvysOdU0FSkpmDSdFOK+UUuVeAvIXJPuLkKUPxxP99NYLoNw\nwviMprCfXewMdJI9h7SvraZpWIa18T7t31yqsX6a7q1eaxgtPHwWWrhtjIox\nVs1257cy9CfxTrkIHazoQ30h3eNsMFeKJvoFazJH5A5oOfnDtD/U97nX6N3z\ngR1Z540aalRXGm64ts55t2PGnea14uQoeMFbDmONy7W3xROK7SUU6K8xLz8P\npkDy\r\n=uYvl\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBs1HyQJ20/A/NeeuircRf0Im4kM5WlHXoGD00Ms3z7jAiAhsTwrpUh1Wn6KHJ8gF4ScXGbVY8ypNcOF2+f18T1q6Q=="}],"size":8293,"noattachment":false,"key":"/scope-analyzer/-/scope-analyzer-2.1.0.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.1.0_1583488968392_0.600560347311492"},"_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":1583488968562,"_cnpm_publish_time":1583488968562,"dist-tags":{"latest":"2.1.2"}}