https://github.com/babel-utils/babel-type-scopes
Utils for looking up and working with Flow & TypeScript scopes in Babel
https://github.com/babel-utils/babel-type-scopes
Last synced: 12 months ago
JSON representation
Utils for looking up and working with Flow & TypeScript scopes in Babel
- Host: GitHub
- URL: https://github.com/babel-utils/babel-type-scopes
- Owner: babel-utils
- License: mit
- Created: 2017-09-01T05:41:28.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-02-09T10:09:08.000Z (over 7 years ago)
- Last Synced: 2025-04-06T04:32:26.159Z (about 1 year ago)
- Language: JavaScript
- Size: 28.3 KB
- Stars: 12
- Watchers: 1
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# babel-type-scopes
> Utils for looking up and working with Flow & TypeScript scopes in Babel
```js
import {
isTypeScope,
getClosestTypeScopePath,
getOwnTypeBindings,
getTypeBinding,
} from 'babel-type-scopes';
isTypeScope(path); // true | false
getClosestTypeScopePath(path); // (Path)
getOwnTypeBindings(path) // { foo: { kind, path, id }, bar: { kind, path, id } }
getTypeBinding(path, 'foo') // { kind, path, id }
```
## Installation
```sh
yarn add babel-type-scopes
```
## API
#### `isTypeScope(path: Path) => boolean`
Check if a path creates a type scope.
#### `getClosestTypeScope(path: Path) => Path`
Find the closest path to a type scope.
#### `getOwnTypeBindings(path: Path) => Bindings`
Find the closest path to a type scope.
#### `getTypeBinding(path: Path) => Binding`
Search for a binding in the current scope and parent scopes.
### Types
#### `Binding`
```js
type Binding = {
kind: 'import' | 'declaration' | 'expression' | 'param',
path: Path,
id: Path,
};
```
#### `Bindings`
```js
type Bindings = { [name: string]: Binding };
```