From 00cfb0f919207fcdc8fe8b6c3b7d76591447b91d Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Fri, 6 Nov 2020 16:06:19 -0800 Subject: [PATCH] Remove pipes from Object literal Flow types Summary: ## Changes {| ... |} -> { ... } **Motivation:** In Flow, object literals are exact by default. So, there's no need for the pipes. Also: Now, the syntax for object literals is consistent across react-native-codegen. Changelog: [Internal] Reviewed By: hramos Differential Revision: D24774771 fbshipit-source-id: 24ceb6f5876122aa8ad9e08c7e903215864ad6f5 --- .../react-native-codegen/src/CodegenSchema.js | 178 +++++++++--------- .../src/generators/RNCodegen.js | 8 +- .../generators/components/GenerateTests.js | 4 +- .../generators/modules/GenerateModuleCpp.js | 8 +- .../src/generators/modules/GenerateModuleH.js | 6 +- .../modules/GenerateModuleJavaSpec.js | 8 +- .../modules/GenerateModuleJniCpp.js | 24 +-- .../generators/modules/GenerateModuleJniH.js | 4 +- .../GenerateModuleObjCpp/StructCollector.js | 12 +- .../header/serializeConstantsStruct.js | 8 +- .../header/serializeRegularStruct.js | 8 +- .../header/serializeStruct.js | 4 +- .../modules/GenerateModuleObjCpp/index.js | 12 +- .../GenerateModuleObjCpp/serializeMethod.js | 20 +- .../source/serializeModule.js | 16 +- .../src/generators/modules/Utils.js | 4 +- .../src/parsers/flow/components/options.js | 4 +- .../src/parsers/flow/components/schema.js | 4 +- .../__tests__/module-parser-e2e-test.js | 40 ++-- .../src/parsers/flow/modules/index.js | 12 +- .../src/parsers/flow/utils.js | 10 +- 21 files changed, 195 insertions(+), 199 deletions(-) diff --git a/packages/react-native-codegen/src/CodegenSchema.js b/packages/react-native-codegen/src/CodegenSchema.js index 4aec6a45332..8b8673f0e5d 100644 --- a/packages/react-native-codegen/src/CodegenSchema.js +++ b/packages/react-native-codegen/src/CodegenSchema.js @@ -12,54 +12,54 @@ export type PlatformType = 'iOS' | 'android'; -export type SchemaType = $ReadOnly<{| - modules: $ReadOnly<{| +export type SchemaType = $ReadOnly<{ + modules: $ReadOnly<{ [hasteModuleName: string]: ComponentSchema | NativeModuleSchema, - |}>, -|}>; + }>, +}>; /** * Component Type Annotations */ -export type DoubleTypeAnnotation = $ReadOnly<{| +export type DoubleTypeAnnotation = $ReadOnly<{ type: 'DoubleTypeAnnotation', -|}>; +}>; -export type FloatTypeAnnotation = $ReadOnly<{| +export type FloatTypeAnnotation = $ReadOnly<{ type: 'FloatTypeAnnotation', -|}>; +}>; -export type BooleanTypeAnnotation = $ReadOnly<{| +export type BooleanTypeAnnotation = $ReadOnly<{ type: 'BooleanTypeAnnotation', -|}>; +}>; -export type Int32TypeAnnotation = $ReadOnly<{| +export type Int32TypeAnnotation = $ReadOnly<{ type: 'Int32TypeAnnotation', -|}>; +}>; -export type StringTypeAnnotation = $ReadOnly<{| +export type StringTypeAnnotation = $ReadOnly<{ type: 'StringTypeAnnotation', -|}>; +}>; -export type StringEnumTypeAnnotation = $ReadOnly<{| +export type StringEnumTypeAnnotation = $ReadOnly<{ type: 'StringEnumTypeAnnotation', options: $ReadOnlyArray, -|}>; +}>; -export type VoidTypeAnnotation = $ReadOnly<{| +export type VoidTypeAnnotation = $ReadOnly<{ type: 'VoidTypeAnnotation', -|}>; +}>; -type ObjectTypeAnnotation<+T> = $ReadOnly<{| +type ObjectTypeAnnotation<+T> = $ReadOnly<{ type: 'ObjectTypeAnnotation', properties: $ReadOnlyArray>, -|}>; +}>; -type FunctionTypeAnnotation<+P, +R> = $ReadOnly<{| +type FunctionTypeAnnotation<+P, +R> = $ReadOnly<{ type: 'FunctionTypeAnnotation', params: $ReadOnlyArray>, returnTypeAnnotation: R, -|}>; +}>; export type NamedShape<+T> = $ReadOnly<{ name: string, @@ -67,22 +67,22 @@ export type NamedShape<+T> = $ReadOnly<{ typeAnnotation: T, }>; -export type ComponentSchema = $ReadOnly<{| +export type ComponentSchema = $ReadOnly<{ type: 'Component', - components: $ReadOnly<{| + components: $ReadOnly<{ [componentName: string]: ComponentShape, - |}>, -|}>; + }>, +}>; -export type ComponentShape = $ReadOnly<{| +export type ComponentShape = $ReadOnly<{ ...OptionsShape, extendsProps: $ReadOnlyArray, events: $ReadOnlyArray, props: $ReadOnlyArray>, commands: $ReadOnlyArray>, -|}>; +}>; -export type OptionsShape = $ReadOnly<{| +export type OptionsShape = $ReadOnly<{ interfaceOnly?: boolean, // Use for components with no current paper rename in progress @@ -95,23 +95,23 @@ export type OptionsShape = $ReadOnly<{| // Use for components currently being renamed in paper // Will use new name if it is available and fallback to this name paperComponentNameDeprecated?: string, -|}>; +}>; -export type ExtendsPropsShape = $ReadOnly<{| +export type ExtendsPropsShape = $ReadOnly<{ type: 'ReactNativeBuiltInType', knownTypeName: 'ReactNativeCoreViewProps', -|}>; +}>; -export type EventTypeShape = $ReadOnly<{| +export type EventTypeShape = $ReadOnly<{ name: string, bubblingType: 'direct' | 'bubble', optional: boolean, paperTopLevelNameDeprecated?: string, - typeAnnotation: $ReadOnly<{| + typeAnnotation: $ReadOnly<{ type: 'EventTypeAnnotation', argument?: ObjectTypeAnnotation, - |}>, -|}>; + }>, +}>; export type EventTypeAnnotation = | BooleanTypeAnnotation @@ -123,39 +123,39 @@ export type EventTypeAnnotation = | ObjectTypeAnnotation; export type PropTypeAnnotation = - | $ReadOnly<{| + | $ReadOnly<{ type: 'BooleanTypeAnnotation', default: boolean | null, - |}> - | $ReadOnly<{| + }> + | $ReadOnly<{ type: 'StringTypeAnnotation', default: string | null, - |}> - | $ReadOnly<{| + }> + | $ReadOnly<{ type: 'DoubleTypeAnnotation', default: number, - |}> - | $ReadOnly<{| + }> + | $ReadOnly<{ type: 'FloatTypeAnnotation', default: number | null, - |}> - | $ReadOnly<{| + }> + | $ReadOnly<{ type: 'Int32TypeAnnotation', default: number, - |}> - | $ReadOnly<{| + }> + | $ReadOnly<{ type: 'StringEnumTypeAnnotation', default: string, options: $ReadOnlyArray, - |}> - | $ReadOnly<{| + }> + | $ReadOnly<{ type: 'Int32EnumTypeAnnotation', default: number, options: $ReadOnlyArray, - |}> + }> | ReservedPropTypeAnnotation | ObjectTypeAnnotation - | $ReadOnly<{| + | $ReadOnly<{ type: 'ArrayTypeAnnotation', elementType: | BooleanTypeAnnotation @@ -163,27 +163,27 @@ export type PropTypeAnnotation = | DoubleTypeAnnotation | FloatTypeAnnotation | Int32TypeAnnotation - | $ReadOnly<{| + | $ReadOnly<{ type: 'StringEnumTypeAnnotation', default: string, options: $ReadOnlyArray, - |}> + }> | ObjectTypeAnnotation | ReservedPropTypeAnnotation - | $ReadOnly<{| + | $ReadOnly<{ type: 'ArrayTypeAnnotation', elementType: ObjectTypeAnnotation, - |}>, - |}>; + }>, + }>; -type ReservedPropTypeAnnotation = $ReadOnly<{| +type ReservedPropTypeAnnotation = $ReadOnly<{ type: 'ReservedPropTypeAnnotation', name: | 'ColorPrimitive' | 'ImageSourcePrimitive' | 'PointPrimitive' | 'EdgeInsetsPrimitive', -|}>; +}>; export type CommandTypeAnnotation = FunctionTypeAnnotation< CommandParamTypeAnnotation, @@ -198,10 +198,10 @@ export type CommandParamTypeAnnotation = | FloatTypeAnnotation | StringTypeAnnotation; -export type ReservedTypeAnnotation = $ReadOnly<{| +export type ReservedTypeAnnotation = $ReadOnly<{ type: 'ReservedTypeAnnotation', name: 'RootTag', // Union with more custom types. -|}>; +}>; /** * NativeModule Types @@ -210,14 +210,12 @@ export type Nullable<+T: NativeModuleTypeAnnotation> = | NullableTypeAnnotation | T; -export type NullableTypeAnnotation< - +T: NativeModuleTypeAnnotation, -> = $ReadOnly<{| +export type NullableTypeAnnotation<+T: NativeModuleTypeAnnotation> = $ReadOnly<{ type: 'NullableTypeAnnotation', typeAnnotation: T, -|}>; +}>; -export type NativeModuleSchema = $ReadOnly<{| +export type NativeModuleSchema = $ReadOnly<{ type: 'NativeModule', aliases: NativeModuleAliasMap, spec: NativeModuleSpec, @@ -226,19 +224,19 @@ export type NativeModuleSchema = $ReadOnly<{| // TODO: It's clearer to define `restrictedToPlatforms` instead, but // `excludedPlatforms` is used here to be consistent with ComponentSchema. excludedPlatforms?: $ReadOnlyArray, -|}>; +}>; -type NativeModuleSpec = $ReadOnly<{| +type NativeModuleSpec = $ReadOnly<{ properties: $ReadOnlyArray, -|}>; +}>; export type NativeModulePropertyShape = NamedShape< Nullable, >; -export type NativeModuleAliasMap = $ReadOnly<{| +export type NativeModuleAliasMap = $ReadOnly<{ [aliasName: string]: NativeModuleObjectTypeAnnotation, -|}>; +}>; export type NativeModuleFunctionTypeAnnotation = FunctionTypeAnnotation< Nullable, @@ -251,51 +249,51 @@ export type NativeModuleObjectTypeAnnotation = ObjectTypeAnnotation< export type NativeModuleArrayTypeAnnotation< +T: Nullable, -> = $ReadOnly<{| +> = $ReadOnly<{ type: 'ArrayTypeAnnotation', /** * TODO(T72031674): Migrate all our NativeModule specs to not use * invalid Array ElementTypes. Then, make the elementType required. */ elementType?: T, -|}>; +}>; -export type NativeModuleStringTypeAnnotation = $ReadOnly<{| +export type NativeModuleStringTypeAnnotation = $ReadOnly<{ type: 'StringTypeAnnotation', -|}>; +}>; -export type NativeModuleNumberTypeAnnotation = $ReadOnly<{| +export type NativeModuleNumberTypeAnnotation = $ReadOnly<{ type: 'NumberTypeAnnotation', -|}>; +}>; -export type NativeModuleInt32TypeAnnotation = $ReadOnly<{| +export type NativeModuleInt32TypeAnnotation = $ReadOnly<{ type: 'Int32TypeAnnotation', -|}>; +}>; -export type NativeModuleDoubleTypeAnnotation = $ReadOnly<{| +export type NativeModuleDoubleTypeAnnotation = $ReadOnly<{ type: 'DoubleTypeAnnotation', -|}>; +}>; -export type NativeModuleFloatTypeAnnotation = $ReadOnly<{| +export type NativeModuleFloatTypeAnnotation = $ReadOnly<{ type: 'FloatTypeAnnotation', -|}>; +}>; -export type NativeModuleBooleanTypeAnnotation = $ReadOnly<{| +export type NativeModuleBooleanTypeAnnotation = $ReadOnly<{ type: 'BooleanTypeAnnotation', -|}>; +}>; -export type NativeModuleGenericObjectTypeAnnotation = $ReadOnly<{| +export type NativeModuleGenericObjectTypeAnnotation = $ReadOnly<{ type: 'GenericObjectTypeAnnotation', -|}>; +}>; -export type NativeModuleTypeAliasTypeAnnotation = $ReadOnly<{| +export type NativeModuleTypeAliasTypeAnnotation = $ReadOnly<{ type: 'TypeAliasTypeAnnotation', name: string, -|}>; +}>; -export type NativeModulePromiseTypeAnnotation = $ReadOnly<{| +export type NativeModulePromiseTypeAnnotation = $ReadOnly<{ type: 'PromiseTypeAnnotation', -|}>; +}>; export type NativeModuleBaseTypeAnnotation = | NativeModuleStringTypeAnnotation diff --git a/packages/react-native-codegen/src/generators/RNCodegen.js b/packages/react-native-codegen/src/generators/RNCodegen.js index 113fb98c962..2a8520fb646 100644 --- a/packages/react-native-codegen/src/generators/RNCodegen.js +++ b/packages/react-native-codegen/src/generators/RNCodegen.js @@ -40,13 +40,13 @@ const schemaValidator = require('../SchemaValidator.js'); import type {SchemaType} from '../CodegenSchema'; -type Options = $ReadOnly<{| +type Options = $ReadOnly<{ libraryName: string, schema: SchemaType, outputDirectory: string, moduleSpecName: string, packageName?: string, // Some platforms have a notion of package, which should be configurable. -|}>; +}>; type Generators = | 'descriptors' @@ -58,10 +58,10 @@ type Generators = | 'modulesCxx' | 'modulesIOS'; -type Config = $ReadOnly<{| +type Config = $ReadOnly<{ generators: Array, test?: boolean, -|}>; +}>; const GENERATORS = { descriptors: [generateComponentDescriptorH.generate], diff --git a/packages/react-native-codegen/src/generators/components/GenerateTests.js b/packages/react-native-codegen/src/generators/components/GenerateTests.js index 155c41fe511..b8fde56ab58 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateTests.js +++ b/packages/react-native-codegen/src/generators/components/GenerateTests.js @@ -16,12 +16,12 @@ const {getImports, toSafeCppString} = require('./CppHelpers'); type FilesOutput = Map; type PropValueType = string | number | boolean; -type TestCase = $ReadOnly<{| +type TestCase = $ReadOnly<{ propName: string, propValue: ?PropValueType, testName?: string, raw?: boolean, -|}>; +}>; const fileTemplate = ` /** diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleCpp.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleCpp.js index e20396e7681..bd94bb33cfb 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleCpp.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleCpp.js @@ -51,14 +51,12 @@ const ModuleTemplate = ({ hostFunctions, moduleName, methods, -}: $ReadOnly<{| +}: $ReadOnly<{ hasteModuleName: string, hostFunctions: $ReadOnlyArray, moduleName: string, - methods: $ReadOnlyArray< - $ReadOnly<{|methodName: string, paramCount: number|}>, - >, -|}>) => { + methods: $ReadOnlyArray<$ReadOnly<{methodName: string, paramCount: number}>>, +}>) => { return `${hostFunctions.join('\n')} ${hasteModuleName}CxxSpecJSI::${hasteModuleName}CxxSpecJSI(std::shared_ptr jsInvoker) diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js index 7b53dea5bfb..e1925f02eed 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js @@ -26,7 +26,7 @@ type FilesOutput = Map; const ModuleClassDeclarationTemplate = ({ hasteModuleName, moduleProperties, -}: $ReadOnly<{|hasteModuleName: string, moduleProperties: string|}>) => { +}: $ReadOnly<{hasteModuleName: string, moduleProperties: string}>) => { return `class JSI_EXPORT ${hasteModuleName}CxxSpecJSI : public TurboModule { protected: ${hasteModuleName}CxxSpecJSI(std::shared_ptr jsInvoker); @@ -39,9 +39,9 @@ ${moduleProperties} const FileTemplate = ({ modules, -}: $ReadOnly<{| +}: $ReadOnly<{ modules: string, -|}>) => { +}>) => { return `/** * ${'C'}opyright (c) Facebook, Inc. and its affiliates. * diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js index 539268b3692..b8238cf4786 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js @@ -27,12 +27,12 @@ const {unwrapNullable} = require('../../parsers/flow/modules/utils'); type FilesOutput = Map; function FileTemplate( - config: $ReadOnly<{| + config: $ReadOnly<{ packageName: string, className: string, methods: string, imports: string, - |}>, + }>, ): string { const {packageName, className, methods, imports} = config; return ` @@ -62,14 +62,14 @@ ${methods} } function MethodTemplate( - config: $ReadOnly<{| + config: $ReadOnly<{ abstract: boolean, methodBody: ?string, methodJavaAnnotation: string, methodName: string, translatedReturnType: string, traversedArgs: Array, - |}>, + }>, ): string { const { abstract, diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleJniCpp.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleJniCpp.js index 9c8a599cc32..b75aea926b7 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleJniCpp.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleJniCpp.js @@ -40,12 +40,12 @@ const HostFunctionTemplate = ({ propertyName, jniSignature, jsReturnType, -}: $ReadOnly<{| +}: $ReadOnly<{ hasteModuleName: string, propertyName: string, jniSignature: string, jsReturnType: JSReturnType, -|}>) => { +}>) => { return `static facebook::jsi::Value __hostFunction_${hasteModuleName}SpecJSI_${propertyName}(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { return static_cast(turboModule).invokeJavaMethod(rt, ${jsReturnType}, "${propertyName}", "${jniSignature}", args, count); }`; @@ -54,13 +54,13 @@ const HostFunctionTemplate = ({ const ModuleClassConstructorTemplate = ({ hasteModuleName, methods, -}: $ReadOnly<{| +}: $ReadOnly<{ hasteModuleName: string, - methods: $ReadOnlyArray<{| + methods: $ReadOnlyArray<{ propertyName: string, argCount: number, - |}>, -|}>) => { + }>, +}>) => { return ` ${hasteModuleName}SpecJSI::${hasteModuleName}SpecJSI(const JavaTurboModule::InitParams ¶ms) : JavaTurboModule(params) { @@ -75,7 +75,7 @@ ${methods const ModuleLookupTemplate = ({ moduleName, hasteModuleName, -}: $ReadOnly<{|moduleName: string, hasteModuleName: string|}>) => { +}: $ReadOnly<{moduleName: string, hasteModuleName: string}>) => { return ` if (moduleName == "${moduleName}") { return std::make_shared<${hasteModuleName}SpecJSI>(params); }`; @@ -86,17 +86,17 @@ const FileTemplate = ({ include, modules, moduleLookups, -}: $ReadOnly<{| +}: $ReadOnly<{ libraryName: string, include: string, modules: string, moduleLookups: $ReadOnlyArray< - $ReadOnly<{| + $ReadOnly<{ hasteModuleName: string, moduleName: string, - |}>, + }>, >, -|}>) => { +}>) => { return ` /** * ${'C'}opyright (c) Facebook, Inc. and its affiliates. @@ -441,7 +441,7 @@ module.exports = { } return 0; }) - .flatMap<{|moduleName: string, hasteModuleName: string|}>( + .flatMap<{moduleName: string, hasteModuleName: string}>( (hasteModuleName: string) => { const {moduleNames} = nativeModules[hasteModuleName]; return moduleNames.map(moduleName => ({ diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js index 83618968675..d611a6be20b 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js @@ -18,7 +18,7 @@ const {getModules} = require('./Utils'); const ModuleClassDeclarationTemplate = ({ hasteModuleName, -}: $ReadOnly<{|hasteModuleName: string|}>) => { +}: $ReadOnly<{hasteModuleName: string}>) => { return `/** * JNI C++ class for module '${hasteModuleName}' */ @@ -32,7 +32,7 @@ public: const HeaderFileTemplate = ({ modules, libraryName, -}: $ReadOnly<{|modules: string, libraryName: string|}>) => { +}: $ReadOnly<{modules: string, libraryName: string}>) => { return ` /** * ${'C'}opyright (c) Facebook, Inc. and its affiliates. diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/StructCollector.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/StructCollector.js index ae48982139a..fda5f8466a7 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/StructCollector.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/StructCollector.js @@ -36,25 +36,25 @@ const { type StructContext = 'CONSTANTS' | 'REGULAR'; -export type RegularStruct = $ReadOnly<{| +export type RegularStruct = $ReadOnly<{ context: 'REGULAR', name: string, properties: $ReadOnlyArray, -|}>; +}>; -export type ConstantsStruct = $ReadOnly<{| +export type ConstantsStruct = $ReadOnly<{ context: 'CONSTANTS', name: string, properties: $ReadOnlyArray, -|}>; +}>; export type Struct = RegularStruct | ConstantsStruct; -export type StructProperty = $ReadOnly<{| +export type StructProperty = $ReadOnly<{ name: string, optional: boolean, typeAnnotation: Nullable, -|}>; +}>; export type StructTypeAnnotation = | NativeModuleStringTypeAnnotation diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js index 0579c28f925..9b39bf1560d 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js @@ -26,11 +26,11 @@ const StructTemplate = ({ hasteModuleName, structName, builderInputProps, -}: $ReadOnly<{| +}: $ReadOnly<{ hasteModuleName: string, structName: string, builderInputProps: string, -|}>) => `namespace JS { +}>) => `namespace JS { namespace ${hasteModuleName} { struct ${structName} { @@ -62,11 +62,11 @@ const MethodTemplate = ({ hasteModuleName, structName, properties, -}: $ReadOnly<{| +}: $ReadOnly<{ hasteModuleName: string, structName: string, properties: string, -|}>) => `inline JS::${hasteModuleName}::${structName}::Builder::Builder(const Input i) : _factory(^{ +}>) => `inline JS::${hasteModuleName}::${structName}::Builder::Builder(const Input i) : _factory(^{ NSMutableDictionary *d = [NSMutableDictionary new]; ${properties} return d; diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js index 3eb5155201d..14b8f7b4e9c 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js @@ -26,11 +26,11 @@ const StructTemplate = ({ hasteModuleName, structName, structProperties, -}: $ReadOnly<{| +}: $ReadOnly<{ hasteModuleName: string, structName: string, structProperties: string, -|}>) => `namespace JS { +}>) => `namespace JS { namespace ${hasteModuleName} { struct ${structName} { ${structProperties} @@ -52,13 +52,13 @@ const MethodTemplate = ({ hasteModuleName, structName, propertyName, -}: $ReadOnly<{| +}: $ReadOnly<{ returnType: string, returnValue: string, hasteModuleName: string, structName: string, propertyName: string, -|}>) => `inline ${returnType}JS::${hasteModuleName}::${structName}::${propertyName}() const +}>) => `inline ${returnType}JS::${hasteModuleName}::${structName}::${propertyName}() const { id const p = _v[@"${propertyName}"]; return ${returnValue}; diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeStruct.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeStruct.js index fa851d24f01..170ac77c8fe 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeStruct.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeStruct.js @@ -15,10 +15,10 @@ import type {Struct} from '../StructCollector'; const {serializeConstantsStruct} = require('./serializeConstantsStruct'); const {serializeRegularStruct} = require('./serializeRegularStruct'); -export type StructSerilizationOutput = $ReadOnly<{| +export type StructSerilizationOutput = $ReadOnly<{ methods: string, declaration: string, -|}>; +}>; function serializeStruct( hasteModuleName: string, diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/index.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/index.js index 2d5dfa78ada..69fecf7e0e3 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/index.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/index.js @@ -26,11 +26,11 @@ const ModuleDeclarationTemplate = ({ hasteModuleName, structDeclarations, protocolMethods, -}: $ReadOnly<{| +}: $ReadOnly<{ hasteModuleName: string, structDeclarations: string, protocolMethods: string, -|}>) => `${structDeclarations} +}>) => `${structDeclarations} @protocol ${hasteModuleName}Spec ${protocolMethods} @@ -51,10 +51,10 @@ namespace facebook { const HeaderFileTemplate = ({ moduleDeclarations, structInlineMethods, -}: $ReadOnly<{| +}: $ReadOnly<{ moduleDeclarations: string, structInlineMethods: string, -|}>) => `/** +}>) => `/** * ${'C'}opyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the @@ -88,10 +88,10 @@ ${structInlineMethods} const SourceFileTemplate = ({ headerFileName, moduleImplementations, -}: $ReadOnly<{| +}: $ReadOnly<{ headerFileName: string, moduleImplementations: string, -|}>) => `/** +}>) => `/** * ${'C'}opyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/serializeMethod.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/serializeMethod.js index e3b5d39bc9b..da2ec00739d 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/serializeMethod.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/serializeMethod.js @@ -32,16 +32,16 @@ const ProtocolMethodTemplate = ({ returnObjCType, methodName, params, -}: $ReadOnly<{| +}: $ReadOnly<{ returnObjCType: string, methodName: string, params: string, -|}>) => `- (${returnObjCType})${methodName}${params};`; +}>) => `- (${returnObjCType})${methodName}${params};`; -export type StructParameterRecord = $ReadOnly<{| +export type StructParameterRecord = $ReadOnly<{ paramIndex: number, structName: string, -|}>; +}>; type ReturnJSType = | 'VoidKind' @@ -51,14 +51,14 @@ type ReturnJSType = | 'NumberKind' | 'StringKind'; -export type MethodSerializationOutput = $ReadOnly<{| +export type MethodSerializationOutput = $ReadOnly<{ methodName: string, protocolMethod: string, selector: string, structParamRecords: $ReadOnlyArray, returnJSType: ReturnJSType, argCount: number, -|}>; +}>; function serializeMethod( hasteModuleName: string, @@ -79,7 +79,7 @@ function serializeMethod( ); } - const methodParams: Array<{|paramName: string, objCType: string|}> = []; + const methodParams: Array<{paramName: string, objCType: string}> = []; const structParamRecords: Array = []; params.forEach((param, index) => { @@ -183,7 +183,7 @@ function getParamObjCType( structName: string, structCollector: StructCollector, resolveAlias: AliasResolver, -): $ReadOnly<{|objCType: string, isStruct: boolean|}> { +): $ReadOnly<{objCType: string, isStruct: boolean}> { const {name: paramName, typeAnnotation: nullableTypeAnnotation} = param; const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation); const notRequired = param.optional || nullable; @@ -215,7 +215,7 @@ function getParamObjCType( * * For example: * Array => NSArray - * type Animal = {||}; + * type Animal = {}; * Array => NSArray, etc. */ return notStruct(wrapIntoNullableIfNeeded('NSArray *')); @@ -398,7 +398,7 @@ function serializeConstantsProtocolMethods( const {returnTypeAnnotation} = propertyTypeAnnotation; if (returnTypeAnnotation.type !== 'ObjectTypeAnnotation') { throw new Error( - `${hasteModuleName}.getConstants() may only return an object literal: {|...|}.`, + `${hasteModuleName}.getConstants() may only return an object literal: {...}.`, ); } diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/source/serializeModule.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/source/serializeModule.js index c930f98b7d8..14796e88a65 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/source/serializeModule.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/source/serializeModule.js @@ -20,11 +20,11 @@ const ModuleTemplate = ({ hasteModuleName, structs, methodSerializationOutputs, -}: $ReadOnly<{| +}: $ReadOnly<{ hasteModuleName: string, structs: $ReadOnlyArray, methodSerializationOutputs: $ReadOnlyArray, -|}>) => `${structs +}>) => `${structs .map(struct => RCTCxxConvertCategoryTemplate({hasteModuleName, structName: struct.name}), ) @@ -61,10 +61,10 @@ namespace facebook { const RCTCxxConvertCategoryTemplate = ({ hasteModuleName, structName, -}: $ReadOnly<{| +}: $ReadOnly<{ hasteModuleName: string, structName: string, -|}>) => `@implementation RCTCxxConvert (${hasteModuleName}_${structName}) +}>) => `@implementation RCTCxxConvert (${hasteModuleName}_${structName}) + (RCTManagedPointer *)JS_${hasteModuleName}_${structName}:(id)json { return facebook::react::managedPointer(json); @@ -76,12 +76,12 @@ const InlineHostFunctionTemplate = ({ methodName, returnJSType, selector, -}: $ReadOnly<{| +}: $ReadOnly<{ hasteModuleName: string, methodName: string, returnJSType: string, selector: string, -|}>) => ` +}>) => ` static facebook::jsi::Value __hostFunction_${hasteModuleName}SpecJSI_${methodName}(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { return static_cast(turboModule).invokeObjCMethod(rt, ${returnJSType}, "${methodName}", ${selector}, args, count); }`; @@ -91,12 +91,12 @@ const MethodMapEntryTemplate = ({ methodName, structParamRecords, argCount, -}: $ReadOnly<{| +}: $ReadOnly<{ hasteModuleName: string, methodName: string, structParamRecords: $ReadOnlyArray, argCount: number, -|}>) => ` +}>) => ` methodMap_["${methodName}"] = MethodMetadata {${argCount}, __hostFunction_${hasteModuleName}SpecJSI_${methodName}}; ${structParamRecords .map(({paramIndex, structName}) => { diff --git a/packages/react-native-codegen/src/generators/modules/Utils.js b/packages/react-native-codegen/src/generators/modules/Utils.js index e5b50c2ddd1..10017bb420b 100644 --- a/packages/react-native-codegen/src/generators/modules/Utils.js +++ b/packages/react-native-codegen/src/generators/modules/Utils.js @@ -33,8 +33,8 @@ function createAliasResolver(aliasMap: NativeModuleAliasMap): AliasResolver { function getModules( schema: SchemaType, -): $ReadOnly<{|[hasteModuleName: string]: NativeModuleSchema|}> { - return Object.keys(schema.modules).reduce<{|[string]: NativeModuleSchema|}>( +): $ReadOnly<{[hasteModuleName: string]: NativeModuleSchema}> { + return Object.keys(schema.modules).reduce<{[string]: NativeModuleSchema}>( (modules, hasteModuleName: string) => { const module = schema.modules[hasteModuleName]; if (module == null || module.type === 'Component') { diff --git a/packages/react-native-codegen/src/parsers/flow/components/options.js b/packages/react-native-codegen/src/parsers/flow/components/options.js index 8044575db15..607ac526aab 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/options.js +++ b/packages/react-native-codegen/src/parsers/flow/components/options.js @@ -15,9 +15,9 @@ import type {OptionsShape} from '../../../CodegenSchema.js'; // $FlowFixMe there's no flowtype for ASTs type OptionsAST = Object; -export type CommandOptions = $ReadOnly<{| +export type CommandOptions = $ReadOnly<{ supportedCommands: $ReadOnlyArray, -|}>; +}>; function getCommandOptions( commandOptionsExpression: OptionsAST, diff --git a/packages/react-native-codegen/src/parsers/flow/components/schema.js b/packages/react-native-codegen/src/parsers/flow/components/schema.js index d48e186d7e0..21ce46d6856 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/schema.js +++ b/packages/react-native-codegen/src/parsers/flow/components/schema.js @@ -20,7 +20,7 @@ import type { OptionsShape, } from '../../../CodegenSchema.js'; -export type ComponentSchemaBuilderConfig = $ReadOnly<{| +export type ComponentSchemaBuilderConfig = $ReadOnly<{ filename: string, componentName: string, extendsProps: $ReadOnlyArray, @@ -28,7 +28,7 @@ export type ComponentSchemaBuilderConfig = $ReadOnly<{| props: $ReadOnlyArray>, commands: $ReadOnlyArray>, options?: ?OptionsShape, -|}>; +}>; function wrapComponentSchema({ filename, diff --git a/packages/react-native-codegen/src/parsers/flow/modules/__tests__/module-parser-e2e-test.js b/packages/react-native-codegen/src/parsers/flow/modules/__tests__/module-parser-e2e-test.js index fc03e16e360..ef3354df45f 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/__tests__/module-parser-e2e-test.js +++ b/packages/react-native-codegen/src/parsers/flow/modules/__tests__/module-parser-e2e-test.js @@ -49,9 +49,9 @@ const RESERVED_FUNCTION_VALUE_TYPE_NAME: $ReadOnlyArray<'RootTag'> = [ const MODULE_NAME = 'NativeFoo'; const TYPE_ALIAS_DECLARATIONS = ` -type Animal = {| +type Animal = { name: string, -|}; +}; type AnimalPointer = Animal; `; @@ -288,10 +288,10 @@ describe('Flow Module Parser', () => { expectAnimalTypeAliasToExist(module); }); - it(`should parse methods that have ${PARAM_TYPE_DESCRIPTION} parameter of type 'Array<{|foo: ?string|}>'`, () => { + it(`should parse methods that have ${PARAM_TYPE_DESCRIPTION} parameter of type 'Array<{foo: ?string}>'`, () => { const [elementType] = parseParamArrayElementType( 'arg', - '{|foo: ?string|}', + '{foo: ?string}', ); expect(elementType).not.toBe(null); @@ -351,9 +351,9 @@ describe('Flow Module Parser', () => { import type {TurboModule} from 'RCTExport'; import * as TurboModuleRegistry from 'TurboModuleRegistry'; - type Animal = ?{| + type Animal = ?{ name: string, - |}; + }; type AnimalPointer = Animal; @@ -428,7 +428,7 @@ describe('Flow Module Parser', () => { ] { const [paramTypeAnnotation, module] = parseParamType( 'arg', - `{|${annotateProp(propName, propType)}|}`, + `{${annotateProp(propName, propType)}}`, ); expect(paramTypeAnnotation.type).toBe('ObjectTypeAnnotation'); @@ -608,10 +608,10 @@ describe('Flow Module Parser', () => { expectAnimalTypeAliasToExist(module); }); - it(`should parse methods that have ${PARAM_TYPE_DESCRIPTION} parameter type of an object literal with ${PROP_TYPE_DESCRIPTION} prop of 'Array<{|foo: ?string|}>'`, () => { + it(`should parse methods that have ${PARAM_TYPE_DESCRIPTION} parameter type of an object literal with ${PROP_TYPE_DESCRIPTION} prop of 'Array<{foo: ?string}>'`, () => { const [elementType] = parseArrayElementType( 'prop', - '{|foo: ?string|}', + '{foo: ?string}', ); expect(elementType.type).toBe('ObjectTypeAnnotation'); @@ -638,10 +638,10 @@ describe('Flow Module Parser', () => { }); }); - it(`should parse methods that have ${PARAM_TYPE_DESCRIPTION} parameter type of an object literal with ${PROP_TYPE_DESCRIPTION} prop of type '{|foo: ?string|}'`, () => { + it(`should parse methods that have ${PARAM_TYPE_DESCRIPTION} parameter type of an object literal with ${PROP_TYPE_DESCRIPTION} prop of type '{foo: ?string}'`, () => { const [property] = parseParamTypeObjectLiteralProp( 'prop', - '{|foo: ?string|}', + '{foo: ?string}', ); expect(property.typeAnnotation.type).toBe( @@ -764,7 +764,7 @@ describe('Flow Module Parser', () => { describe( IS_RETURN_TYPE_NULLABLE ? 'Nullable Returns' : 'Non-Nullable Returns', () => { - ['Promise', 'Promise<{||}>', 'Promise<*>'].forEach( + ['Promise', 'Promise<{}>', 'Promise<*>'].forEach( promiseFlowType => { it(`should parse methods that have ${RETURN_TYPE_DESCRIPTION} return of type '${promiseFlowType}'`, () => { const [returnTypeAnnotation] = parseReturnType(promiseFlowType); @@ -872,9 +872,9 @@ describe('Flow Module Parser', () => { expectAnimalTypeAliasToExist(module); }); - it(`should parse methods that have ${RETURN_TYPE_DESCRIPTION} return of type 'Array<{|foo: ?string|}>'`, () => { + it(`should parse methods that have ${RETURN_TYPE_DESCRIPTION} return of type 'Array<{foo: ?string}>'`, () => { const [elementType] = parseArrayElementReturnType( - '{|foo: ?string|}', + '{foo: ?string}', ); expect(elementType.type).toBe('ObjectTypeAnnotation'); invariant(elementType.type === 'ObjectTypeAnnotation', ''); @@ -926,7 +926,7 @@ describe('Flow Module Parser', () => { // TODO: Inexact vs exact object literals? it(`should parse methods that have ${RETURN_TYPE_DESCRIPTION} return type of an empty object literal`, () => { - const [returnTypeAnnotation] = parseReturnType('{||}'); + const [returnTypeAnnotation] = parseReturnType('{}'); expect(returnTypeAnnotation.type).toBe('ObjectTypeAnnotation'); invariant( returnTypeAnnotation.type === 'ObjectTypeAnnotation', @@ -978,7 +978,7 @@ describe('Flow Module Parser', () => { NativeModuleSchema, ] { const [returnTypeAnnotation, module] = parseReturnType( - `{|${annotateProp(propName, propType)}|}`, + `{${annotateProp(propName, propType)}}`, ); expect(returnTypeAnnotation.type).toBe('ObjectTypeAnnotation'); invariant( @@ -1168,10 +1168,10 @@ describe('Flow Module Parser', () => { expectAnimalTypeAliasToExist(module); }); - it(`should parse methods that have ${RETURN_TYPE_DESCRIPTION} return type of an object literal with ${PROP_TYPE_DESCRIPTION} prop of type 'Array<{|foo: ?string|}>'`, () => { + it(`should parse methods that have ${RETURN_TYPE_DESCRIPTION} return type of an object literal with ${PROP_TYPE_DESCRIPTION} prop of type 'Array<{foo: ?string}>'`, () => { const [elementType] = parseArrayElementType( 'prop', - '{|foo: ?string|}', + '{foo: ?string}', ); expect(elementType.type).toBe('ObjectTypeAnnotation'); invariant( @@ -1198,10 +1198,10 @@ describe('Flow Module Parser', () => { }); }); - it(`should parse methods that have ${RETURN_TYPE_DESCRIPTION} return type of an object literal with ${PROP_TYPE_DESCRIPTION} prop of '{|foo: ?string|}'`, () => { + it(`should parse methods that have ${RETURN_TYPE_DESCRIPTION} return type of an object literal with ${PROP_TYPE_DESCRIPTION} prop of '{foo: ?string}'`, () => { const [property] = parseObjectLiteralReturnTypeProp( 'prop', - '{|foo: ?string|}', + '{foo: ?string}', ); expect(property.typeAnnotation.type).toBe( diff --git a/packages/react-native-codegen/src/parsers/flow/modules/index.js b/packages/react-native-codegen/src/parsers/flow/modules/index.js index 7bcff0dd894..c95308c7e5e 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/index.js +++ b/packages/react-native-codegen/src/parsers/flow/modules/index.js @@ -288,9 +288,9 @@ function translateTypeAnnotation( * * Consider this case: * - * type Animal = ?{| + * type Animal = ?{ * name: string, - * |}; + * }; * * type B = Animal * @@ -298,11 +298,11 @@ function translateTypeAnnotation( * +greet: (animal: B) => void; * } * - * In this case, we follow B to Animal, and then Animal to ?{|name: string|}. + * In this case, we follow B to Animal, and then Animal to ?{name: string}. * * We: * 1. Replace `+greet: (animal: B) => void;` with `+greet: (animal: ?Animal) => void;`, - * 2. Pretend that Animal = {|name: string|}. + * 2. Pretend that Animal = {name: string}. * * Why do we do this? * 1. In ObjC, we need to generate a struct called Animal, not B. @@ -572,10 +572,10 @@ function buildModuleSchema( const declaration = types[moduleInterfaceName]; return (declaration.body.properties: $ReadOnlyArray<$FlowFixMe>) .filter(property => property.type === 'ObjectTypeProperty') - .map(property => { + }>(property => { const aliasMap: {...NativeModuleAliasMap} = {}; return guard(() => ({ diff --git a/packages/react-native-codegen/src/parsers/flow/utils.js b/packages/react-native-codegen/src/parsers/flow/utils.js index 8bc2770b44e..d96f4d1b52e 100644 --- a/packages/react-native-codegen/src/parsers/flow/utils.js +++ b/packages/react-native-codegen/src/parsers/flow/utils.js @@ -20,7 +20,7 @@ const {ParserError} = require('./errors'); * * TODO(T71778680): Flow type AST Nodes */ -export type TypeDeclarationMap = {|[declarationName: string]: $FlowFixMe|}; +export type TypeDeclarationMap = {[declarationName: string]: $FlowFixMe}; function getTypes(ast: $FlowFixMe): TypeDeclarationMap { return ast.body.reduce((types, node) => { @@ -47,13 +47,13 @@ export type ASTNode = Object; const invariant = require('invariant'); type TypeAliasResolutionStatus = - | $ReadOnly<{| + | $ReadOnly<{ successful: true, aliasName: string, - |}> - | $ReadOnly<{| + }> + | $ReadOnly<{ successful: false, - |}>; + }>; function resolveTypeAnnotation( // TODO(T71778680): This is an Flow TypeAnnotation. Flow-type this