codegen 107: add interfaceDeclaration prop in parsers (#37361)

Summary:
part of codegen issue https://github.com/facebook/react-native/issues/34872

> Add a interfaceDeclaration: string property to the Parser class. Implement it in the Flow parser so that it returns InterfaceDeclaration and in the TypeScriptParser so that it returns TSInterfaceDeclaration. Replace the case in the switch  in the [parsers/typescript/utils.js](e133100721/packages/react-native-codegen/src/parsers/typescript/utils.js (L69)) with this prop.

bypass-github-export-checks

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal][Added]: Add interfaceDeclaration property in parsers

Pull Request resolved: https://github.com/facebook/react-native/pull/37361

Test Plan: yarn test

Differential Revision: D45769316

Pulled By: cipolleschi

fbshipit-source-id: a7f3c6339984e643e3e35fb5b920442aea027b78
This commit is contained in:
shubham0142 2023-05-17 03:45:34 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 91c60cb365
Коммит 9301c8fea5
6 изменённых файлов: 22 добавлений и 2 удалений

Просмотреть файл

@ -317,6 +317,12 @@ describe('FlowParser', () => {
expect(parser.enumDeclaration).toEqual('EnumDeclaration');
});
});
describe('interfaceDelcaration', () => {
it('returns interfaceDelcaration Property', () => {
expect(parser.interfaceDelcaration).toEqual('InterfaceDeclaration');
});
});
});
describe('TypeScriptParser', () => {
@ -606,4 +612,10 @@ describe('TypeScriptParser', () => {
expect(parser.enumDeclaration).toEqual('TSEnumDeclaration');
});
});
describe('interfaceDelcaration', () => {
it('returns interfaceDelcaration Property', () => {
expect(parser.interfaceDelcaration).toEqual('TSInterfaceDeclaration');
});
});
});

Просмотреть файл

@ -64,6 +64,7 @@ class FlowParser implements Parser {
typeParameterInstantiation: string = 'TypeParameterInstantiation';
typeAlias: string = 'TypeAlias';
enumDeclaration: string = 'EnumDeclaration';
interfaceDelcaration: string = 'InterfaceDeclaration';
isProperty(property: $FlowFixMe): boolean {
return property.type === 'ObjectTypeProperty';

Просмотреть файл

@ -93,6 +93,11 @@ export interface Parser {
*/
enumDeclaration: string;
/**
* InterfaceDelcaration property of the Parser
*/
interfaceDelcaration: string;
/**
* Given a declaration, it returns true if it is a property
*/

Просмотреть файл

@ -62,6 +62,7 @@ export class MockedParser implements Parser {
typeParameterInstantiation: string = 'TypeParameterInstantiation';
typeAlias: string = 'TypeAlias';
enumDeclaration: string = 'EnumDeclaration';
interfaceDelcaration: string = 'InterfaceDelcaration';
isProperty(property: $FlowFixMe): boolean {
return property.type === 'ObjectTypeProperty';

Просмотреть файл

@ -62,6 +62,7 @@ class TypeScriptParser implements Parser {
typeParameterInstantiation: string = 'TSTypeParameterInstantiation';
typeAlias: string = 'TSTypeAliasDeclaration';
enumDeclaration: string = 'TSEnumDeclaration';
interfaceDelcaration: string = 'TSInterfaceDeclaration';
isProperty(property: $FlowFixMe): boolean {
return property.type === 'TSPropertySignature';

Просмотреть файл

@ -67,7 +67,7 @@ function resolveTypeAnnotation(
node = resolvedTypeAnnotation.typeAnnotation;
break;
}
case 'TSInterfaceDeclaration': {
case parser.interfaceDelcaration: {
typeResolutionStatus = {
successful: true,
type: 'alias',
@ -87,7 +87,7 @@ function resolveTypeAnnotation(
}
default: {
throw new TypeError(
`A non GenericTypeAnnotation must be a type declaration ('${parser.typeAlias}'), an interface ('TSInterfaceDeclaration'), or enum ('${parser.enumDeclaration}'). Instead, got the unsupported ${resolvedTypeAnnotation.type}.`,
`A non GenericTypeAnnotation must be a type declaration ('${parser.typeAlias}'), an interface ('${parser.interfaceDelcaration}'), or enum ('${parser.enumDeclaration}'). Instead, got the unsupported ${resolvedTypeAnnotation.type}.`,
);
}
}