hermes-parser 0.36.0 → 0.37.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/HermesAST.js.flow +2 -2
- package/dist/HermesASTAdapter.js +1 -1
- package/dist/HermesParser.js +1 -1
- package/dist/HermesParserDecodeUTF8String.js +1 -1
- package/dist/HermesParserDeserializer.js +1 -1
- package/dist/HermesParserDeserializer.js.flow +8 -8
- package/dist/HermesParserNodeDeserializers.js +1 -1
- package/dist/HermesParserNodeDeserializers.js.flow +1 -1
- package/dist/HermesParserWASM.js +1 -1
- package/dist/HermesParserWASM.js.flow +6 -6
- package/dist/HermesToESTreeAdapter.js +3 -2
- package/dist/HermesToESTreeAdapter.js.flow +4 -3
- package/dist/ParserOptions.js +5 -3
- package/dist/ParserOptions.js.flow +5 -5
- package/dist/babel/TransformESTreeToBabel.js +4 -3
- package/dist/babel/TransformESTreeToBabel.js.flow +101 -100
- package/dist/estree/StripFlowTypes.js +1 -1
- package/dist/estree/StripFlowTypesForBabel.js +1 -1
- package/dist/estree/TransformComponentSyntax.js +1 -1
- package/dist/estree/TransformComponentSyntax.js.flow +3 -3
- package/dist/estree/TransformEnumSyntax.js +1 -1
- package/dist/estree/TransformEnumSyntax.js.flow +1 -1
- package/dist/estree/TransformMatchSyntax.js +11 -2
- package/dist/estree/TransformMatchSyntax.js.flow +10 -9
- package/dist/estree/TransformRecordSyntax.js +1 -1
- package/dist/generated/ESTreeVisitorKeys.js +1 -1
- package/dist/generated/ESTreeVisitorKeys.js.flow +1 -1
- package/dist/generated/ParserVisitorKeys.js +1 -1
- package/dist/generated/ParserVisitorKeys.js.flow +2 -2
- package/dist/getModuleDocblock.js +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.flow +5 -5
- package/dist/src/HermesASTAdapter.js +1 -1
- package/dist/src/HermesParser.js +1 -1
- package/dist/src/HermesParserDecodeUTF8String.js +1 -1
- package/dist/src/HermesParserDeserializer.js +1 -1
- package/dist/src/HermesParserNodeDeserializers.js +1 -1
- package/dist/src/HermesToESTreeAdapter.js +3 -2
- package/dist/src/ParserOptions.js +5 -3
- package/dist/src/babel/TransformESTreeToBabel.js +4 -3
- package/dist/src/estree/StripFlowTypes.js +1 -1
- package/dist/src/estree/StripFlowTypesForBabel.js +1 -1
- package/dist/src/estree/TransformComponentSyntax.js +1 -1
- package/dist/src/estree/TransformEnumSyntax.js +1 -1
- package/dist/src/estree/TransformMatchSyntax.js +11 -2
- package/dist/src/estree/TransformRecordSyntax.js +1 -1
- package/dist/src/generated/ESTreeVisitorKeys.js +1 -1
- package/dist/src/generated/ParserVisitorKeys.js +1 -1
- package/dist/src/getModuleDocblock.js +1 -1
- package/dist/src/index.js +4 -3
- package/dist/src/transform/SimpleTransform.js +10 -1
- package/dist/src/transform/astArrayMutationHelpers.js +1 -1
- package/dist/src/transform/astNodeMutationHelpers.js +4 -3
- package/dist/src/traverse/SimpleTraverser.js +4 -2
- package/dist/src/traverse/getVisitorKeys.js +5 -3
- package/dist/src/utils/Builders.js +2 -3
- package/dist/src/utils/GenID.js +1 -1
- package/dist/src/utils/createSyntaxError.js +1 -1
- package/dist/src/utils/isReservedWord.js +1 -1
- package/dist/src/utils/mutateESTreeASTForPrettier.js +1 -1
- package/dist/transform/SimpleTransform.js +10 -1
- package/dist/transform/SimpleTransform.js.flow +6 -7
- package/dist/transform/astArrayMutationHelpers.js +1 -1
- package/dist/transform/astArrayMutationHelpers.js.flow +8 -8
- package/dist/transform/astNodeMutationHelpers.js +4 -3
- package/dist/transform/astNodeMutationHelpers.js.flow +12 -6
- package/dist/traverse/SimpleTraverser.js +4 -2
- package/dist/traverse/SimpleTraverser.js.flow +4 -4
- package/dist/traverse/getVisitorKeys.js +5 -3
- package/dist/traverse/getVisitorKeys.js.flow +5 -3
- package/dist/utils/Builders.js +2 -3
- package/dist/utils/Builders.js.flow +6 -6
- package/dist/utils/GenID.js +1 -1
- package/dist/utils/GenID.js.flow +2 -2
- package/dist/utils/createSyntaxError.js +1 -1
- package/dist/utils/isReservedWord.js +1 -1
- package/dist/utils/mutateESTreeASTForPrettier.js +1 -1
- package/dist/utils/mutateESTreeASTForPrettier.js.flow +1 -1
- package/package.json +4 -3
|
@@ -12,11 +12,11 @@ type INTENTIONAL_ANY = $FlowFixMe;
|
|
|
12
12
|
type JSType = 'number' | 'string' | 'array' | 'boolean';
|
|
13
13
|
type CBoolean = ?(number | boolean);
|
|
14
14
|
|
|
15
|
-
type WASMModuleOverrides =
|
|
15
|
+
type WASMModuleOverrides = Readonly<{
|
|
16
16
|
quit(status: number, toThrow: Error): void,
|
|
17
17
|
}>;
|
|
18
18
|
|
|
19
|
-
export type HermesParserWASM =
|
|
19
|
+
export type HermesParserWASM = Readonly<{
|
|
20
20
|
HEAP8: Int8Array,
|
|
21
21
|
HEAP16: Int16Array,
|
|
22
22
|
HEAP32: Int32Array,
|
|
@@ -32,11 +32,11 @@ export type HermesParserWASM = $ReadOnly<{
|
|
|
32
32
|
ccall(
|
|
33
33
|
ident: string,
|
|
34
34
|
returnType: JSType | null,
|
|
35
|
-
argTypes:
|
|
36
|
-
args:
|
|
37
|
-
number | string |
|
|
35
|
+
argTypes: ReadonlyArray<JSType>,
|
|
36
|
+
args: ReadonlyArray<
|
|
37
|
+
number | string | ReadonlyArray<INTENTIONAL_ANY> | boolean,
|
|
38
38
|
>,
|
|
39
|
-
opts?:
|
|
39
|
+
opts?: Readonly<{
|
|
40
40
|
async?: boolean | void,
|
|
41
41
|
}>,
|
|
42
42
|
): INTENTIONAL_ANY,
|
|
@@ -17,9 +17,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
17
17
|
* This source code is licensed under the MIT license found in the
|
|
18
18
|
* LICENSE file in the root directory of this source tree.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
20
|
+
* strict
|
|
21
21
|
* @format
|
|
22
22
|
*/
|
|
23
|
+
// eslint-disable-next-line no-unused-vars
|
|
23
24
|
class HermesToESTreeAdapter extends _HermesASTAdapter.default {
|
|
24
25
|
constructor(options, code) {
|
|
25
26
|
super(options);
|
|
@@ -185,7 +186,7 @@ class HermesToESTreeAdapter extends _HermesASTAdapter.default {
|
|
|
185
186
|
|
|
186
187
|
try {
|
|
187
188
|
value = new RegExp(pattern, flags);
|
|
188
|
-
} catch
|
|
189
|
+
} catch {
|
|
189
190
|
value = null;
|
|
190
191
|
}
|
|
191
192
|
|
|
@@ -14,10 +14,11 @@ import type {ParserOptions} from './ParserOptions';
|
|
|
14
14
|
import HermesASTAdapter from './HermesASTAdapter';
|
|
15
15
|
import {getModuleDocblock} from './getModuleDocblock';
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
// eslint-disable-next-line no-unused-vars
|
|
18
|
+
declare var BigInt: ?(value: $FlowFixMe) => unknown;
|
|
18
19
|
|
|
19
20
|
export default class HermesToESTreeAdapter extends HermesASTAdapter {
|
|
20
|
-
|
|
21
|
+
readonly code: string;
|
|
21
22
|
|
|
22
23
|
constructor(options: ParserOptions, code: string) {
|
|
23
24
|
super(options);
|
|
@@ -161,7 +162,7 @@ export default class HermesToESTreeAdapter extends HermesASTAdapter {
|
|
|
161
162
|
let value;
|
|
162
163
|
try {
|
|
163
164
|
value = new RegExp(pattern, flags);
|
|
164
|
-
} catch
|
|
165
|
+
} catch {
|
|
165
166
|
value = null;
|
|
166
167
|
}
|
|
167
168
|
|
package/dist/ParserOptions.js
CHANGED
|
@@ -11,8 +11,10 @@ exports.ParserOptionsKeys = void 0;
|
|
|
11
11
|
* This source code is licensed under the MIT license found in the
|
|
12
12
|
* LICENSE file in the root directory of this source tree.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
* @
|
|
14
|
+
* strict
|
|
15
|
+
* @noformat
|
|
16
16
|
*/
|
|
17
|
-
const ParserOptionsKeys
|
|
17
|
+
const ParserOptionsKeys
|
|
18
|
+
/*: ReadonlySet<keyof ParserOptions> */
|
|
19
|
+
= new Set(['allowReturnOutsideFunction', 'babel', 'flow', 'enableExperimentalComponentSyntax', 'enableExperimentalFlowMatchSyntax', 'enableExperimentalFlowRecordSyntax', 'reactRuntimeTarget', 'sourceFilename', 'sourceType', 'tokens', 'transformOptions']);
|
|
18
20
|
exports.ParserOptionsKeys = ParserOptionsKeys;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
* @flow strict
|
|
8
|
-
* @
|
|
8
|
+
* @noformat
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import type {Expression} from 'hermes-estree';
|
|
@@ -22,14 +22,14 @@ export type ParserOptions = {
|
|
|
22
22
|
sourceType?: 'module' | 'script' | 'unambiguous',
|
|
23
23
|
tokens?: boolean,
|
|
24
24
|
transformOptions?: {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
readonly TransformEnumSyntax?: {
|
|
26
|
+
readonly enable: boolean,
|
|
27
|
+
readonly getRuntime?: () => Expression,
|
|
28
28
|
},
|
|
29
29
|
},
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
export const ParserOptionsKeys
|
|
32
|
+
export const ParserOptionsKeys /*: ReadonlySet<keyof ParserOptions> */ = new Set([
|
|
33
33
|
'allowReturnOutsideFunction',
|
|
34
34
|
'babel',
|
|
35
35
|
'flow',
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* strict
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
@@ -277,14 +277,15 @@ function mapProperty(node) {
|
|
|
277
277
|
|
|
278
278
|
return newNode;
|
|
279
279
|
} // Non-method property nodes should be renamed to ObjectProperty
|
|
280
|
+
// $FlowExpectedError[incompatible-type]
|
|
280
281
|
|
|
281
282
|
|
|
283
|
+
const propertyValue = value;
|
|
282
284
|
return {
|
|
283
285
|
type: 'ObjectProperty',
|
|
284
286
|
computed: node.computed,
|
|
285
287
|
key: node.key,
|
|
286
|
-
|
|
287
|
-
value: node.value,
|
|
288
|
+
value: propertyValue,
|
|
288
289
|
method: node.method,
|
|
289
290
|
shorthand: node.shorthand,
|
|
290
291
|
loc: node.loc,
|
|
@@ -95,7 +95,7 @@ const FlowESTreeAndBabelVisitorKeys: VisitorKeys = {
|
|
|
95
95
|
CommentLine: [],
|
|
96
96
|
};
|
|
97
97
|
|
|
98
|
-
function nodeWith<T
|
|
98
|
+
function nodeWith<T extends ESNode>(node: T, overrideProps: Partial<T>): T {
|
|
99
99
|
return SimpleTransform.nodeWith(
|
|
100
100
|
node,
|
|
101
101
|
overrideProps,
|
|
@@ -109,33 +109,33 @@ function nodeWith<T: ESNode>(node: T, overrideProps: Partial<T>): T {
|
|
|
109
109
|
* Copied from: https://github.com/babel/babel/blob/main/packages/babel-types/src/ast-types/generated/index.ts
|
|
110
110
|
*/
|
|
111
111
|
export interface BabelFile extends BaseNode {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
readonly type: 'File';
|
|
113
|
+
readonly program: Program;
|
|
114
|
+
readonly comments: ReadonlyArray<BabelComment>;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
interface BabelCommentBlock extends BaseToken {
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
readonly type: 'CommentBlock';
|
|
119
|
+
readonly value: string;
|
|
120
120
|
}
|
|
121
121
|
interface BabelCommentLine extends BaseToken {
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
readonly type: 'CommentLine';
|
|
123
|
+
readonly value: string;
|
|
124
124
|
}
|
|
125
125
|
type BabelComment = BabelCommentBlock | BabelCommentLine;
|
|
126
126
|
|
|
127
127
|
interface BabelObjectMethod extends BaseNode {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
128
|
+
readonly type: 'ObjectMethod';
|
|
129
|
+
readonly kind: 'method' | 'get' | 'set';
|
|
130
|
+
readonly key: Expression;
|
|
131
|
+
readonly params: ReadonlyArray<FunctionParameter>;
|
|
132
|
+
readonly body: BlockStatement;
|
|
133
|
+
readonly computed: boolean;
|
|
134
|
+
readonly generator: boolean;
|
|
135
|
+
readonly async: boolean;
|
|
136
|
+
readonly returnType?: TypeAnnotation | null;
|
|
137
|
+
readonly typeParameters?: TypeParameterDeclaration | null;
|
|
138
|
+
readonly variance?: boolean | null;
|
|
139
139
|
|
|
140
140
|
// TODO: Should these exist?
|
|
141
141
|
// +id: ...,
|
|
@@ -145,146 +145,146 @@ interface BabelObjectMethod extends BaseNode {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
interface BabelObjectProperty extends BaseNode {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
148
|
+
readonly type: 'ObjectProperty';
|
|
149
|
+
readonly computed: boolean;
|
|
150
|
+
readonly key: Expression;
|
|
151
|
+
readonly value: Expression;
|
|
152
|
+
readonly method: boolean;
|
|
153
|
+
readonly shorthand: boolean;
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
interface BabelClassMethodBase extends BaseNode {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
157
|
+
readonly kind: 'get' | 'set' | 'method' | 'constructor';
|
|
158
|
+
readonly computed: boolean;
|
|
159
|
+
readonly static: boolean;
|
|
160
|
+
readonly key:
|
|
161
161
|
| Identifier
|
|
162
162
|
| StringLiteral
|
|
163
163
|
| ClassPropertyNameComputed
|
|
164
164
|
| ClassPropertyNameNonComputed;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
165
|
+
readonly id: null;
|
|
166
|
+
readonly params: ReadonlyArray<FunctionParameter>;
|
|
167
|
+
readonly body: BlockStatement;
|
|
168
|
+
readonly async: boolean;
|
|
169
|
+
readonly generator: boolean;
|
|
170
|
+
readonly returnType?: TypeAnnotation | null;
|
|
171
|
+
readonly typeParameters?: TypeParameterDeclaration | null;
|
|
172
|
+
readonly predicate: null;
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
interface BabelClassPrivateMethod extends BabelClassMethodBase {
|
|
176
|
-
|
|
176
|
+
readonly type: 'ClassPrivateMethod';
|
|
177
177
|
}
|
|
178
178
|
interface BabelClassMethod extends BabelClassMethodBase {
|
|
179
|
-
|
|
179
|
+
readonly type: 'ClassMethod';
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
interface BabelClassProperty extends BaseNode {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
183
|
+
readonly type: 'ClassProperty';
|
|
184
|
+
readonly key: Expression;
|
|
185
|
+
readonly value: null | Expression;
|
|
186
|
+
readonly typeAnnotation: null | TypeAnnotation;
|
|
187
|
+
readonly static: boolean;
|
|
188
|
+
readonly variance: null | Variance;
|
|
189
|
+
readonly declare: boolean;
|
|
190
|
+
readonly optional: null | boolean;
|
|
191
|
+
readonly computed: boolean;
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
interface BabelClassPrivateProperty extends BaseNode {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
195
|
+
readonly type: 'ClassPrivateProperty';
|
|
196
|
+
readonly key: BabelPrivateName;
|
|
197
|
+
readonly value: null | Expression;
|
|
198
|
+
readonly typeAnnotation: null | TypeAnnotation;
|
|
199
|
+
readonly static: boolean;
|
|
200
|
+
readonly variance: null | Variance;
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
interface BabelExportNamespaceSpecifier extends BaseNode {
|
|
204
|
-
|
|
205
|
-
|
|
204
|
+
readonly type: 'ExportNamespaceSpecifier';
|
|
205
|
+
readonly exported: Identifier;
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
interface BabelExportNamedDeclaration extends BaseNode {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
209
|
+
readonly type: 'ExportNamedDeclaration';
|
|
210
|
+
readonly declaration?: null;
|
|
211
|
+
readonly specifiers: ReadonlyArray<BabelExportNamespaceSpecifier>;
|
|
212
|
+
readonly source?: StringLiteral | null;
|
|
213
|
+
readonly exportKind: 'value' | 'type';
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
interface BabelPrivateName extends BaseNode {
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
readonly type: 'PrivateName';
|
|
218
|
+
readonly id: Identifier;
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
interface BabelOptionalMemberExpression extends BaseNode {
|
|
222
|
-
|
|
223
|
-
|
|
222
|
+
readonly type: 'OptionalMemberExpression';
|
|
223
|
+
readonly object:
|
|
224
224
|
| Expression
|
|
225
225
|
| Super
|
|
226
226
|
| BabelOptionalMemberExpression
|
|
227
227
|
| BabelOptionalCallExpression;
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
228
|
+
readonly property: Expression | Identifier | PrivateIdentifier;
|
|
229
|
+
readonly computed: boolean;
|
|
230
|
+
readonly optional: boolean;
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
interface BabelOptionalCallExpression extends BaseNode {
|
|
234
|
-
|
|
235
|
-
|
|
234
|
+
readonly type: 'OptionalCallExpression';
|
|
235
|
+
readonly callee:
|
|
236
236
|
| Expression
|
|
237
237
|
| Super
|
|
238
238
|
| BabelOptionalMemberExpression
|
|
239
239
|
| BabelOptionalCallExpression;
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
240
|
+
readonly arguments: ReadonlyArray<Expression | SpreadElement>;
|
|
241
|
+
readonly optional: boolean;
|
|
242
|
+
readonly typeArguments?: TypeParameterInstantiation | null;
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
interface BabelStringLiteral extends BaseNode {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
246
|
+
readonly type: 'StringLiteral';
|
|
247
|
+
readonly value: string;
|
|
248
|
+
readonly extra: Readonly<{
|
|
249
|
+
readonly rawValue: string,
|
|
250
|
+
readonly raw: string,
|
|
251
251
|
}>;
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
interface BabelNumericLiteral extends BaseNode {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
255
|
+
readonly type: 'NumericLiteral';
|
|
256
|
+
readonly value: number;
|
|
257
|
+
readonly extra: Readonly<{
|
|
258
|
+
readonly rawValue: number,
|
|
259
|
+
readonly raw: string,
|
|
260
260
|
}>;
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
interface BabelBigIntLiteral extends BaseNode {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
264
|
+
readonly type: 'BigIntLiteral';
|
|
265
|
+
readonly value: string;
|
|
266
|
+
readonly extra: Readonly<{
|
|
267
|
+
readonly rawValue: string,
|
|
268
|
+
readonly raw: string,
|
|
269
269
|
}>;
|
|
270
270
|
}
|
|
271
271
|
|
|
272
272
|
interface BabelBooleanLiteral extends BaseNode {
|
|
273
|
-
|
|
274
|
-
|
|
273
|
+
readonly type: 'BooleanLiteral';
|
|
274
|
+
readonly value: boolean;
|
|
275
275
|
}
|
|
276
276
|
|
|
277
277
|
interface BabelNullLiteral extends BaseNode {
|
|
278
|
-
|
|
278
|
+
readonly type: 'NullLiteral';
|
|
279
279
|
}
|
|
280
280
|
|
|
281
281
|
interface BabelRegExpLiteral extends BaseNode {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
282
|
+
readonly type: 'RegExpLiteral';
|
|
283
|
+
readonly extra: Readonly<{
|
|
284
|
+
readonly raw: string,
|
|
285
285
|
}>;
|
|
286
|
-
|
|
287
|
-
|
|
286
|
+
readonly pattern: string;
|
|
287
|
+
readonly flags: string;
|
|
288
288
|
}
|
|
289
289
|
|
|
290
290
|
type BabelLiteral =
|
|
@@ -345,7 +345,7 @@ function fixSourceLocation(
|
|
|
345
345
|
delete node.parent;
|
|
346
346
|
}
|
|
347
347
|
|
|
348
|
-
function mapNodeWithDirectives<T
|
|
348
|
+
function mapNodeWithDirectives<T extends Program | BlockStatement>(node: T): T {
|
|
349
349
|
// $FlowExpectedError[prop-missing]
|
|
350
350
|
if (node.directives != null) {
|
|
351
351
|
return node;
|
|
@@ -412,7 +412,7 @@ function mapProgram(node: Program): BabelFile {
|
|
|
412
412
|
};
|
|
413
413
|
const range = [0, endRange];
|
|
414
414
|
|
|
415
|
-
const babelComments:
|
|
415
|
+
const babelComments: ReadonlyArray<BabelComment> = program.comments.map(
|
|
416
416
|
comment => {
|
|
417
417
|
switch (comment.type) {
|
|
418
418
|
case 'Line': {
|
|
@@ -534,12 +534,13 @@ function mapProperty(node: Property): BabelObjectMethod | BabelObjectProperty {
|
|
|
534
534
|
}
|
|
535
535
|
|
|
536
536
|
// Non-method property nodes should be renamed to ObjectProperty
|
|
537
|
+
// $FlowExpectedError[incompatible-type]
|
|
538
|
+
const propertyValue: Expression = value;
|
|
537
539
|
return {
|
|
538
540
|
type: 'ObjectProperty',
|
|
539
541
|
computed: node.computed,
|
|
540
542
|
key: node.key,
|
|
541
|
-
|
|
542
|
-
value: (node.value: Expression),
|
|
543
|
+
value: propertyValue,
|
|
543
544
|
method: node.method,
|
|
544
545
|
shorthand: node.shorthand,
|
|
545
546
|
loc: node.loc,
|
|
@@ -174,9 +174,9 @@ function createPropsTypeAnnotation(
|
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
function mapComponentParameters(
|
|
177
|
-
params:
|
|
177
|
+
params: ReadonlyArray<ComponentParameter | RestElement>,
|
|
178
178
|
options: ParserOptions,
|
|
179
|
-
):
|
|
179
|
+
): Readonly<{
|
|
180
180
|
props: ?(ObjectPattern | Identifier),
|
|
181
181
|
ref: ?(BindingName | AssignmentPattern),
|
|
182
182
|
}> {
|
|
@@ -723,7 +723,7 @@ function mapComponentDeclarationIntoList(
|
|
|
723
723
|
}
|
|
724
724
|
|
|
725
725
|
function mapStatementList(
|
|
726
|
-
stmts:
|
|
726
|
+
stmts: ReadonlyArray<Statement | ModuleDeclaration>,
|
|
727
727
|
options: ParserOptions,
|
|
728
728
|
) {
|
|
729
729
|
const newBody: Array<Statement | ModuleDeclaration> = [];
|
|
@@ -98,7 +98,7 @@ export function transformProgram(
|
|
|
98
98
|
options: ParserOptions,
|
|
99
99
|
): Program {
|
|
100
100
|
return SimpleTransform.transformProgram(program, {
|
|
101
|
-
transform(node: ESNode): ESNode |
|
|
101
|
+
transform(node: ESNode): ESNode | ReadonlyArray<ESNode> {
|
|
102
102
|
switch (node.type) {
|
|
103
103
|
case 'EnumDeclaration': {
|
|
104
104
|
return mapEnumDeclaration(node, options);
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* strict
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
@@ -48,6 +48,14 @@ function genIdent() {
|
|
|
48
48
|
* location of to be tested against, or location to be extracted to a binding.
|
|
49
49
|
*/
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* The conditional aspect of a match pattern for a single location.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A binding introduced by a match pattern.
|
|
57
|
+
*/
|
|
58
|
+
|
|
51
59
|
|
|
52
60
|
function objKeyToString(node) {
|
|
53
61
|
switch (node.type) {
|
|
@@ -368,7 +376,8 @@ function analyzePattern(pattern, key, seenBindingNames) {
|
|
|
368
376
|
conditions,
|
|
369
377
|
bindings
|
|
370
378
|
} = analyzePattern(asPattern, key, seenBindingNames);
|
|
371
|
-
const
|
|
379
|
+
const constKind = 'const';
|
|
380
|
+
const [id, kind] = target.type === 'MatchBindingPattern' ? [target.id, target.kind] : [target, constKind];
|
|
372
381
|
checkDuplicateBindingName(seenBindingNames, pattern, id.name);
|
|
373
382
|
checkBindingKind(pattern, kind);
|
|
374
383
|
const binding = {
|
|
@@ -351,10 +351,11 @@ function analyzePattern(
|
|
|
351
351
|
key,
|
|
352
352
|
seenBindingNames,
|
|
353
353
|
);
|
|
354
|
+
const constKind: 'const' = 'const';
|
|
354
355
|
const [id, kind] =
|
|
355
356
|
target.type === 'MatchBindingPattern'
|
|
356
357
|
? [target.id, target.kind]
|
|
357
|
-
: [target,
|
|
358
|
+
: [target, constKind];
|
|
358
359
|
checkDuplicateBindingName(seenBindingNames, pattern, id.name);
|
|
359
360
|
checkBindingKind(pattern, kind);
|
|
360
361
|
const binding: Binding = {type: 'id', key, kind, id};
|
|
@@ -725,19 +726,19 @@ function calculateSimpleArgument(node: Expression | Super): boolean {
|
|
|
725
726
|
* Analyze the match cases and return information we will use to build the result.
|
|
726
727
|
*/
|
|
727
728
|
type CaseAnalysis<T> = {
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
729
|
+
readonly conditions: Array<Condition>,
|
|
730
|
+
readonly bindings: Array<Binding>,
|
|
731
|
+
readonly guard: Expression | null,
|
|
732
|
+
readonly body: T,
|
|
732
733
|
};
|
|
733
734
|
|
|
734
735
|
interface MatchCase<T> {
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
736
|
+
readonly pattern: MatchPattern;
|
|
737
|
+
readonly guard: Expression | null;
|
|
738
|
+
readonly body: T;
|
|
738
739
|
}
|
|
739
740
|
|
|
740
|
-
function analyzeCases<T>(cases:
|
|
741
|
+
function analyzeCases<T>(cases: ReadonlyArray<MatchCase<T>>): {
|
|
741
742
|
hasBindings: boolean,
|
|
742
743
|
hasWildcard: boolean,
|
|
743
744
|
analyses: Array<CaseAnalysis<T>>,
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
/* eslint no-undef: 'error', no-unused-vars: ['error', {vars: "local"}], no-redeclare: 'error' */
|
|
20
20
|
|
|
21
|
-
/* global
|
|
21
|
+
/* global NonNullable, Partial, Readonly, ReadonlyArray, $FlowFixMe */
|
|
22
22
|
'use strict';
|
|
23
23
|
|
|
24
24
|
module.exports = {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
/* eslint no-undef: 'error', no-unused-vars: ['error', {vars: "local"}], no-redeclare: 'error' */
|
|
20
20
|
|
|
21
|
-
/* global
|
|
21
|
+
/* global NonNullable, Partial, Readonly, ReadonlyArray, $FlowFixMe */
|
|
22
22
|
'use strict';
|
|
23
23
|
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
|
|
11
11
|
declare export var NODE_CHILD: 'Node';
|
|
12
12
|
declare export var NODE_LIST_CHILD: 'NodeList';
|
|
13
|
-
declare export var HERMES_AST_VISITOR_KEYS:
|
|
14
|
-
[string]:
|
|
13
|
+
declare export var HERMES_AST_VISITOR_KEYS: Readonly<{
|
|
14
|
+
[string]: Readonly<{
|
|
15
15
|
[string]: 'Node' | 'NodeList',
|
|
16
16
|
}>,
|
|
17
17
|
}>;
|