ast-types 0.12.3 → 0.13.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/README.md +218 -201
- package/def/core.js +4 -7
- package/def/flow.js +4 -0
- package/def/typescript.js +5 -5
- package/fork.d.ts +3 -7
- package/fork.js +1 -2
- package/gen/builders.d.ts +500 -497
- package/gen/kinds.d.ts +262 -262
- package/gen/namedTypes.d.ts +1791 -262
- package/gen/namedTypes.js +3 -0
- package/gen/nodes.d.ts +16 -16
- package/gen/visitor.d.ts +262 -262
- package/lib/node-path.js +8 -6
- package/lib/path-visitor.d.ts +1 -1
- package/lib/scope.js +7 -2
- package/lib/types.d.ts +2 -6
- package/main.d.ts +25 -13
- package/main.js +25 -6
- package/package.json +19 -19
package/.travis.yml
CHANGED
package/README.md
CHANGED
|
@@ -24,13 +24,15 @@ From GitHub:
|
|
|
24
24
|
Basic Usage
|
|
25
25
|
---
|
|
26
26
|
```js
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
import assert from "assert";
|
|
28
|
+
import {
|
|
29
|
+
namedTypes as n,
|
|
30
|
+
builders as b,
|
|
31
|
+
} from "ast-types";
|
|
30
32
|
|
|
31
33
|
var fooId = b.identifier("foo");
|
|
32
34
|
var ifFoo = b.ifStatement(fooId, b.blockStatement([
|
|
33
|
-
|
|
35
|
+
b.expressionStatement(b.callExpression(fooId, []))
|
|
34
36
|
]));
|
|
35
37
|
|
|
36
38
|
assert.ok(n.IfStatement.check(ifFoo));
|
|
@@ -39,8 +41,9 @@ assert.ok(n.Node.check(ifFoo));
|
|
|
39
41
|
|
|
40
42
|
assert.ok(n.BlockStatement.check(ifFoo.consequent));
|
|
41
43
|
assert.strictEqual(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
ifFoo.consequent.body[0].expression.arguments.length,
|
|
45
|
+
0,
|
|
46
|
+
);
|
|
44
47
|
|
|
45
48
|
assert.strictEqual(ifFoo.test, fooId);
|
|
46
49
|
assert.ok(n.Expression.check(ifFoo.test));
|
|
@@ -59,18 +62,22 @@ of enumerating the known fields of your AST nodes and getting their
|
|
|
59
62
|
values, you may be interested in the primitives `getFieldNames` and
|
|
60
63
|
`getFieldValue`:
|
|
61
64
|
```js
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
import {
|
|
66
|
+
getFieldNames,
|
|
67
|
+
getFieldValue,
|
|
68
|
+
} from "ast-types";
|
|
69
|
+
|
|
70
|
+
const partialFunExpr = { type: "FunctionExpression" };
|
|
64
71
|
|
|
65
72
|
// Even though partialFunExpr doesn't actually contain all the fields that
|
|
66
73
|
// are expected for a FunctionExpression, types.getFieldNames knows:
|
|
67
|
-
console.log(
|
|
74
|
+
console.log(getFieldNames(partialFunExpr));
|
|
68
75
|
// [ 'type', 'id', 'params', 'body', 'generator', 'expression',
|
|
69
76
|
// 'defaults', 'rest', 'async' ]
|
|
70
77
|
|
|
71
78
|
// For fields that have default values, types.getFieldValue will return
|
|
72
79
|
// the default if the field is not actually defined.
|
|
73
|
-
console.log(
|
|
80
|
+
console.log(getFieldValue(partialFunExpr, "generator"));
|
|
74
81
|
// false
|
|
75
82
|
```
|
|
76
83
|
|
|
@@ -81,31 +88,32 @@ defined in terms of `getFieldNames` and `getFieldValue`:
|
|
|
81
88
|
// or undefined, passing each field name and effective value (as returned
|
|
82
89
|
// by getFieldValue) to the callback. If the object has no corresponding
|
|
83
90
|
// Def, the callback will never be called.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
91
|
+
export function eachField(object, callback, context) {
|
|
92
|
+
getFieldNames(object).forEach(function(name) {
|
|
93
|
+
callback.call(this, name, getFieldValue(object, name));
|
|
94
|
+
}, context);
|
|
95
|
+
}
|
|
89
96
|
|
|
90
97
|
// Similar to eachField, except that iteration stops as soon as the
|
|
91
98
|
// callback returns a truthy value. Like Array.prototype.some, the final
|
|
92
99
|
// result is either true or false to indicates whether the callback
|
|
93
100
|
// returned true for any element or not.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
101
|
+
export function someField(object, callback, context) {
|
|
102
|
+
return getFieldNames(object).some(function(name) {
|
|
103
|
+
return callback.call(this, name, getFieldValue(object, name));
|
|
104
|
+
}, context);
|
|
105
|
+
}
|
|
99
106
|
```
|
|
100
107
|
|
|
101
108
|
So here's how you might make a copy of an AST node:
|
|
102
109
|
```js
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
import { eachField } from "ast-types";
|
|
111
|
+
const copy = {};
|
|
112
|
+
eachField(node, function(name, value) {
|
|
113
|
+
// Note that undefined fields will be visited too, according to
|
|
114
|
+
// the rules associated with node.type, and default field values
|
|
115
|
+
// will be substituted if appropriate.
|
|
116
|
+
copy[name] = value;
|
|
109
117
|
})
|
|
110
118
|
```
|
|
111
119
|
|
|
@@ -115,30 +123,34 @@ the powerful `types.visit` abstraction.
|
|
|
115
123
|
Here's a trivial example of how you might assert that `arguments.callee`
|
|
116
124
|
is never used in `ast`:
|
|
117
125
|
```js
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
types
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
// method) before the visitor method returns, or return false to
|
|
138
|
-
// indicate that the traversal need not continue any further down
|
|
139
|
-
// this subtree.
|
|
140
|
-
this.traverse(path);
|
|
126
|
+
import assert from "assert";
|
|
127
|
+
import {
|
|
128
|
+
visit,
|
|
129
|
+
namedTypes as n,
|
|
130
|
+
} from "ast-types";
|
|
131
|
+
|
|
132
|
+
visit(ast, {
|
|
133
|
+
// This method will be called for any node with .type "MemberExpression":
|
|
134
|
+
visitMemberExpression(path) {
|
|
135
|
+
// Visitor methods receive a single argument, a NodePath object
|
|
136
|
+
// wrapping the node of interest.
|
|
137
|
+
var node = path.node;
|
|
138
|
+
|
|
139
|
+
if (
|
|
140
|
+
n.Identifier.check(node.object) &&
|
|
141
|
+
node.object.name === "arguments" &&
|
|
142
|
+
n.Identifier.check(node.property)
|
|
143
|
+
) {
|
|
144
|
+
assert.notStrictEqual(node.property.name, "callee");
|
|
141
145
|
}
|
|
146
|
+
|
|
147
|
+
// It's your responsibility to call this.traverse with some
|
|
148
|
+
// NodePath object (usually the one passed into the visitor
|
|
149
|
+
// method) before the visitor method returns, or return false to
|
|
150
|
+
// indicate that the traversal need not continue any further down
|
|
151
|
+
// this subtree.
|
|
152
|
+
this.traverse(path);
|
|
153
|
+
}
|
|
142
154
|
});
|
|
143
155
|
```
|
|
144
156
|
|
|
@@ -146,87 +158,87 @@ Here's a slightly more involved example of transforming `...rest`
|
|
|
146
158
|
parameters into browser-runnable ES5 JavaScript:
|
|
147
159
|
|
|
148
160
|
```js
|
|
149
|
-
|
|
161
|
+
import { builders as b, visit } from "ast-types";
|
|
150
162
|
|
|
151
163
|
// Reuse the same AST structure for Array.prototype.slice.call.
|
|
152
164
|
var sliceExpr = b.memberExpression(
|
|
165
|
+
b.memberExpression(
|
|
153
166
|
b.memberExpression(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
false
|
|
158
|
-
),
|
|
159
|
-
b.identifier("slice"),
|
|
160
|
-
false
|
|
167
|
+
b.identifier("Array"),
|
|
168
|
+
b.identifier("prototype"),
|
|
169
|
+
false
|
|
161
170
|
),
|
|
162
|
-
b.identifier("
|
|
171
|
+
b.identifier("slice"),
|
|
163
172
|
false
|
|
173
|
+
),
|
|
174
|
+
b.identifier("call"),
|
|
175
|
+
false
|
|
164
176
|
);
|
|
165
177
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// For the purposes of this example, we won't worry about functions
|
|
197
|
-
// with Expression bodies.
|
|
198
|
-
n.BlockStatement.assert(node.body);
|
|
199
|
-
|
|
200
|
-
// Use types.builders to build a variable declaration of the form
|
|
201
|
-
//
|
|
202
|
-
// var rest = Array.prototype.slice.call(arguments, n);
|
|
203
|
-
//
|
|
204
|
-
// where `rest` is the name of the rest parameter, and `n` is a
|
|
205
|
-
// numeric literal specifying the number of named parameters the
|
|
206
|
-
// function takes.
|
|
207
|
-
var restVarDecl = b.variableDeclaration("var", [
|
|
208
|
-
b.variableDeclarator(
|
|
209
|
-
node.rest,
|
|
210
|
-
b.callExpression(sliceExpr, [
|
|
211
|
-
b.identifier("arguments"),
|
|
212
|
-
b.literal(node.params.length)
|
|
213
|
-
])
|
|
214
|
-
)
|
|
215
|
-
]);
|
|
216
|
-
|
|
217
|
-
// Similar to doing node.body.body.unshift(restVarDecl), except
|
|
218
|
-
// that the other NodePath objects wrapping body statements will
|
|
219
|
-
// have their indexes updated to accommodate the new statement.
|
|
220
|
-
path.get("body", "body").unshift(restVarDecl);
|
|
221
|
-
|
|
222
|
-
// Nullify node.rest now that we have simulated the behavior of
|
|
223
|
-
// the rest parameter using ordinary JavaScript.
|
|
224
|
-
path.get("rest").replace(null);
|
|
225
|
-
|
|
226
|
-
// There's nothing wrong with doing node.rest = null, but I wanted
|
|
227
|
-
// to point out that the above statement has the same effect.
|
|
228
|
-
assert.strictEqual(node.rest, null);
|
|
178
|
+
visit(ast, {
|
|
179
|
+
// This method will be called for any node whose type is a subtype of
|
|
180
|
+
// Function (e.g., FunctionDeclaration, FunctionExpression, and
|
|
181
|
+
// ArrowFunctionExpression). Note that types.visit precomputes a
|
|
182
|
+
// lookup table from every known type to the appropriate visitor
|
|
183
|
+
// method to call for nodes of that type, so the dispatch takes
|
|
184
|
+
// constant time.
|
|
185
|
+
visitFunction(path) {
|
|
186
|
+
// Visitor methods receive a single argument, a NodePath object
|
|
187
|
+
// wrapping the node of interest.
|
|
188
|
+
const node = path.node;
|
|
189
|
+
|
|
190
|
+
// It's your responsibility to call this.traverse with some
|
|
191
|
+
// NodePath object (usually the one passed into the visitor
|
|
192
|
+
// method) before the visitor method returns, or return false to
|
|
193
|
+
// indicate that the traversal need not continue any further down
|
|
194
|
+
// this subtree. An assertion will fail if you forget, which is
|
|
195
|
+
// awesome, because it means you will never again make the
|
|
196
|
+
// disastrous mistake of forgetting to traverse a subtree. Also
|
|
197
|
+
// cool: because you can call this method at any point in the
|
|
198
|
+
// visitor method, it's up to you whether your traversal is
|
|
199
|
+
// pre-order, post-order, or both!
|
|
200
|
+
this.traverse(path);
|
|
201
|
+
|
|
202
|
+
// This traversal is only concerned with Function nodes that have
|
|
203
|
+
// rest parameters.
|
|
204
|
+
if (!node.rest) {
|
|
205
|
+
return;
|
|
229
206
|
}
|
|
207
|
+
|
|
208
|
+
// For the purposes of this example, we won't worry about functions
|
|
209
|
+
// with Expression bodies.
|
|
210
|
+
n.BlockStatement.assert(node.body);
|
|
211
|
+
|
|
212
|
+
// Use types.builders to build a variable declaration of the form
|
|
213
|
+
//
|
|
214
|
+
// var rest = Array.prototype.slice.call(arguments, n);
|
|
215
|
+
//
|
|
216
|
+
// where `rest` is the name of the rest parameter, and `n` is a
|
|
217
|
+
// numeric literal specifying the number of named parameters the
|
|
218
|
+
// function takes.
|
|
219
|
+
const restVarDecl = b.variableDeclaration("var", [
|
|
220
|
+
b.variableDeclarator(
|
|
221
|
+
node.rest,
|
|
222
|
+
b.callExpression(sliceExpr, [
|
|
223
|
+
b.identifier("arguments"),
|
|
224
|
+
b.literal(node.params.length)
|
|
225
|
+
])
|
|
226
|
+
)
|
|
227
|
+
]);
|
|
228
|
+
|
|
229
|
+
// Similar to doing node.body.body.unshift(restVarDecl), except
|
|
230
|
+
// that the other NodePath objects wrapping body statements will
|
|
231
|
+
// have their indexes updated to accommodate the new statement.
|
|
232
|
+
path.get("body", "body").unshift(restVarDecl);
|
|
233
|
+
|
|
234
|
+
// Nullify node.rest now that we have simulated the behavior of
|
|
235
|
+
// the rest parameter using ordinary JavaScript.
|
|
236
|
+
path.get("rest").replace(null);
|
|
237
|
+
|
|
238
|
+
// There's nothing wrong with doing node.rest = null, but I wanted
|
|
239
|
+
// to point out that the above statement has the same effect.
|
|
240
|
+
assert.strictEqual(node.rest, null);
|
|
241
|
+
}
|
|
230
242
|
});
|
|
231
243
|
```
|
|
232
244
|
|
|
@@ -235,64 +247,64 @@ determines if a given function node refers to `this`:
|
|
|
235
247
|
|
|
236
248
|
```js
|
|
237
249
|
function usesThis(funcNode) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
250
|
+
n.Function.assert(funcNode);
|
|
251
|
+
var result = false;
|
|
252
|
+
|
|
253
|
+
visit(funcNode, {
|
|
254
|
+
visitThisExpression(path) {
|
|
255
|
+
result = true;
|
|
256
|
+
|
|
257
|
+
// The quickest way to terminate the traversal is to call
|
|
258
|
+
// this.abort(), which throws a special exception (instanceof
|
|
259
|
+
// this.AbortRequest) that will be caught in the top-level
|
|
260
|
+
// types.visit method, so you don't have to worry about
|
|
261
|
+
// catching the exception yourself.
|
|
262
|
+
this.abort();
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
visitFunction(path) {
|
|
266
|
+
// ThisExpression nodes in nested scopes don't count as `this`
|
|
267
|
+
// references for the original function node, so we can safely
|
|
268
|
+
// avoid traversing this subtree.
|
|
269
|
+
return false;
|
|
270
|
+
},
|
|
271
|
+
|
|
272
|
+
visitCallExpression(path) {
|
|
273
|
+
const node = path.node;
|
|
274
|
+
|
|
275
|
+
// If the function contains CallExpression nodes involving
|
|
276
|
+
// super, those expressions will implicitly depend on the
|
|
277
|
+
// value of `this`, even though they do not explicitly contain
|
|
278
|
+
// any ThisExpression nodes.
|
|
279
|
+
if (this.isSuperCallExpression(node)) {
|
|
280
|
+
result = true;
|
|
281
|
+
this.abort(); // Throws AbortRequest exception.
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
this.traverse(path);
|
|
285
|
+
},
|
|
286
|
+
|
|
287
|
+
// Yes, you can define arbitrary helper methods.
|
|
288
|
+
isSuperCallExpression(callExpr) {
|
|
289
|
+
n.CallExpression.assert(callExpr);
|
|
290
|
+
return this.isSuperIdentifier(callExpr.callee)
|
|
291
|
+
|| this.isSuperMemberExpression(callExpr.callee);
|
|
292
|
+
},
|
|
293
|
+
|
|
294
|
+
// And even helper helper methods!
|
|
295
|
+
isSuperIdentifier(node) {
|
|
296
|
+
return n.Identifier.check(node.callee)
|
|
297
|
+
&& node.callee.name === "super";
|
|
298
|
+
},
|
|
299
|
+
|
|
300
|
+
isSuperMemberExpression(node) {
|
|
301
|
+
return n.MemberExpression.check(node.callee)
|
|
302
|
+
&& n.Identifier.check(node.callee.object)
|
|
303
|
+
&& node.callee.object.name === "super";
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
return result;
|
|
296
308
|
}
|
|
297
309
|
```
|
|
298
310
|
|
|
@@ -384,8 +396,8 @@ fifth.replace(newerNode);
|
|
|
384
396
|
|
|
385
397
|
// Replace the third element in an array with two new nodes:
|
|
386
398
|
path.get("elements", 2).replace(
|
|
387
|
-
|
|
388
|
-
|
|
399
|
+
b.identifier("foo"),
|
|
400
|
+
b.thisExpression()
|
|
389
401
|
);
|
|
390
402
|
|
|
391
403
|
// Remove a node and its parent if it would leave a redundant AST node:
|
|
@@ -432,35 +444,40 @@ The `ast-types` module was designed to be extended. To that end, it
|
|
|
432
444
|
provides a readable, declarative syntax for specifying new AST node types,
|
|
433
445
|
based primarily upon the `require("ast-types").Type.def` function:
|
|
434
446
|
```js
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
447
|
+
import {
|
|
448
|
+
Type,
|
|
449
|
+
builtInTypes,
|
|
450
|
+
builders as b,
|
|
451
|
+
finalize,
|
|
452
|
+
} from "ast-types";
|
|
453
|
+
|
|
454
|
+
const { def } = Type;
|
|
455
|
+
const { string } = builtInTypes;
|
|
439
456
|
|
|
440
457
|
// Suppose you need a named File type to wrap your Programs.
|
|
441
458
|
def("File")
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
459
|
+
.bases("Node")
|
|
460
|
+
.build("name", "program")
|
|
461
|
+
.field("name", string)
|
|
462
|
+
.field("program", def("Program"));
|
|
446
463
|
|
|
447
464
|
// Prevent further modifications to the File type (and any other
|
|
448
465
|
// types newly introduced by def(...)).
|
|
449
|
-
|
|
466
|
+
finalize();
|
|
450
467
|
|
|
451
468
|
// The b.file builder function is now available. It expects two
|
|
452
469
|
// arguments, as named by .build("name", "program") above.
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
470
|
+
const main = b.file("main.js", b.program([
|
|
471
|
+
// Pointless program contents included for extra color.
|
|
472
|
+
b.functionDeclaration(b.identifier("succ"), [
|
|
473
|
+
b.identifier("x")
|
|
474
|
+
], b.blockStatement([
|
|
475
|
+
b.returnStatement(
|
|
476
|
+
b.binaryExpression(
|
|
477
|
+
"+", b.identifier("x"), b.literal(1)
|
|
478
|
+
)
|
|
479
|
+
)
|
|
480
|
+
]))
|
|
464
481
|
]));
|
|
465
482
|
|
|
466
483
|
assert.strictEqual(main.name, "main.js");
|
package/def/core.js
CHANGED
|
@@ -157,8 +157,7 @@ function default_1(fork) {
|
|
|
157
157
|
.build("id", "init")
|
|
158
158
|
.field("id", def("Pattern"))
|
|
159
159
|
.field("init", or(def("Expression"), null), defaults["null"]);
|
|
160
|
-
|
|
161
|
-
def("Expression").bases("Node", "Pattern");
|
|
160
|
+
def("Expression").bases("Node");
|
|
162
161
|
def("ThisExpression").bases("Expression").build();
|
|
163
162
|
def("ArrayExpression")
|
|
164
163
|
.bases("Expression")
|
|
@@ -201,7 +200,7 @@ function default_1(fork) {
|
|
|
201
200
|
.bases("Expression")
|
|
202
201
|
.build("operator", "left", "right")
|
|
203
202
|
.field("operator", AssignmentOperator)
|
|
204
|
-
.field("left", def("Pattern"))
|
|
203
|
+
.field("left", or(def("Pattern"), def("MemberExpression")))
|
|
205
204
|
.field("right", def("Expression"));
|
|
206
205
|
var UpdateOperator = or("++", "--");
|
|
207
206
|
def("UpdateExpression")
|
|
@@ -258,14 +257,12 @@ function default_1(fork) {
|
|
|
258
257
|
.field("test", or(def("Expression"), null))
|
|
259
258
|
.field("consequent", [def("Statement")]);
|
|
260
259
|
def("Identifier")
|
|
261
|
-
|
|
262
|
-
.bases("Node", "Expression", "Pattern")
|
|
260
|
+
.bases("Expression", "Pattern")
|
|
263
261
|
.build("name")
|
|
264
262
|
.field("name", String)
|
|
265
263
|
.field("optional", Boolean, defaults["false"]);
|
|
266
264
|
def("Literal")
|
|
267
|
-
|
|
268
|
-
.bases("Node", "Expression")
|
|
265
|
+
.bases("Expression")
|
|
269
266
|
.build("value")
|
|
270
267
|
.field("value", or(String, Boolean, null, Number, RegExp))
|
|
271
268
|
.field("regex", or({
|
package/def/flow.js
CHANGED
|
@@ -285,6 +285,10 @@ function default_1(fork) {
|
|
|
285
285
|
.bases("FlowPredicate")
|
|
286
286
|
.build("value")
|
|
287
287
|
.field("value", def("Expression"));
|
|
288
|
+
def("CallExpression")
|
|
289
|
+
.field("typeArguments", or(null, def("TypeParameterInstantiation")), defaults["null"]);
|
|
290
|
+
def("NewExpression")
|
|
291
|
+
.field("typeArguments", or(null, def("TypeParameterInstantiation")), defaults["null"]);
|
|
288
292
|
}
|
|
289
293
|
exports.default = default_1;
|
|
290
294
|
module.exports = exports["default"];
|
package/def/typescript.js
CHANGED
|
@@ -54,13 +54,13 @@ function default_1(fork) {
|
|
|
54
54
|
.field("left", TSEntityName)
|
|
55
55
|
.field("right", TSEntityName);
|
|
56
56
|
def("TSAsExpression")
|
|
57
|
-
.bases("Expression")
|
|
58
|
-
.build("expression")
|
|
57
|
+
.bases("Expression", "Pattern")
|
|
58
|
+
.build("expression", "typeAnnotation")
|
|
59
59
|
.field("expression", def("Expression"))
|
|
60
60
|
.field("typeAnnotation", def("TSType"))
|
|
61
61
|
.field("extra", or({ parenthesized: Boolean }, null), defaults["null"]);
|
|
62
62
|
def("TSNonNullExpression")
|
|
63
|
-
.bases("Expression")
|
|
63
|
+
.bases("Expression", "Pattern")
|
|
64
64
|
.build("expression")
|
|
65
65
|
.field("expression", def("Expression"));
|
|
66
66
|
[
|
|
@@ -89,7 +89,7 @@ function default_1(fork) {
|
|
|
89
89
|
def("TSLiteralType")
|
|
90
90
|
.bases("TSType")
|
|
91
91
|
.build("literal")
|
|
92
|
-
.field("literal", or(def("NumericLiteral"), def("StringLiteral"), def("BooleanLiteral")));
|
|
92
|
+
.field("literal", or(def("NumericLiteral"), def("StringLiteral"), def("BooleanLiteral"), def("TemplateLiteral"), def("UnaryExpression")));
|
|
93
93
|
["TSUnionType",
|
|
94
94
|
"TSIntersectionType",
|
|
95
95
|
].forEach(function (typeName) {
|
|
@@ -244,7 +244,7 @@ function default_1(fork) {
|
|
|
244
244
|
.field("constraint", or(def("TSType"), void 0), defaults["undefined"])
|
|
245
245
|
.field("default", or(def("TSType"), void 0), defaults["undefined"]);
|
|
246
246
|
def("TSTypeAssertion")
|
|
247
|
-
.bases("Expression")
|
|
247
|
+
.bases("Expression", "Pattern")
|
|
248
248
|
.build("typeAnnotation", "expression")
|
|
249
249
|
.field("typeAnnotation", def("TSType"))
|
|
250
250
|
.field("expression", def("Expression"))
|
package/fork.d.ts
CHANGED
|
@@ -20,12 +20,8 @@ export default function (defs: Def[]): {
|
|
|
20
20
|
null: import("./lib/types").Type<null>;
|
|
21
21
|
undefined: import("./lib/types").Type<undefined>;
|
|
22
22
|
};
|
|
23
|
-
namedTypes:
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
builders: {
|
|
27
|
-
[name: string]: import("./lib/types").Builder;
|
|
28
|
-
};
|
|
23
|
+
namedTypes: import("./gen/namedTypes").NamedTypes;
|
|
24
|
+
builders: import("./gen/builders").builders;
|
|
29
25
|
defineMethod: (name: any, func?: Function | undefined) => Function;
|
|
30
26
|
getFieldNames: (object: any) => string[];
|
|
31
27
|
getFieldValue: (object: any, fieldName: any) => any;
|
|
@@ -42,5 +38,5 @@ export default function (defs: Def[]): {
|
|
|
42
38
|
NodePath: import("./lib/node-path").NodePathConstructor;
|
|
43
39
|
PathVisitor: import("./lib/path-visitor").PathVisitorConstructor;
|
|
44
40
|
use: <T>(plugin: Plugin<T>) => T;
|
|
45
|
-
visit: (node: import("./lib/types").ASTNode, methods?:
|
|
41
|
+
visit: <M = {}>(node: import("./lib/types").ASTNode, methods?: import("./main").Visitor<M> | undefined) => any;
|
|
46
42
|
};
|
package/fork.js
CHANGED
|
@@ -14,7 +14,7 @@ function default_1(defs) {
|
|
|
14
14
|
defs.forEach(fork.use);
|
|
15
15
|
types.finalize();
|
|
16
16
|
var PathVisitor = fork.use(path_visitor_1.default);
|
|
17
|
-
|
|
17
|
+
return {
|
|
18
18
|
Type: types.Type,
|
|
19
19
|
builtInTypes: types.builtInTypes,
|
|
20
20
|
namedTypes: types.namedTypes,
|
|
@@ -34,7 +34,6 @@ function default_1(defs) {
|
|
|
34
34
|
use: fork.use,
|
|
35
35
|
visit: PathVisitor.visit,
|
|
36
36
|
};
|
|
37
|
-
return exports;
|
|
38
37
|
}
|
|
39
38
|
exports.default = default_1;
|
|
40
39
|
function createFork() {
|