{"name":"periscopic","description":"periscopic","version":"3.0.0","repository":{"type":"git","url":"git+https://github.com/Rich-Harris/periscopic.git"},"module":"src/index.js","type":"module","exports":{"import":"./src/index.js"},"types":"types/index.d.ts","devDependencies":{"@types/estree":"0.0.39","acorn":"^7.0.0","typescript":"^4.1.2","uvu":"^0.5.1"},"scripts":{"test":"uvu test","prepublishOnly":"npm test && tsc"},"license":"MIT","dependencies":{"estree-walker":"^2.0.2","is-reference":"^1.1.4"},"gitHead":"ed79d47c7d0598d9e77cfa52399f35f2c3774edd","bugs":{"url":"https://github.com/Rich-Harris/periscopic/issues"},"homepage":"https://github.com/Rich-Harris/periscopic#readme","_id":"periscopic@3.0.0","_nodeVersion":"12.18.3","_npmVersion":"6.14.6","dist":{"integrity":"sha512-m/MBWIgwELB00OdTvM+Ei5saKHNKmyFWy0iW2MpbADmIdK/sL+kir3Yvb+Z2vzYeItZVtemA0bgAg5lZXoJmaA==","shasum":"474aaec74bec1eed136e2516c935e736a5efc6dd","tarball":"http://registry-npm.ywwl.com/periscopic/download/periscopic-3.0.0.tgz","fileCount":6,"unpackedSize":15078,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgFH4kCRA9TVsSAnZWagAAr+wP/iJHmZPY5NTgu+Lj4JbS\nkA4ZXCs4JaQTHOemYiiurpPRm9B2rOLS4dN6oo8PjPMWO4YonmIEr437sADL\nm1vUqj5ZOp/MJ2TPPcAD1tsEHAUFsq/DY9PtGOhye0a+34EsCkdRTRryjlBr\nkQo2VBYnON//jZuqz3m2hDQ70ZMz8+HaFunpKRWjW3a5xMEdcyV5JwgvJhnl\naby6ytaRGtLgzhQdIOOjfjQn1fihedbXHm+oNYNgRHrbgeFzftFm+XqCmLnB\nKRY07ki6wBnfwuz7X4RCIEqTGHEC3+hlNDvh2JzUDLBREJjsoKTCH5wN1UAS\nTgacAWoioSp9RlEHu1Es6Lc0oI275DyaU+SZ4CdtODLjp44CGOMce4ouQCt4\n1dgbVQouxHkkLmALdyEhdTNx1CDttYy2cEVQWqJ2M6JPhHIe+xFH7JJJcO0Y\n/AbjcMLDOUqtSMNdOTGb3X4tJpP9EQ1PmigxKv8B9zvbxpk9BA+v75oeyxf/\nbx0vPmQLibOCpnayUVC1N2LFNyqDK8j8ltSbi+s221vmBVEuUcrUy5UoLw8h\n+6XK0U7qgaq2qkRCkRQKGsPFPZASQraPjJNWlJ0NVqb2/Y+AnChPlC/cJoDg\nkgELdlIYKzm3b8dEu+qWc/lae9xQm9P2sDlrUbK3ViJXt8CSHwcUBudfqM1i\n1K++\r\n=7Lck\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCn/wtyhAl9x8lKMpVJ2PH/tKFgAO3hgCH4fzymw6fBWgIhAJR1zIr5U59NflT4R4QfWL3wID4v/tL7cGgVxEXqJY3D"}],"size":4458,"noattachment":false,"key":"/periscopic/-/periscopic-3.0.0.tgz"},"_npmUser":{"name":"rich_harris","email":"richard.a.harris@gmail.com"},"directories":{},"maintainers":[{"name":"rich_harris","email":"richard.a.harris@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/periscopic_3.0.0_1611955748095_0.02564174058440627"},"_hasShrinkwrap":false,"readme":"# periscopic\n\nUtility for analyzing scopes belonging to an ESTree-compliant AST.\n\n\n## API\n\n```js\nimport { analyze } from 'periscopic';\n\nconst ast = acorn.parse(`\nconst a = b;\nconsole.log(a);\n`);\n\nconst { map, globals, scope } = analyze(ast);\n```\n\n* `map` is a `WeakMap<Node, Scope>`, where the keys are the nodes of your AST that create a scope\n* `globals` is a `Map<string, Node>` of all the identifiers that are referenced without being declared anywhere in the program (in this case, `b` and `console`)\n* `scope` is the top-level `Scope` belonging to the program\n\n\n### Scope\n\nEach `Scope` instance has the following properties:\n\n* `scope.block` — true if the scope is created by a block statement (i.e. `let`, `const` and `class` are contained to it), false otherwise\n* `scope.parent` — the parent scope object\n* `scope.declarations` — a `Map<string, Node>` of all the variables declared in this scope, the node value referes to the declaration statement\n* `scope.initialised_declarations` — a `Set<string>` of all the variables declared and initialised in this scope\n* `scope.references` — a `Set<string>` of all the names referenced in this scope (or child scopes)\n\nIt also has two methods:\n\n* `scope.has(name)` — returns `true` if `name` is declared in this scope or an ancestor scope\n* `scope.find_owner(name)` — returns the scope object in which `name` is declared (or `null` if it is not declared)\n\n\n### `extract_identifiers` and `extract_names`\n\nThis package also exposes utilities for extracting the identifiers contained in a declaration or a function parameter:\n\n```js\nimport { extract_identifiers, extract_names } from 'periscopic';\n\nconst ast = acorn.parse(`\nconst { a, b: [c, d] = e } = opts;\n`);\n\nconst lhs = ast.body[0].declarations[0].id;\n\nextract_identifiers(lhs);\n/*\n[\n\t{ type: 'Identifier', name: 'a', start: 9, end: 10 },\n\t{ type: 'Identifier', name: 'c', start: 16, end: 17 },\n\t{ type: 'Identifier', name: 'd', start: 19, end: 20 }\n]\n*/\n\nextract_names(lhs);\n/*\n['a', 'c', 'd']\n*/\n```\n\n\n## License\n\n[MIT](LICENSE)","publish_time":1611955748266,"_cnpm_publish_time":1611955748266,"dist-tags":{"latest":"4.0.3"}}