ast-types 0.11.6 → 0.11.7

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/def/es6.js CHANGED
@@ -88,6 +88,9 @@ module.exports = function (fork) {
88
88
  .field("shorthand", Boolean, defaults["false"])
89
89
  .field("computed", Boolean, defaults["false"]);
90
90
 
91
+ def("ObjectProperty")
92
+ .field("shorthand", Boolean, defaults["false"]);
93
+
91
94
  def("PropertyPattern")
92
95
  .bases("Pattern")
93
96
  .build("key", "pattern")
package/def/flow.js CHANGED
@@ -1,5 +1,6 @@
1
1
  module.exports = function (fork) {
2
2
  fork.use(require("./es7"));
3
+ fork.use(require("./type-annotations"));
3
4
 
4
5
  var types = fork.use(require("../lib/types"));
5
6
  var def = types.Type.def;
@@ -206,12 +207,6 @@ module.exports = function (fork) {
206
207
  .build("argument")
207
208
  .field("argument", def("FlowType"));
208
209
 
209
- def("Identifier")
210
- .field("typeAnnotation", or(def("TypeAnnotation"), null), defaults["null"]);
211
-
212
- def("ObjectPattern")
213
- .field("typeAnnotation", or(def("TypeAnnotation"), null), defaults["null"]);
214
-
215
210
  def("TypeParameterDeclaration")
216
211
  .bases("Node")
217
212
  .build("params")
@@ -231,33 +226,9 @@ module.exports = function (fork) {
231
226
  or(def("TypeAnnotation"), null),
232
227
  defaults["null"]);
233
228
 
234
- def("Function")
235
- .field("returnType",
236
- or(def("TypeAnnotation"), null),
237
- defaults["null"])
238
- .field("typeParameters",
239
- or(def("TypeParameterDeclaration"), null),
240
- defaults["null"]);
241
-
242
229
  def("ClassProperty")
243
- .build("key", "value", "typeAnnotation", "static")
244
- .field("value", or(def("Expression"), null))
245
- .field("typeAnnotation", or(def("TypeAnnotation"), null))
246
- .field("static", Boolean, defaults["false"])
247
230
  .field("variance", LegacyVariance, defaults["null"]);
248
231
 
249
- ["ClassDeclaration",
250
- "ClassExpression",
251
- ].forEach(typeName => {
252
- def(typeName)
253
- .field("typeParameters",
254
- or(def("TypeParameterDeclaration"), null),
255
- defaults["null"])
256
- .field("superTypeParameters",
257
- or([def("GenericTypeAnnotation")], null),
258
- defaults["null"]);
259
- });
260
-
261
232
  def("ClassImplements")
262
233
  .bases("Node")
263
234
  .build("id")
@@ -267,13 +238,6 @@ module.exports = function (fork) {
267
238
  or(def("TypeParameterInstantiation"), null),
268
239
  defaults["null"]);
269
240
 
270
- ["ClassDeclaration",
271
- "ClassExpression",
272
- ].forEach(typeName => {
273
- def(typeName)
274
- .field("implements", [def("ClassImplements")], defaults.emptyArray);
275
- });
276
-
277
241
  def("InterfaceDeclaration")
278
242
  .bases("Declaration")
279
243
  .build("id", "body", "extends")
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Type annotation defs shared between Flow and TypeScript.
3
+ * These defs could not be defined in ./flow.js or ./typescript.js directly
4
+ * because they use the same name.
5
+ */
6
+ module.exports = function (fork) {
7
+ var types = fork.use(require("../lib/types"));
8
+ var def = types.Type.def;
9
+ var or = types.Type.or;
10
+ var defaults = fork.use(require("../lib/shared")).defaults;
11
+
12
+ var TypeAnnotation = or(
13
+ def("TypeAnnotation"),
14
+ def("TSTypeAnnotation"),
15
+ null
16
+ );
17
+
18
+ var TypeParamDecl = or(
19
+ def("TypeParameterDeclaration"),
20
+ def("TSTypeParameterDeclaration"),
21
+ null
22
+ );
23
+
24
+ def("Identifier")
25
+ .field("typeAnnotation", TypeAnnotation, defaults["null"]);
26
+
27
+ def("ObjectPattern")
28
+ .field("typeAnnotation", TypeAnnotation, defaults["null"]);
29
+
30
+ def("Function")
31
+ .field("returnType", TypeAnnotation, defaults["null"])
32
+ .field("typeParameters", TypeParamDecl, defaults["null"]);
33
+
34
+ def("ClassProperty")
35
+ .build("key", "value", "typeAnnotation", "static")
36
+ .field("value", or(def("Expression"), null))
37
+ .field("static", Boolean, defaults["false"])
38
+ .field("typeAnnotation", TypeAnnotation, defaults["null"]);
39
+
40
+ ["ClassDeclaration",
41
+ "ClassExpression",
42
+ ].forEach(typeName => {
43
+ def(typeName)
44
+ .field("typeParameters", TypeParamDecl, defaults["null"])
45
+ .field("superTypeParameters",
46
+ or(def("TypeParameterInstantiation"),
47
+ def("TSTypeParameterInstantiation"),
48
+ null),
49
+ defaults["null"]);
50
+ });
51
+
52
+ ["ClassDeclaration",
53
+ "ClassExpression",
54
+ ].forEach(typeName => {
55
+ def(typeName)
56
+ .field("implements",
57
+ or([def("ClassImplements")],
58
+ [def("TSExpressionWithTypeArguments")]),
59
+ defaults.emptyArray);
60
+ });
61
+ };
package/def/typescript.js CHANGED
@@ -2,6 +2,7 @@ module.exports = function (fork) {
2
2
  // Since TypeScript is parsed by Babylon, include the core Babylon types
3
3
  // but omit the Flow-related types.
4
4
  fork.use(require("./babel-core"));
5
+ fork.use(require("./type-annotations"));
5
6
 
6
7
  var types = fork.use(require("../lib/types"));
7
8
  var n = types.namedTypes;
@@ -202,9 +203,9 @@ module.exports = function (fork) {
202
203
  def("TSMappedType")
203
204
  .bases("TSType")
204
205
  .build("typeParameter", "typeAnnotation")
205
- .field("readonly", Boolean, defaults["false"])
206
+ .field("readonly", or(Boolean, "+", "-"), defaults["false"])
206
207
  .field("typeParameter", def("TSTypeParameter"))
207
- .field("optional", Boolean, defaults["false"])
208
+ .field("optional", or(Boolean, "+", "-"), defaults["false"])
208
209
  .field("typeAnnotation",
209
210
  or(def("TSType"), null),
210
211
  defaults["null"]);
@@ -300,7 +301,7 @@ module.exports = function (fork) {
300
301
  def("TSTypeQuery")
301
302
  .bases("TSType")
302
303
  .build("exprName")
303
- .field("exprName", def("Identifier"));
304
+ .field("exprName", IdOrQualifiedName);
304
305
 
305
306
  // Inferred from Babylon's tsParseTypeMember method.
306
307
  var TSTypeMember = or(
@@ -318,6 +319,7 @@ module.exports = function (fork) {
318
319
 
319
320
  def("TSTypeParameter")
320
321
  .bases("Identifier")
322
+ .build("name", "constraint", "default")
321
323
  .field("name", String)
322
324
  .field("constraint", or(def("TSType"), null), defaults["null"])
323
325
  .field("default", or(def("TSType"), null), defaults["null"]);
@@ -423,15 +425,6 @@ module.exports = function (fork) {
423
425
  defaults["null"])
424
426
  .field("body", def("TSInterfaceBody"));
425
427
 
426
- ["ClassDeclaration",
427
- "ClassExpression",
428
- ].forEach(typeName => {
429
- def(typeName)
430
- .field("implements",
431
- [def("TSExpressionWithTypeArguments")],
432
- defaults.emptyArray);
433
- });
434
-
435
428
  def("TSParameterProperty")
436
429
  .bases("Pattern")
437
430
  .build("parameter")
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Ben Newman <bn@cs.stanford.edu>",
3
3
  "name": "ast-types",
4
- "version": "0.11.6",
4
+ "version": "0.11.7",
5
5
  "description": "Esprima-compatible implementation of the Mozilla JS Parser API",
6
6
  "keywords": [
7
7
  "ast",