mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Remove miscellaneous exports of NativeModule Flow types in Codegen Schema
Summary: CodegenSchema exports `NativeModuleMethodParamSchema` and `NativeModuleObjectTypeAnnotationPropertySchema`, which are partials of NativeModule type annotations. This creates unnecessary coupling between the type annotations of CodegenSchema and the files that depend on it. **Actual Problem:** Suppose that we want to rename one of these partials. Then, all imports in all files would have to be updated, even when the actual shape of the composed type annotation wasn't changed. This diff removes these partials, which reduces the surface area of the exports of CodegenSchema.js Changelog: [Internal] Reviewed By: yungsters Differential Revision: D24719396 fbshipit-source-id: c822aaa252f156c524f4ef4917ebb61b1a39ff9e
This commit is contained in:
committed by
Facebook GitHub Bot
parent
04f235e7fb
commit
c6b8c75b6b
+1
-9
@@ -251,22 +251,14 @@ export type NativeModuleAliasMap = $ReadOnly<{|
|
||||
|
||||
export type NativeModuleFunctionTypeAnnotation = $ReadOnly<{|
|
||||
type: 'FunctionTypeAnnotation',
|
||||
params: $ReadOnlyArray<NativeModuleMethodParamSchema>,
|
||||
params: $ReadOnlyArray<NamedShape<Nullable<NativeModuleParamTypeAnnotation>>>,
|
||||
returnTypeAnnotation: Nullable<NativeModuleReturnTypeAnnotation>,
|
||||
|}>;
|
||||
|
||||
export type NativeModuleMethodParamSchema = NamedShape<
|
||||
Nullable<NativeModuleParamTypeAnnotation>,
|
||||
>;
|
||||
|
||||
export type NativeModuleObjectTypeAnnotation = ObjectTypeAnnotation<
|
||||
Nullable<NativeModuleBaseTypeAnnotation>,
|
||||
>;
|
||||
|
||||
export type NativeModuleObjectTypeAnnotationPropertySchema = NamedShape<
|
||||
Nullable<NativeModuleBaseTypeAnnotation>,
|
||||
>;
|
||||
|
||||
export type NativeModuleArrayTypeAnnotation<
|
||||
+T: Nullable<NativeModuleBaseTypeAnnotation>,
|
||||
> = $ReadOnly<{|
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
import type {
|
||||
SchemaType,
|
||||
NativeModulePropertySchema,
|
||||
NativeModuleMethodParamSchema,
|
||||
Nullable,
|
||||
NamedShape,
|
||||
NativeModuleFunctionTypeAnnotation,
|
||||
NativeModuleParamTypeAnnotation,
|
||||
} from '../../CodegenSchema';
|
||||
@@ -99,8 +100,10 @@ ${modules}
|
||||
`;
|
||||
};
|
||||
|
||||
type Param = NamedShape<Nullable<NativeModuleParamTypeAnnotation>>;
|
||||
|
||||
function serializeArg(
|
||||
arg: NativeModuleMethodParamSchema,
|
||||
arg: Param,
|
||||
index: number,
|
||||
resolveAlias: AliasResolver,
|
||||
): string {
|
||||
|
||||
+4
-2
@@ -12,9 +12,9 @@
|
||||
|
||||
import type {
|
||||
Nullable,
|
||||
NamedShape,
|
||||
SchemaType,
|
||||
NativeModulePropertySchema,
|
||||
NativeModuleMethodParamSchema,
|
||||
NativeModuleReturnTypeAnnotation,
|
||||
NativeModuleFunctionTypeAnnotation,
|
||||
NativeModuleParamTypeAnnotation,
|
||||
@@ -91,8 +91,10 @@ function MethodTemplate(
|
||||
)})${methodClosing}`;
|
||||
}
|
||||
|
||||
type Param = NamedShape<Nullable<NativeModuleParamTypeAnnotation>>;
|
||||
|
||||
function translateFunctionParamToJavaType(
|
||||
param: NativeModuleMethodParamSchema,
|
||||
param: Param,
|
||||
createErrorMessage: (typeName: string) => string,
|
||||
resolveAlias: AliasResolver,
|
||||
imports: Set<string>,
|
||||
|
||||
+4
-2
@@ -12,9 +12,9 @@
|
||||
|
||||
import type {
|
||||
Nullable,
|
||||
NamedShape,
|
||||
SchemaType,
|
||||
NativeModulePropertySchema,
|
||||
NativeModuleMethodParamSchema,
|
||||
NativeModuleReturnTypeAnnotation,
|
||||
NativeModuleParamTypeAnnotation,
|
||||
NativeModuleFunctionTypeAnnotation,
|
||||
@@ -177,8 +177,10 @@ function translateReturnTypeToKind(
|
||||
}
|
||||
}
|
||||
|
||||
type Param = NamedShape<Nullable<NativeModuleParamTypeAnnotation>>;
|
||||
|
||||
function translateParamTypeToJniType(
|
||||
param: NativeModuleMethodParamSchema,
|
||||
param: Param,
|
||||
resolveAlias: AliasResolver,
|
||||
): string {
|
||||
const {optional, typeAnnotation: nullableTypeAnnotation} = param;
|
||||
|
||||
Vendored
+7
-7
@@ -11,10 +11,11 @@
|
||||
'use strict';
|
||||
|
||||
import type {
|
||||
NativeModuleMethodParamSchema,
|
||||
NativeModuleReturnTypeAnnotation,
|
||||
NativeModulePropertySchema,
|
||||
Nullable,
|
||||
NamedShape,
|
||||
NativeModuleParamTypeAnnotation,
|
||||
NativeModuleReturnTypeAnnotation,
|
||||
} from '../../../CodegenSchema';
|
||||
|
||||
import type {AliasResolver} from '../Utils';
|
||||
@@ -164,10 +165,9 @@ function serializeMethod(
|
||||
];
|
||||
}
|
||||
|
||||
function getParamStructName(
|
||||
methodName: string,
|
||||
param: NativeModuleMethodParamSchema,
|
||||
): string {
|
||||
type Param = NamedShape<Nullable<NativeModuleParamTypeAnnotation>>;
|
||||
|
||||
function getParamStructName(methodName: string, param: Param): string {
|
||||
const [typeAnnotation] = unwrapNullable(param.typeAnnotation);
|
||||
if (typeAnnotation.type === 'TypeAliasTypeAnnotation') {
|
||||
return typeAnnotation.name;
|
||||
@@ -179,7 +179,7 @@ function getParamStructName(
|
||||
function getParamObjCType(
|
||||
hasteModuleName: string,
|
||||
methodName: string,
|
||||
param: NativeModuleMethodParamSchema,
|
||||
param: Param,
|
||||
structName: string,
|
||||
structCollector: StructCollector,
|
||||
resolveAlias: AliasResolver,
|
||||
|
||||
+65
-62
@@ -11,13 +11,13 @@
|
||||
'use strict';
|
||||
|
||||
import type {
|
||||
NamedShape,
|
||||
NativeModuleAliasMap,
|
||||
NativeModuleArrayTypeAnnotation,
|
||||
NativeModuleBaseTypeAnnotation,
|
||||
NativeModuleFunctionTypeAnnotation,
|
||||
NativeModuleMethodParamSchema,
|
||||
NativeModuleObjectTypeAnnotationPropertySchema,
|
||||
NativeModulePropertySchema,
|
||||
NativeModuleParamTypeAnnotation,
|
||||
NativeModuleSchema,
|
||||
Nullable,
|
||||
} from '../../../CodegenSchema.js';
|
||||
@@ -207,68 +207,70 @@ function translateTypeAnnotation(
|
||||
const objectTypeAnnotation = {
|
||||
type: 'ObjectTypeAnnotation',
|
||||
properties: (typeAnnotation.properties: Array<$FlowFixMe>)
|
||||
.map<?NativeModuleObjectTypeAnnotationPropertySchema>(property => {
|
||||
return guard(() => {
|
||||
if (property.type !== 'ObjectTypeProperty') {
|
||||
throw new UnsupportedObjectPropertyTypeAnnotationParserError(
|
||||
hasteModuleName,
|
||||
property,
|
||||
property.type,
|
||||
);
|
||||
}
|
||||
.map<?NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>>(
|
||||
property => {
|
||||
return guard(() => {
|
||||
if (property.type !== 'ObjectTypeProperty') {
|
||||
throw new UnsupportedObjectPropertyTypeAnnotationParserError(
|
||||
hasteModuleName,
|
||||
property,
|
||||
property.type,
|
||||
);
|
||||
}
|
||||
|
||||
const {optional, key} = property;
|
||||
const {optional, key} = property;
|
||||
|
||||
const [
|
||||
propertyTypeAnnotation,
|
||||
isPropertyNullable,
|
||||
] = unwrapNullable(
|
||||
translateTypeAnnotation(
|
||||
hasteModuleName,
|
||||
property.value,
|
||||
types,
|
||||
aliasMap,
|
||||
guard,
|
||||
),
|
||||
);
|
||||
|
||||
if (propertyTypeAnnotation.type === 'FunctionTypeAnnotation') {
|
||||
throw new UnsupportedObjectPropertyValueTypeAnnotationParserError(
|
||||
hasteModuleName,
|
||||
property.value,
|
||||
property.key,
|
||||
propertyTypeAnnotation.type,
|
||||
);
|
||||
}
|
||||
|
||||
if (propertyTypeAnnotation.type === 'VoidTypeAnnotation') {
|
||||
throw new UnsupportedObjectPropertyValueTypeAnnotationParserError(
|
||||
hasteModuleName,
|
||||
property.value,
|
||||
property.key,
|
||||
'void',
|
||||
);
|
||||
}
|
||||
|
||||
if (propertyTypeAnnotation.type === 'PromiseTypeAnnotation') {
|
||||
throw new UnsupportedObjectPropertyValueTypeAnnotationParserError(
|
||||
hasteModuleName,
|
||||
property.value,
|
||||
property.key,
|
||||
'Promise',
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
name: key.name,
|
||||
optional,
|
||||
typeAnnotation: wrapNullable(
|
||||
isPropertyNullable,
|
||||
const [
|
||||
propertyTypeAnnotation,
|
||||
),
|
||||
};
|
||||
});
|
||||
})
|
||||
isPropertyNullable,
|
||||
] = unwrapNullable(
|
||||
translateTypeAnnotation(
|
||||
hasteModuleName,
|
||||
property.value,
|
||||
types,
|
||||
aliasMap,
|
||||
guard,
|
||||
),
|
||||
);
|
||||
|
||||
if (propertyTypeAnnotation.type === 'FunctionTypeAnnotation') {
|
||||
throw new UnsupportedObjectPropertyValueTypeAnnotationParserError(
|
||||
hasteModuleName,
|
||||
property.value,
|
||||
property.key,
|
||||
propertyTypeAnnotation.type,
|
||||
);
|
||||
}
|
||||
|
||||
if (propertyTypeAnnotation.type === 'VoidTypeAnnotation') {
|
||||
throw new UnsupportedObjectPropertyValueTypeAnnotationParserError(
|
||||
hasteModuleName,
|
||||
property.value,
|
||||
property.key,
|
||||
'void',
|
||||
);
|
||||
}
|
||||
|
||||
if (propertyTypeAnnotation.type === 'PromiseTypeAnnotation') {
|
||||
throw new UnsupportedObjectPropertyValueTypeAnnotationParserError(
|
||||
hasteModuleName,
|
||||
property.value,
|
||||
property.key,
|
||||
'Promise',
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
name: key.name,
|
||||
optional,
|
||||
typeAnnotation: wrapNullable(
|
||||
isPropertyNullable,
|
||||
propertyTypeAnnotation,
|
||||
),
|
||||
};
|
||||
});
|
||||
},
|
||||
)
|
||||
.filter(Boolean),
|
||||
};
|
||||
|
||||
@@ -391,7 +393,8 @@ function translateFunctionTypeAnnotation(
|
||||
aliasMap: {...NativeModuleAliasMap},
|
||||
guard: ParserErrorCapturer,
|
||||
): NativeModuleFunctionTypeAnnotation {
|
||||
const params: Array<NativeModuleMethodParamSchema> = [];
|
||||
type Param = NamedShape<Nullable<NativeModuleParamTypeAnnotation>>;
|
||||
const params: Array<Param> = [];
|
||||
|
||||
for (const flowParam of (flowFunctionTypeAnnotation.params: $ReadOnlyArray<$FlowFixMe>)) {
|
||||
const parsedParam = guard(() => {
|
||||
|
||||
Reference in New Issue
Block a user