Skip to content

Commit

Permalink
Extract the buildSchema function in the parsers-commons.js (#35158)
Browse files Browse the repository at this point in the history
Summary:
This PR aims to extract  the buildSchema function into parsers-commons that is shared between typescript and flow. It is a task of #34872:
> Extract the buildSchema function ([Flow](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/flow/index.js#L66), [TypeScript](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/typescript/index.js#L72)) in the parsers-commons.js file to a top level buildSchema function which takes additional parameters to properly parse the content, get the config type and to build the schema, based on the language used.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[Internal] [Changed] - Extract the buildSchema function in the parsers-commons.js

Pull Request resolved: #35158

Test Plan:
yarn test:
<img width="380" alt="image" src="https://user-images.githubusercontent.com/40902940/209584411-40f66047-e25d-43d4-975d-af10cd202f24.png">

yarn flow:
<img width="150" alt="image" src="https://user-images.githubusercontent.com/40902940/209584423-4cf2cb5a-a300-40a6-962c-e57934f19ad2.png">

yarn lint:
<img width="510" alt="image" src="https://user-images.githubusercontent.com/40902940/209584440-2d2b2658-73d8-47e2-bb8c-64d4633369a2.png">

Reviewed By: cortinico

Differential Revision: D42386804

Pulled By: cipolleschi

fbshipit-source-id: 2a238f7cec982d8ef3fd57a34dc9f58171e32b53
  • Loading branch information
MaeIg authored and facebook-github-bot committed Jan 12, 2023
1 parent 91397d4 commit dc4d73c
Show file tree
Hide file tree
Showing 15 changed files with 721 additions and 539 deletions.
3 changes: 1 addition & 2 deletions packages/eslint-plugin-specs/react-native-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,11 @@ function rule(context) {

const {buildModuleSchema, createParserErrorCapturer, parser} =
requireModuleParser();
const flowParser = require('flow-parser');

const [parsingErrors, tryParse] = createParserErrorCapturer();

const sourceCode = context.getSourceCode().getText();
const ast = flowParser.parse(sourceCode, {enums: true});
const ast = parser.getAst(sourceCode);

tryParse(() => {
buildModuleSchema(hasteModuleName, ast, tryParse, parser);
Expand Down
Loading

0 comments on commit dc4d73c

Please sign in to comment.