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
This commit is contained in:
Ramanpreet Nara
2020-11-06 16:24:44 -08:00
committed by Facebook GitHub Bot
parent cb7f3f4499
commit 00cfb0f919
21 changed files with 195 additions and 199 deletions
@@ -36,25 +36,25 @@ const {
type StructContext = 'CONSTANTS' | 'REGULAR';
export type RegularStruct = $ReadOnly<{|
export type RegularStruct = $ReadOnly<{
context: 'REGULAR',
name: string,
properties: $ReadOnlyArray<StructProperty>,
|}>;
}>;
export type ConstantsStruct = $ReadOnly<{|
export type ConstantsStruct = $ReadOnly<{
context: 'CONSTANTS',
name: string,
properties: $ReadOnlyArray<StructProperty>,
|}>;
}>;
export type Struct = RegularStruct | ConstantsStruct;
export type StructProperty = $ReadOnly<{|
export type StructProperty = $ReadOnly<{
name: string,
optional: boolean,
typeAnnotation: Nullable<StructTypeAnnotation>,
|}>;
}>;
export type StructTypeAnnotation =
| NativeModuleStringTypeAnnotation
@@ -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;
@@ -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};
@@ -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,
@@ -26,11 +26,11 @@ const ModuleDeclarationTemplate = ({
hasteModuleName,
structDeclarations,
protocolMethods,
}: $ReadOnly<{|
}: $ReadOnly<{
hasteModuleName: string,
structDeclarations: string,
protocolMethods: string,
|}>) => `${structDeclarations}
}>) => `${structDeclarations}
@protocol ${hasteModuleName}Spec <RCTBridgeModule, RCTTurboModule>
${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
@@ -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<StructParameterRecord>,
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<StructParameterRecord> = [];
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<number> => NSArray<NSNumber *>
* type Animal = {||};
* type Animal = {};
* Array<Animal> => NSArray<JS::NativeSampleTurboModule::Animal *>, 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: {...}.`,
);
}
@@ -20,11 +20,11 @@ const ModuleTemplate = ({
hasteModuleName,
structs,
methodSerializationOutputs,
}: $ReadOnly<{|
}: $ReadOnly<{
hasteModuleName: string,
structs: $ReadOnlyArray<Struct>,
methodSerializationOutputs: $ReadOnlyArray<MethodSerializationOutput>,
|}>) => `${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<JS::${hasteModuleName}::${structName}>(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<ObjCTurboModule&>(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<StructParameterRecord>,
argCount: number,
|}>) => `
}>) => `
methodMap_["${methodName}"] = MethodMetadata {${argCount}, __hostFunction_${hasteModuleName}SpecJSI_${methodName}};
${structParamRecords
.map(({paramIndex, structName}) => {