flow-parser 0.325.0 → 0.326.0
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/dist/FlowParserDeserializer.js.flow +9 -9
- package/dist/FlowParserWASM.js +1 -1
- package/dist/HermesAST.js.flow +2 -2
- package/dist/ParserOptions.js.flow +3 -3
- package/dist/babel/TransformESTreeToBabel.js.flow +97 -97
- package/dist/estree/TransformMatchSyntax.js.flow +7 -7
- package/dist/transform/SimpleTransform.js.flow +1 -1
- package/dist/transform/astNodeMutationHelpers.js.flow +3 -3
- package/dist/traverse/getVisitorKeys.js.flow +2 -2
- package/dist/utils/GenID.js.flow +2 -2
- package/package.json +2 -2
package/dist/HermesAST.js.flow
CHANGED
|
@@ -31,9 +31,9 @@ export type ParserOptions = {
|
|
|
31
31
|
throwOnParseErrors?: boolean,
|
|
32
32
|
tokens?: boolean,
|
|
33
33
|
transformOptions?: {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
readonly TransformEnumSyntax?: {
|
|
35
|
+
readonly enable: boolean,
|
|
36
|
+
readonly getRuntime?: () => Expression,
|
|
37
37
|
},
|
|
38
38
|
},
|
|
39
39
|
};
|
|
@@ -96,7 +96,7 @@ const FlowESTreeAndBabelVisitorKeys: VisitorKeys = {
|
|
|
96
96
|
CommentLine: [],
|
|
97
97
|
};
|
|
98
98
|
|
|
99
|
-
function nodeWith<T
|
|
99
|
+
function nodeWith<T extends ESNode>(node: T, overrideProps: Partial<T>): T {
|
|
100
100
|
return SimpleTransform.nodeWith(
|
|
101
101
|
node,
|
|
102
102
|
overrideProps,
|
|
@@ -110,33 +110,33 @@ function nodeWith<T: ESNode>(node: T, overrideProps: Partial<T>): T {
|
|
|
110
110
|
* Copied from: https://github.com/babel/babel/blob/main/packages/babel-types/src/ast-types/generated/index.ts
|
|
111
111
|
*/
|
|
112
112
|
export interface BabelFile extends BaseNode {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
readonly type: 'File';
|
|
114
|
+
readonly program: Program;
|
|
115
|
+
readonly comments: ReadonlyArray<BabelComment>;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
interface BabelCommentBlock extends BaseToken {
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
readonly type: 'CommentBlock';
|
|
120
|
+
readonly value: string;
|
|
121
121
|
}
|
|
122
122
|
interface BabelCommentLine extends BaseToken {
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
readonly type: 'CommentLine';
|
|
124
|
+
readonly value: string;
|
|
125
125
|
}
|
|
126
126
|
type BabelComment = BabelCommentBlock | BabelCommentLine;
|
|
127
127
|
|
|
128
128
|
interface BabelObjectMethod extends BaseNode {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
129
|
+
readonly type: 'ObjectMethod';
|
|
130
|
+
readonly kind: 'method' | 'get' | 'set';
|
|
131
|
+
readonly key: Expression;
|
|
132
|
+
readonly params: ReadonlyArray<FunctionParameter>;
|
|
133
|
+
readonly body: BlockStatement;
|
|
134
|
+
readonly computed: boolean;
|
|
135
|
+
readonly generator: boolean;
|
|
136
|
+
readonly async: boolean;
|
|
137
|
+
readonly returnType?: TypeAnnotation | null;
|
|
138
|
+
readonly typeParameters?: TypeParameterDeclaration | null;
|
|
139
|
+
readonly variance?: boolean | null;
|
|
140
140
|
|
|
141
141
|
// TODO: Should these exist?
|
|
142
142
|
// +id: ...,
|
|
@@ -146,146 +146,146 @@ interface BabelObjectMethod extends BaseNode {
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
interface BabelObjectProperty extends BaseNode {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
149
|
+
readonly type: 'ObjectProperty';
|
|
150
|
+
readonly computed: boolean;
|
|
151
|
+
readonly key: Expression;
|
|
152
|
+
readonly value: Expression;
|
|
153
|
+
readonly method: boolean;
|
|
154
|
+
readonly shorthand: boolean;
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
interface BabelClassMethodBase extends BaseNode {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
158
|
+
readonly kind: 'get' | 'set' | 'method' | 'constructor';
|
|
159
|
+
readonly computed: boolean;
|
|
160
|
+
readonly static: boolean;
|
|
161
|
+
readonly key:
|
|
162
162
|
| Identifier
|
|
163
163
|
| StringLiteral
|
|
164
164
|
| ClassPropertyNameComputed
|
|
165
165
|
| ClassPropertyNameNonComputed;
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
166
|
+
readonly id: null;
|
|
167
|
+
readonly params: ReadonlyArray<FunctionParameter>;
|
|
168
|
+
readonly body: BlockStatement;
|
|
169
|
+
readonly async: boolean;
|
|
170
|
+
readonly generator: boolean;
|
|
171
|
+
readonly returnType?: TypeAnnotation | null;
|
|
172
|
+
readonly typeParameters?: TypeParameterDeclaration | null;
|
|
173
|
+
readonly predicate: null;
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
interface BabelClassPrivateMethod extends BabelClassMethodBase {
|
|
177
|
-
|
|
177
|
+
readonly type: 'ClassPrivateMethod';
|
|
178
178
|
}
|
|
179
179
|
interface BabelClassMethod extends BabelClassMethodBase {
|
|
180
|
-
|
|
180
|
+
readonly type: 'ClassMethod';
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
interface BabelClassProperty extends BaseNode {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
184
|
+
readonly type: 'ClassProperty';
|
|
185
|
+
readonly key: Expression;
|
|
186
|
+
readonly value: null | Expression;
|
|
187
|
+
readonly typeAnnotation: null | TypeAnnotation;
|
|
188
|
+
readonly static: boolean;
|
|
189
|
+
readonly variance: null | Variance;
|
|
190
|
+
readonly declare: boolean;
|
|
191
|
+
readonly optional: null | boolean;
|
|
192
|
+
readonly computed: boolean;
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
interface BabelClassPrivateProperty extends BaseNode {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
196
|
+
readonly type: 'ClassPrivateProperty';
|
|
197
|
+
readonly key: BabelPrivateName;
|
|
198
|
+
readonly value: null | Expression;
|
|
199
|
+
readonly typeAnnotation: null | TypeAnnotation;
|
|
200
|
+
readonly static: boolean;
|
|
201
|
+
readonly variance: null | Variance;
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
interface BabelExportNamespaceSpecifier extends BaseNode {
|
|
205
|
-
|
|
206
|
-
|
|
205
|
+
readonly type: 'ExportNamespaceSpecifier';
|
|
206
|
+
readonly exported: Identifier;
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
interface BabelExportNamedDeclaration extends BaseNode {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
210
|
+
readonly type: 'ExportNamedDeclaration';
|
|
211
|
+
readonly declaration?: null;
|
|
212
|
+
readonly specifiers: ReadonlyArray<BabelExportNamespaceSpecifier>;
|
|
213
|
+
readonly source?: StringLiteral | null;
|
|
214
|
+
readonly exportKind: 'value' | 'type';
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
interface BabelPrivateName extends BaseNode {
|
|
218
|
-
|
|
219
|
-
|
|
218
|
+
readonly type: 'PrivateName';
|
|
219
|
+
readonly id: Identifier;
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
interface BabelOptionalMemberExpression extends BaseNode {
|
|
223
|
-
|
|
224
|
-
|
|
223
|
+
readonly type: 'OptionalMemberExpression';
|
|
224
|
+
readonly object:
|
|
225
225
|
| Expression
|
|
226
226
|
| Super
|
|
227
227
|
| BabelOptionalMemberExpression
|
|
228
228
|
| BabelOptionalCallExpression;
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
229
|
+
readonly property: Expression | Identifier | PrivateIdentifier;
|
|
230
|
+
readonly computed: boolean;
|
|
231
|
+
readonly optional: boolean;
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
interface BabelOptionalCallExpression extends BaseNode {
|
|
235
|
-
|
|
236
|
-
|
|
235
|
+
readonly type: 'OptionalCallExpression';
|
|
236
|
+
readonly callee:
|
|
237
237
|
| Expression
|
|
238
238
|
| Super
|
|
239
239
|
| BabelOptionalMemberExpression
|
|
240
240
|
| BabelOptionalCallExpression;
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
241
|
+
readonly arguments: ReadonlyArray<Expression | SpreadElement>;
|
|
242
|
+
readonly optional: boolean;
|
|
243
|
+
readonly typeArguments?: TypeParameterInstantiation | null;
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
interface BabelStringLiteral extends BaseNode {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
247
|
+
readonly type: 'StringLiteral';
|
|
248
|
+
readonly value: string;
|
|
249
|
+
readonly extra: Readonly<{
|
|
250
|
+
readonly rawValue: string,
|
|
251
|
+
readonly raw: string,
|
|
252
252
|
}>;
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
interface BabelNumericLiteral extends BaseNode {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
256
|
+
readonly type: 'NumericLiteral';
|
|
257
|
+
readonly value: number;
|
|
258
|
+
readonly extra: Readonly<{
|
|
259
|
+
readonly rawValue: number,
|
|
260
|
+
readonly raw: string,
|
|
261
261
|
}>;
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
interface BabelBigIntLiteral extends BaseNode {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
265
|
+
readonly type: 'BigIntLiteral';
|
|
266
|
+
readonly value: string;
|
|
267
|
+
readonly extra: Readonly<{
|
|
268
|
+
readonly rawValue: string,
|
|
269
|
+
readonly raw: string,
|
|
270
270
|
}>;
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
interface BabelBooleanLiteral extends BaseNode {
|
|
274
|
-
|
|
275
|
-
|
|
274
|
+
readonly type: 'BooleanLiteral';
|
|
275
|
+
readonly value: boolean;
|
|
276
276
|
}
|
|
277
277
|
|
|
278
278
|
interface BabelNullLiteral extends BaseNode {
|
|
279
|
-
|
|
279
|
+
readonly type: 'NullLiteral';
|
|
280
280
|
}
|
|
281
281
|
|
|
282
282
|
interface BabelRegExpLiteral extends BaseNode {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
283
|
+
readonly type: 'RegExpLiteral';
|
|
284
|
+
readonly extra: Readonly<{
|
|
285
|
+
readonly raw: string,
|
|
286
286
|
}>;
|
|
287
|
-
|
|
288
|
-
|
|
287
|
+
readonly pattern: string;
|
|
288
|
+
readonly flags: string;
|
|
289
289
|
}
|
|
290
290
|
|
|
291
291
|
type BabelLiteral =
|
|
@@ -346,7 +346,7 @@ function fixSourceLocation(
|
|
|
346
346
|
delete node.parent;
|
|
347
347
|
}
|
|
348
348
|
|
|
349
|
-
function mapNodeWithDirectives<T
|
|
349
|
+
function mapNodeWithDirectives<T extends Program | BlockStatement>(node: T): T {
|
|
350
350
|
// $FlowExpectedError[prop-missing]
|
|
351
351
|
if (node.directives != null) {
|
|
352
352
|
return node;
|
|
@@ -726,16 +726,16 @@ function calculateSimpleArgument(node: Expression | Super): boolean {
|
|
|
726
726
|
* Analyze the match cases and return information we will use to build the result.
|
|
727
727
|
*/
|
|
728
728
|
type CaseAnalysis<T> = {
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
729
|
+
readonly conditions: Array<Condition>,
|
|
730
|
+
readonly bindings: Array<Binding>,
|
|
731
|
+
readonly guard: Expression | null,
|
|
732
|
+
readonly body: T,
|
|
733
733
|
};
|
|
734
734
|
|
|
735
735
|
interface MatchCase<T> {
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
736
|
+
readonly pattern: MatchPattern;
|
|
737
|
+
readonly guard: Expression | null;
|
|
738
|
+
readonly body: T;
|
|
739
739
|
}
|
|
740
740
|
|
|
741
741
|
function analyzeCases<T>(cases: ReadonlyArray<MatchCase<T>>): {
|
|
@@ -158,7 +158,7 @@ export class SimpleTransform {
|
|
|
158
158
|
* @return Either the orginal node if the properties matched the existing node or a new node with
|
|
159
159
|
* the new properties.
|
|
160
160
|
*/
|
|
161
|
-
static nodeWith<T
|
|
161
|
+
static nodeWith<T extends ESNode>(
|
|
162
162
|
node: T,
|
|
163
163
|
overrideProps: Partial<T>,
|
|
164
164
|
visitorKeys?: VisitorKeysType,
|
|
@@ -179,7 +179,7 @@ export function updateAllParentPointers(
|
|
|
179
179
|
*
|
|
180
180
|
* This will only create a new object if the overrides actually result in a change.
|
|
181
181
|
*/
|
|
182
|
-
export function nodeWith<T
|
|
182
|
+
export function nodeWith<T extends ESNode>(
|
|
183
183
|
node: T,
|
|
184
184
|
overrideProps: Partial<T>,
|
|
185
185
|
visitorKeys?: ?VisitorKeysType,
|
|
@@ -216,7 +216,7 @@ export function nodeWith<T: ESNode>(
|
|
|
216
216
|
/**
|
|
217
217
|
* Shallow clones node, providing a new reference for an existing node.
|
|
218
218
|
*/
|
|
219
|
-
export function shallowCloneNode<T
|
|
219
|
+
export function shallowCloneNode<T extends ESNode>(
|
|
220
220
|
node: T,
|
|
221
221
|
visitorKeys?: ?VisitorKeysType,
|
|
222
222
|
): T {
|
|
@@ -232,7 +232,7 @@ export function shallowCloneNode<T: ESNode>(
|
|
|
232
232
|
/**
|
|
233
233
|
* Deeply clones node and its entire tree.
|
|
234
234
|
*/
|
|
235
|
-
export function deepCloneNode<T
|
|
235
|
+
export function deepCloneNode<T extends ESNode>(
|
|
236
236
|
node: T,
|
|
237
237
|
visitorKeys?: ?VisitorKeysType,
|
|
238
238
|
): T {
|
|
@@ -15,14 +15,14 @@ import type {VisitorKeys as VisitorKeysType} from '../generated/ESTreeVisitorKey
|
|
|
15
15
|
|
|
16
16
|
import FlowVisitorKeys from '../generated/ESTreeVisitorKeys';
|
|
17
17
|
|
|
18
|
-
export function isNode(thing: unknown) /*: implies thing is {
|
|
18
|
+
export function isNode(thing: unknown) /*: implies thing is {readonly [string]: unknown} */ {
|
|
19
19
|
return (
|
|
20
20
|
typeof thing === 'object' && thing != null && typeof thing.type === 'string'
|
|
21
21
|
);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export type {VisitorKeysType};
|
|
25
|
-
export function getVisitorKeys<T
|
|
25
|
+
export function getVisitorKeys<T extends ESNode>(
|
|
26
26
|
node: T,
|
|
27
27
|
visitorKeys?: ?VisitorKeysType,
|
|
28
28
|
) /*: ReadonlyArray<keyof T> */ {
|
package/dist/utils/GenID.js.flow
CHANGED
|
@@ -14,8 +14,8 @@ const genPrefix = '$$gen$';
|
|
|
14
14
|
|
|
15
15
|
export default class GenID {
|
|
16
16
|
genN: number = 0;
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
readonly used: Set<string> = new Set();
|
|
18
|
+
readonly prefix: string;
|
|
19
19
|
|
|
20
20
|
constructor(uniqueTransformPrefix: string) {
|
|
21
21
|
this.prefix = `${genPrefix}${uniqueTransformPrefix}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flow-parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.326.0",
|
|
4
4
|
"description": "JavaScript parser written in OCaml. Produces ESTree AST",
|
|
5
5
|
"homepage": "https://flow.org",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"test": "node test/run_tests.js"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"flow-estree": "0.
|
|
26
|
+
"flow-estree": "0.326.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@babel/generator": "7.7.4",
|