Skip to content

Commit

Permalink
refactor(parsers): remove parserOptions param to pass it directly in …
Browse files Browse the repository at this point in the history
…parser implementation
  • Loading branch information
MaeIg committed Nov 10, 2022
1 parent 93e3a03 commit 656b486
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 34 deletions.
6 changes: 0 additions & 6 deletions packages/react-native-codegen/src/parsers/flow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ function parseModuleFixture(filename: string): SchemaType {
contents,
'path/NativeSampleTurboModule.js',
flowParser,
{
enums: true,
},
Visitor,
wrapComponentSchema,
buildComponentSchema,
Expand All @@ -67,9 +64,6 @@ function parseString(contents: string, filename: ?string): SchemaType {
contents,
filename,
flowParser,
{
enums: true,
},
Visitor,
wrapComponentSchema,
buildComponentSchema,
Expand Down
8 changes: 5 additions & 3 deletions packages/react-native-codegen/src/parsers/flow/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// $FlowFixMe[untyped-import] there's no flowtype flow-parser
const flowParser = require('flow-parser');
import type {ParserType} from '../errors';
import type {Parser, ParserOptions} from '../parser';
import type {Parser} from '../parser';

class FlowParser implements Parser {
typeParameterInstantiation: string = 'TypeParameterInstantiation';
Expand All @@ -36,8 +36,10 @@ class FlowParser implements Parser {
return typeAnnotation.id.name;
}

parse(contents: string, parserOptions: ParserOptions): $FlowFixMe {
return flowParser.parse(contents, parserOptions);
parse(contents: string): $FlowFixMe {
return flowParser.parse(contents, {
enums: true,
});
}
}

Expand Down
12 changes: 1 addition & 11 deletions packages/react-native-codegen/src/parsers/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@

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

export interface ParserOptions {
enums?: boolean;
sourceType?: string;
plugins?: Array<string>;
}

/**
* This is the main interface for Parsers of various languages.
* It exposes all the methods that contain language-specific logic.
Expand Down Expand Up @@ -53,11 +47,7 @@ export interface Parser {
/**
* Given the content of a file and options, it returns an AST.
* @parameter contents: the content of the file.
* @parameter parserOptions: the options given to the parser.
* @returns: the AST of the file (given in program property for typescript).
*/
parse(
contents: string,
parserOptions: ParserOptions,
): $FlowFixMe | {program: $FlowFixMe};
parse(contents: string): $FlowFixMe | {program: $FlowFixMe};
}
5 changes: 2 additions & 3 deletions packages/react-native-codegen/src/parsers/parsers-commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type {
import type {ParserType} from './errors';
import type {ParserErrorCapturer, TypeDeclarationMap} from './utils';
import type {ComponentSchemaBuilderConfig} from './flow/components/schema';
import type {Parser, ParserOptions} from './parser';
import type {Parser} from './parser';

const {
MissingTypeParameterGenericParserError,
Expand Down Expand Up @@ -111,7 +111,6 @@ function buildSchema(
contents: string,
filename: ?string,
parser: Parser,
parserOptions: ParserOptions,
Visitor: ({isComponent: boolean, isModule: boolean}) => {
[type: string]: (node: $FlowFixMe) => void,
},
Expand All @@ -131,7 +130,7 @@ function buildSchema(
return {modules: {}};
}

const result = parser.parse(contents, parserOptions);
const result = parser.parse(contents);
const ast = parser.language() === 'Flow' ? result : result.program;
const configType = getConfigType(ast, Visitor);

Expand Down
8 changes: 0 additions & 8 deletions packages/react-native-codegen/src/parsers/typescript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ function parseModuleFixture(filename: string): SchemaType {
contents,
'path/NativeSampleTurboModule.ts',
typescriptParser,
{
sourceType: 'module',
plugins: ['typescript'],
},
Visitor,
wrapComponentSchema,
buildComponentSchema,
Expand All @@ -74,10 +70,6 @@ function parseString(contents: string, filename: ?string): SchemaType {
contents,
filename,
typescriptParser,
{
sourceType: 'module',
plugins: ['typescript'],
},
Visitor,
wrapComponentSchema,
buildComponentSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
const babelParser = require('@babel/parser');

import type {ParserType} from '../errors';
import type {Parser, ParserOptions} from '../parser';
import type {Parser} from '../parser';

class TypeScriptParser implements Parser {
typeParameterInstantiation: string = 'TSTypeParameterInstantiation';
Expand All @@ -41,8 +41,11 @@ class TypeScriptParser implements Parser {
return typeAnnotation.typeName.name;
}

parse(contents: string, parserOptions: ParserOptions): {program: $FlowFixMe} {
return babelParser.parse(contents, parserOptions);
parse(contents: string): {program: $FlowFixMe} {
return babelParser.parse(contents, {
sourceType: 'module',
plugins: ['typescript'],
});
}
}
module.exports = {
Expand Down

0 comments on commit 656b486

Please sign in to comment.