Skip to content

Commit a6b76c0

Browse files
marcoww6meta-codesync[bot]
authored andcommitted
Support Readonly in react-native-codegen (#54925)
Summary: Pull Request resolved: #54925 The lint is triggered in D89415612. Not sure what those file do but it seems a good fix Changelog: [General][Added] Support parsing `Readonly` for the new Flow utility types Reviewed By: SamChou19815 Differential Revision: D89418629 fbshipit-source-id: 34a2776711155dbd52046d55af18104e2eb32322
1 parent 3bf7a09 commit a6b76c0

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

packages/react-native-codegen/src/parsers/flow/components/componentsUtils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ function getTypeAnnotationForArray<+T>(
4545
// Resolve the type alias if it's not defined inline
4646
const objectType = getValueFromTypes(extractedTypeAnnotation, types);
4747

48-
if (objectType.id.name === '$ReadOnly') {
48+
if (
49+
objectType.id.name === '$ReadOnly' ||
50+
objectType.id.name === 'Readonly'
51+
) {
4952
return {
5053
type: 'ObjectTypeAnnotation',
5154
properties: flattenProperties(
@@ -247,7 +250,8 @@ function getTypeAnnotation<+T>(
247250

248251
if (
249252
typeAnnotation.type === 'GenericTypeAnnotation' &&
250-
parser.getTypeAnnotationName(typeAnnotation) === '$ReadOnly'
253+
(parser.getTypeAnnotationName(typeAnnotation) === '$ReadOnly' ||
254+
parser.getTypeAnnotationName(typeAnnotation) === 'Readonly')
251255
) {
252256
return {
253257
type: 'ObjectTypeAnnotation',

packages/react-native-codegen/src/parsers/flow/components/events.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function getPropertyType(
6262
case 'Float':
6363
return emitFloatProp(name, optional);
6464
case '$ReadOnly':
65+
case 'Readonly':
6566
return getPropertyType(
6667
name,
6768
optional,
@@ -187,7 +188,7 @@ function findEventArgumentsAndType(
187188
): EventArgumentReturnType {
188189
throwIfEventHasNoName(typeAnnotation, parser);
189190
const name = parser.getTypeAnnotationName(typeAnnotation);
190-
if (name === '$ReadOnly') {
191+
if (name === '$ReadOnly' || name === 'Readonly') {
191192
return {
192193
argumentProps: typeAnnotation.typeParameters.params[0].properties,
193194
paperTopLevelNameDeprecated: paperName,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ function translateTypeAnnotation(
114114
translateTypeAnnotation,
115115
);
116116
}
117-
case '$ReadOnly': {
117+
case '$ReadOnly':
118+
case 'Readonly': {
118119
assertGenericTypeAnnotationHasExactlyOneTypeParameter(
119120
hasteModuleName,
120121
typeAnnotation,

0 commit comments

Comments
 (0)