{"name":"periscopic","description":"periscopic","version":"2.0.1","repository":{"type":"git","url":"git+https://github.com/Rich-Harris/periscopic.git"},"main":"dist/periscopic.js","module":"dist/periscopic.mjs","types":"types/index.d.ts","devDependencies":{"@types/estree":"0.0.39","@types/mocha":"^5.2.5","@types/node":"^10.9.4","acorn":"^7.0.0","estree-walker":"^0.8.1","mocha":"^5.2.0","rollup":"^0.65.2","rollup-plugin-sucrase":"^2.1.0","sander":"^0.6.0","sucrase":"^3.9.5","tiny-glob":"^0.2.6","typescript":"^3.6.2"},"scripts":{"build-declarations":"tsc -d && node scripts/move-type-declarations.js","build":"npm run build-declarations && rollup -c","dev":"rollup -cw","test":"mocha --opts mocha.opts","prepublishOnly":"npm test && npm run build"},"license":"MIT","dependencies":{"is-reference":"^1.1.4"},"gitHead":"43017f235eb39e9582228c26f9811ed26000a1de","bugs":{"url":"https://github.com/Rich-Harris/periscopic/issues"},"homepage":"https://github.com/Rich-Harris/periscopic#readme","_id":"periscopic@2.0.1","_nodeVersion":"12.13.0","_npmVersion":"6.12.0","dist":{"integrity":"sha512-twJ8e4RatllMAcbmBqKj8cvZ94HtqSzbb8hJoGj4iSCcCHXxKb06HRxOq4heyq2x/6mKynJDvTTreHCz+m6lJw==","shasum":"c6578152a83e76c5e09b11cd2fc6a97c1e8806cc","tarball":"http://registry-npm.ywwl.com/periscopic/download/periscopic-2.0.1.tgz","fileCount":7,"unpackedSize":14389,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdyeA7CRA9TVsSAnZWagAAa5gP/0M+BORxrvxp2tgmUENr\nRfj+XanibaHwNQlyOoj+hrynWE/EJWB359vT3JlIQL4NS5sC/FlpX2P/Mj/c\nEuxGtpB6oZH0CFibD2cfiQgaOQTv4F7q4dbpvRA2BxZvIcCJkcZ6VbhgD/M4\nehlIGfnii/KNqU8mJwdfNJcfDfelCsaxGRXgfg3BCxTRQEajaPNTRelHwV+1\nIBI3QU4WKymi6aSq4Orl1GI18CEB/k4RvtVHWpw+vSU2Tzido/S+VQC9PJMk\n8gJMOd7+iuXZODv06OUtqonGDlBHUP+mI3BPObN2MSB36KT5gwZDNpRHlBBy\nr8Ty8AVLYVQnPfP6EdNeH9zlMXJQAeyESvj9le5OqFnUORVOzbfYmwhiR9Hc\nIWi9M1i2mYlHwMVJDeKQJwbE74c/U3sc9GZC6wZpknEpuqcZfyl6SX6TMF5K\nSZLNjSB8q6z9bnJ92MVsYZ/typ4PM4uf70DaP9E1qoAZmQx3hl98Go1wAGzx\naWNmLd7QDEbfJqYQ+J2bWG1/NfHuburh7M2Uz6mbvfRKmy6Hamzok6KakiZw\nO/iPatwR21jNvqsU/DMwkqybJGLWSbvvsRRIzcMNFbxaML/owBnratopE/9Z\nDcIbFAwLtPBhB9oKe6FLhFQ9f/tr5IJnAFxJpu2tjCCcfsr6P4ik/kCCB4bg\nVlks\r\n=1Zr/\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD6llpU0Luu2pQgul65ikaRTANHpqRYh2IHY9h0mepO1QIhAKET1PLoePVbTSNEJ4i1L3ae3I6EkMKwEqoCwD2L5Zey"}],"size":3942,"noattachment":false,"key":"/periscopic/-/periscopic-2.0.1.tgz"},"maintainers":[{"name":"rich_harris","email":"richard.a.harris@gmail.com"}],"_npmUser":{"name":"rich_harris","email":"richard.a.harris@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/periscopic_2.0.1_1573511227125_0.64510566156433"},"_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":1573511227353,"_cnpm_publish_time":1573511227353,"dist-tags":{"latest":"4.0.3"}}