Skip to content

Commit

Permalink
fix: apply review comments, add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski committed Nov 12, 2024
1 parent 12b7143 commit d38fffd
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ import * as TurboModuleRegistry from '../TurboModuleRegistry';
export enum SomeEnum {
NUM = 1,
SUBFACTORIAL = !5,
STR = 'str',
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ export enum Quality {
}
export enum Resolution {
Corrupted = -1,
Low = 720,
High = 1080,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ exports[`RN Codegen Flow Parser Fails with error message EMPTY_ENUM_NATIVE_MODUL
exports[`RN Codegen Flow Parser Fails with error message MAP_WITH_EXTRA_KEYS_NATIVE_MODULE 1`] = `"Module NativeSampleTurboModule: 'ObjectTypeAnnotation' cannot contain both an indexer and properties."`;

exports[`RN Codegen Flow Parser Fails with error message MIXED_VALUES_ENUM_NATIVE_MODULE 1`] = `
"Syntax error in path/NativeSampleTurboModule.js: cannot use string initializer in number enum (19:2)
STR = 'str',
^~~~~~~~~~~
note: start of enum body (17:21)
export enum SomeEnum {
^"
"Syntax error in path/NativeSampleTurboModule.js: 'true', 'false', 'string', 'number' or 'bigint' expected in enum member initializer (19:17)
SUBFACTORIAL = !5,
~~~~~~~~~~~~~~~^"
`;

exports[`RN Codegen Flow Parser Fails with error message NATIVE_MODULES_WITH_ARRAY_WITH_NO_TYPE_FOR_CONTENT 1`] = `"Module NativeSampleTurboModule: Generic 'Array' must have type parameters."`;
Expand Down Expand Up @@ -154,6 +151,10 @@ exports[`RN Codegen Flow Parser can generate fixture CXX_ONLY_NATIVE_MODULE 1`]
'type': 'EnumDeclarationWithMembers',
'memberType': 'NumberTypeAnnotation',
'members': [
{
'name': 'Corrupted',
'value': -1
},
{
'name': 'Low',
'value': 720
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboMo
export enum SomeEnum {
NUM = 1,
SUBFACTORIAL = !5,
STR = 'str',
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ export enum Quality {
}
export enum Resolution {
Corrupted = -1,
Low = 720,
High = 1080,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ exports[`RN Codegen TypeScript Parser can generate fixture CXX_ONLY_NATIVE_MODUL
'type': 'EnumDeclarationWithMembers',
'memberType': 'NumberTypeAnnotation',
'members': [
{
'name': 'Corrupted',
'value': -1
},
{
'name': 'Low',
'value': 720
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,11 @@ class TypeScriptParser implements Parser {

let enumMembersType: ?NativeModuleEnumMemberType = null;

if (!enumInitializerType) {
return 'StringTypeAnnotation';
}

switch (enumInitializerType) {
case undefined:
case 'StringLiteral':
enumMembersType = 'StringTypeAnnotation';
break;
Expand Down

0 comments on commit d38fffd

Please sign in to comment.