{"id":13527485,"url":"https://github.com/Rich-Harris/periscopic","last_synced_at":"2025-04-01T09:31:39.044Z","repository":{"id":35103595,"uuid":"207163270","full_name":"Rich-Harris/periscopic","owner":"Rich-Harris","description":"Utility for analyzing scopes belonging to an ESTree-compliant AST","archived":false,"fork":false,"pushed_at":"2024-02-08T11:28:58.000Z","size":1997,"stargazers_count":96,"open_issues_count":6,"forks_count":8,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-03T14:44:12.971Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Rich-Harris.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-08T19:33:55.000Z","updated_at":"2024-12-16T14:13:10.000Z","dependencies_parsed_at":"2024-06-18T13:41:56.994Z","dependency_job_id":"5d43c51c-4e47-451f-ae62-b3f4981b8a85","html_url":"https://github.com/Rich-Harris/periscopic","commit_stats":{"total_commits":44,"total_committers":8,"mean_commits":5.5,"dds":"0.40909090909090906","last_synced_commit":"088d446fb269993ece75ba24e9ac3e9ff07c9e6f"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rich-Harris%2Fperiscopic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rich-Harris%2Fperiscopic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rich-Harris%2Fperiscopic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rich-Harris%2Fperiscopic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rich-Harris","download_url":"https://codeload.github.com/Rich-Harris/periscopic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246616150,"owners_count":20806065,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T06:01:49.092Z","updated_at":"2025-04-01T09:31:36.818Z","avatar_url":"https://github.com/Rich-Harris.png","language":"JavaScript","funding_links":[],"categories":["Repository"],"sub_categories":["AST"],"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\u003cNode, Scope\u003e`, where the keys are the nodes of your AST that create a scope\n* `globals` is a `Map\u003cstring, Node\u003e` 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\u003cstring, Node\u003e` of all the variables declared in this scope, the node value referes to the declaration statement\n* `scope.initialised_declarations` — a `Set\u003cstring\u003e` of all the variables declared and initialised in this scope\n* `scope.references` — a `Set\u003cstring\u003e` 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)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRich-Harris%2Fperiscopic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRich-Harris%2Fperiscopic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRich-Harris%2Fperiscopic/lists"}