forked from benjamn/ast-types
-
Notifications
You must be signed in to change notification settings - Fork 0
/
es2020.ts
59 lines (46 loc) · 1.62 KB
/
es2020.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
import { Fork } from "../types";
import { LogicalOperators } from "./core-operators";
import es2019Def from "./es2019";
import typesPlugin from "../lib/types";
import sharedPlugin from "../lib/shared";
export default function (fork: Fork) {
fork.use(es2019Def);
const types = fork.use(typesPlugin);
const def = types.Type.def;
const or = types.Type.or;
const shared = fork.use(sharedPlugin);
const defaults = shared.defaults;
def("ImportExpression")
.bases("Expression")
.build("source")
.field("source", def("Expression"));
def("ExportAllDeclaration")
.build("source", "exported")
.field("source", def("Literal"))
.field("exported", or(def("Identifier"), null));
// Optional chaining
def("ChainElement")
.bases("Node")
.field("optional", Boolean, defaults["false"]);
def("CallExpression")
.bases("Expression", "ChainElement");
def("MemberExpression")
.bases("Expression", "ChainElement");
def("ChainExpression")
.bases("Expression")
.build("expression")
.field("expression", def("ChainElement"));
def("OptionalCallExpression")
.bases("CallExpression")
.build("callee", "arguments", "optional")
.field("optional", Boolean, defaults["true"]);
// Deprecated optional chaining type, doesn't work with babelParser@7.11.0 or newer
def("OptionalMemberExpression")
.bases("MemberExpression")
.build("object", "property", "computed", "optional")
.field("optional", Boolean, defaults["true"]);
// Nullish coalescing
const LogicalOperator = or(...LogicalOperators, "??");
def("LogicalExpression")
.field("operator", LogicalOperator)
};