-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathindex.mjs
More file actions
42 lines (37 loc) · 847 Bytes
/
index.mjs
File metadata and controls
42 lines (37 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/** @type {null | typeof import('@babel/core').types} */
let _t = null;
/** @type {null | typeof import('@babel/core')} */
let babelApi = null;
/**
* @param {import('@babel/core')} api
*/
export const register = api => {
babelApi = api;
_t = api.types;
};
/**
* @returns {typeof import('@babel/core')}
*/
export const getBabelApi = () => {
if (!babelApi) {
throw new Error('Please call register() before using the babel api');
}
return babelApi;
};
export function traverse(node, visitor) {
getBabelApi().traverse(node, visitor);
}
export const types = new Proxy(
{},
{
get: (_, p, receiver) => {
if (!_t) {
throw new Error('Please call register() before using the babel types');
}
if (p in _t) {
return Reflect.get(_t, p, receiver);
}
return undefined;
},
}
);