Skip to content

Commit 1e3b195

Browse files
tarunrajputcipolleschi
authored andcommitted
refactor: add ParserType for parser errors
1 parent e4fb1a3 commit 1e3b195

File tree

1 file changed

+23
-21
lines changed
  • packages/react-native-codegen/src/parsers

1 file changed

+23
-21
lines changed

packages/react-native-codegen/src/parsers/errors.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
const invariant = require('invariant');
1414

15+
type ParserType = 'Flow' | 'TypeScript';
16+
1517
class ParserError extends Error {
1618
nodes: $ReadOnlyArray<$FlowFixMe>;
1719
constructor(
@@ -34,7 +36,7 @@ class ParserError extends Error {
3436
}
3537

3638
class MisnamedModuleInterfaceParserError extends ParserError {
37-
constructor(nativeModuleName: string, id: $FlowFixMe, language: string) {
39+
constructor(nativeModuleName: string, id: $FlowFixMe, language: ParserType) {
3840
super(
3941
nativeModuleName,
4042
id,
@@ -44,7 +46,7 @@ class MisnamedModuleInterfaceParserError extends ParserError {
4446
}
4547

4648
class ModuleInterfaceNotFoundParserError extends ParserError {
47-
constructor(nativeModuleName: string, ast: $FlowFixMe, language: string) {
49+
constructor(nativeModuleName: string, ast: $FlowFixMe, language: ParserType) {
4850
super(
4951
nativeModuleName,
5052
ast,
@@ -58,7 +60,7 @@ class MoreThanOneModuleInterfaceParserError extends ParserError {
5860
nativeModuleName: string,
5961
flowModuleInterfaces: $ReadOnlyArray<$FlowFixMe>,
6062
names: $ReadOnlyArray<string>,
61-
language: string,
63+
language: ParserType,
6264
) {
6365
const finalName = names[names.length - 1];
6466
const allButLastName = names.slice(0, -1);
@@ -81,7 +83,7 @@ class UnsupportedModulePropertyParserError extends ParserError {
8183
propertyValue: $FlowFixMe,
8284
propertyName: string,
8385
invalidPropertyValueType: string,
84-
language: string,
86+
language: ParserType,
8587
) {
8688
super(
8789
nativeModuleName,
@@ -96,7 +98,7 @@ class UnsupportedTypeAnnotationParserError extends ParserError {
9698
constructor(
9799
nativeModuleName: string,
98100
typeAnnotation: $FlowFixMe,
99-
language: string,
101+
language: ParserType,
100102
) {
101103
super(
102104
nativeModuleName,
@@ -113,7 +115,7 @@ class UnsupportedGenericParserError extends ParserError {
113115
constructor(
114116
nativeModuleName: string,
115117
genericTypeAnnotation: $FlowFixMe,
116-
language: string,
118+
language: ParserType,
117119
) {
118120
const genericName =
119121
language === 'TypeScript'
@@ -137,7 +139,7 @@ class IncorrectlyParameterizedGenericParserError extends ParserError {
137139
constructor(
138140
nativeModuleName: string,
139141
genericTypeAnnotation: $FlowFixMe,
140-
language: string,
142+
language: ParserType,
141143
) {
142144
const genericName =
143145
language === 'TypeScript'
@@ -182,7 +184,7 @@ class UnsupportedArrayElementTypeAnnotationParserError extends ParserError {
182184
arrayElementTypeAST: $FlowFixMe,
183185
arrayType: 'Array' | '$ReadOnlyArray' | 'ReadonlyArray',
184186
invalidArrayElementType: string,
185-
language: string,
187+
language: ParserType,
186188
) {
187189
super(
188190
nativeModuleName,
@@ -201,7 +203,7 @@ class UnsupportedObjectPropertyTypeAnnotationParserError extends ParserError {
201203
nativeModuleName: string,
202204
propertyAST: $FlowFixMe,
203205
invalidPropertyType: string,
204-
language: string,
206+
language: ParserType,
205207
) {
206208
let message = `'ObjectTypeAnnotation' cannot contain '${invalidPropertyType}'.`;
207209

@@ -222,7 +224,7 @@ class UnsupportedObjectPropertyValueTypeAnnotationParserError extends ParserErro
222224
propertyValueAST: $FlowFixMe,
223225
propertyName: string,
224226
invalidPropertyValueType: string,
225-
language: string,
227+
language: ParserType,
226228
) {
227229
super(
228230
nativeModuleName,
@@ -240,7 +242,7 @@ class UnnamedFunctionParamParserError extends ParserError {
240242
constructor(
241243
functionParam: $FlowFixMe,
242244
nativeModuleName: string,
243-
language: string,
245+
language: ParserType,
244246
) {
245247
super(
246248
nativeModuleName,
@@ -256,7 +258,7 @@ class UnsupportedFunctionParamTypeAnnotationParserError extends ParserError {
256258
flowParamTypeAnnotation: $FlowFixMe,
257259
paramName: string,
258260
invalidParamType: string,
259-
language: string,
261+
language: ParserType,
260262
) {
261263
super(
262264
nativeModuleName,
@@ -271,7 +273,7 @@ class UnsupportedFunctionReturnTypeAnnotationParserError extends ParserError {
271273
nativeModuleName: string,
272274
flowReturnTypeAnnotation: $FlowFixMe,
273275
invalidReturnType: string,
274-
language: string,
276+
language: ParserType,
275277
) {
276278
super(
277279
nativeModuleName,
@@ -290,7 +292,7 @@ class UnsupportedEnumDeclarationParserError extends ParserError {
290292
nativeModuleName: string,
291293
arrayElementTypeAST: $FlowFixMe,
292294
memberType: string,
293-
language: string,
295+
language: ParserType,
294296
) {
295297
super(
296298
nativeModuleName,
@@ -309,7 +311,7 @@ class UnsupportedUnionTypeAnnotationParserError extends ParserError {
309311
nativeModuleName: string,
310312
arrayElementTypeAST: $FlowFixMe,
311313
types: string[],
312-
language: string,
314+
language: ParserType,
313315
) {
314316
super(
315317
nativeModuleName,
@@ -329,7 +331,7 @@ class UnusedModuleInterfaceParserError extends ParserError {
329331
constructor(
330332
nativeModuleName: string,
331333
flowInterface: $FlowFixMe,
332-
language: string,
334+
language: ParserType,
333335
) {
334336
super(
335337
nativeModuleName,
@@ -344,7 +346,7 @@ class MoreThanOneModuleRegistryCallsParserError extends ParserError {
344346
nativeModuleName: string,
345347
flowCallExpressions: $FlowFixMe,
346348
numCalls: number,
347-
language: string,
349+
language: ParserType,
348350
) {
349351
super(
350352
nativeModuleName,
@@ -360,7 +362,7 @@ class UntypedModuleRegistryCallParserError extends ParserError {
360362
flowCallExpression: $FlowFixMe,
361363
methodName: string,
362364
moduleName: string,
363-
language: string,
365+
language: ParserType,
364366
) {
365367
super(
366368
nativeModuleName,
@@ -376,7 +378,7 @@ class IncorrectModuleRegistryCallTypeParameterParserError extends ParserError {
376378
flowTypeArguments: $FlowFixMe,
377379
methodName: string,
378380
moduleName: string,
379-
language: string,
381+
language: ParserType,
380382
) {
381383
super(
382384
nativeModuleName,
@@ -392,7 +394,7 @@ class IncorrectModuleRegistryCallArityParserError extends ParserError {
392394
flowCallExpression: $FlowFixMe,
393395
methodName: string,
394396
incorrectArity: number,
395-
language: string,
397+
language: ParserType,
396398
) {
397399
super(
398400
nativeModuleName,
@@ -408,7 +410,7 @@ class IncorrectModuleRegistryCallArgumentTypeParserError extends ParserError {
408410
flowArgument: $FlowFixMe,
409411
methodName: string,
410412
type: string,
411-
language: string,
413+
language: ParserType,
412414
) {
413415
const a = /[aeiouy]/.test(type.toLowerCase()) ? 'an' : 'a';
414416
super(

0 commit comments

Comments
 (0)