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 assertGenericTypeAnnotationHasExactlyOneTypeParameter to parsers-commons #34933

Conversation

AntoineDoubovetzky
Copy link
Contributor

Summary

This PR is a task from #34872:

Extract the function assertGenericTypeAnnotationHasExactlyOneTypeParameter (Flow TypeScript) into a single function in the parsers-common.js file and replace its invocation with this new function.

Changelog

[Internal] [Changed] - Extract assertGenericTypeAnnotationHasExactlyOneTypeParameter from the flow and typescript folders to parsers-commons

Test Plan

I tested using jest and flow commands.

@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 10, 2022
@AntoineDoubovetzky AntoineDoubovetzky force-pushed the refactor/extract-assertGenericTypeAnnotationHasExactlyOneTypeParameter-to-parsers-commons branch from fa21a90 to 4eeeb57 Compare October 10, 2022 19:42
@analysis-bot
Copy link

analysis-bot commented Oct 10, 2022

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,768,182 -105
android hermes armeabi-v7a 7,169,296 -84
android hermes x86 8,081,411 -138
android hermes x86_64 8,053,024 -91
android jsc arm64-v8a 9,629,382 -83
android jsc armeabi-v7a 8,393,808 -63
android jsc x86 9,578,801 -127
android jsc x86_64 10,171,894 -73

Base commit: 11f4743
Branch: main

@analysis-bot
Copy link

analysis-bot commented Oct 10, 2022

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

Base commit: 11f4743
Branch: main

@facebook-github-bot
Copy link
Contributor

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

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.

Amazing job! Thank you so much for this. I left a small nit to improve unit tests.

