/
virtual-types.ts
77 lines (57 loc) 路 2.23 KB
/
virtual-types.ts
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import type * as t from "@babel/types";
export interface VirtualTypeAliases {
BindingIdentifier: t.Identifier;
BlockScoped: t.Node;
ExistentialTypeParam: t.ExistsTypeAnnotation;
Expression: t.Expression;
Flow: t.Flow | t.ImportDeclaration | t.ExportDeclaration | t.ImportSpecifier;
ForAwaitStatement: t.ForOfStatement;
Generated: t.Node;
NumericLiteralTypeAnnotation: t.NumberLiteralTypeAnnotation;
Pure: t.Node;
Referenced: t.Node;
ReferencedIdentifier: t.Identifier | t.JSXIdentifier;
ReferencedMemberExpression: t.MemberExpression;
RestProperty: t.RestElement;
Scope: t.Scopable | t.Pattern;
SpreadProperty: t.RestElement;
Statement: t.Statement;
User: t.Node;
Var: t.VariableDeclaration;
}
type VirtualTypeMapping = readonly (t.Node["type"] | keyof t.Aliases)[] | null;
export const ReferencedIdentifier: VirtualTypeMapping = [
"Identifier",
"JSXIdentifier",
] as const;
export const ReferencedMemberExpression: VirtualTypeMapping = [
"MemberExpression",
] as const;
export const BindingIdentifier: VirtualTypeMapping = ["Identifier"] as const;
export const Statement: VirtualTypeMapping = ["Statement"] as const;
export const Expression: VirtualTypeMapping = ["Expression"] as const;
export const Scope: VirtualTypeMapping = ["Scopable", "Pattern"] as const;
export const Referenced: VirtualTypeMapping = null as null;
export const BlockScoped: VirtualTypeMapping = null as null;
export const Var: VirtualTypeMapping = ["VariableDeclaration"];
export const User: VirtualTypeMapping = null as null;
export const Generated: VirtualTypeMapping = null as null;
export const Pure: VirtualTypeMapping = null as null;
export const Flow: VirtualTypeMapping = [
"Flow",
"ImportDeclaration",
"ExportDeclaration",
"ImportSpecifier",
] as const;
// TODO: 7.0 Backwards Compat
export const RestProperty: VirtualTypeMapping = ["RestElement"] as const;
export const SpreadProperty: VirtualTypeMapping = ["RestElement"] as const;
export const ExistentialTypeParam: VirtualTypeMapping = [
"ExistsTypeAnnotation",
] as const;
export const NumericLiteralTypeAnnotation: VirtualTypeMapping = [
"NumberLiteralTypeAnnotation",
] as const;
export const ForAwaitStatement: VirtualTypeMapping = [
"ForOfStatement",
] as const;