Skip to content

Commit bba3b40

Browse files
committed
refactor: pass parser as a param to buildSchema and other functions that consume it
1 parent 09df623 commit bba3b40

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'use strict';
1212

1313
import type {SchemaType} from '../../CodegenSchema.js';
14+
import type {Parser} from '../parser';
1415

1516
// $FlowFixMe[untyped-import] there's no flowtype flow-parser
1617
const flowParser = require('flow-parser');
@@ -49,7 +50,11 @@ function Visitor(infoMap: {isComponent: boolean, isModule: boolean}) {
4950
};
5051
}
5152

52-
function buildSchema(contents: string, filename: ?string): SchemaType {
53+
function buildSchema(
54+
contents: string,
55+
filename: ?string,
56+
parser: Parser,
57+
): SchemaType {
5358
// Early return for non-Spec JavaScript files
5459
if (
5560
!contents.includes('codegenNativeComponent') &&
@@ -75,11 +80,11 @@ function buildSchema(contents: string, filename: ?string): SchemaType {
7580
function parseModuleFixture(filename: string): SchemaType {
7681
const contents = fs.readFileSync(filename, 'utf8');
7782

78-
return buildSchema(contents, 'path/NativeSampleTurboModule.js');
83+
return buildSchema(contents, 'path/NativeSampleTurboModule.js', parser);
7984
}
8085

8186
function parseString(contents: string, filename: ?string): SchemaType {
82-
return buildSchema(contents, filename);
87+
return buildSchema(contents, filename, parser);
8388
}
8489

8590
module.exports = {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class FlowParser implements Parser {
8787
parseFile(filename: string): SchemaType {
8888
const contents = fs.readFileSync(filename, 'utf8');
8989

90-
return buildSchema(contents, filename);
90+
return buildSchema(contents, filename, this);
9191
}
9292
}
9393

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'use strict';
1212

1313
import type {SchemaType} from '../../CodegenSchema.js';
14+
import type {Parser} from '../parser';
1415

1516
// $FlowFixMe[untyped-import] Use flow-types for @babel/parser
1617
const babelParser = require('@babel/parser');
@@ -55,7 +56,11 @@ function Visitor(infoMap: {isComponent: boolean, isModule: boolean}) {
5556
};
5657
}
5758

58-
function buildSchema(contents: string, filename: ?string): SchemaType {
59+
function buildSchema(
60+
contents: string,
61+
filename: ?string,
62+
parser: Parser,
63+
): SchemaType {
5964
// Early return for non-Spec JavaScript files
6065
if (
6166
!contents.includes('codegenNativeComponent') &&
@@ -85,11 +90,11 @@ function buildSchema(contents: string, filename: ?string): SchemaType {
8590
function parseModuleFixture(filename: string): SchemaType {
8691
const contents = fs.readFileSync(filename, 'utf8');
8792

88-
return buildSchema(contents, 'path/NativeSampleTurboModule.ts');
93+
return buildSchema(contents, 'path/NativeSampleTurboModule.ts', parser);
8994
}
9095

9196
function parseString(contents: string, filename: ?string): SchemaType {
92-
return buildSchema(contents, filename);
97+
return buildSchema(contents, filename, parser);
9398
}
9499

95100
module.exports = {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class TypeScriptParser implements Parser {
9292
parseFile(filename: string): SchemaType {
9393
const contents = fs.readFileSync(filename, 'utf8');
9494

95-
return buildSchema(contents, filename);
95+
return buildSchema(contents, filename, this);
9696
}
9797
}
9898
module.exports = {

0 commit comments

Comments
 (0)