Comment on lines 103 to 136
it("throws an error if typeAnnotation.typeParameters.type doesn't have the correct value depending on language", () => {
const moduleName = 'testModuleName';
const flowTypeAnnotation = {
typeParameters: {
type: 'TypeParameterInstantiation',
},
id: {
name: 'typeAnnotationName',
},
};
expect(() =>
assertGenericTypeAnnotationHasExactlyOneTypeParameter(
moduleName,
flowTypeAnnotation,
'Flow',
),
).toThrow(Error);

const typeScriptTypeAnnotation = {
typeParameters: {
type: 'TypeParameterInstantiation',
},
typeName: {
name: 'typeAnnotationName',
},
};
expect(() =>
assertGenericTypeAnnotationHasExactlyOneTypeParameter(
moduleName,
typeScriptTypeAnnotation,
'TypeScript',
),
).toThrow(Error);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this could be split in two separate tests. In this way, if it fails, it is immediately clear what languages is making it fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, I corrrected

@@ -65,7 +68,6 @@ const {
IncorrectModuleRegistryCallArgumentTypeParserError,
} = require('../../errors.js');

const invariant = require('invariant');
Copy link
Contributor

Choose a reason for hiding this comment

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

Very nice! :D

@AntoineDoubovetzky AntoineDoubovetzky force-pushed the refactor/extract-assertGenericTypeAnnotationHasExactlyOneTypeParameter-to-parsers-commons branch from b1d3b34 to 920e115 Compare October 11, 2022 12:23
facebook-github-bot pushed a commit that referenced this pull request Oct 11, 2022
…#34935)

Summary:
This PR is a task from #34872:
> Extract the content of the case 'Promise' ([Flow](https://github.com/facebook/react-native/blob/b444f0e44e0d8670139acea5f14c2de32c5e2ddc/packages/react-native-codegen/src/parsers/flow/modules/index.js#L90-L97), [TypeScript](https://github.com/facebook/react-native/blob/00b795642a6562fb52d6df12e367b84674994623/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L197-L205)) into a single emitPromise function in the parsers-primitives.js file. Use the new function in the parsers.

Note that this PR should be merged after #34933

## 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 contents of the case 'Promise' into a single emitPromise function inside parsers-primitives

Pull Request resolved: #34935

Test Plan: I tested using jest and flow commands.

Reviewed By: cipolleschi

Differential Revision: D40257033

Pulled By: cipolleschi

fbshipit-source-id: 0246f43c6b688629e2de1259e7f535c2cf6dd0a4
@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @AntoineDoubovetzky in 29e5655.

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

@react-native-bot react-native-bot added the Merged This PR has been merged. label Oct 11, 2022
facebook-github-bot pushed a commit that referenced this pull request Oct 19, 2022
…34942)

Summary:
#34933 has been merged just after I pushed a new commit to the branch to improve tests of `assertGenericTypeAnnotationHasExactlyOneTypeParameter` function, but the last commit was not imported to the internal repository.

The `assertGenericTypeAnnotationHasExactlyOneTypeParameter` can throw different types of Error, and I believe that `.toThrow(Error)` is not specific enough. So I replaced it with `toThrowErrorMatchingInlineSnapshot()`.

## 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] - Improve assertGenericTypeAnnotationHasExactlyOneTypeParameter tests in parsers-commons

Pull Request resolved: #34942

Test Plan: Some test cases were ok because the assertGenericTypeAnnotationHasExactlyOneTypeParameter function threw an Error, but for the wrong reason. I've made sure that the error displayed in the inline snapshot is the one we expect.

Reviewed By: cortinico

Differential Revision: D40384993

Pulled By: cipolleschi

fbshipit-source-id: aaa943be1e808af2c5131f7d06baf24bc3bffa31
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
…ers-commons (facebook#34933)

Summary:
This PR is a task from facebook#34872:
> Extract the function assertGenericTypeAnnotationHasExactlyOneTypeParameter ([Flow](https://github.com/facebook/react-native/blob/b444f0e44e0d8670139acea5f14c2de32c5e2ddc/packages/react-native-codegen/src/parsers/flow/modules/index.js#L441) [TypeScript](https://github.com/facebook/react-native/blob/00b795642a6562fb52d6df12e367b84674994623/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L476)) into a single function in the parsers-common.js file and replace its invocation with this new function.

## 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 assertGenericTypeAnnotationHasExactlyOneTypeParameter from the flow and typescript folders to parsers-commons

Pull Request resolved: facebook#34933

Test Plan: I tested using jest and flow commands.

Reviewed By: cipolleschi

Differential Revision: D40257022

Pulled By: cipolleschi

fbshipit-source-id: 609972914deade9afdd1c0cf1e17be1c08c1d37b
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
…facebook#34935)

Summary:
This PR is a task from facebook#34872:
> Extract the content of the case 'Promise' ([Flow](https://github.com/facebook/react-native/blob/b444f0e44e0d8670139acea5f14c2de32c5e2ddc/packages/react-native-codegen/src/parsers/flow/modules/index.js#L90-L97), [TypeScript](https://github.com/facebook/react-native/blob/00b795642a6562fb52d6df12e367b84674994623/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L197-L205)) into a single emitPromise function in the parsers-primitives.js file. Use the new function in the parsers.

Note that this PR should be merged after facebook#34933

## 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 contents of the case 'Promise' into a single emitPromise function inside parsers-primitives

Pull Request resolved: facebook#34935

Test Plan: I tested using jest and flow commands.

Reviewed By: cipolleschi

Differential Revision: D40257033

Pulled By: cipolleschi

fbshipit-source-id: 0246f43c6b688629e2de1259e7f535c2cf6dd0a4
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
…acebook#34942)

Summary:
facebook#34933 has been merged just after I pushed a new commit to the branch to improve tests of `assertGenericTypeAnnotationHasExactlyOneTypeParameter` function, but the last commit was not imported to the internal repository.

The `assertGenericTypeAnnotationHasExactlyOneTypeParameter` can throw different types of Error, and I believe that `.toThrow(Error)` is not specific enough. So I replaced it with `toThrowErrorMatchingInlineSnapshot()`.

## 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] - Improve assertGenericTypeAnnotationHasExactlyOneTypeParameter tests in parsers-commons

Pull Request resolved: facebook#34942

Test Plan: Some test cases were ok because the assertGenericTypeAnnotationHasExactlyOneTypeParameter function threw an Error, but for the wrong reason. I've made sure that the error displayed in the inline snapshot is the one we expect.

Reviewed By: cortinico

Differential Revision: D40384993

Pulled By: cipolleschi

fbshipit-source-id: aaa943be1e808af2c5131f7d06baf24bc3bffa31
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.

None yet

6 participants