-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace ternary in assertGenericTypeAnnotationHasExactlyOneTypeParame…
…ter with typeParameterInstantiation attribute in parser (#35157) Summary: Part of #34872: > Create a new function typeParameterInstantiation in the [parsers.js file](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/parser.js) and add documentation to it. Implement it properly in the [FlowParser.js](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/flow/parser.js#L15) and in the [TypeScriptParser.js](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/typescript/parser.js#L15). Update the signature of [assertGenericTypeAnnotationHasExactlyOneTypeParameter](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/parsers-commons.js#L67) function to take the Parser instead of the language and use the new function in place of the [ternary operator ?:](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/parsers-commons.js#L83). There are 3 things I'm not sure about: 1. The issue suggests to create a new function. For this case I believe an attribute is simpler. Is there a reason to prefer a function ? 2. To update the tests I had to create a mocked parser. I created a new file `parserMock` (I took example on [AnimatedMock](https://github.com/facebook/react-native/blob/main/Libraries/Animated/AnimatedMock.js)). Does it seem ok ? 3. I'm not sure what to add in the documentation of `typeParameterInstantiation` ## 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] - Replace ternary in assertGenericTypeAnnotationHasExactlyOneTypeParameter with typeParameterInstantiation attribute in parser Pull Request resolved: #35157 Test Plan: I tested using Jest and Flow commands. Reviewed By: rshest Differential Revision: D40889856 Pulled By: cipolleschi fbshipit-source-id: 8d9a8e087852f98dcc3fc0ecf1d4a7153f482ce7
- Loading branch information
1 parent
2245603
commit 8a847a3
Showing
10 changed files
with
74 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type {Parser} from './parser'; | ||
import type {ParserType} from './errors'; | ||
|
||
export class MockedParser implements Parser { | ||
typeParameterInstantiation: string = 'TypeParameterInstantiation'; | ||
|
||
getMaybeEnumMemberType(maybeEnumDeclaration: $FlowFixMe): string { | ||
return maybeEnumDeclaration.body.type | ||
.replace('EnumNumberBody', 'NumberTypeAnnotation') | ||
.replace('EnumStringBody', 'StringTypeAnnotation'); | ||
} | ||
|
||
isEnumDeclaration(maybeEnumDeclaration: $FlowFixMe): boolean { | ||
return maybeEnumDeclaration.type === 'EnumDeclaration'; | ||
} | ||
|
||
language(): ParserType { | ||
return 'Flow'; | ||
} | ||
|
||
nameForGenericTypeAnnotation(typeAnnotation: $FlowFixMe): string { | ||
return typeAnnotation.id.name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters