forked from benjamn/ast-types
-
Notifications
You must be signed in to change notification settings - Fork 0
/
es-proposals.ts
93 lines (80 loc) · 2.32 KB
/
es-proposals.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { Fork } from "../types";
import typesPlugin from "../lib/types";
import sharedPlugin from "../lib/shared";
import es2022Def from "./es2022";
export default function (fork: Fork) {
fork.use(es2022Def);
const types = fork.use(typesPlugin);
const Type = types.Type;
const def = types.Type.def;
const or = Type.or;
const shared = fork.use(sharedPlugin);
const defaults = shared.defaults;
def("AwaitExpression")
.build("argument", "all")
.field("argument", or(def("Expression"), null))
.field("all", Boolean, defaults["false"]);
// Decorators
def("Decorator")
.bases("Node")
.build("expression")
.field("expression", def("Expression"));
def("Property")
.field("decorators",
or([def("Decorator")], null),
defaults["null"]);
def("MethodDefinition")
.field("decorators",
or([def("Decorator")], null),
defaults["null"]);
// Private names
def("PrivateName")
.bases("Expression", "Pattern")
.build("id")
.field("id", def("Identifier"));
def("ClassPrivateProperty")
.bases("ClassProperty")
.build("key", "value")
.field("key", def("PrivateName"))
.field("value", or(def("Expression"), null), defaults["null"]);
// https://github.com/tc39/proposal-import-assertions
def("ImportAttribute")
.bases("Node")
.build("key", "value")
.field("key", or(def("Identifier"), def("Literal")))
.field("value", def("Expression"));
[ "ImportDeclaration",
"ExportAllDeclaration",
"ExportNamedDeclaration",
].forEach(decl => {
def(decl).field(
"assertions",
[def("ImportAttribute")],
defaults.emptyArray,
);
});
// https://github.com/tc39/proposal-record-tuple
// https://github.com/babel/babel/pull/10865
def("RecordExpression")
.bases("Expression")
.build("properties")
.field("properties", [or(
def("ObjectProperty"),
def("ObjectMethod"),
def("SpreadElement"),
)]);
def("TupleExpression")
.bases("Expression")
.build("elements")
.field("elements", [or(
def("Expression"),
def("SpreadElement"),
null,
)]);
// https://github.com/tc39/proposal-js-module-blocks
// https://github.com/babel/babel/pull/12469
def("ModuleExpression")
.bases("Node")
.build("body")
.field("body", def("Program"));
};