Utility functions for looking up and working with Flow and TypeScript type scopes in Babel. Version 1.1.0 provides four main functions: isTypeScope, getClosestTypeScopePath, getOwnTypeBindings, and getTypeBinding. These helpers identify whether a Babel path creates a type scope, find the nearest ancestor type scope, retrieve type bindings defined in the current scope, and search for type bindings up the scope chain. The package supports both Flow and TypeScript, and is intended for Babel plugin or tool authors. It is lightweight with no production dependencies. Released in 2018, the library is stable but sees infrequent updates. Similar functionality exists in @babel/traverse, but this package provides more targeted scope inspection.
npm install babel-type-scopesVerified import paths — ran on the pinned version, not inferred.
Parses TypeScript code, traverses AST, and demonstrates each exported function on a type alias.
Use @babel/traverse's getBinding for non-type bindings.
Check if the returned path is the same as the input; if so, the path itself is a type scope.
Use getTypeBinding only for type-level bindings (types, interfaces). For value bindings, use @babel/traverse's scope.getBinding.
Run 'npm install babel-type-scopes' or 'yarn add babel-type-scopes'.
Use 'import { isTypeScope } from 'babel-type-scopes';'Ensure the name exists as a type binding; consider checking getOwnTypeBindings first.
No dependency data recorded yet.