diff --git a/packages/react-native-codegen/src/parsers/consistency/__tests__/checkComponentSnaps-test.js b/packages/react-native-codegen/src/parsers/consistency/__tests__/checkComponentSnaps-test.js index 9fce55095a7a33..c1088b1f0b0c67 100644 --- a/packages/react-native-codegen/src/parsers/consistency/__tests__/checkComponentSnaps-test.js +++ b/packages/react-native-codegen/src/parsers/consistency/__tests__/checkComponentSnaps-test.js @@ -17,7 +17,10 @@ const flowSnaps = require('../../../../src/parsers/flow/components/__tests__/__s const flowExtraCases = []; const tsFixtures = require('../../typescript/components/__test_fixtures__/fixtures.js'); const tsSnaps = require('../../../../src/parsers/typescript/components/__tests__/__snapshots__/typescript-component-parser-test.js.snap'); -const tsExtraCases = ['ARRAY2_PROP_TYPES_NO_EVENTS', 'PROPS_AND_EVENTS_WITH_INTERFACES']; +const tsExtraCases = [ + 'ARRAY2_PROP_TYPES_NO_EVENTS', + 'PROPS_AND_EVENTS_WITH_INTERFACES', +]; const ignoredCases = ['ARRAY_PROP_TYPES_NO_EVENTS']; compareSnaps( diff --git a/packages/react-native-codegen/src/parsers/typescript/components/events.js b/packages/react-native-codegen/src/parsers/typescript/components/events.js index f84d4428e3cd65..bfe81281a489f9 100644 --- a/packages/react-native-codegen/src/parsers/typescript/components/events.js +++ b/packages/react-native-codegen/src/parsers/typescript/components/events.js @@ -148,7 +148,12 @@ function findEventArgumentsAndType( } const name = typeAnnotation.typeName.name; if (name === 'Readonly') { - return findEventArgumentsAndType(typeAnnotation.typeParameters.params[0], types, bubblingType, paperName); + return findEventArgumentsAndType( + typeAnnotation.typeParameters.params[0], + types, + bubblingType, + paperName, + ); } else if (name === 'BubblingEventHandler' || name === 'DirectEventHandler') { const eventType = name === 'BubblingEventHandler' ? 'bubble' : 'direct'; const paperTopLevelNameDeprecated = diff --git a/packages/react-native-codegen/src/parsers/typescript/components/props.js b/packages/react-native-codegen/src/parsers/typescript/components/props.js index 27f9bbba964171..6f11394443660b 100644 --- a/packages/react-native-codegen/src/parsers/typescript/components/props.js +++ b/packages/react-native-codegen/src/parsers/typescript/components/props.js @@ -53,9 +53,16 @@ function getTypeAnnotationForArrayOfArrayOfObject( ) { // for array of array of a type // such type must be an object literal - const elementType = getTypeAnnotationForArray(name,typeAnnotation,null,types); - if(elementType.type !== 'ObjectTypeAnnotation') { - throw new Error(`Only array of array of object is supported for "${name}".`); + const elementType = getTypeAnnotationForArray( + name, + typeAnnotation, + null, + types, + ); + if (elementType.type !== 'ObjectTypeAnnotation') { + throw new Error( + `Only array of array of object is supported for "${name}".`, + ); } return { @@ -115,7 +122,12 @@ function getTypeAnnotationForArray( const objectType = getValueFromTypes(extractedTypeAnnotation, types); if (objectType.typeName.name === 'Readonly') { - return getTypeAnnotationForArray(name, objectType.typeParameters.params[0],defaultValue , types); + return getTypeAnnotationForArray( + name, + objectType.typeParameters.params[0], + defaultValue, + types, + ); } // Covers: ReadonlyArray @@ -137,11 +149,14 @@ function getTypeAnnotationForArray( switch (type) { case 'TSTypeLiteral': - case 'TSInterfaceDeclaration': { - const rawProperties = type === 'TSInterfaceDeclaration' ? [typeAnnotation] : typeAnnotation.members; + case 'TSInterfaceDeclaration': { + const rawProperties = + type === 'TSInterfaceDeclaration' + ? [typeAnnotation] + : typeAnnotation.members; return { type: 'ObjectTypeAnnotation', - properties: flattenProperties(rawProperties,types) + properties: flattenProperties(rawProperties, types) .map(prop => buildPropSchema(prop, types)) .filter(Boolean), }; @@ -351,12 +366,15 @@ function getTypeAnnotation( switch (type) { case 'TSTypeLiteral': case 'TSInterfaceDeclaration': { - const rawProperties = type === 'TSInterfaceDeclaration' ? [typeAnnotation] : typeAnnotation.members; + const rawProperties = + type === 'TSInterfaceDeclaration' + ? [typeAnnotation] + : typeAnnotation.members; const flattenedProperties = flattenProperties(rawProperties, types); const properties = flattenedProperties .map(prop => buildPropSchema(prop, types)) .filter(Boolean); - + return { type: 'ObjectTypeAnnotation', properties, @@ -654,20 +672,25 @@ function flattenProperties( getPropProperties(property.typeName.name, types), types, ); - } else if (property.type === 'TSExpressionWithTypeArguments' || property.type === 'TSInterfaceHeritage') { + } else if ( + property.type === 'TSExpressionWithTypeArguments' || + property.type === 'TSInterfaceHeritage' + ) { return flattenProperties( getPropProperties(property.expression.name, types), types, ); } else if (property.type === 'TSTypeLiteral') { - return flattenProperties(property.members,types); + return flattenProperties(property.members, types); } else if (property.type === 'TSInterfaceDeclaration') { return flattenProperties( getPropProperties(property.id.name, types), types, ); } else { - throw new Error(`${property.type} is not a supported object literal type.`); + throw new Error( + `${property.type} is not a supported object literal type.`, + ); } }) .filter(Boolean)