Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Codegen]: Extract module/errors into a shared file #34896

Closed

Conversation

tarunrajput
Copy link
Contributor

Summary

This PR reduces code duplication by extracting all the errors in the module/errors into a single parsers/errors.js file. All the errors must drop the corresponding Flow or Typescript token in the name and take an extra language parameter in the constructor. Also, rename the hasteModuleName parameter to nativeModuleName.

Part of #34872

Changelog

[Internal] [Changed] - Extract all the parsers errors in the module/errors into a single parsers/errors.js file

Test Plan

run yarn jest react-native-codegen and check all test case passes.

image

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 7, 2022
@tarunrajput tarunrajput changed the title refactor: Extract module/errors into a shared file [Codegen]: Extract module/errors into a shared file Oct 7, 2022
@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@analysis-bot
Copy link

analysis-bot commented Oct 7, 2022

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,768,507 +0
android hermes armeabi-v7a 7,169,463 +0
android hermes x86 8,081,647 +0
android hermes x86_64 8,053,150 +0
android jsc arm64-v8a 9,629,226 +0
android jsc armeabi-v7a 8,393,656 +0
android jsc x86 9,578,642 +0
android jsc x86_64 10,171,751 +0

Base commit: fa22a6e
Branch: main

@analysis-bot
Copy link

analysis-bot commented Oct 7, 2022

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: fa22a6e
Branch: main

@cipolleschi
Copy link
Contributor

/rebase

@github-actions github-actions bot force-pushed the extract-codegen-module-errors branch from beb5481 to 6523b87 Compare October 8, 2022 13:54
@cipolleschi
Copy link
Contributor

This PR should depend on this: #34874.
Plus, there are some JS errors in CI that should be addressed.

@cipolleschi
Copy link
Contributor

We merged #34874 earlier today! :D
Could you rebase once more on top of that, please? 🙏

@tarunrajput tarunrajput force-pushed the extract-codegen-module-errors branch from 49765f3 to 563f0aa Compare October 9, 2022 15:30
@tarunrajput
Copy link
Contributor Author

We merged #34874 earlier today! :D Could you rebase once more on top of that, please? 🙏

Sure.

@tarunrajput tarunrajput force-pushed the extract-codegen-module-errors branch from 563f0aa to 8958a1e Compare October 10, 2022 06:08
Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for this work! :D
This will enable further improvements!

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@@ -31,6 +33,413 @@ class ParserError extends Error {
}
}

class MisnamedModuleInterfaceParserError extends ParserError {
constructor(nativeModuleName: string, id: $FlowFixMe, language: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #34916, another contributor suggested to use a union type to describe the parsers. I really like this suggestion, and Flow will help users typing the errors if we type this correctly.

Ideally, we can do something like:

type ParserType = 'Flow' | 'TypeScript'

// ...

// update all the constructors
class MisnamedModuleInterfaceParserError extends ParserError {
  constructor(nativeModuleName: string, id: $FlowFixMe, language: ParserType) {
// ...

Nothing else in the logic will change, but the types will be more precise.

What do you think? Could you please update the PR? 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I'll update the PR

Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it! ❤️ Thank you so much for this change!

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@cipolleschi
Copy link
Contributor

/rebase

@github-actions github-actions bot force-pushed the extract-codegen-module-errors branch from 7a4dbfd to 1e3b195 Compare October 10, 2022 10:07
@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @tarunrajput in 7b345bc.

When will my fix make it into a release? | Upcoming Releases

OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
Summary:
This PR reduces code duplication by extracting all the errors in the module/errors into a single parsers/errors.js file. All the errors must drop the corresponding Flow or Typescript token in the name and take an extra language parameter in the constructor. Also, rename the hasteModuleName parameter to nativeModuleName.

Part of facebook#34872

## 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 all the parsers errors in the module/errors into a single parsers/errors.js file

Pull Request resolved: facebook#34896

Test Plan:
run ```yarn jest react-native-codegen``` and check all test case passes.

<img width="793" alt="image" src="https://user-images.githubusercontent.com/34857453/194545577-cf2d980b-b6b7-4f93-b13e-2e45d92dceab.png">

Reviewed By: rshest

Differential Revision: D40176486

Pulled By: rshest

fbshipit-source-id: b33ae49b2bcceeffd307370ee5e3b24a9e1bb340
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. hacktoberfest-accepted Merged This PR has been merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants