{"name":"periscopic","description":"periscopic","version":"3.1.0","repository":{"type":"git","url":"git+https://github.com/Rich-Harris/periscopic.git"},"main":"src/index.js","module":"src/index.js","type":"module","exports":{"types":"./types/index.js","import":"./src/index.js"},"types":"types/index.d.ts","devDependencies":{"acorn":"^8.0.0","typescript":"^4.9.0","uvu":"^0.5.1"},"scripts":{"test":"uvu test","prepublishOnly":"npm test && tsc"},"license":"MIT","dependencies":{"@types/estree":"^1.0.0","estree-walker":"^3.0.0","is-reference":"^3.0.0"},"gitHead":"088d446fb269993ece75ba24e9ac3e9ff07c9e6f","bugs":{"url":"https://github.com/Rich-Harris/periscopic/issues"},"homepage":"https://github.com/Rich-Harris/periscopic#readme","_id":"periscopic@3.1.0","_nodeVersion":"16.17.0","_npmVersion":"8.15.0","dist":{"integrity":"sha512-vKiQ8RRtkl9P+r/+oefh25C3fhybptkHKCZSPlcXiJux2tJF55GnEj3BVn4A5gKfq9NWWXXrxkHBwVPUfH0opw==","shasum":"7e9037bf51c5855bd33b48928828db4afa79d97a","tarball":"http://registry-npm.ywwl.com/periscopic/download/periscopic-3.1.0.tgz","fileCount":5,"unpackedSize":11219,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEhf8w5nUlenrR7FdLb0OXFsiEbL8V2OdZoJCe1DXCCTAiEA6F87+WOiY2zG75SIlWAGnyt0Wr8DwAun619ahZLI+xA="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj0uWIACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqBvg/9HndcfDhrUgA4kO+VszJ6M77aWKbBXQtJ3pxgITP7IH2Ua2d5\r\n+cEgkWFAI17zu+HeabYykiHll/coEeUXaZe5Ixq6iKogt6s9QAC3chvBTy/g\r\npXYZBg/QogtYPWdjEPBj+LxJpbqsnz9rrQ65RrDjKrS6CJfjMfV0DK45TSDU\r\nCR/0V+oPVURZYtiKU9WDEU8TrOR8CSiLYKvmfQl5HFva9OhGS0rnUAW4Q4iw\r\n1XZg1CvFf/jOTsI6JuT9FGTgOjTzPt9WsvzTHQ0CYbU5Y3cC8eijpmuJ+loa\r\nYUuFWxn6lCDdU66Y8oH3NHBjrqdrTtlr6m9t38MPe440Mt5rPY+oG65h/UfP\r\neAKB1qyobsWovfnJc3C94CVaCXIpZAPydRNp0AKtdEJP4bG801mio2plXm0T\r\nKkGCBPirVvdws0ClHNADAL870fZs4+EY+RhcNHfMkhFrkwg/TzCUavfcZRtY\r\naSL3RZ7wmRrnm9E56nAASZQx/WVevPIpV6GTpNu/9tsT8+gx9cUW+1eGJCEA\r\nBg+zEQ6ZDcc9vOmzFMkjrhqJDxf221COJlJOdh3CTMr/eYquJr6jK4kratbF\r\n/0zqLo9zs+p3mI/vLb9FLtF3C3fkKcUHl/SPbB3UEbfAjE3gpdO7z6UA3rSr\r\noZ4vTubMX26ZAe15C2s5V6J3fs1SLHj55jg=\r\n=I3AA\r\n-----END PGP SIGNATURE-----\r\n","size":3595,"noattachment":false,"key":"/periscopic/-/periscopic-3.1.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.1.0_1674765703987_0.8300928900086799"},"_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":1674765704167,"_cnpm_publish_time":1674765704167,"dist-tags":{"latest":"4.0.3"}}