{"name":"periscopic","description":"periscopic","version":"2.0.3","repository":{"type":"git","url":"git+https://github.com/Rich-Harris/periscopic.git"},"main":"dist/periscopic.js","module":"dist/periscopic.mjs","exports":{"import":"./dist/periscopic.mjs","require":"./dist/periscopic.js"},"types":"types/index.d.ts","devDependencies":{"@types/estree":"0.0.39","acorn":"^7.0.0","rollup":"^0.65.2","typescript":"^4.1.2","uvu":"^0.5.1"},"scripts":{"build":"tsc && rollup -c","dev":"rollup -cw","test":"uvu test","prepublishOnly":"npm test && npm run build"},"license":"MIT","dependencies":{"estree-walker":"^2.0.2","is-reference":"^1.1.4"},"gitHead":"c6bc9e61c94c6da41cb47435f8604f3f9a03af93","bugs":{"url":"https://github.com/Rich-Harris/periscopic/issues"},"homepage":"https://github.com/Rich-Harris/periscopic#readme","_id":"periscopic@2.0.3","_nodeVersion":"12.18.3","_npmVersion":"6.14.6","dist":{"integrity":"sha512-FuCZe61mWxQOJAQFEfmt9FjzebRlcpFz8sFPbyaCKtdusPkMEbA9ey0eARnRav5zAhmXznhaQkKGFAPn7X9NUw==","shasum":"326e16c46068172ca9a9d20af1a684cd0796fa99","tarball":"http://registry-npm.ywwl.com/periscopic/download/periscopic-2.0.3.tgz","fileCount":7,"unpackedSize":21603,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfz8MuCRA9TVsSAnZWagAAupIQAJ6pBKEr2oLJVGXihAYk\nIfLdHsQvG1Qin33ODqMfAYhjm5Yo2/5LuMZMD/nvA4YD2xNuFFEzUofuJsp/\nTXHIPCCEitRM9HB5CNghn0H0SFTvHkCzXj6Ez3p73SO9NvYTOt+7j9m/RXuI\nGkIFZEpEMuDFgRISTidnOxpid4q5QJ/en08px0hZzzIQ/hRIg72oyoEAkgL0\nLFxDOaQ8C3+JuvREahp0dHIokt/VdIH1cJ+BOI/FOeipAHOAHZG4FhlgWOoO\nPoziz6vHyKdgyMHJZ1FEGGJbelC37eIhiWb96R6AuHqleSejoHvBVYJ4oIQT\nViVIoW4WY95OwjRL/YARxe5dnIFyS4TuZWAtJihR2vXrg0LfaWjMQpq5V7DA\nUcFvHr1ck0BMvVYZ5DXcYB/K4j8zF5AQB1zZRD4VeZ8EWErnyDRCMROOqZKv\nlKJhhcx28ekDzm9ReGdGHW9mCuzdDma5Z+ilp2+fJJ4BPaDILV4aF6Ataats\nW7WSsOCwmkVRoclcUE37nbY+kW5httmM1TWIjWad26tUhtR86MeVx3mSTCqh\neeEQUNm6Mm8B6QUHt1vzqzcxeyKuyhbHUMBmSXK/8QAgR+LJjGzWgFiSVGNs\n/+wxlN3HGeGg/2Ph8x0hGOFcK6X0d+UwYCbHMiF75n4Pb4kuwAtUcZLgrLgU\nogBv\r\n=uPMX\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDCV1Tt6NPqEXiPZL4nyLfr9Yzpyo4u/vIRPHRVJ/tfRAIgBVzt5AHZ38mgRQrap+U3SXaad8NcNnByrUjCrBcXahM="}],"size":4793,"noattachment":false,"key":"/periscopic/-/periscopic-2.0.3.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_2.0.3_1607451437854_0.8502689405595525"},"_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":1607451437973,"_cnpm_publish_time":1607451437973,"dist-tags":{"latest":"4.0.3"}}