Skip to content

Commit

Permalink
yarn prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
ZihanChen-MSFT committed Sep 24, 2022
1 parent ecbc385 commit 94fb3ab
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<T>
Expand All @@ -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),
};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 94fb3ab

Please sign in to comment.