{"name":"periscopic","description":"periscopic","version":"4.0.3","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","default":"./src/index.js"},"types":"types/index.d.ts","devDependencies":{"@changesets/cli":"^2.31.0","acorn":"^8.10.0","dts-buddy":"^0.2.4","typescript":"^5.2.2","uvu":"^0.5.6"},"license":"MIT","dependencies":{"@types/estree":"*","is-reference":"^3.0.2","zimmerframe":"^1.0.0"},"publishConfig":{"access":"public"},"scripts":{"test":"uvu test","changeset:version":"changeset version","changeset:publish":"changeset publish"},"_id":"periscopic@4.0.3","bugs":{"url":"https://github.com/Rich-Harris/periscopic/issues"},"homepage":"https://github.com/Rich-Harris/periscopic#readme","_integrity":"sha512-iD/CnjEI6TJYwqLXmEVByEbT1RwUGSW3W51t/uWf+2Ag7FMHLqJ1XNhawGaXBf9/gZr+DhF3bTGLOw+03GJnzg==","_resolved":"/tmp/aebae4cd03149447254dc7d9dd390a0c/periscopic-4.0.3.tgz","_from":"file:periscopic-4.0.3.tgz","_nodeVersion":"24.14.1","_npmVersion":"11.11.0","dist":{"integrity":"sha512-iD/CnjEI6TJYwqLXmEVByEbT1RwUGSW3W51t/uWf+2Ag7FMHLqJ1XNhawGaXBf9/gZr+DhF3bTGLOw+03GJnzg==","shasum":"89084ddef6b2302eb5f470aa3a788464760aed79","tarball":"http://registry-npm.ywwl.com/periscopic/download/periscopic-4.0.3.tgz","fileCount":6,"unpackedSize":11030,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/periscopic@4.0.3","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIDLn72A69q3SNfrXQb3HMBNfIylpUIn7QaCpQvlQggsmAiEA11/+Gezhd999mZgePDZInN6zxtqstSK4OOoQQjtLdVQ="}],"size":3917,"noattachment":false,"key":"/periscopic/-/periscopic-4.0.3.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:3022822a-1e8f-42b8-9be2-23199c418e99"}},"directories":{},"maintainers":[{"name":"rich_harris","email":"richard.a.harris@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/periscopic_4.0.3_1776762598314_0.32801778451694186"},"_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`, { ecmaVersion: 2022 });\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`, { ecmaVersion: 2022 });\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)\n","publish_time":1776762598429,"_cnpm_publish_time":1776762598429,"dist-tags":{"latest":"4.0.3"}}