From e7d9e4dbb5cf8a9a5d615cd15e23ec107fa1ae1c Mon Sep 17 00:00:00 2001 From: George Zahariev Date: Tue, 3 May 2022 21:55:01 -0700 Subject: [PATCH] Collapse object initialization in Xplat Summary: Collapse multiline object initialization into one single object literal (as much as possible). Run codemod (requires temporary xplat task runner config changes), then manual fixes. ``` ./scripts/typedjs/flow/runner codemod lti/collapseObjectInitialization ~/fbsource/xplat/js/ ``` - Announcement: [post](https://fb.workplace.com/groups/flowlang/posts/903386663600331) - Support group: [Flow Support](https://fb.workplace.com/groups/flow) drop-conflicts Format: ``` arc f ``` Sort imports ``` hg l -n | xargs js1 lint --fix --rule 'fb-tools/sort-requires' ``` Changelog: [Internal] Reviewed By: SamChou19815 Differential Revision: D36112168 fbshipit-source-id: 23db87c3bd8ffe693019ffeb5ac8300ec46c8532 --- .../Utilities/__tests__/stringifySafe-test.js | 2 +- .../src/parsers/flow/components/index.js | 17 +++++++++-------- .../src/parsers/typescript/components/index.js | 17 +++++++++-------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Libraries/Utilities/__tests__/stringifySafe-test.js b/Libraries/Utilities/__tests__/stringifySafe-test.js index 0107f7179d1..5453f7d45c0 100644 --- a/Libraries/Utilities/__tests__/stringifySafe-test.js +++ b/Libraries/Utilities/__tests__/stringifySafe-test.js @@ -33,7 +33,7 @@ describe('stringifySafe', () => { }); it('stringifySafe stringifies circular objects with toString', () => { - const arg = {}; + const arg: {arg?: {...}} = {...null}; arg.arg = arg; const result = stringifySafe(arg); expect(result).toEqual('[object Object]'); diff --git a/packages/react-native-codegen/src/parsers/flow/components/index.js b/packages/react-native-codegen/src/parsers/flow/components/index.js index feb34a24a3c..39345342c67 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/index.js +++ b/packages/react-native-codegen/src/parsers/flow/components/index.js @@ -9,16 +9,16 @@ */ 'use strict'; -import type {CommandOptions} from './options'; import type {TypeDeclarationMap} from '../utils'; - +import type {CommandOptions} from './options'; import type {ComponentSchemaBuilderConfig} from './schema.js'; + +const {getTypes} = require('../utils'); const {getCommands} = require('./commands'); const {getEvents} = require('./events'); -const {getProps, getPropProperties} = require('./props'); -const {getCommandOptions, getOptions} = require('./options'); const {getExtendsProps, removeKnownExtends} = require('./extends'); -const {getTypes} = require('../utils'); +const {getCommandOptions, getOptions} = require('./options'); +const {getPropProperties, getProps} = require('./props'); function findComponentConfig(ast) { const foundConfigs = []; @@ -41,9 +41,10 @@ function findComponentConfig(ast) { const typeArgumentParams = declaration.typeArguments.params; const funcArgumentParams = declaration.arguments; - const nativeComponentType = {}; - nativeComponentType.propsTypeName = typeArgumentParams[0].id.name; - nativeComponentType.componentName = funcArgumentParams[0].value; + const nativeComponentType: {[string]: string} = { + propsTypeName: typeArgumentParams[0].id.name, + componentName: funcArgumentParams[0].value, + }; if (funcArgumentParams.length > 1) { nativeComponentType.optionsExpression = funcArgumentParams[1]; } diff --git a/packages/react-native-codegen/src/parsers/typescript/components/index.js b/packages/react-native-codegen/src/parsers/typescript/components/index.js index b36394f8425..14200463b51 100644 --- a/packages/react-native-codegen/src/parsers/typescript/components/index.js +++ b/packages/react-native-codegen/src/parsers/typescript/components/index.js @@ -9,16 +9,16 @@ */ 'use strict'; -import type {CommandOptions} from './options'; import type {TypeDeclarationMap} from '../utils'; - +import type {CommandOptions} from './options'; import type {ComponentSchemaBuilderConfig} from './schema.js'; + +const {getTypes} = require('../utils'); const {getCommands} = require('./commands'); const {getEvents} = require('./events'); -const {getProps, getPropProperties} = require('./props'); -const {getCommandOptions, getOptions} = require('./options'); const {getExtendsProps, removeKnownExtends} = require('./extends'); -const {getTypes} = require('../utils'); +const {getCommandOptions, getOptions} = require('./options'); +const {getPropProperties, getProps} = require('./props'); function findComponentConfig(ast) { const foundConfigs = []; @@ -41,9 +41,10 @@ function findComponentConfig(ast) { const typeArgumentParams = declaration.typeParameters.params; const funcArgumentParams = declaration.arguments; - const nativeComponentType = {}; - nativeComponentType.propsTypeName = typeArgumentParams[0].typeName.name; - nativeComponentType.componentName = funcArgumentParams[0].value; + const nativeComponentType: {[string]: string} = { + propsTypeName: typeArgumentParams[0].typeName.name, + componentName: funcArgumentParams[0].value, + }; if (funcArgumentParams.length > 1) { nativeComponentType.optionsExpression = funcArgumentParams[1]; }