Skip to content

Commit 91c60cb

Browse files
tarunrajputfacebook-github-bot
authored andcommitted
Codegen 106: add enumDeclaration property in parser class (#37355)
Summary: Part of Codegen Issue: #34872 > Add a enumDeclaration: string property to the Parser class. Implement it in the Flow parser so that it returns EnumDeclaration and in the TypeScriptParser so that it returns TSEnumDeclaration. Replace the case in the switch in the [parsers/flow/utils.js](https://github.com/facebook/react-native/blob/e133100721939108b0f28dfa9f60ac627c804018/packages/react-native-codegen/src/parsers/flow/utils.js#L66) and [parsers/typescript/utils.js](https://github.com/facebook/react-native/blob/e133100721939108b0f28dfa9f60ac627c804018/packages/react-native-codegen/src/parsers/typescript/utils.js#L78) 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 enumDeclaration property in parser class Pull Request resolved: #37355 Test Plan: ```yarn test``` Reviewed By: christophpurrer Differential Revision: D45736088 Pulled By: cipolleschi fbshipit-source-id: 706a9f1fff52563e12dd6fc54cb0e89c396bba7c
1 parent 0de4768 commit 91c60cb

File tree

7 files changed

+24
-4
lines changed

7 files changed

+24
-4
lines changed

packages/react-native-codegen/src/parsers/__tests__/parsers-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,12 @@ describe('FlowParser', () => {
311311
expect(parser.typeAlias).toEqual('TypeAlias');
312312
});
313313
});
314+
315+
describe('enumDeclaration', () => {
316+
it('returns enumDeclaration Property', () => {
317+
expect(parser.enumDeclaration).toEqual('EnumDeclaration');
318+
});
319+
});
314320
});
315321

316322
describe('TypeScriptParser', () => {
@@ -594,4 +600,10 @@ describe('TypeScriptParser', () => {
594600
expect(parser.typeAlias).toEqual('TSTypeAliasDeclaration');
595601
});
596602
});
603+
604+
describe('enumDeclaration', () => {
605+
it('returns enumDeclaration Property', () => {
606+
expect(parser.enumDeclaration).toEqual('TSEnumDeclaration');
607+
});
608+
});
597609
});

packages/react-native-codegen/src/parsers/flow/parser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const {
6363
class FlowParser implements Parser {
6464
typeParameterInstantiation: string = 'TypeParameterInstantiation';
6565
typeAlias: string = 'TypeAlias';
66+
enumDeclaration: string = 'EnumDeclaration';
6667

6768
isProperty(property: $FlowFixMe): boolean {
6869
return property.type === 'ObjectTypeProperty';

packages/react-native-codegen/src/parsers/flow/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function resolveTypeAnnotation(
6262
node = resolvedTypeAnnotation.right;
6363
break;
6464
}
65-
case 'EnumDeclaration': {
65+
case parser.enumDeclaration: {
6666
typeResolutionStatus = {
6767
successful: true,
6868
type: 'enum',
@@ -73,7 +73,7 @@ function resolveTypeAnnotation(
7373
}
7474
default: {
7575
throw new TypeError(
76-
`A non GenericTypeAnnotation must be a type declaration ('${parser.typeAlias}') or enum ('EnumDeclaration'). Instead, got the unsupported ${resolvedTypeAnnotation.type}.`,
76+
`A non GenericTypeAnnotation must be a type declaration ('${parser.typeAlias}') or enum ('${parser.enumDeclaration}'). Instead, got the unsupported ${resolvedTypeAnnotation.type}.`,
7777
);
7878
}
7979
}

packages/react-native-codegen/src/parsers/parser.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ export interface Parser {
8888
*/
8989
typeAlias: string;
9090

91+
/**
92+
* enumDeclaration Property of the Parser
93+
*/
94+
enumDeclaration: string;
95+
9196
/**
9297
* Given a declaration, it returns true if it is a property
9398
*/

packages/react-native-codegen/src/parsers/parserMock.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const schemaMock = {
6161
export class MockedParser implements Parser {
6262
typeParameterInstantiation: string = 'TypeParameterInstantiation';
6363
typeAlias: string = 'TypeAlias';
64+
enumDeclaration: string = 'EnumDeclaration';
6465

6566
isProperty(property: $FlowFixMe): boolean {
6667
return property.type === 'ObjectTypeProperty';

packages/react-native-codegen/src/parsers/typescript/parser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const {
6161
class TypeScriptParser implements Parser {
6262
typeParameterInstantiation: string = 'TSTypeParameterInstantiation';
6363
typeAlias: string = 'TSTypeAliasDeclaration';
64+
enumDeclaration: string = 'TSEnumDeclaration';
6465

6566
isProperty(property: $FlowFixMe): boolean {
6667
return property.type === 'TSPropertySignature';

packages/react-native-codegen/src/parsers/typescript/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function resolveTypeAnnotation(
7676
node = resolvedTypeAnnotation;
7777
break;
7878
}
79-
case 'TSEnumDeclaration': {
79+
case parser.enumDeclaration: {
8080
typeResolutionStatus = {
8181
successful: true,
8282
type: 'enum',
@@ -87,7 +87,7 @@ function resolveTypeAnnotation(
8787
}
8888
default: {
8989
throw new TypeError(
90-
`A non GenericTypeAnnotation must be a type declaration ('${parser.typeAlias}'), an interface ('TSInterfaceDeclaration'), or enum ('TSEnumDeclaration'). Instead, got the unsupported ${resolvedTypeAnnotation.type}.`,
90+
`A non GenericTypeAnnotation must be a type declaration ('${parser.typeAlias}'), an interface ('TSInterfaceDeclaration'), or enum ('${parser.enumDeclaration}'). Instead, got the unsupported ${resolvedTypeAnnotation.type}.`,
9191
);
9292
}
9393
}

0 commit comments

Comments
 (0)