ast-types 0.10.1 → 0.11.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 +1 -0
- package/def/babel-core.js +20 -3
- package/def/core.js +6 -4
- package/def/es6.js +36 -9
- package/def/es7.js +34 -30
- package/def/esprima.js +61 -93
- package/def/flow.js +23 -0
- package/def/jsx.js +22 -0
- package/def/typescript.js +445 -0
- package/lib/scope.js +4 -0
- package/main.js +2 -1
- package/package.json +7 -5
package/.travis.yml
CHANGED
package/def/babel-core.js
CHANGED
|
@@ -7,7 +7,7 @@ module.exports = function (fork) {
|
|
|
7
7
|
var or = types.Type.or;
|
|
8
8
|
|
|
9
9
|
def("Noop")
|
|
10
|
-
.bases("
|
|
10
|
+
.bases("Statement")
|
|
11
11
|
.build();
|
|
12
12
|
|
|
13
13
|
def("DoExpression")
|
|
@@ -136,7 +136,17 @@ module.exports = function (fork) {
|
|
|
136
136
|
def("NumericLiteral")
|
|
137
137
|
.bases("Literal")
|
|
138
138
|
.build("value")
|
|
139
|
-
.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
|
+
});
|
|
140
150
|
|
|
141
151
|
def("BigIntLiteral")
|
|
142
152
|
.bases("Literal")
|
|
@@ -177,7 +187,8 @@ module.exports = function (fork) {
|
|
|
177
187
|
def("Property"),
|
|
178
188
|
def("ObjectMethod"),
|
|
179
189
|
def("ObjectProperty"),
|
|
180
|
-
def("SpreadProperty")
|
|
190
|
+
def("SpreadProperty"),
|
|
191
|
+
def("SpreadElement")
|
|
181
192
|
);
|
|
182
193
|
|
|
183
194
|
// Split Property -> ObjectProperty and ObjectMethod
|
|
@@ -197,6 +208,9 @@ module.exports = function (fork) {
|
|
|
197
208
|
.field("computed", Boolean, defaults["false"])
|
|
198
209
|
.field("generator", Boolean, defaults["false"])
|
|
199
210
|
.field("async", Boolean, defaults["false"])
|
|
211
|
+
.field("accessibility", // TypeScript
|
|
212
|
+
or(def("Literal"), null),
|
|
213
|
+
defaults["null"])
|
|
200
214
|
.field("decorators",
|
|
201
215
|
or([def("Decorator")], null),
|
|
202
216
|
defaults["null"]);
|
|
@@ -206,6 +220,9 @@ module.exports = function (fork) {
|
|
|
206
220
|
.build("key", "value")
|
|
207
221
|
.field("key", or(def("Literal"), def("Identifier"), def("Expression")))
|
|
208
222
|
.field("value", or(def("Expression"), def("Pattern")))
|
|
223
|
+
.field("accessibility", // TypeScript
|
|
224
|
+
or(def("Literal"), null),
|
|
225
|
+
defaults["null"])
|
|
209
226
|
.field("computed", Boolean, defaults["false"]);
|
|
210
227
|
|
|
211
228
|
var ClassBodyElement = or(
|
package/def/core.js
CHANGED
|
@@ -131,7 +131,8 @@ module.exports = function (fork) {
|
|
|
131
131
|
def("CatchClause")
|
|
132
132
|
.bases("Node")
|
|
133
133
|
.build("param", "guard", "body")
|
|
134
|
-
.
|
|
134
|
+
// https://github.com/tc39/proposal-optional-catch-binding
|
|
135
|
+
.field("param", or(def("Pattern"), null), defaults["null"])
|
|
135
136
|
.field("guard", or(def("Expression"), null), defaults["null"])
|
|
136
137
|
.field("body", def("BlockStatement"));
|
|
137
138
|
|
|
@@ -237,7 +238,7 @@ module.exports = function (fork) {
|
|
|
237
238
|
"==", "!=", "===", "!==",
|
|
238
239
|
"<", "<=", ">", ">=",
|
|
239
240
|
"<<", ">>", ">>>",
|
|
240
|
-
"+", "-", "*", "/", "%",
|
|
241
|
+
"+", "-", "*", "/", "%", "**",
|
|
241
242
|
"&", // TODO Missing from the Parser API.
|
|
242
243
|
"|", "^", "in",
|
|
243
244
|
"instanceof", "..");
|
|
@@ -329,7 +330,8 @@ module.exports = function (fork) {
|
|
|
329
330
|
// But aren't Expressions and Patterns already Nodes? TODO Report this.
|
|
330
331
|
.bases("Node", "Expression", "Pattern")
|
|
331
332
|
.build("name")
|
|
332
|
-
.field("name", String)
|
|
333
|
+
.field("name", String)
|
|
334
|
+
.field("optional", Boolean, defaults["false"]);
|
|
333
335
|
|
|
334
336
|
def("Literal")
|
|
335
337
|
// But aren't Expressions already Nodes? TODO Report this.
|
|
@@ -367,4 +369,4 @@ module.exports = function (fork) {
|
|
|
367
369
|
// e.g. { /*dangling*/ }.
|
|
368
370
|
.field("leading", Boolean, defaults["true"])
|
|
369
371
|
.field("trailing", Boolean, defaults["false"]);
|
|
370
|
-
};
|
|
372
|
+
};
|
package/def/es6.js
CHANGED
|
@@ -16,7 +16,9 @@ module.exports = function (fork) {
|
|
|
16
16
|
def("RestElement")
|
|
17
17
|
.bases("Pattern")
|
|
18
18
|
.build("argument")
|
|
19
|
-
.field("argument", def("Pattern"))
|
|
19
|
+
.field("argument", def("Pattern"))
|
|
20
|
+
.field("typeAnnotation", // for Babylon. Flow parser puts it on the identifier
|
|
21
|
+
or(def("TypeAnnotation"), def("TSTypeAnnotation"), null), defaults["null"]);
|
|
20
22
|
|
|
21
23
|
def("SpreadElementPattern")
|
|
22
24
|
.bases("Pattern")
|
|
@@ -107,7 +109,7 @@ module.exports = function (fork) {
|
|
|
107
109
|
.bases("Declaration")
|
|
108
110
|
.build("kind", "key", "value", "static")
|
|
109
111
|
.field("kind", or("constructor", "method", "get", "set"))
|
|
110
|
-
.field("key",
|
|
112
|
+
.field("key", def("Expression"))
|
|
111
113
|
.field("value", def("Function"))
|
|
112
114
|
.field("computed", Boolean, defaults["false"])
|
|
113
115
|
.field("static", Boolean, defaults["false"]);
|
|
@@ -179,13 +181,6 @@ module.exports = function (fork) {
|
|
|
179
181
|
.build("id", "body", "superClass")
|
|
180
182
|
.field("id", or(def("Identifier"), null), defaults["null"])
|
|
181
183
|
.field("body", def("ClassBody"))
|
|
182
|
-
.field("superClass", or(def("Expression"), null), defaults["null"])
|
|
183
|
-
.field("implements", [def("ClassImplements")], defaults.emptyArray);
|
|
184
|
-
|
|
185
|
-
def("ClassImplements")
|
|
186
|
-
.bases("Node")
|
|
187
|
-
.build("id")
|
|
188
|
-
.field("id", def("Identifier"))
|
|
189
184
|
.field("superClass", or(def("Expression"), null), defaults["null"]);
|
|
190
185
|
|
|
191
186
|
// Specifier and ModuleSpecifier are abstract non-standard types
|
|
@@ -208,6 +203,38 @@ module.exports = function (fork) {
|
|
|
208
203
|
.field("id", or(def("Identifier"), null), defaults["null"])
|
|
209
204
|
.field("name", or(def("Identifier"), null), defaults["null"]);
|
|
210
205
|
|
|
206
|
+
// Like ModuleSpecifier, except type:"ImportSpecifier" and buildable.
|
|
207
|
+
// import {<id [as name]>} from ...;
|
|
208
|
+
def("ImportSpecifier")
|
|
209
|
+
.bases("ModuleSpecifier")
|
|
210
|
+
.build("id", "name");
|
|
211
|
+
|
|
212
|
+
// import <* as id> from ...;
|
|
213
|
+
def("ImportNamespaceSpecifier")
|
|
214
|
+
.bases("ModuleSpecifier")
|
|
215
|
+
.build("id");
|
|
216
|
+
|
|
217
|
+
// import <id> from ...;
|
|
218
|
+
def("ImportDefaultSpecifier")
|
|
219
|
+
.bases("ModuleSpecifier")
|
|
220
|
+
.build("id");
|
|
221
|
+
|
|
222
|
+
def("ImportDeclaration")
|
|
223
|
+
.bases("Declaration")
|
|
224
|
+
.build("specifiers", "source", "importKind")
|
|
225
|
+
.field("specifiers", [or(
|
|
226
|
+
def("ImportSpecifier"),
|
|
227
|
+
def("ImportNamespaceSpecifier"),
|
|
228
|
+
def("ImportDefaultSpecifier")
|
|
229
|
+
)], defaults.emptyArray)
|
|
230
|
+
.field("source", def("Literal"))
|
|
231
|
+
.field("importKind", or(
|
|
232
|
+
"value",
|
|
233
|
+
"type"
|
|
234
|
+
), function() {
|
|
235
|
+
return "value";
|
|
236
|
+
});
|
|
237
|
+
|
|
211
238
|
def("TaggedTemplateExpression")
|
|
212
239
|
.bases("Expression")
|
|
213
240
|
.build("tag", "quasi")
|
package/def/es7.js
CHANGED
|
@@ -1,38 +1,42 @@
|
|
|
1
1
|
module.exports = function (fork) {
|
|
2
|
-
|
|
2
|
+
fork.use(require('./es6'));
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
var types = fork.use(require("../lib/types"));
|
|
5
|
+
var def = types.Type.def;
|
|
6
|
+
var or = types.Type.or;
|
|
7
|
+
var builtin = types.builtInTypes;
|
|
8
|
+
var defaults = fork.use(require("../lib/shared")).defaults;
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
def("Function")
|
|
11
|
+
.field("async", Boolean, defaults["false"]);
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
def("SpreadProperty")
|
|
14
|
+
.bases("Node")
|
|
15
|
+
.build("argument")
|
|
16
|
+
.field("argument", def("Expression"));
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
def("ObjectExpression")
|
|
19
|
+
.field("properties", [or(
|
|
20
|
+
def("Property"),
|
|
21
|
+
def("SpreadProperty"),
|
|
22
|
+
def("SpreadElement")
|
|
23
|
+
)]);
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
def("SpreadPropertyPattern")
|
|
26
|
+
.bases("Pattern")
|
|
27
|
+
.build("argument")
|
|
28
|
+
.field("argument", def("Pattern"));
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
def("ObjectPattern")
|
|
31
|
+
.field("properties", [or(
|
|
32
|
+
def("Property"),
|
|
33
|
+
def("PropertyPattern"),
|
|
34
|
+
def("SpreadPropertyPattern")
|
|
35
|
+
)]);
|
|
32
36
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
37
|
+
def("AwaitExpression")
|
|
38
|
+
.bases("Expression")
|
|
39
|
+
.build("argument", "all")
|
|
40
|
+
.field("argument", or(def("Expression"), null))
|
|
41
|
+
.field("all", Boolean, defaults["false"]);
|
|
42
|
+
};
|
package/def/esprima.js
CHANGED
|
@@ -1,104 +1,72 @@
|
|
|
1
1
|
module.exports = function (fork) {
|
|
2
|
-
|
|
2
|
+
fork.use(require("./es7"));
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
def("VariableDeclaration")
|
|
10
|
+
.field("declarations", [or(
|
|
11
|
+
def("VariableDeclarator"),
|
|
12
|
+
def("Identifier") // Esprima deviation.
|
|
13
|
+
)]);
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
def("Property")
|
|
16
|
+
.field("value", or(
|
|
17
|
+
def("Expression"),
|
|
18
|
+
def("Pattern") // Esprima deviation.
|
|
19
|
+
));
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
def("ArrayPattern")
|
|
22
|
+
.field("elements", [or(
|
|
23
|
+
def("Pattern"),
|
|
24
|
+
def("SpreadElement"),
|
|
25
|
+
null
|
|
26
|
+
)]);
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
def("ObjectPattern")
|
|
29
|
+
.field("properties", [or(
|
|
30
|
+
def("Property"),
|
|
31
|
+
def("PropertyPattern"),
|
|
32
|
+
def("SpreadPropertyPattern"),
|
|
33
|
+
def("SpreadProperty") // Used by Esprima.
|
|
34
|
+
)]);
|
|
35
35
|
|
|
36
|
-
// Like ModuleSpecifier, except type:"ExportSpecifier" and buildable.
|
|
37
|
-
// export {<id [as name]>} [from ...];
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
// Like ModuleSpecifier, except type:"ExportSpecifier" and buildable.
|
|
37
|
+
// export {<id [as name]>} [from ...];
|
|
38
|
+
def("ExportSpecifier")
|
|
39
|
+
.bases("ModuleSpecifier")
|
|
40
|
+
.build("id", "name");
|
|
41
41
|
|
|
42
|
-
// export <*> from ...;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
// export <*> from ...;
|
|
43
|
+
def("ExportBatchSpecifier")
|
|
44
|
+
.bases("Specifier")
|
|
45
|
+
.build();
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
def("ExportDeclaration")
|
|
48
|
+
.bases("Declaration")
|
|
49
|
+
.build("default", "declaration", "specifiers", "source")
|
|
50
|
+
.field("default", Boolean)
|
|
51
|
+
.field("declaration", or(
|
|
52
|
+
def("Declaration"),
|
|
53
|
+
def("Expression"), // Implies default.
|
|
54
|
+
null
|
|
55
|
+
))
|
|
56
|
+
.field("specifiers", [or(
|
|
57
|
+
def("ExportSpecifier"),
|
|
58
|
+
def("ExportBatchSpecifier")
|
|
59
|
+
)], defaults.emptyArray)
|
|
60
|
+
.field("source", or(
|
|
61
|
+
def("Literal"),
|
|
62
|
+
null
|
|
63
|
+
), defaults["null"]);
|
|
52
64
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
.build("id");
|
|
65
|
+
def("Block")
|
|
66
|
+
.bases("Comment")
|
|
67
|
+
.build("value", /*optional:*/ "leading", "trailing");
|
|
57
68
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
def("ExportDeclaration")
|
|
64
|
-
.bases("Declaration")
|
|
65
|
-
.build("default", "declaration", "specifiers", "source")
|
|
66
|
-
.field("default", Boolean)
|
|
67
|
-
.field("declaration", or(
|
|
68
|
-
def("Declaration"),
|
|
69
|
-
def("Expression"), // Implies default.
|
|
70
|
-
null
|
|
71
|
-
))
|
|
72
|
-
.field("specifiers", [or(
|
|
73
|
-
def("ExportSpecifier"),
|
|
74
|
-
def("ExportBatchSpecifier")
|
|
75
|
-
)], defaults.emptyArray)
|
|
76
|
-
.field("source", or(
|
|
77
|
-
def("Literal"),
|
|
78
|
-
null
|
|
79
|
-
), defaults["null"]);
|
|
80
|
-
|
|
81
|
-
def("ImportDeclaration")
|
|
82
|
-
.bases("Declaration")
|
|
83
|
-
.build("specifiers", "source", "importKind")
|
|
84
|
-
.field("specifiers", [or(
|
|
85
|
-
def("ImportSpecifier"),
|
|
86
|
-
def("ImportNamespaceSpecifier"),
|
|
87
|
-
def("ImportDefaultSpecifier")
|
|
88
|
-
)], defaults.emptyArray)
|
|
89
|
-
.field("source", def("Literal"))
|
|
90
|
-
.field("importKind", or(
|
|
91
|
-
"value",
|
|
92
|
-
"type"
|
|
93
|
-
), function() {
|
|
94
|
-
return "value";
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
def("Block")
|
|
98
|
-
.bases("Comment")
|
|
99
|
-
.build("value", /*optional:*/ "leading", "trailing");
|
|
100
|
-
|
|
101
|
-
def("Line")
|
|
102
|
-
.bases("Comment")
|
|
103
|
-
.build("value", /*optional:*/ "leading", "trailing");
|
|
104
|
-
};
|
|
69
|
+
def("Line")
|
|
70
|
+
.bases("Comment")
|
|
71
|
+
.build("value", /*optional:*/ "leading", "trailing");
|
|
72
|
+
};
|
package/def/flow.js
CHANGED
|
@@ -242,11 +242,34 @@ module.exports = function (fork) {
|
|
|
242
242
|
.field("static", Boolean, defaults["false"])
|
|
243
243
|
.field("variance", LegacyVariance, defaults["null"]);
|
|
244
244
|
|
|
245
|
+
["ClassDeclaration",
|
|
246
|
+
"ClassExpression",
|
|
247
|
+
].forEach(typeName => {
|
|
248
|
+
def(typeName)
|
|
249
|
+
.field("typeParameters",
|
|
250
|
+
or(def("TypeParameterDeclaration"), null),
|
|
251
|
+
defaults["null"])
|
|
252
|
+
.field("superTypeParameters",
|
|
253
|
+
or([def("GenericTypeAnnotation")], null),
|
|
254
|
+
defaults["null"]);
|
|
255
|
+
});
|
|
256
|
+
|
|
245
257
|
def("ClassImplements")
|
|
258
|
+
.bases("Node")
|
|
259
|
+
.build("id")
|
|
260
|
+
.field("id", def("Identifier"))
|
|
261
|
+
.field("superClass", or(def("Expression"), null), defaults["null"])
|
|
246
262
|
.field("typeParameters",
|
|
247
263
|
or(def("TypeParameterInstantiation"), null),
|
|
248
264
|
defaults["null"]);
|
|
249
265
|
|
|
266
|
+
["ClassDeclaration",
|
|
267
|
+
"ClassExpression",
|
|
268
|
+
].forEach(typeName => {
|
|
269
|
+
def(typeName)
|
|
270
|
+
.field("implements", [def("ClassImplements")], defaults.emptyArray);
|
|
271
|
+
});
|
|
272
|
+
|
|
250
273
|
def("InterfaceDeclaration")
|
|
251
274
|
.bases("Declaration")
|
|
252
275
|
.build("id", "body", "extends")
|
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")
|
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
module.exports = function (fork) {
|
|
2
|
+
// Since TypeScript is parsed by Babylon, include the core Babylon types
|
|
3
|
+
// but omit the Flow-related types.
|
|
4
|
+
fork.use(require("./babel-core"));
|
|
5
|
+
|
|
6
|
+
var types = fork.use(require("../lib/types"));
|
|
7
|
+
var n = types.namedTypes;
|
|
8
|
+
var def = types.Type.def;
|
|
9
|
+
var or = types.Type.or;
|
|
10
|
+
var defaults = fork.use(require("../lib/shared")).defaults;
|
|
11
|
+
var StringLiteral = new types.Type(function (value, deep) {
|
|
12
|
+
if (n.StringLiteral &&
|
|
13
|
+
n.StringLiteral.check(value, deep)) {
|
|
14
|
+
return true
|
|
15
|
+
}
|
|
16
|
+
if (n.Literal &&
|
|
17
|
+
n.Literal.check(value, deep) &&
|
|
18
|
+
typeof value.value === "string") {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}, "StringLiteral");
|
|
23
|
+
|
|
24
|
+
def("TSType")
|
|
25
|
+
.bases("Node");
|
|
26
|
+
|
|
27
|
+
var IdOrQualifiedName = or(
|
|
28
|
+
def("Identifier"),
|
|
29
|
+
def("TSQualifiedName")
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
def("TSTypeReference")
|
|
33
|
+
.bases("TSType")
|
|
34
|
+
.field("typeName", IdOrQualifiedName)
|
|
35
|
+
.field("typeParameters",
|
|
36
|
+
or(def("TSTypeParameterInstantiation"), null),
|
|
37
|
+
defaults["null"]);
|
|
38
|
+
|
|
39
|
+
// An abstract (non-buildable) base type that provide a commonly-needed
|
|
40
|
+
// optional .typeParameters field.
|
|
41
|
+
def("TSHasOptionalTypeParameters")
|
|
42
|
+
.field("typeParameters",
|
|
43
|
+
or(def("TSTypeParameterDeclaration"), null),
|
|
44
|
+
defaults["null"]);
|
|
45
|
+
|
|
46
|
+
// An abstract (non-buildable) base type that provide a commonly-needed
|
|
47
|
+
// optional .typeAnnotation field.
|
|
48
|
+
def("TSHasOptionalTypeAnnotation")
|
|
49
|
+
.field("typeAnnotation",
|
|
50
|
+
or(def("TSTypeAnnotation"), null),
|
|
51
|
+
defaults["null"]);
|
|
52
|
+
|
|
53
|
+
def("TSQualifiedName")
|
|
54
|
+
.bases("Node")
|
|
55
|
+
.build("left", "right")
|
|
56
|
+
.field("left", IdOrQualifiedName)
|
|
57
|
+
.field("right", IdOrQualifiedName);
|
|
58
|
+
|
|
59
|
+
def("TSAsExpression")
|
|
60
|
+
.bases("Expression")
|
|
61
|
+
.build("expression")
|
|
62
|
+
.field("expression", def("Expression"))
|
|
63
|
+
.field("typeAnnotation", def("TSType"))
|
|
64
|
+
.field("extra",
|
|
65
|
+
or({ parenthesized: Boolean }, null),
|
|
66
|
+
defaults["null"]);
|
|
67
|
+
|
|
68
|
+
def("TSNonNullExpression")
|
|
69
|
+
.bases("Expression")
|
|
70
|
+
.build("expression")
|
|
71
|
+
.field("expression", def("Expression"));
|
|
72
|
+
|
|
73
|
+
[ // Define all the simple keyword types.
|
|
74
|
+
"TSAnyKeyword",
|
|
75
|
+
"TSBooleanKeyword",
|
|
76
|
+
"TSNeverKeyword",
|
|
77
|
+
"TSNullKeyword",
|
|
78
|
+
"TSNumberKeyword",
|
|
79
|
+
"TSObjectKeyword",
|
|
80
|
+
"TSStringKeyword",
|
|
81
|
+
"TSSymbolKeyword",
|
|
82
|
+
"TSUndefinedKeyword",
|
|
83
|
+
"TSVoidKeyword",
|
|
84
|
+
"TSThisType",
|
|
85
|
+
].forEach(keywordType => {
|
|
86
|
+
def(keywordType)
|
|
87
|
+
.bases("TSType")
|
|
88
|
+
.build();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
def("TSArrayType")
|
|
92
|
+
.bases("TSType")
|
|
93
|
+
.build("elementType")
|
|
94
|
+
.field("elementType", def("TSType"))
|
|
95
|
+
|
|
96
|
+
def("TSLiteralType")
|
|
97
|
+
.bases("TSType")
|
|
98
|
+
.build("literal")
|
|
99
|
+
.field("literal",
|
|
100
|
+
or(def("NumericLiteral"),
|
|
101
|
+
def("StringLiteral"),
|
|
102
|
+
def("BooleanLiteral")));
|
|
103
|
+
|
|
104
|
+
["TSUnionType",
|
|
105
|
+
"TSIntersectionType",
|
|
106
|
+
].forEach(typeName => {
|
|
107
|
+
def(typeName)
|
|
108
|
+
.bases("TSType")
|
|
109
|
+
.build("types")
|
|
110
|
+
.field("types", [def("TSType")]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
def("TSConditionalType")
|
|
114
|
+
.bases("TSType")
|
|
115
|
+
.build("checkType", "extendsType", "trueType", "falseType")
|
|
116
|
+
.field("checkType", def("TSType"))
|
|
117
|
+
.field("extendsType", def("TSType"))
|
|
118
|
+
.field("trueType", def("TSType"))
|
|
119
|
+
.field("falseType", def("TSType"));
|
|
120
|
+
|
|
121
|
+
def("TSInferType")
|
|
122
|
+
.bases("TSType")
|
|
123
|
+
.build("typeParameter")
|
|
124
|
+
.field("typeParameter", def("TSType"));
|
|
125
|
+
|
|
126
|
+
def("TSParenthesizedType")
|
|
127
|
+
.bases("TSType")
|
|
128
|
+
.build("typeAnnotation")
|
|
129
|
+
.field("typeAnnotation", def("TSType"));
|
|
130
|
+
|
|
131
|
+
var ParametersType = [or(
|
|
132
|
+
def("Identifier"),
|
|
133
|
+
def("RestElement")
|
|
134
|
+
)];
|
|
135
|
+
|
|
136
|
+
["TSFunctionType",
|
|
137
|
+
"TSConstructorType",
|
|
138
|
+
].forEach(typeName => {
|
|
139
|
+
def(typeName)
|
|
140
|
+
.bases("TSType",
|
|
141
|
+
"TSHasOptionalTypeParameters",
|
|
142
|
+
"TSHasOptionalTypeAnnotation")
|
|
143
|
+
.build("parameters")
|
|
144
|
+
.field("parameters", ParametersType);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
def("TSDeclareFunction")
|
|
148
|
+
.bases("Declaration", "TSHasOptionalTypeParameters")
|
|
149
|
+
.build("id", "params", "returnType")
|
|
150
|
+
.field("declare", Boolean, defaults["false"])
|
|
151
|
+
.field("async", Boolean, defaults["false"])
|
|
152
|
+
.field("generator", Boolean, defaults["false"])
|
|
153
|
+
.field("id", or(def("Identifier"), null), defaults["null"])
|
|
154
|
+
.field("params", [def("Pattern")])
|
|
155
|
+
// tSFunctionTypeAnnotationCommon
|
|
156
|
+
.field("returnType",
|
|
157
|
+
or(def("TSTypeAnnotation"),
|
|
158
|
+
def("Noop"), // Still used?
|
|
159
|
+
null),
|
|
160
|
+
defaults["null"]);
|
|
161
|
+
|
|
162
|
+
def("TSDeclareMethod")
|
|
163
|
+
.bases("Declaration", "TSHasOptionalTypeParameters")
|
|
164
|
+
.build("key", "params", "returnType")
|
|
165
|
+
.field("async", Boolean, defaults["false"])
|
|
166
|
+
.field("generator", Boolean, defaults["false"])
|
|
167
|
+
.field("params", [def("Pattern")])
|
|
168
|
+
// classMethodOrPropertyCommon
|
|
169
|
+
.field("abstract", Boolean, defaults["false"])
|
|
170
|
+
.field("accessibility",
|
|
171
|
+
or("public", "private", "protected", void 0),
|
|
172
|
+
defaults["undefined"])
|
|
173
|
+
.field("static", Boolean, defaults["false"])
|
|
174
|
+
.field("computed", Boolean, defaults["false"])
|
|
175
|
+
.field("optional", Boolean, defaults["false"])
|
|
176
|
+
.field("key", or(
|
|
177
|
+
def("Identifier"),
|
|
178
|
+
def("StringLiteral"),
|
|
179
|
+
def("NumericLiteral"),
|
|
180
|
+
// Only allowed if .computed is true.
|
|
181
|
+
def("Expression")
|
|
182
|
+
))
|
|
183
|
+
// classMethodOrDeclareMethodCommon
|
|
184
|
+
.field("kind",
|
|
185
|
+
or("get", "set", "method", "constructor"),
|
|
186
|
+
function getDefault() { return "method"; })
|
|
187
|
+
.field("access", // Not "accessibility"?
|
|
188
|
+
or("public", "private", "protected", void 0),
|
|
189
|
+
defaults["undefined"])
|
|
190
|
+
.field("decorators",
|
|
191
|
+
or([def("Decorator")], null),
|
|
192
|
+
defaults["null"])
|
|
193
|
+
// tSFunctionTypeAnnotationCommon
|
|
194
|
+
.field("returnType",
|
|
195
|
+
or(def("TSTypeAnnotation"),
|
|
196
|
+
def("Noop"), // Still used?
|
|
197
|
+
null),
|
|
198
|
+
defaults["null"]);
|
|
199
|
+
|
|
200
|
+
def("TSMappedType")
|
|
201
|
+
.bases("TSType")
|
|
202
|
+
.build("typeParameter", "typeAnnotation")
|
|
203
|
+
.field("readonly", Boolean, defaults["false"])
|
|
204
|
+
.field("typeParameter", def("TSTypeParameter"))
|
|
205
|
+
.field("optional", Boolean, defaults["false"])
|
|
206
|
+
.field("typeAnnotation",
|
|
207
|
+
or(def("TSType"), null),
|
|
208
|
+
defaults["null"]);
|
|
209
|
+
|
|
210
|
+
def("TSTupleType")
|
|
211
|
+
.bases("TSType")
|
|
212
|
+
.build("elementTypes")
|
|
213
|
+
.field("elementTypes", [def("TSType")]);
|
|
214
|
+
|
|
215
|
+
def("TSIndexedAccessType")
|
|
216
|
+
.bases("TSType")
|
|
217
|
+
.build("objectType", "indexType")
|
|
218
|
+
.field("objectType", def("TSType"))
|
|
219
|
+
.field("indexType", def("TSType"))
|
|
220
|
+
|
|
221
|
+
def("TSTypeOperator")
|
|
222
|
+
.bases("TSType")
|
|
223
|
+
.build("operator")
|
|
224
|
+
.field("operator", String)
|
|
225
|
+
.field("typeAnnotation", def("TSType"));
|
|
226
|
+
|
|
227
|
+
def("TSTypeAnnotation")
|
|
228
|
+
.bases("Node")
|
|
229
|
+
.build("typeAnnotation")
|
|
230
|
+
.field("typeAnnotation",
|
|
231
|
+
or(def("TSType"),
|
|
232
|
+
def("TSTypeAnnotation")));
|
|
233
|
+
|
|
234
|
+
def("TSIndexSignature")
|
|
235
|
+
.bases("Declaration", "TSHasOptionalTypeAnnotation")
|
|
236
|
+
.build("parameters")
|
|
237
|
+
.field("parameters", [def("Identifier")]) // Length === 1
|
|
238
|
+
.field("readonly", Boolean, defaults["false"]);
|
|
239
|
+
|
|
240
|
+
def("TSPropertySignature")
|
|
241
|
+
.bases("Declaration", "TSHasOptionalTypeAnnotation")
|
|
242
|
+
.build("key")
|
|
243
|
+
.field("key", def("Expression"))
|
|
244
|
+
.field("computed", Boolean, defaults["false"])
|
|
245
|
+
.field("readonly", Boolean, defaults["false"])
|
|
246
|
+
.field("optional", Boolean, defaults["false"])
|
|
247
|
+
.field("initializer",
|
|
248
|
+
or(def("Expression"), null),
|
|
249
|
+
defaults["null"]);
|
|
250
|
+
|
|
251
|
+
def("TSMethodSignature")
|
|
252
|
+
.bases("Declaration",
|
|
253
|
+
"TSHasOptionalTypeParameters",
|
|
254
|
+
"TSHasOptionalTypeAnnotation")
|
|
255
|
+
.build("key")
|
|
256
|
+
.field("key", def("Expression"))
|
|
257
|
+
.field("computed", Boolean, defaults["false"])
|
|
258
|
+
.field("optional", Boolean, defaults["false"])
|
|
259
|
+
.field("parameters", ParametersType);
|
|
260
|
+
|
|
261
|
+
def("TSTypePredicate")
|
|
262
|
+
.bases("TSTypeAnnotation")
|
|
263
|
+
.build("parameterName", "typeAnnotation")
|
|
264
|
+
.field("parameterName",
|
|
265
|
+
or(def("Identifier"),
|
|
266
|
+
def("TSThisType")))
|
|
267
|
+
.field("typeAnnotation", def("TSTypeAnnotation"));
|
|
268
|
+
|
|
269
|
+
["TSCallSignatureDeclaration",
|
|
270
|
+
"TSConstructSignatureDeclaration",
|
|
271
|
+
].forEach(typeName => {
|
|
272
|
+
def(typeName)
|
|
273
|
+
.bases("Declaration",
|
|
274
|
+
"TSHasOptionalTypeParameters",
|
|
275
|
+
"TSHasOptionalTypeAnnotation")
|
|
276
|
+
.build("parameters")
|
|
277
|
+
.field("parameters", ParametersType);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
def("TSEnumMember")
|
|
281
|
+
.bases("Node")
|
|
282
|
+
.build("id", "initializer")
|
|
283
|
+
.field("id", or(def("Identifier"), StringLiteral))
|
|
284
|
+
.field("initializer",
|
|
285
|
+
or(def("Expression"), null),
|
|
286
|
+
defaults["null"]);
|
|
287
|
+
|
|
288
|
+
def("TSTypeQuery")
|
|
289
|
+
.bases("TSType")
|
|
290
|
+
.build("exprName")
|
|
291
|
+
.field("exprName", def("Identifier"));
|
|
292
|
+
|
|
293
|
+
// Inferred from Babylon's tsParseTypeMember method.
|
|
294
|
+
var TSTypeMember = or(
|
|
295
|
+
def("TSCallSignatureDeclaration"),
|
|
296
|
+
def("TSConstructSignatureDeclaration"),
|
|
297
|
+
def("TSIndexSignature"),
|
|
298
|
+
def("TSMethodSignature"),
|
|
299
|
+
def("TSPropertySignature")
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
def("TSTypeLiteral")
|
|
303
|
+
.bases("TSType")
|
|
304
|
+
.build("members")
|
|
305
|
+
.field("members", [TSTypeMember]);
|
|
306
|
+
|
|
307
|
+
def("TSTypeParameter")
|
|
308
|
+
.bases("Identifier")
|
|
309
|
+
.field("name", String)
|
|
310
|
+
.field("constraint", or(def("TSType"), null), defaults["null"])
|
|
311
|
+
.field("default", or(def("TSType"), null), defaults["null"]);
|
|
312
|
+
|
|
313
|
+
def("TSTypeAssertion")
|
|
314
|
+
.bases("Expression")
|
|
315
|
+
.build("typeAnnotation", "expression")
|
|
316
|
+
.field("typeAnnotation", def("TSType"))
|
|
317
|
+
.field("expression", def("Expression"))
|
|
318
|
+
.field("extra",
|
|
319
|
+
or({ parenthesized: Boolean }, null),
|
|
320
|
+
defaults["null"]);
|
|
321
|
+
|
|
322
|
+
def("TSTypeParameterDeclaration")
|
|
323
|
+
.bases("Declaration")
|
|
324
|
+
.build("params")
|
|
325
|
+
.field("params", [def("TSTypeParameter")]);
|
|
326
|
+
|
|
327
|
+
def("TSTypeParameterInstantiation")
|
|
328
|
+
.bases("Node")
|
|
329
|
+
.build("params")
|
|
330
|
+
.field("params", [def("TSType")]);
|
|
331
|
+
|
|
332
|
+
def("TSEnumDeclaration")
|
|
333
|
+
.bases("Declaration")
|
|
334
|
+
.build("id", "members")
|
|
335
|
+
.field("id", def("Identifier"))
|
|
336
|
+
.field("const", Boolean, defaults["false"])
|
|
337
|
+
.field("declare", Boolean, defaults["false"])
|
|
338
|
+
.field("members", [def("TSEnumMember")])
|
|
339
|
+
.field("initializer",
|
|
340
|
+
or(def("Expression"), null),
|
|
341
|
+
defaults["null"]);
|
|
342
|
+
|
|
343
|
+
def("TSTypeAliasDeclaration")
|
|
344
|
+
.bases("Declaration", "TSHasOptionalTypeParameters")
|
|
345
|
+
.build("id")
|
|
346
|
+
.field("id", def("Identifier"))
|
|
347
|
+
.field("declare", Boolean, defaults["false"])
|
|
348
|
+
.field("typeAnnotation", def("TSType"));
|
|
349
|
+
|
|
350
|
+
def("TSModuleBlock")
|
|
351
|
+
.bases("Node")
|
|
352
|
+
.build("body")
|
|
353
|
+
.field("body", [def("Statement")]);
|
|
354
|
+
|
|
355
|
+
def("TSModuleDeclaration")
|
|
356
|
+
.bases("Declaration")
|
|
357
|
+
.build("id", "body")
|
|
358
|
+
.field("id", or(StringLiteral, IdOrQualifiedName))
|
|
359
|
+
.field("declare", Boolean, defaults["false"])
|
|
360
|
+
.field("global", Boolean, defaults["false"])
|
|
361
|
+
.field("body",
|
|
362
|
+
or(def("TSModuleBlock"),
|
|
363
|
+
def("TSModuleDeclaration"),
|
|
364
|
+
null),
|
|
365
|
+
defaults["null"]);
|
|
366
|
+
|
|
367
|
+
def("TSImportEqualsDeclaration")
|
|
368
|
+
.bases("Declaration")
|
|
369
|
+
.build("id", "moduleReference")
|
|
370
|
+
.field("id", def("Identifier"))
|
|
371
|
+
.field("isExport", Boolean, defaults["false"])
|
|
372
|
+
.field("moduleReference",
|
|
373
|
+
or(IdOrQualifiedName,
|
|
374
|
+
def("TSExternalModuleReference")));
|
|
375
|
+
|
|
376
|
+
def("TSExternalModuleReference")
|
|
377
|
+
.bases("Declaration")
|
|
378
|
+
.build("expression")
|
|
379
|
+
.field("expression", StringLiteral);
|
|
380
|
+
|
|
381
|
+
def("TSExportAssignment")
|
|
382
|
+
.bases("Statement")
|
|
383
|
+
.build("expression")
|
|
384
|
+
.field("expression", def("Expression"));
|
|
385
|
+
|
|
386
|
+
def("TSNamespaceExportDeclaration")
|
|
387
|
+
.bases("Declaration")
|
|
388
|
+
.build("id")
|
|
389
|
+
.field("id", def("Identifier"));
|
|
390
|
+
|
|
391
|
+
def("TSInterfaceBody")
|
|
392
|
+
.bases("Node")
|
|
393
|
+
.build("body")
|
|
394
|
+
.field("body", [TSTypeMember]);
|
|
395
|
+
|
|
396
|
+
def("TSExpressionWithTypeArguments")
|
|
397
|
+
.bases("TSType")
|
|
398
|
+
.build("expression", "typeParameters")
|
|
399
|
+
.field("expression", IdOrQualifiedName)
|
|
400
|
+
.field("typeParameters",
|
|
401
|
+
or(def("TSTypeParameterInstantiation"), null),
|
|
402
|
+
defaults["null"]);
|
|
403
|
+
|
|
404
|
+
def("TSInterfaceDeclaration")
|
|
405
|
+
.bases("Declaration", "TSHasOptionalTypeParameters")
|
|
406
|
+
.build("id", "body")
|
|
407
|
+
.field("id", IdOrQualifiedName)
|
|
408
|
+
.field("declare", Boolean, defaults["false"])
|
|
409
|
+
.field("extends",
|
|
410
|
+
or([def("TSExpressionWithTypeArguments")], null),
|
|
411
|
+
defaults["null"])
|
|
412
|
+
.field("body", def("TSInterfaceBody"));
|
|
413
|
+
|
|
414
|
+
["ClassDeclaration",
|
|
415
|
+
"ClassExpression",
|
|
416
|
+
].forEach(typeName => {
|
|
417
|
+
def(typeName)
|
|
418
|
+
.field("implements",
|
|
419
|
+
[def("TSExpressionWithTypeArguments")],
|
|
420
|
+
defaults.emptyArray);
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
def("TSParameterProperty")
|
|
424
|
+
.bases("Pattern")
|
|
425
|
+
.build("parameter")
|
|
426
|
+
.field("accessibility",
|
|
427
|
+
or("public", "private", "protected", void 0),
|
|
428
|
+
defaults["undefined"])
|
|
429
|
+
.field("readonly", Boolean, defaults["false"])
|
|
430
|
+
.field("parameter", or(def("Identifier"),
|
|
431
|
+
def("AssignmentPattern")));
|
|
432
|
+
|
|
433
|
+
// Defined already in es6 and babel-core.
|
|
434
|
+
def("ClassBody")
|
|
435
|
+
.field("body", [or(
|
|
436
|
+
def("MethodDefinition"),
|
|
437
|
+
def("VariableDeclarator"),
|
|
438
|
+
def("ClassPropertyDefinition"),
|
|
439
|
+
def("ClassProperty"),
|
|
440
|
+
def("ClassMethod"),
|
|
441
|
+
// Just need to add these types:
|
|
442
|
+
def("TSDeclareMethod"),
|
|
443
|
+
TSTypeMember
|
|
444
|
+
)]);
|
|
445
|
+
};
|
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
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"transformation",
|
|
19
19
|
"syntax"
|
|
20
20
|
],
|
|
21
|
-
"version": "0.
|
|
21
|
+
"version": "0.11.2",
|
|
22
22
|
"homepage": "http://github.com/benjamn/ast-types",
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|
|
@@ -27,17 +27,19 @@
|
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"main": "main.js",
|
|
29
29
|
"scripts": {
|
|
30
|
-
"test": "
|
|
30
|
+
"test": "test/run.sh"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"babel-types": "^6.26.0",
|
|
35
|
-
"babylon": "^7.0.0-beta.
|
|
35
|
+
"babylon": "^7.0.0-beta.40",
|
|
36
36
|
"espree": "^3.1.7",
|
|
37
37
|
"esprima": "~4.0.0",
|
|
38
38
|
"esprima-fb": "~14001.1.0-dev-harmony-fb",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
39
|
+
"flow-parser": "^0.66.0",
|
|
40
|
+
"glob": "^7.1.2",
|
|
41
|
+
"mocha": "^5.0.0",
|
|
42
|
+
"reify": "^0.14.1"
|
|
41
43
|
},
|
|
42
44
|
"engines": {
|
|
43
45
|
"node": ">= 0.8"
|