From 92a6722bf279b6cff1fa0b69bd0ba7d85ed3518a Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Tue, 29 Sep 2020 14:33:06 -0700 Subject: [PATCH] Refactor: Make NativeModuleAliasMap $ReadOnly Summary: We were using `$ReadOnly` everywhere, so I figured we'd just make the type itself `$ReadOnly`. Changelog: [Internal] Reviewed By: PeteTheHeat Differential Revision: D23645207 fbshipit-source-id: 4e018d5768f4fcfd00492def7d840a5054cb2b73 --- packages/react-native-codegen/src/CodegenSchema.js | 6 +++--- .../src/parsers/flow/modules/index.js | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/react-native-codegen/src/CodegenSchema.js b/packages/react-native-codegen/src/CodegenSchema.js index 6ed318c6237..55d9b2aa7b7 100644 --- a/packages/react-native-codegen/src/CodegenSchema.js +++ b/packages/react-native-codegen/src/CodegenSchema.js @@ -267,13 +267,13 @@ export type Required = $ReadOnly<{...T, nullable: false}>; export type NativeModuleSchema = $ReadOnly<{| // We only support aliases to Objects - aliases: $ReadOnly, + aliases: NativeModuleAliasMap, properties: $ReadOnlyArray, |}>; -export type NativeModuleAliasMap = { +export type NativeModuleAliasMap = $ReadOnly<{| [aliasName: string]: Required, -}; +|}>; export type NativeModulePropertySchema = $ReadOnly<{| name: string, 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 31de4e511f8..ca1b95216e2 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/index.js +++ b/packages/react-native-codegen/src/parsers/flow/modules/index.js @@ -38,7 +38,7 @@ function translateTypeAnnotation( */ flowTypeAnnotation: $FlowFixMe, types: TypeDeclarationMap, - aliasMap: NativeModuleAliasMap, + aliasMap: {...NativeModuleAliasMap}, ): NativeModuleTypeAnnotation { const { nullable, @@ -306,7 +306,7 @@ function translateFunctionTypeAnnotation( flowFunctionTypeAnnotation: $FlowFixMe, types: TypeDeclarationMap, nullable: boolean, - aliasMap: NativeModuleAliasMap, + aliasMap: {...NativeModuleAliasMap}, ): NativeModuleFunctionTypeAnnotation { const params: Array = []; for (const flowParam of (flowFunctionTypeAnnotation.params: $ReadOnlyArray<$FlowFixMe>)) { @@ -367,7 +367,7 @@ function buildPropertySchema( // Flow type this node property: $FlowFixMe, types: TypeDeclarationMap, - aliasMap: NativeModuleAliasMap, + aliasMap: {...NativeModuleAliasMap}, ): NativeModulePropertySchema { let nullable = false; let {key, value} = property; @@ -422,7 +422,7 @@ function buildModuleSchema( return (declaration.body.properties: $ReadOnlyArray<$FlowFixMe>) .filter(property => property.type === 'ObjectTypeProperty') .map(property => { - const aliasMap: NativeModuleAliasMap = {}; + const aliasMap: {...NativeModuleAliasMap} = {}; return { aliasMap: aliasMap, propertySchema: buildPropertySchema(