Skip to content

Commit e9ed4ac

Browse files
committed
refactor(parsers): remove parserOptions param to pass it directly in parser implementation
1 parent dfc5ee5 commit e9ed4ac

File tree

6 files changed

+14
-34
lines changed

6 files changed

+14
-34
lines changed

packages/react-native-codegen/src/parsers/flow/index.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ function parseModuleFixture(filename: string): SchemaType {
5252
contents,
5353
'path/NativeSampleTurboModule.js',
5454
flowParser,
55-
{
56-
enums: true,
57-
},
5855
Visitor,
5956
wrapComponentSchema,
6057
buildComponentSchema,
@@ -67,9 +64,6 @@ function parseString(contents: string, filename: ?string): SchemaType {
6764
contents,
6865
filename,
6966
flowParser,
70-
{
71-
enums: true,
72-
},
7367
Visitor,
7468
wrapComponentSchema,
7569
buildComponentSchema,

packages/react-native-codegen/src/parsers/flow/parser.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// $FlowFixMe[untyped-import] there's no flowtype flow-parser
1414
const flowParser = require('flow-parser');
1515
import type {ParserType} from '../errors';
16-
import type {Parser, ParserOptions} from '../parser';
16+
import type {Parser} from '../parser';
1717

1818
class FlowParser implements Parser {
1919
getMaybeEnumMemberType(maybeEnumDeclaration: $FlowFixMe): string {
@@ -34,8 +34,10 @@ class FlowParser implements Parser {
3434
return typeAnnotation.id.name;
3535
}
3636

37-
parse(contents: string, parserOptions: ParserOptions): $FlowFixMe {
38-
return flowParser.parse(contents, parserOptions);
37+
parse(contents: string): $FlowFixMe {
38+
return flowParser.parse(contents, {
39+
enums: true,
40+
});
3941
}
4042
}
4143

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@
1212

1313
import type {ParserType} from './errors';
1414

15-
export interface ParserOptions {
16-
enums?: boolean;
17-
sourceType?: string;
18-
plugins?: Array<string>;
19-
}
20-
2115
/**
2216
* This is the main interface for Parsers of various languages.
2317
* It exposes all the methods that contain language-specific logic.
@@ -48,11 +42,7 @@ export interface Parser {
4842
/**
4943
* Given the content of a file and options, it returns an AST.
5044
* @parameter contents: the content of the file.
51-
* @parameter parserOptions: the options given to the parser.
5245
* @returns: the AST of the file (given in program property for typescript).
5346
*/
54-
parse(
55-
contents: string,
56-
parserOptions: ParserOptions,
57-
): $FlowFixMe | {program: $FlowFixMe};
47+
parse(contents: string): $FlowFixMe | {program: $FlowFixMe};
5848
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type {
1919
UnionTypeAnnotationMemberType,
2020
NativeModuleUnionTypeAnnotation,
2121
} from '../CodegenSchema.js';
22-
import type {Parser, ParserOptions} from './parser';
22+
import type {Parser} from './parser';
2323
import type {ParserType} from './errors';
2424
import type {ParserErrorCapturer, TypeDeclarationMap} from './utils';
2525
import type {ComponentSchemaBuilderConfig} from './flow/components/schema';
@@ -110,7 +110,6 @@ function buildSchema(
110110
contents: string,
111111
filename: ?string,
112112
parser: Parser,
113-
parserOptions: ParserOptions,
114113
Visitor: ({isComponent: boolean, isModule: boolean}) => {
115114
[type: string]: (node: $FlowFixMe) => void,
116115
},
@@ -130,7 +129,7 @@ function buildSchema(
130129
return {modules: {}};
131130
}
132131

133-
const result = parser.parse(contents, parserOptions);
132+
const result = parser.parse(contents);
134133
const ast = parser.language() === 'Flow' ? result : result.program;
135134
const configType = getConfigType(ast, Visitor);
136135

packages/react-native-codegen/src/parsers/typescript/index.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ function parseModuleFixture(filename: string): SchemaType {
5858
contents,
5959
'path/NativeSampleTurboModule.ts',
6060
typescriptParser,
61-
{
62-
sourceType: 'module',
63-
plugins: ['typescript'],
64-
},
6561
Visitor,
6662
wrapComponentSchema,
6763
buildComponentSchema,
@@ -74,10 +70,6 @@ function parseString(contents: string, filename: ?string): SchemaType {
7470
contents,
7571
filename,
7672
typescriptParser,
77-
{
78-
sourceType: 'module',
79-
plugins: ['typescript'],
80-
},
8173
Visitor,
8274
wrapComponentSchema,
8375
buildComponentSchema,

packages/react-native-codegen/src/parsers/typescript/parser.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
const babelParser = require('@babel/parser');
1515

1616
import type {ParserType} from '../errors';
17-
import type {Parser, ParserOptions} from '../parser';
17+
import type {Parser} from '../parser';
1818

1919
class TypeScriptParser implements Parser {
2020
getMaybeEnumMemberType(maybeEnumDeclaration: $FlowFixMe): string {
@@ -39,8 +39,11 @@ class TypeScriptParser implements Parser {
3939
return typeAnnotation.typeName.name;
4040
}
4141

42-
parse(contents: string, parserOptions: ParserOptions): {program: $FlowFixMe} {
43-
return babelParser.parse(contents, parserOptions);
42+
parse(contents: string): {program: $FlowFixMe} {
43+
return babelParser.parse(contents, {
44+
sourceType: 'module',
45+
plugins: ['typescript'],
46+
});
4447
}
4548
}
4649
module.exports = {

0 commit comments

Comments
 (0)