{"name":"scope-analyzer","description":"simple scope analysis for javascript ASTs","version":"2.0.4","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":"^5.5.3","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":"dd1615eb31154d06adb72933427423494e871f5f","_id":"scope-analyzer@2.0.4","_npmVersion":"6.0.1","_nodeVersion":"10.1.0","_npmUser":{"name":"goto-bus-stop","email":"rene@kooi.me"},"dist":{"integrity":"sha512-oZkemAjbde97D2Joa7t8e/DJ1d0ulC9vJrAvd8jiCpX6UGWj2qcU+9ScwHZgxm1nQidmpMd36EeVYaodANFEXA==","shasum":"0d2a93961a751260514c6554f9a0e62ce4375703","tarball":"http://registry-npm.ywwl.com/scope-analyzer/download/scope-analyzer-2.0.4.tgz","fileCount":12,"unpackedSize":25619,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbA+zbCRA9TVsSAnZWagAAiicP/0K7efx+vv2FLs/D70OL\nSc0QNf/z3sqy/yIU7fvDU2lVxSlAYtXdvqLtZP2HKbxx8DPdi0abOZ4f5zqf\nkrrB1SL0J+ee4xLCWkrBjGy2WsJSbU4x8NqpuFpDp+q1SYcZt2ehz6dLaRof\nnysWmOXgAoc8yLvQgJNfHh4xOZQzjDhbcjcilteSQU6gVCgZOEb/PCobVd2F\nClT3p6YH2dujI9k9Rk3X0DB9q97qLKX8QmMI7B/OPaJHwLSk4LDceR8AUIyV\nUlFLeIElmPUy+fV6zrG1UweIEt1MNog4F79J3qlv6cMrla0C/zUqYX1Z8pgX\n2R5b7UpYsoZA5Mm62mC6Anl8JGu4xw4Cet3Si7fdH5BdeGRgc5RZResS0VMr\nl5Jim+X8/t9wBTTzcoV8PMDbOXVbRHmmgIp+6e48Vkyqrgxl6F5oRFfhqkul\n5zOCADgLcPIoY4dM9lj92ljw1OTlUsqqsHjj4skC4KFzmVzGfrQCp7MD2xQ+\nZfvdfh5t7cU2ObJCVADsPM10pFh9Q2BWiUfkcVVaW0+DVV0zO6Dgx4wxvfIf\n8KijeN7mV8fgkLpNNzL8QbIHmGe50fWM3AMp4WCs1k2zGxJwx2YWkeYGLYmR\nyNwVSc2ky0+d8x5LB1Lv5Kwojrt+7RaQ98v1Ke83D3uBbyfpdfLpOEMIWT/9\nnuJv\r\n=rw7H\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDitgDrE6uUEw366FVb+4GWn1lYFSJeUCV3lb3PgI/EjAiAe0i0qt3YtjwIawMtWkZS/ZhTnaev8/4hmFtE1w0KPAA=="}],"size":7475,"noattachment":false,"key":"/scope-analyzer/-/scope-analyzer-2.0.4.tgz"},"maintainers":[{"name":"goto-bus-stop","email":"rene@kooi.me"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/scope-analyzer_2.0.4_1526983898602_0.25357425567263325"},"_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":1526983898722,"_cnpm_publish_time":1526983898722,"dist-tags":{"latest":"2.1.2"}}