ast-types 0.9.13 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  language: node_js
2
2
  node_js:
3
+ - "9"
3
4
  - "8"
4
5
  - "7"
5
6
  - "6"
@@ -1,13 +1,110 @@
1
1
  module.exports = function (fork) {
2
- fork.use(require("./babel"));
2
+ fork.use(require("./es7"));
3
3
 
4
- // var types = fork.types;
5
4
  var types = fork.use(require("../lib/types"));
6
- // var defaults = fork.shared.defaults;
7
5
  var defaults = fork.use(require("../lib/shared")).defaults;
8
6
  var def = types.Type.def;
9
7
  var or = types.Type.or;
10
8
 
9
+ def("Noop")
10
+ .bases("Statement")
11
+ .build();
12
+
13
+ def("DoExpression")
14
+ .bases("Expression")
15
+ .build("body")
16
+ .field("body", [def("Statement")]);
17
+
18
+ def("Super")
19
+ .bases("Expression")
20
+ .build();
21
+
22
+ def("BindExpression")
23
+ .bases("Expression")
24
+ .build("object", "callee")
25
+ .field("object", or(def("Expression"), null))
26
+ .field("callee", def("Expression"));
27
+
28
+ def("Decorator")
29
+ .bases("Node")
30
+ .build("expression")
31
+ .field("expression", def("Expression"));
32
+
33
+ def("Property")
34
+ .field("decorators",
35
+ or([def("Decorator")], null),
36
+ defaults["null"]);
37
+
38
+ def("MethodDefinition")
39
+ .field("decorators",
40
+ or([def("Decorator")], null),
41
+ defaults["null"]);
42
+
43
+ def("MetaProperty")
44
+ .bases("Expression")
45
+ .build("meta", "property")
46
+ .field("meta", def("Identifier"))
47
+ .field("property", def("Identifier"));
48
+
49
+ def("ParenthesizedExpression")
50
+ .bases("Expression")
51
+ .build("expression")
52
+ .field("expression", def("Expression"));
53
+
54
+ def("ImportSpecifier")
55
+ .bases("ModuleSpecifier")
56
+ .build("imported", "local")
57
+ .field("imported", def("Identifier"));
58
+
59
+ def("ImportDefaultSpecifier")
60
+ .bases("ModuleSpecifier")
61
+ .build("local");
62
+
63
+ def("ImportNamespaceSpecifier")
64
+ .bases("ModuleSpecifier")
65
+ .build("local");
66
+
67
+ def("ExportDefaultDeclaration")
68
+ .bases("Declaration")
69
+ .build("declaration")
70
+ .field("declaration", or(def("Declaration"), def("Expression")));
71
+
72
+ def("ExportNamedDeclaration")
73
+ .bases("Declaration")
74
+ .build("declaration", "specifiers", "source")
75
+ .field("declaration", or(def("Declaration"), null))
76
+ .field("specifiers", [def("ExportSpecifier")], defaults.emptyArray)
77
+ .field("source", or(def("Literal"), null), defaults["null"]);
78
+
79
+ def("ExportSpecifier")
80
+ .bases("ModuleSpecifier")
81
+ .build("local", "exported")
82
+ .field("exported", def("Identifier"));
83
+
84
+ def("ExportNamespaceSpecifier")
85
+ .bases("Specifier")
86
+ .build("exported")
87
+ .field("exported", def("Identifier"));
88
+
89
+ def("ExportDefaultSpecifier")
90
+ .bases("Specifier")
91
+ .build("exported")
92
+ .field("exported", def("Identifier"));
93
+
94
+ def("ExportAllDeclaration")
95
+ .bases("Declaration")
96
+ .build("exported", "source")
97
+ .field("exported", or(def("Identifier"), null))
98
+ .field("source", def("Literal"));
99
+
100
+ def("CommentBlock")
101
+ .bases("Comment")
102
+ .build("value", /*optional:*/ "leading", "trailing");
103
+
104
+ def("CommentLine")
105
+ .bases("Comment")
106
+ .build("value", /*optional:*/ "leading", "trailing");
107
+
11
108
  def("Directive")
12
109
  .bases("Node")
13
110
  .build("value")
@@ -39,7 +136,33 @@ module.exports = function (fork) {
39
136
  def("NumericLiteral")
40
137
  .bases("Literal")
41
138
  .build("value")
42
- .field("value", Number);
139
+ .field("value", Number)
140
+ .field("raw", or(String, null), defaults["null"])
141
+ .field("extra", {
142
+ rawValue: Number,
143
+ raw: String
144
+ }, function getDefault() {
145
+ return {
146
+ rawValue: this.value,
147
+ raw: this.value + ""
148
+ }
149
+ });
150
+
151
+ def("BigIntLiteral")
152
+ .bases("Literal")
153
+ .build("value")
154
+ // Only String really seems appropriate here, since BigInt values
155
+ // often exceed the limits of JS numbers.
156
+ .field("value", or(String, Number))
157
+ .field("extra", {
158
+ rawValue: String,
159
+ raw: String
160
+ }, function getDefault() {
161
+ return {
162
+ rawValue: String(this.value),
163
+ raw: this.value + "n"
164
+ };
165
+ });
43
166
 
44
167
  def("NullLiteral")
45
168
  .bases("Literal")
package/def/babel.js CHANGED
@@ -1,107 +1,4 @@
1
1
  module.exports = function (fork) {
2
- fork.use(require("./es7"));
3
-
4
- var types = fork.use(require("../lib/types"));
5
- var defaults = fork.use(require("../lib/shared")).defaults;
6
- var def = types.Type.def;
7
- var or = types.Type.or;
8
-
9
- def("Noop")
10
- .bases("Node")
11
- .build();
12
-
13
- def("DoExpression")
14
- .bases("Expression")
15
- .build("body")
16
- .field("body", [def("Statement")]);
17
-
18
- def("Super")
19
- .bases("Expression")
20
- .build();
21
-
22
- def("BindExpression")
23
- .bases("Expression")
24
- .build("object", "callee")
25
- .field("object", or(def("Expression"), null))
26
- .field("callee", def("Expression"));
27
-
28
- def("Decorator")
29
- .bases("Node")
30
- .build("expression")
31
- .field("expression", def("Expression"));
32
-
33
- def("Property")
34
- .field("decorators",
35
- or([def("Decorator")], null),
36
- defaults["null"]);
37
-
38
- def("MethodDefinition")
39
- .field("decorators",
40
- or([def("Decorator")], null),
41
- defaults["null"]);
42
-
43
- def("MetaProperty")
44
- .bases("Expression")
45
- .build("meta", "property")
46
- .field("meta", def("Identifier"))
47
- .field("property", def("Identifier"));
48
-
49
- def("ParenthesizedExpression")
50
- .bases("Expression")
51
- .build("expression")
52
- .field("expression", def("Expression"));
53
-
54
- def("ImportSpecifier")
55
- .bases("ModuleSpecifier")
56
- .build("imported", "local")
57
- .field("imported", def("Identifier"));
58
-
59
- def("ImportDefaultSpecifier")
60
- .bases("ModuleSpecifier")
61
- .build("local");
62
-
63
- def("ImportNamespaceSpecifier")
64
- .bases("ModuleSpecifier")
65
- .build("local");
66
-
67
- def("ExportDefaultDeclaration")
68
- .bases("Declaration")
69
- .build("declaration")
70
- .field("declaration", or(def("Declaration"), def("Expression")));
71
-
72
- def("ExportNamedDeclaration")
73
- .bases("Declaration")
74
- .build("declaration", "specifiers", "source")
75
- .field("declaration", or(def("Declaration"), null))
76
- .field("specifiers", [def("ExportSpecifier")], defaults.emptyArray)
77
- .field("source", or(def("Literal"), null), defaults["null"]);
78
-
79
- def("ExportSpecifier")
80
- .bases("ModuleSpecifier")
81
- .build("local", "exported")
82
- .field("exported", def("Identifier"));
83
-
84
- def("ExportNamespaceSpecifier")
85
- .bases("Specifier")
86
- .build("exported")
87
- .field("exported", def("Identifier"));
88
-
89
- def("ExportDefaultSpecifier")
90
- .bases("Specifier")
91
- .build("exported")
92
- .field("exported", def("Identifier"));
93
-
94
- def("ExportAllDeclaration")
95
- .bases("Declaration")
96
- .build("exported", "source")
97
- .field("exported", or(def("Identifier"), null))
98
- .field("source", def("Literal"));
99
-
100
- def("CommentBlock")
101
- .bases("Comment")
102
- .build("value", /*optional:*/ "leading", "trailing");
103
-
104
- def("CommentLine")
105
- .bases("Comment")
106
- .build("value", /*optional:*/ "leading", "trailing");
107
- };
2
+ fork.use(require("./babel-core"));
3
+ fork.use(require("./flow"));
4
+ };
package/def/flow.js CHANGED
@@ -1,349 +1,356 @@
1
1
  module.exports = function (fork) {
2
- fork.use(require("./es7"));
3
-
4
- var types = fork.use(require("../lib/types"));
5
- var def = types.Type.def;
6
- var or = types.Type.or;
7
- var defaults = fork.use(require("../lib/shared")).defaults;
8
-
9
- // Type Annotations
10
- def("Type").bases("Node");
11
-
12
- def("AnyTypeAnnotation")
13
- .bases("Type")
14
- .build();
15
-
16
- def("EmptyTypeAnnotation")
17
- .bases("Type")
18
- .build();
19
-
20
- def("MixedTypeAnnotation")
21
- .bases("Type")
22
- .build();
23
-
24
- def("VoidTypeAnnotation")
25
- .bases("Type")
26
- .build();
27
-
28
- def("NumberTypeAnnotation")
29
- .bases("Type")
30
- .build();
31
-
32
- def("NumberLiteralTypeAnnotation")
33
- .bases("Type")
34
- .build("value", "raw")
35
- .field("value", Number)
36
- .field("raw", String);
37
-
38
- // Babylon 6 differs in AST from Flow
39
- // same as NumberLiteralTypeAnnotation
40
- def("NumericLiteralTypeAnnotation")
41
- .bases("Type")
42
- .build("value", "raw")
43
- .field("value", Number)
44
- .field("raw", String);
45
-
46
- def("StringTypeAnnotation")
47
- .bases("Type")
48
- .build();
49
-
50
- def("StringLiteralTypeAnnotation")
51
- .bases("Type")
52
- .build("value", "raw")
53
- .field("value", String)
54
- .field("raw", String);
55
-
56
- def("BooleanTypeAnnotation")
57
- .bases("Type")
58
- .build();
59
-
60
- def("BooleanLiteralTypeAnnotation")
61
- .bases("Type")
62
- .build("value", "raw")
63
- .field("value", Boolean)
64
- .field("raw", String);
65
-
66
- def("TypeAnnotation")
67
- .bases("Node")
68
- .build("typeAnnotation")
69
- .field("typeAnnotation", def("Type"));
70
-
71
- def("NullableTypeAnnotation")
72
- .bases("Type")
73
- .build("typeAnnotation")
74
- .field("typeAnnotation", def("Type"));
75
-
76
- def("NullLiteralTypeAnnotation")
77
- .bases("Type")
78
- .build();
79
-
80
- def("NullTypeAnnotation")
81
- .bases("Type")
82
- .build();
83
-
84
- def("ThisTypeAnnotation")
85
- .bases("Type")
86
- .build();
87
-
88
- def("ExistsTypeAnnotation")
89
- .bases("Type")
90
- .build();
91
-
92
- def("ExistentialTypeParam")
93
- .bases("Type")
94
- .build();
95
-
96
- def("FunctionTypeAnnotation")
97
- .bases("Type")
98
- .build("params", "returnType", "rest", "typeParameters")
99
- .field("params", [def("FunctionTypeParam")])
100
- .field("returnType", def("Type"))
101
- .field("rest", or(def("FunctionTypeParam"), null))
102
- .field("typeParameters", or(def("TypeParameterDeclaration"), null));
103
-
104
- def("FunctionTypeParam")
105
- .bases("Node")
106
- .build("name", "typeAnnotation", "optional")
107
- .field("name", def("Identifier"))
108
- .field("typeAnnotation", def("Type"))
109
- .field("optional", Boolean);
110
-
111
- def("ArrayTypeAnnotation")
112
- .bases("Type")
113
- .build("elementType")
114
- .field("elementType", def("Type"));
115
-
116
- def("ObjectTypeAnnotation")
117
- .bases("Type")
118
- .build("properties", "indexers", "callProperties")
119
- .field("properties", [def("ObjectTypeProperty")])
120
- .field("indexers", [def("ObjectTypeIndexer")], defaults.emptyArray)
121
- .field("callProperties",
122
- [def("ObjectTypeCallProperty")],
123
- defaults.emptyArray)
124
- .field("exact", Boolean, defaults["false"]);
125
-
126
- def("ObjectTypeProperty")
127
- .bases("Node")
128
- .build("key", "value", "optional")
129
- .field("key", or(def("Literal"), def("Identifier")))
130
- .field("value", def("Type"))
131
- .field("optional", Boolean)
132
- .field("variance",
133
- or("plus", "minus", null),
134
- defaults["null"]);
135
-
136
- def("ObjectTypeIndexer")
137
- .bases("Node")
138
- .build("id", "key", "value")
139
- .field("id", def("Identifier"))
140
- .field("key", def("Type"))
141
- .field("value", def("Type"))
142
- .field("variance",
143
- or("plus", "minus", null),
144
- defaults["null"]);
145
-
146
- def("ObjectTypeCallProperty")
147
- .bases("Node")
148
- .build("value")
149
- .field("value", def("FunctionTypeAnnotation"))
150
- .field("static", Boolean, defaults["false"]);
151
-
152
- def("QualifiedTypeIdentifier")
153
- .bases("Node")
154
- .build("qualification", "id")
155
- .field("qualification",
156
- or(def("Identifier"),
157
- def("QualifiedTypeIdentifier")))
158
- .field("id", def("Identifier"));
159
-
160
- def("GenericTypeAnnotation")
161
- .bases("Type")
162
- .build("id", "typeParameters")
163
- .field("id", or(def("Identifier"), def("QualifiedTypeIdentifier")))
164
- .field("typeParameters", or(def("TypeParameterInstantiation"), null));
165
-
166
- def("MemberTypeAnnotation")
167
- .bases("Type")
168
- .build("object", "property")
169
- .field("object", def("Identifier"))
170
- .field("property",
171
- or(def("MemberTypeAnnotation"),
172
- def("GenericTypeAnnotation")));
173
-
174
- def("UnionTypeAnnotation")
175
- .bases("Type")
176
- .build("types")
177
- .field("types", [def("Type")]);
178
-
179
- def("IntersectionTypeAnnotation")
180
- .bases("Type")
181
- .build("types")
182
- .field("types", [def("Type")]);
183
-
184
- def("TypeofTypeAnnotation")
185
- .bases("Type")
186
- .build("argument")
187
- .field("argument", def("Type"));
188
-
189
- def("ObjectTypeSpreadProperty")
190
- .bases("Node")
191
- .build("argument")
192
- .field("argument", def("Type"));
193
-
194
- def("Identifier")
195
- .field("typeAnnotation", or(def("TypeAnnotation"), null), defaults["null"]);
196
-
197
- def("ObjectPattern")
198
- .field("typeAnnotation", or(def("TypeAnnotation"), null), defaults["null"]);
199
-
200
- def("TypeParameterDeclaration")
201
- .bases("Node")
202
- .build("params")
203
- .field("params", [def("TypeParameter")]);
204
-
205
- def("TypeParameterInstantiation")
206
- .bases("Node")
207
- .build("params")
208
- .field("params", [def("Type")]);
209
-
210
- def("TypeParameter")
211
- .bases("Type")
212
- .build("name", "variance", "bound")
213
- .field("name", String)
214
- .field("variance",
215
- or("plus", "minus", null),
216
- defaults["null"])
217
- .field("bound",
218
- or(def("TypeAnnotation"), null),
219
- defaults["null"]);
220
-
221
- def("Function")
222
- .field("returnType",
223
- or(def("TypeAnnotation"), null),
224
- defaults["null"])
225
- .field("typeParameters",
226
- or(def("TypeParameterDeclaration"), null),
227
- defaults["null"]);
228
-
229
- def("ClassProperty")
230
- .build("key", "value", "typeAnnotation", "static")
231
- .field("value", or(def("Expression"), null))
232
- .field("typeAnnotation", or(def("TypeAnnotation"), null))
233
- .field("static", Boolean, defaults["false"])
234
- .field("variance",
235
- or("plus", "minus", null),
236
- defaults["null"]);
237
-
238
- def("ClassImplements")
239
- .field("typeParameters",
240
- or(def("TypeParameterInstantiation"), null),
241
- defaults["null"]);
242
-
243
- def("InterfaceDeclaration")
244
- .bases("Declaration")
245
- .build("id", "body", "extends")
246
- .field("id", def("Identifier"))
247
- .field("typeParameters",
248
- or(def("TypeParameterDeclaration"), null),
249
- defaults["null"])
250
- .field("body", def("ObjectTypeAnnotation"))
251
- .field("extends", [def("InterfaceExtends")]);
252
-
253
- def("DeclareInterface")
254
- .bases("InterfaceDeclaration")
255
- .build("id", "body", "extends");
256
-
257
- def("InterfaceExtends")
258
- .bases("Node")
259
- .build("id")
260
- .field("id", def("Identifier"))
261
- .field("typeParameters", or(def("TypeParameterInstantiation"), null));
262
-
263
- def("TypeAlias")
264
- .bases("Declaration")
265
- .build("id", "typeParameters", "right")
266
- .field("id", def("Identifier"))
267
- .field("typeParameters", or(def("TypeParameterDeclaration"), null))
268
- .field("right", def("Type"));
269
-
270
- def("OpaqueType")
271
- .bases("Declaration")
272
- .build("id", "typeParameters", "impltype", "supertype")
273
- .field("id", def("Identifier"))
274
- .field("typeParameters", or(def("TypeParameterDeclaration"), null))
275
- .field("implType", def("Type"))
276
- .field("superType", def("Type"));
277
-
278
- def("DeclareTypeAlias")
279
- .bases("TypeAlias")
280
- .build("id", "typeParameters", "right");
281
-
282
- def("DeclareOpaqueType")
283
- .bases("TypeAlias")
284
- .build("id", "typeParameters", "supertype");
285
-
286
- def("TypeCastExpression")
287
- .bases("Expression")
288
- .build("expression", "typeAnnotation")
289
- .field("expression", def("Expression"))
290
- .field("typeAnnotation", def("TypeAnnotation"));
291
-
292
- def("TupleTypeAnnotation")
293
- .bases("Type")
294
- .build("types")
295
- .field("types", [def("Type")]);
296
-
297
- def("DeclareVariable")
298
- .bases("Statement")
299
- .build("id")
300
- .field("id", def("Identifier"));
301
-
302
- def("DeclareFunction")
303
- .bases("Statement")
304
- .build("id")
305
- .field("id", def("Identifier"));
306
-
307
- def("DeclareClass")
308
- .bases("InterfaceDeclaration")
309
- .build("id");
310
-
311
- def("DeclareModule")
312
- .bases("Statement")
313
- .build("id", "body")
314
- .field("id", or(def("Identifier"), def("Literal")))
315
- .field("body", def("BlockStatement"));
316
-
317
- def("DeclareModuleExports")
318
- .bases("Statement")
319
- .build("typeAnnotation")
320
- .field("typeAnnotation", def("Type"));
321
-
322
- def("DeclareExportDeclaration")
323
- .bases("Declaration")
324
- .build("default", "declaration", "specifiers", "source")
325
- .field("default", Boolean)
326
- .field("declaration", or(
327
- def("DeclareVariable"),
328
- def("DeclareFunction"),
329
- def("DeclareClass"),
330
- def("Type"), // Implies default.
331
- null
332
- ))
333
- .field("specifiers", [or(
334
- def("ExportSpecifier"),
335
- def("ExportBatchSpecifier")
336
- )], defaults.emptyArray)
337
- .field("source", or(
338
- def("Literal"),
339
- null
340
- ), defaults["null"]);
341
-
342
- def("DeclareExportAllDeclaration")
343
- .bases("Declaration")
344
- .build("source")
345
- .field("source", or(
346
- def("Literal"),
347
- null
348
- ), defaults["null"]);
2
+ fork.use(require("./es7"));
3
+
4
+ var types = fork.use(require("../lib/types"));
5
+ var def = types.Type.def;
6
+ var or = types.Type.or;
7
+ var defaults = fork.use(require("../lib/shared")).defaults;
8
+
9
+ // Type Annotations
10
+ def("Type").bases("Node");
11
+
12
+ def("AnyTypeAnnotation")
13
+ .bases("Type")
14
+ .build();
15
+
16
+ def("EmptyTypeAnnotation")
17
+ .bases("Type")
18
+ .build();
19
+
20
+ def("MixedTypeAnnotation")
21
+ .bases("Type")
22
+ .build();
23
+
24
+ def("VoidTypeAnnotation")
25
+ .bases("Type")
26
+ .build();
27
+
28
+ def("NumberTypeAnnotation")
29
+ .bases("Type")
30
+ .build();
31
+
32
+ def("NumberLiteralTypeAnnotation")
33
+ .bases("Type")
34
+ .build("value", "raw")
35
+ .field("value", Number)
36
+ .field("raw", String);
37
+
38
+ // Babylon 6 differs in AST from Flow
39
+ // same as NumberLiteralTypeAnnotation
40
+ def("NumericLiteralTypeAnnotation")
41
+ .bases("Type")
42
+ .build("value", "raw")
43
+ .field("value", Number)
44
+ .field("raw", String);
45
+
46
+ def("StringTypeAnnotation")
47
+ .bases("Type")
48
+ .build();
49
+
50
+ def("StringLiteralTypeAnnotation")
51
+ .bases("Type")
52
+ .build("value", "raw")
53
+ .field("value", String)
54
+ .field("raw", String);
55
+
56
+ def("BooleanTypeAnnotation")
57
+ .bases("Type")
58
+ .build();
59
+
60
+ def("BooleanLiteralTypeAnnotation")
61
+ .bases("Type")
62
+ .build("value", "raw")
63
+ .field("value", Boolean)
64
+ .field("raw", String);
65
+
66
+ def("TypeAnnotation")
67
+ .bases("Node")
68
+ .build("typeAnnotation")
69
+ .field("typeAnnotation", def("Type"));
70
+
71
+ def("NullableTypeAnnotation")
72
+ .bases("Type")
73
+ .build("typeAnnotation")
74
+ .field("typeAnnotation", def("Type"));
75
+
76
+ def("NullLiteralTypeAnnotation")
77
+ .bases("Type")
78
+ .build();
79
+
80
+ def("NullTypeAnnotation")
81
+ .bases("Type")
82
+ .build();
83
+
84
+ def("ThisTypeAnnotation")
85
+ .bases("Type")
86
+ .build();
87
+
88
+ def("ExistsTypeAnnotation")
89
+ .bases("Type")
90
+ .build();
91
+
92
+ def("ExistentialTypeParam")
93
+ .bases("Type")
94
+ .build();
95
+
96
+ def("FunctionTypeAnnotation")
97
+ .bases("Type")
98
+ .build("params", "returnType", "rest", "typeParameters")
99
+ .field("params", [def("FunctionTypeParam")])
100
+ .field("returnType", def("Type"))
101
+ .field("rest", or(def("FunctionTypeParam"), null))
102
+ .field("typeParameters", or(def("TypeParameterDeclaration"), null));
103
+
104
+ def("FunctionTypeParam")
105
+ .bases("Node")
106
+ .build("name", "typeAnnotation", "optional")
107
+ .field("name", def("Identifier"))
108
+ .field("typeAnnotation", def("Type"))
109
+ .field("optional", Boolean);
110
+
111
+ def("ArrayTypeAnnotation")
112
+ .bases("Type")
113
+ .build("elementType")
114
+ .field("elementType", def("Type"));
115
+
116
+ def("ObjectTypeAnnotation")
117
+ .bases("Type")
118
+ .build("properties", "indexers", "callProperties")
119
+ .field("properties", [
120
+ or(def("ObjectTypeProperty"),
121
+ def("ObjectTypeSpreadProperty"))
122
+ ])
123
+ .field("indexers", [def("ObjectTypeIndexer")], defaults.emptyArray)
124
+ .field("callProperties",
125
+ [def("ObjectTypeCallProperty")],
126
+ defaults.emptyArray)
127
+ .field("exact", Boolean, defaults["false"]);
128
+
129
+ def("Variance")
130
+ .bases("Node")
131
+ .build("kind")
132
+ .field("kind", or("plus", "minus"));
133
+
134
+ var LegacyVariance = or(
135
+ def("Variance"),
136
+ "plus",
137
+ "minus",
138
+ null
139
+ );
140
+
141
+ def("ObjectTypeProperty")
142
+ .bases("Node")
143
+ .build("key", "value", "optional")
144
+ .field("key", or(def("Literal"), def("Identifier")))
145
+ .field("value", def("Type"))
146
+ .field("optional", Boolean)
147
+ .field("variance", LegacyVariance, defaults["null"]);
148
+
149
+ def("ObjectTypeIndexer")
150
+ .bases("Node")
151
+ .build("id", "key", "value")
152
+ .field("id", def("Identifier"))
153
+ .field("key", def("Type"))
154
+ .field("value", def("Type"))
155
+ .field("variance", LegacyVariance, defaults["null"]);
156
+
157
+ def("ObjectTypeCallProperty")
158
+ .bases("Node")
159
+ .build("value")
160
+ .field("value", def("FunctionTypeAnnotation"))
161
+ .field("static", Boolean, defaults["false"]);
162
+
163
+ def("QualifiedTypeIdentifier")
164
+ .bases("Node")
165
+ .build("qualification", "id")
166
+ .field("qualification",
167
+ or(def("Identifier"),
168
+ def("QualifiedTypeIdentifier")))
169
+ .field("id", def("Identifier"));
170
+
171
+ def("GenericTypeAnnotation")
172
+ .bases("Type")
173
+ .build("id", "typeParameters")
174
+ .field("id", or(def("Identifier"), def("QualifiedTypeIdentifier")))
175
+ .field("typeParameters", or(def("TypeParameterInstantiation"), null));
176
+
177
+ def("MemberTypeAnnotation")
178
+ .bases("Type")
179
+ .build("object", "property")
180
+ .field("object", def("Identifier"))
181
+ .field("property",
182
+ or(def("MemberTypeAnnotation"),
183
+ def("GenericTypeAnnotation")));
184
+
185
+ def("UnionTypeAnnotation")
186
+ .bases("Type")
187
+ .build("types")
188
+ .field("types", [def("Type")]);
189
+
190
+ def("IntersectionTypeAnnotation")
191
+ .bases("Type")
192
+ .build("types")
193
+ .field("types", [def("Type")]);
194
+
195
+ def("TypeofTypeAnnotation")
196
+ .bases("Type")
197
+ .build("argument")
198
+ .field("argument", def("Type"));
199
+
200
+ def("ObjectTypeSpreadProperty")
201
+ .bases("Node")
202
+ .build("argument")
203
+ .field("argument", def("Type"));
204
+
205
+ def("Identifier")
206
+ .field("typeAnnotation", or(def("TypeAnnotation"), null), defaults["null"]);
207
+
208
+ def("ObjectPattern")
209
+ .field("typeAnnotation", or(def("TypeAnnotation"), null), defaults["null"]);
210
+
211
+ def("TypeParameterDeclaration")
212
+ .bases("Node")
213
+ .build("params")
214
+ .field("params", [def("TypeParameter")]);
215
+
216
+ def("TypeParameterInstantiation")
217
+ .bases("Node")
218
+ .build("params")
219
+ .field("params", [def("Type")]);
220
+
221
+ def("TypeParameter")
222
+ .bases("Type")
223
+ .build("name", "variance", "bound")
224
+ .field("name", String)
225
+ .field("variance", LegacyVariance, defaults["null"])
226
+ .field("bound",
227
+ or(def("TypeAnnotation"), null),
228
+ defaults["null"]);
229
+
230
+ def("Function")
231
+ .field("returnType",
232
+ or(def("TypeAnnotation"), null),
233
+ defaults["null"])
234
+ .field("typeParameters",
235
+ or(def("TypeParameterDeclaration"), null),
236
+ defaults["null"]);
237
+
238
+ def("ClassProperty")
239
+ .build("key", "value", "typeAnnotation", "static")
240
+ .field("value", or(def("Expression"), null))
241
+ .field("typeAnnotation", or(def("TypeAnnotation"), null))
242
+ .field("static", Boolean, defaults["false"])
243
+ .field("variance", LegacyVariance, defaults["null"]);
244
+
245
+ def("ClassImplements")
246
+ .field("typeParameters",
247
+ or(def("TypeParameterInstantiation"), null),
248
+ defaults["null"]);
249
+
250
+ def("InterfaceDeclaration")
251
+ .bases("Declaration")
252
+ .build("id", "body", "extends")
253
+ .field("id", def("Identifier"))
254
+ .field("typeParameters",
255
+ or(def("TypeParameterDeclaration"), null),
256
+ defaults["null"])
257
+ .field("body", def("ObjectTypeAnnotation"))
258
+ .field("extends", [def("InterfaceExtends")]);
259
+
260
+ def("DeclareInterface")
261
+ .bases("InterfaceDeclaration")
262
+ .build("id", "body", "extends");
263
+
264
+ def("InterfaceExtends")
265
+ .bases("Node")
266
+ .build("id")
267
+ .field("id", def("Identifier"))
268
+ .field("typeParameters", or(def("TypeParameterInstantiation"), null));
269
+
270
+ def("TypeAlias")
271
+ .bases("Declaration")
272
+ .build("id", "typeParameters", "right")
273
+ .field("id", def("Identifier"))
274
+ .field("typeParameters", or(def("TypeParameterDeclaration"), null))
275
+ .field("right", def("Type"));
276
+
277
+ def("OpaqueType")
278
+ .bases("Declaration")
279
+ .build("id", "typeParameters", "impltype", "supertype")
280
+ .field("id", def("Identifier"))
281
+ .field("typeParameters", or(def("TypeParameterDeclaration"), null))
282
+ .field("implType", def("Type"))
283
+ .field("superType", def("Type"));
284
+
285
+ def("DeclareTypeAlias")
286
+ .bases("TypeAlias")
287
+ .build("id", "typeParameters", "right");
288
+
289
+ def("DeclareOpaqueType")
290
+ .bases("TypeAlias")
291
+ .build("id", "typeParameters", "supertype");
292
+
293
+ def("TypeCastExpression")
294
+ .bases("Expression")
295
+ .build("expression", "typeAnnotation")
296
+ .field("expression", def("Expression"))
297
+ .field("typeAnnotation", def("TypeAnnotation"));
298
+
299
+ def("TupleTypeAnnotation")
300
+ .bases("Type")
301
+ .build("types")
302
+ .field("types", [def("Type")]);
303
+
304
+ def("DeclareVariable")
305
+ .bases("Statement")
306
+ .build("id")
307
+ .field("id", def("Identifier"));
308
+
309
+ def("DeclareFunction")
310
+ .bases("Statement")
311
+ .build("id")
312
+ .field("id", def("Identifier"));
313
+
314
+ def("DeclareClass")
315
+ .bases("InterfaceDeclaration")
316
+ .build("id");
317
+
318
+ def("DeclareModule")
319
+ .bases("Statement")
320
+ .build("id", "body")
321
+ .field("id", or(def("Identifier"), def("Literal")))
322
+ .field("body", def("BlockStatement"));
323
+
324
+ def("DeclareModuleExports")
325
+ .bases("Statement")
326
+ .build("typeAnnotation")
327
+ .field("typeAnnotation", def("Type"));
328
+
329
+ def("DeclareExportDeclaration")
330
+ .bases("Declaration")
331
+ .build("default", "declaration", "specifiers", "source")
332
+ .field("default", Boolean)
333
+ .field("declaration", or(
334
+ def("DeclareVariable"),
335
+ def("DeclareFunction"),
336
+ def("DeclareClass"),
337
+ def("Type"), // Implies default.
338
+ null
339
+ ))
340
+ .field("specifiers", [or(
341
+ def("ExportSpecifier"),
342
+ def("ExportBatchSpecifier")
343
+ )], defaults.emptyArray)
344
+ .field("source", or(
345
+ def("Literal"),
346
+ null
347
+ ), defaults["null"]);
348
+
349
+ def("DeclareExportAllDeclaration")
350
+ .bases("Declaration")
351
+ .build("source")
352
+ .field("source", or(
353
+ def("Literal"),
354
+ null
355
+ ), defaults["null"]);
349
356
  };
package/def/jsx.js CHANGED
@@ -63,6 +63,7 @@ module.exports = function (fork) {
63
63
  .field("children", [or(
64
64
  def("JSXElement"),
65
65
  def("JSXExpressionContainer"),
66
+ def("JSXFragment"),
66
67
  def("JSXText"),
67
68
  def("Literal") // TODO Esprima should return JSXText instead.
68
69
  )], defaults.emptyArray)
@@ -93,6 +94,27 @@ module.exports = function (fork) {
93
94
  .build("name")
94
95
  .field("name", JSXElementName);
95
96
 
97
+ def("JSXFragment")
98
+ .bases("Expression")
99
+ .build("openingElement", "closingElement", "children")
100
+ .field("openingElement", def("JSXOpeningFragment"))
101
+ .field("closingElement", def("JSXClosingFragment"))
102
+ .field("children", [or(
103
+ def("JSXElement"),
104
+ def("JSXExpressionContainer"),
105
+ def("JSXFragment"),
106
+ def("JSXText"),
107
+ def("Literal") // TODO Esprima should return JSXText instead.
108
+ )], defaults.emptyArray)
109
+
110
+ def("JSXOpeningFragment")
111
+ .bases("Node") // TODO Same concern.
112
+ .build();
113
+
114
+ def("JSXClosingFragment")
115
+ .bases("Node") // TODO Same concern.
116
+ .build();
117
+
96
118
  def("JSXText")
97
119
  .bases("Literal")
98
120
  .build("value")
package/lib/scope.js CHANGED
@@ -274,6 +274,10 @@ module.exports = function (fork) {
274
274
  bindings[pattern.name] = [patternPath];
275
275
  }
276
276
 
277
+ } else if (namedTypes.AssignmentPattern &&
278
+ namedTypes.AssignmentPattern.check(pattern)) {
279
+ addPattern(patternPath.get('left'), bindings);
280
+
277
281
  } else if (namedTypes.ObjectPattern &&
278
282
  namedTypes.ObjectPattern.check(pattern)) {
279
283
  patternPath.get('properties').each(function(propertyPath) {
package/main.js CHANGED
@@ -1,17 +1,16 @@
1
1
  module.exports = require('./fork')([
2
- // This core module of AST types captures ES5 as it is parsed today by
3
- // git://github.com/ariya/esprima.git#master.
4
- require("./def/core"),
2
+ // This core module of AST types captures ES5 as it is parsed today by
3
+ // git://github.com/ariya/esprima.git#master.
4
+ require("./def/core"),
5
5
 
6
- // Feel free to add to or remove from this list of extension modules to
7
- // configure the precise type hierarchy that you need.
8
- require("./def/es6"),
9
- require("./def/es7"),
10
- require("./def/mozilla"),
11
- require("./def/e4x"),
12
- require("./def/jsx"),
13
- require("./def/flow"),
14
- require("./def/esprima"),
15
- require("./def/babel"),
16
- require("./def/babel6")
6
+ // Feel free to add to or remove from this list of extension modules to
7
+ // configure the precise type hierarchy that you need.
8
+ require("./def/es6"),
9
+ require("./def/es7"),
10
+ require("./def/mozilla"),
11
+ require("./def/e4x"),
12
+ require("./def/jsx"),
13
+ require("./def/flow"),
14
+ require("./def/esprima"),
15
+ require("./def/babel")
17
16
  ]);
package/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "transformation",
19
19
  "syntax"
20
20
  ],
21
- "version": "0.9.13",
21
+ "version": "0.10.2",
22
22
  "homepage": "http://github.com/benjamn/ast-types",
23
23
  "repository": {
24
24
  "type": "git",
@@ -32,12 +32,12 @@
32
32
  "dependencies": {},
33
33
  "devDependencies": {
34
34
  "babel-types": "^6.26.0",
35
- "babylon": "^6.16.1",
35
+ "babylon": "^7.0.0-beta.31",
36
36
  "espree": "^3.1.7",
37
37
  "esprima": "~4.0.0",
38
38
  "esprima-fb": "~14001.1.0-dev-harmony-fb",
39
- "mocha": "^3.4.2",
40
- "reify": "^0.12.0"
39
+ "mocha": "^5.0.0",
40
+ "reify": "^0.14.1"
41
41
  },
42
42
  "engines": {
43
43
  "node": ">= 0.8"
package/def/babel6.js DELETED
@@ -1,4 +0,0 @@
1
- module.exports = function (fork) {
2
- fork.use(require("./babel6-core"));
3
- fork.use(require("./flow"));
4
- };