UNPKG

2.41 kBJavaScriptView Raw
1require("./es7");
2
3var types = require("../lib/types");
4var defaults = require("../lib/shared").defaults;
5var def = types.Type.def;
6var or = types.Type.or;
7
8def("VariableDeclaration")
9 .field("declarations", [or(
10 def("VariableDeclarator"),
11 def("Identifier") // Esprima deviation.
12 )]);
13
14def("Property")
15 .field("value", or(
16 def("Expression"),
17 def("Pattern") // Esprima deviation.
18 ));
19
20def("ArrayPattern")
21 .field("elements", [or(
22 def("Pattern"),
23 def("SpreadElement"),
24 null
25 )]);
26
27def("ObjectPattern")
28 .field("properties", [or(
29 def("Property"),
30 def("PropertyPattern"),
31 def("SpreadPropertyPattern"),
32 def("SpreadProperty") // Used by Esprima.
33 )]);
34
35// Like ModuleSpecifier, except type:"ExportSpecifier" and buildable.
36// export {<id [as name]>} [from ...];
37def("ExportSpecifier")
38 .bases("ModuleSpecifier")
39 .build("id", "name");
40
41// export <*> from ...;
42def("ExportBatchSpecifier")
43 .bases("Specifier")
44 .build();
45
46// Like ModuleSpecifier, except type:"ImportSpecifier" and buildable.
47// import {<id [as name]>} from ...;
48def("ImportSpecifier")
49 .bases("ModuleSpecifier")
50 .build("id", "name");
51
52// import <* as id> from ...;
53def("ImportNamespaceSpecifier")
54 .bases("ModuleSpecifier")
55 .build("id");
56
57// import <id> from ...;
58def("ImportDefaultSpecifier")
59 .bases("ModuleSpecifier")
60 .build("id");
61
62def("ExportDeclaration")
63 .bases("Declaration")
64 .build("default", "declaration", "specifiers", "source")
65 .field("default", Boolean)
66 .field("declaration", or(
67 def("Declaration"),
68 def("Expression"), // Implies default.
69 null
70 ))
71 .field("specifiers", [or(
72 def("ExportSpecifier"),
73 def("ExportBatchSpecifier")
74 )], defaults.emptyArray)
75 .field("source", or(
76 def("Literal"),
77 null
78 ), defaults["null"]);
79
80def("ImportDeclaration")
81 .bases("Declaration")
82 .build("specifiers", "source")
83 .field("specifiers", [or(
84 def("ImportSpecifier"),
85 def("ImportNamespaceSpecifier"),
86 def("ImportDefaultSpecifier")
87 )], defaults.emptyArray)
88 .field("source", def("Literal"));
89
90def("Block")
91 .bases("Comment")
92 .build("value", /*optional:*/ "leading", "trailing");
93
94def("Line")
95 .bases("Comment")
96 .build("value", /*optional:*/ "leading", "trailing");