Skip to content

Commit 09fc043

Browse files
marcoww6meta-codesync[bot]
authored andcommitted
Fix a few readonly 10/n (#56948)
Summary: Pull Request resolved: #56948 ``` js1 flow-runner codemod flow/transformAllVariance --variance readonly --format-files=false ``` drop-conflicts landed-with-radar-review Reviewed By: SamChou19815 Differential Revision: D106144499 fbshipit-source-id: 85493334eae630d3dec7e5920633c076f8f09729
1 parent 0676eb6 commit 09fc043

193 files changed

Lines changed: 1493 additions & 1332 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/react-native-codegen/src/generators/ReservedPrimitiveTypes.js

Lines changed: 84 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -28,99 +28,104 @@ export type ReservedPrimitiveName =
2828
| 'DimensionPrimitive';
2929

3030
type CppTypeInfo = {
31-
+typeName: string,
32-
+localIncludes: ReadonlyArray<string>,
33-
+conversionIncludes: ReadonlyArray<string>,
31+
readonly typeName: string,
32+
readonly localIncludes: ReadonlyArray<string>,
33+
readonly conversionIncludes: ReadonlyArray<string>,
3434
};
3535

3636
type JavaImportInfo = {
37-
+interfaceImports: ReadonlyArray<string>,
38-
+delegateImports: ReadonlyArray<string>,
37+
readonly interfaceImports: ReadonlyArray<string>,
38+
readonly delegateImports: ReadonlyArray<string>,
3939
};
4040

4141
type ReservedTypeMapping = {
42-
+cpp: CppTypeInfo,
43-
+java: JavaImportInfo,
42+
readonly cpp: CppTypeInfo,
43+
readonly java: JavaImportInfo,
4444
};
4545

46-
const RESERVED_TYPES: {+[ReservedPrimitiveName]: ReservedTypeMapping} = {
47-
ColorPrimitive: {
48-
cpp: {
49-
typeName: 'SharedColor',
50-
localIncludes: ['#include <react/renderer/graphics/Color.h>'],
51-
conversionIncludes: [],
46+
const RESERVED_TYPES: {readonly [ReservedPrimitiveName]: ReservedTypeMapping} =
47+
{
48+
ColorPrimitive: {
49+
cpp: {
50+
typeName: 'SharedColor',
51+
localIncludes: ['#include <react/renderer/graphics/Color.h>'],
52+
conversionIncludes: [],
53+
},
54+
java: {
55+
interfaceImports: [],
56+
delegateImports: [
57+
'import com.facebook.react.bridge.ColorPropConverter;',
58+
],
59+
},
5260
},
53-
java: {
54-
interfaceImports: [],
55-
delegateImports: ['import com.facebook.react.bridge.ColorPropConverter;'],
61+
ImageSourcePrimitive: {
62+
cpp: {
63+
typeName: 'ImageSource',
64+
localIncludes: ['#include <react/renderer/imagemanager/primitives.h>'],
65+
conversionIncludes: [
66+
'#include <react/renderer/components/image/conversions.h>',
67+
],
68+
},
69+
java: {
70+
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
71+
delegateImports: ['import com.facebook.react.bridge.ReadableMap;'],
72+
},
5673
},
57-
},
58-
ImageSourcePrimitive: {
59-
cpp: {
60-
typeName: 'ImageSource',
61-
localIncludes: ['#include <react/renderer/imagemanager/primitives.h>'],
62-
conversionIncludes: [
63-
'#include <react/renderer/components/image/conversions.h>',
64-
],
74+
ImageRequestPrimitive: {
75+
cpp: {
76+
typeName: 'ImageRequest',
77+
localIncludes: [
78+
'#include <react/renderer/imagemanager/ImageRequest.h>',
79+
],
80+
conversionIncludes: [],
81+
},
82+
java: {
83+
// ImageRequestPrimitive is not used in Java component props
84+
interfaceImports: [],
85+
delegateImports: [],
86+
},
6587
},
66-
java: {
67-
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
68-
delegateImports: ['import com.facebook.react.bridge.ReadableMap;'],
88+
PointPrimitive: {
89+
cpp: {
90+
typeName: 'Point',
91+
localIncludes: ['#include <react/renderer/graphics/Point.h>'],
92+
conversionIncludes: [],
93+
},
94+
java: {
95+
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
96+
delegateImports: ['import com.facebook.react.bridge.ReadableMap;'],
97+
},
6998
},
70-
},
71-
ImageRequestPrimitive: {
72-
cpp: {
73-
typeName: 'ImageRequest',
74-
localIncludes: ['#include <react/renderer/imagemanager/ImageRequest.h>'],
75-
conversionIncludes: [],
99+
EdgeInsetsPrimitive: {
100+
cpp: {
101+
typeName: 'EdgeInsets',
102+
localIncludes: ['#include <react/renderer/graphics/RectangleEdges.h>'],
103+
conversionIncludes: [],
104+
},
105+
java: {
106+
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
107+
delegateImports: ['import com.facebook.react.bridge.ReadableMap;'],
108+
},
76109
},
77-
java: {
78-
// ImageRequestPrimitive is not used in Java component props
79-
interfaceImports: [],
80-
delegateImports: [],
110+
DimensionPrimitive: {
111+
cpp: {
112+
typeName: 'YGValue',
113+
localIncludes: [
114+
'#include <yoga/Yoga.h>',
115+
'#include <react/renderer/core/graphicsConversions.h>',
116+
],
117+
conversionIncludes: [
118+
'#include <react/renderer/components/view/conversions.h>',
119+
],
120+
},
121+
java: {
122+
interfaceImports: ['import com.facebook.yoga.YogaValue;'],
123+
delegateImports: [
124+
'import com.facebook.react.bridge.DimensionPropConverter;',
125+
],
126+
},
81127
},
82-
},
83-
PointPrimitive: {
84-
cpp: {
85-
typeName: 'Point',
86-
localIncludes: ['#include <react/renderer/graphics/Point.h>'],
87-
conversionIncludes: [],
88-
},
89-
java: {
90-
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
91-
delegateImports: ['import com.facebook.react.bridge.ReadableMap;'],
92-
},
93-
},
94-
EdgeInsetsPrimitive: {
95-
cpp: {
96-
typeName: 'EdgeInsets',
97-
localIncludes: ['#include <react/renderer/graphics/RectangleEdges.h>'],
98-
conversionIncludes: [],
99-
},
100-
java: {
101-
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
102-
delegateImports: ['import com.facebook.react.bridge.ReadableMap;'],
103-
},
104-
},
105-
DimensionPrimitive: {
106-
cpp: {
107-
typeName: 'YGValue',
108-
localIncludes: [
109-
'#include <yoga/Yoga.h>',
110-
'#include <react/renderer/core/graphicsConversions.h>',
111-
],
112-
conversionIncludes: [
113-
'#include <react/renderer/components/view/conversions.h>',
114-
],
115-
},
116-
java: {
117-
interfaceImports: ['import com.facebook.yoga.YogaValue;'],
118-
delegateImports: [
119-
'import com.facebook.react.bridge.DimensionPropConverter;',
120-
],
121-
},
122-
},
123-
};
128+
};
124129

125130
function getCppTypeForReservedPrimitive(name: ReservedPrimitiveName): string {
126131
return RESERVED_TYPES[name].cpp.typeName;

packages/react-native-codegen/src/generators/components/ComponentsGeneratorUtils.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ function getNativeTypeFromAnnotation(
4949
| ObjectTypeAnnotation<PropTypeAnnotation>
5050
| ReservedPropTypeAnnotation
5151
| {
52-
+default: string,
53-
+options: ReadonlyArray<string>,
54-
+type: 'StringEnumTypeAnnotation',
52+
readonly default: string,
53+
readonly options: ReadonlyArray<string>,
54+
readonly type: 'StringEnumTypeAnnotation',
5555
}
5656
| {
57-
+elementType: ObjectTypeAnnotation<PropTypeAnnotation>,
58-
+type: 'ArrayTypeAnnotation',
57+
readonly elementType: ObjectTypeAnnotation<PropTypeAnnotation>,
58+
readonly type: 'ArrayTypeAnnotation',
5959
},
6060
},
6161
nameParts: ReadonlyArray<string>,

packages/react-native-codegen/src/parsers/errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class UnsupportedModulePropertyParserError extends ParserError {
128128
}
129129

130130
class UnsupportedTypeAnnotationParserError extends ParserError {
131-
+typeAnnotationType: string;
131+
readonly typeAnnotationType: string;
132132
constructor(
133133
nativeModuleName: string,
134134
typeAnnotation: $FlowFixMe,

packages/react-native-compatibility-check/src/__tests__/__fixtures__/native-component-all-types/NativeComponent.js.flow

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,53 +91,83 @@ type CustomObj = {foo: string, bar: number};
9191
type CustomObj2 = {a: Int32, b: string};
9292

9393
interface NativeCommands {
94-
+methodInt: (viewRef: React.ElementRef<NativeType>, a: Int32) => void;
95-
+methodIntString: (
94+
readonly methodInt: (viewRef: React.ElementRef<NativeType>, a: Int32) => void;
95+
readonly methodIntString: (
9696
viewRef: React.ElementRef<NativeType>,
9797
a: Int32,
9898
b: string,
9999
) => void;
100-
+methodString: (viewRef: React.ElementRef<NativeType>, a: string) => void;
101-
+methodBool: (viewRef: React.ElementRef<NativeType>, a: boolean) => void;
102-
+methodFloat: (viewRef: React.ElementRef<NativeType>, a: Float) => void;
103-
+methodDouble: (viewRef: React.ElementRef<NativeType>, a: Double) => void;
100+
readonly methodString: (
101+
viewRef: React.ElementRef<NativeType>,
102+
a: string,
103+
) => void;
104+
readonly methodBool: (
105+
viewRef: React.ElementRef<NativeType>,
106+
a: boolean,
107+
) => void;
108+
readonly methodFloat: (
109+
viewRef: React.ElementRef<NativeType>,
110+
a: Float,
111+
) => void;
112+
readonly methodDouble: (
113+
viewRef: React.ElementRef<NativeType>,
114+
a: Double,
115+
) => void;
104116

105-
+methodIntAlias: (viewRef: React.ElementRef<NativeType>, a: Int) => void;
106-
+methodStringAlias: (viewRef: React.ElementRef<NativeType>, a: Str) => void;
107-
+methodBoolAlias: (viewRef: React.ElementRef<NativeType>, a: Bool) => void;
108-
+methodFloatAlias: (viewRef: React.ElementRef<NativeType>, a: Fl) => void;
109-
+methodDoubleAlias: (viewRef: React.ElementRef<NativeType>, a: Dbl) => void;
117+
readonly methodIntAlias: (
118+
viewRef: React.ElementRef<NativeType>,
119+
a: Int,
120+
) => void;
121+
readonly methodStringAlias: (
122+
viewRef: React.ElementRef<NativeType>,
123+
a: Str,
124+
) => void;
125+
readonly methodBoolAlias: (
126+
viewRef: React.ElementRef<NativeType>,
127+
a: Bool,
128+
) => void;
129+
readonly methodFloatAlias: (
130+
viewRef: React.ElementRef<NativeType>,
131+
a: Fl,
132+
) => void;
133+
readonly methodDoubleAlias: (
134+
viewRef: React.ElementRef<NativeType>,
135+
a: Dbl,
136+
) => void;
110137

111-
+methodIntArray: (
138+
readonly methodIntArray: (
112139
viewRef: React.ElementRef<NativeType>,
113140
a: Array<Int32>,
114141
) => void;
115-
+methodStringArray: (
142+
readonly methodStringArray: (
116143
viewRef: React.ElementRef<NativeType>,
117144
a: Array<string>,
118145
) => void;
119-
+methodBoolArray: (
146+
readonly methodBoolArray: (
120147
viewRef: React.ElementRef<NativeType>,
121148
a: Array<boolean>,
122149
) => void;
123-
+methodFloatArray: (
150+
readonly methodFloatArray: (
124151
viewRef: React.ElementRef<NativeType>,
125152
a: Array<Float>,
126153
) => void;
127-
+methodDoubleArray: (
154+
readonly methodDoubleArray: (
128155
viewRef: React.ElementRef<NativeType>,
129156
a: Array<Double>,
130157
) => void;
131-
+methodCustomObjArray: (
158+
readonly methodCustomObjArray: (
132159
viewRef: React.ElementRef<NativeType>,
133160
a: Array<CustomObj>,
134161
) => void;
135-
+methodCustomObj2Array: (
162+
readonly methodCustomObj2Array: (
136163
viewRef: React.ElementRef<NativeType>,
137164
a: Array<CustomObj2>,
138165
) => void;
139166

140-
+methodRootTag: (viewRef: React.ElementRef<NativeType>, a: RootTag) => void;
167+
readonly methodRootTag: (
168+
viewRef: React.ElementRef<NativeType>,
169+
a: RootTag,
170+
) => void;
141171
}
142172

143173
export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({

packages/react-native-compatibility-check/src/__tests__/__fixtures__/native-component-with-command-all-basic-types-arrays/NativeComponent.js.flow

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,23 @@ type NativeProps = Readonly<{
2626
type NativeType = HostComponent<NativeProps>;
2727

2828
interface NativeCommands {
29-
+methodInt: (viewRef: React.ElementRef<NativeType>, a: Array<Int32>) => void;
30-
+methodString: (
29+
readonly methodInt: (
30+
viewRef: React.ElementRef<NativeType>,
31+
a: Array<Int32>,
32+
) => void;
33+
readonly methodString: (
3134
viewRef: React.ElementRef<NativeType>,
3235
a: Array<string>,
3336
) => void;
34-
+methodBool: (
37+
readonly methodBool: (
3538
viewRef: React.ElementRef<NativeType>,
3639
a: Array<boolean>,
3740
) => void;
38-
+methodFloat: (
41+
readonly methodFloat: (
3942
viewRef: React.ElementRef<NativeType>,
4043
a: Array<Float>,
4144
) => void;
42-
+methodDouble: (
45+
readonly methodDouble: (
4346
viewRef: React.ElementRef<NativeType>,
4447
a: Array<Double>,
4548
) => void;

packages/react-native-compatibility-check/src/__tests__/__fixtures__/native-component-with-command-all-basic-types/NativeComponent.js.flow

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,23 @@ type NativeProps = Readonly<{
2626
type NativeType = HostComponent<NativeProps>;
2727

2828
interface NativeCommands {
29-
+methodInt: (viewRef: React.ElementRef<NativeType>, a: Int32) => void;
30-
+methodString: (viewRef: React.ElementRef<NativeType>, a: string) => void;
31-
+methodBool: (viewRef: React.ElementRef<NativeType>, a: boolean) => void;
32-
+methodFloat: (viewRef: React.ElementRef<NativeType>, a: Float) => void;
33-
+methodDouble: (viewRef: React.ElementRef<NativeType>, a: Double) => void;
29+
readonly methodInt: (viewRef: React.ElementRef<NativeType>, a: Int32) => void;
30+
readonly methodString: (
31+
viewRef: React.ElementRef<NativeType>,
32+
a: string,
33+
) => void;
34+
readonly methodBool: (
35+
viewRef: React.ElementRef<NativeType>,
36+
a: boolean,
37+
) => void;
38+
readonly methodFloat: (
39+
viewRef: React.ElementRef<NativeType>,
40+
a: Float,
41+
) => void;
42+
readonly methodDouble: (
43+
viewRef: React.ElementRef<NativeType>,
44+
a: Double,
45+
) => void;
3446
}
3547

3648
export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({

packages/react-native-compatibility-check/src/__tests__/__fixtures__/native-component-with-command-changed/NativeComponent.js.flow

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ type NativeProps = Readonly<{
2121
type NativeType = HostComponent<NativeProps>;
2222

2323
interface NativeCommands {
24-
+methodInt: (viewRef: React.ElementRef<NativeType>, a: string) => void;
24+
readonly methodInt: (
25+
viewRef: React.ElementRef<NativeType>,
26+
a: string,
27+
) => void;
2528
}
2629

2730
export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({

packages/react-native-compatibility-check/src/__tests__/__fixtures__/native-component-with-command-extra-arg/NativeComponent.js.flow

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type NativeProps = Readonly<{
2222
type NativeType = HostComponent<NativeProps>;
2323

2424
interface NativeCommands {
25-
+methodInt: (
25+
readonly methodInt: (
2626
viewRef: React.ElementRef<NativeType>,
2727
a: Int32,
2828
b: string,

0 commit comments

Comments
 (0)