MCPcopy Index your code
hub / github.com/Rich-Harris/periscopic

github.com/Rich-Harris/periscopic @v4.0.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release v4.0.3 ↗ · + Follow
16 symbols 43 edges 3 files 6 documented · 38% 3 cross-repo links updated 2mo agov4.0.3 · 2026-04-21★ 1084 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

periscopic

Utility for analyzing scopes belonging to an ESTree-compliant AST.

API

import { analyze } from 'periscopic';

const ast = acorn.parse(`
const a = b;
console.log(a);
`, { ecmaVersion: 2022 });

const { map, globals, scope } = analyze(ast);
  • map is a WeakMap<Node, Scope>, where the keys are the nodes of your AST that create a scope
  • 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)
  • scope is the top-level Scope belonging to the program

Scope

Each Scope instance has the following properties:

  • scope.block — true if the scope is created by a block statement (i.e. let, const and class are contained to it), false otherwise
  • scope.parent — the parent scope object
  • scope.declarations — a Map<string, Node> of all the variables declared in this scope, the node value referes to the declaration statement
  • scope.initialised_declarations — a Set<string> of all the variables declared and initialised in this scope
  • scope.references — a Set<string> of all the names referenced in this scope (or child scopes)

It also has two methods:

  • scope.has(name) — returns true if name is declared in this scope or an ancestor scope
  • scope.find_owner(name) — returns the scope object in which name is declared (or null if it is not declared)

extract_identifiers and extract_names

This package also exposes utilities for extracting the identifiers contained in a declaration or a function parameter:

import { extract_identifiers, extract_names } from 'periscopic';

const ast = acorn.parse(`
const { a, b: [c, d] = e } = opts;
`, { ecmaVersion: 2022 });

const lhs = ast.body[0].declarations[0].id;

extract_identifiers(lhs);
/*
[
    { type: 'Identifier', name: 'a', start: 9, end: 10 },
    { type: 'Identifier', name: 'c', start: 16, end: 17 },
    { type: 'Identifier', name: 'd', start: 19, end: 20 }
]
*/

extract_names(lhs);
/*
['a', 'c', 'd']
*/

License

MIT

Core symbols most depended-on inside this repo

has
called by 13
src/index.js
parse
called by 9
test/test.js
analyze
called by 8
src/index.js
push
called by 4
src/index.js
extract_names
called by 4
src/index.js
pojo
called by 2
test/test.js
extract_identifiers
called by 2
src/index.js
add_reference
called by 1
src/index.js

Shape

Function 10
Method 4
Class 2

Languages

TypeScript100%

Modules by API surface

src/index.js12 symbols
test/test.js4 symbols

Used by 3 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add periscopic \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact