Skip to content

Commit b5df52d

Browse files
TypeScript Parser Changes (facebook#54598)
Summary: TypeScript Parser changes to accomodate new emitUnion Changelog: [Internal] Differential Revision: D87412635
1 parent 3cd11c2 commit b5df52d

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

packages/react-native-codegen/src/parsers/typescript/components/events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function extractArrayElementType(
127127
};
128128
case 'TSUnionType':
129129
return {
130-
type: 'StringLiteralUnionTypeAnnotation',
130+
type: 'UnionTypeAnnotation',
131131
types: typeAnnotation.types.map(option => ({
132132
type: 'StringLiteralTypeAnnotation',
133133
value: parser.getLiteralValue(option),

packages/react-native-codegen/src/parsers/typescript/modules/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,18 @@ function translateTypeAnnotation(
398398
);
399399
}
400400
case 'TSUnionType': {
401-
return emitUnion(nullable, hasteModuleName, typeAnnotation, parser);
401+
return emitUnion(
402+
nullable,
403+
hasteModuleName,
404+
typeAnnotation,
405+
types,
406+
aliasMap,
407+
enumMap,
408+
tryParse,
409+
cxxOnly,
410+
translateTypeAnnotation,
411+
parser,
412+
);
402413
}
403414
case 'TSLiteralType': {
404415
const literal = typeAnnotation.literal;

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import type {
1818
NativeModuleEnumMember,
1919
NativeModuleEnumMemberType,
2020
NativeModuleParamTypeAnnotation,
21+
NativeModuleUnionTypeAnnotationMemberType,
2122
Nullable,
2223
PropTypeAnnotation,
2324
SchemaType,
24-
UnionTypeAnnotationMemberType,
2525
} from '../../CodegenSchema';
2626
import type {ParserType} from '../errors';
2727
import type {
@@ -109,7 +109,7 @@ class TypeScriptParser implements Parser {
109109

110110
remapUnionTypeAnnotationMemberNames(
111111
membersTypes: Array<$FlowFixMe>,
112-
): Array<UnionTypeAnnotationMemberType> {
112+
): Array<NativeModuleUnionTypeAnnotationMemberType> {
113113
const remapLiteral = (item: $FlowFixMe) => {
114114
return item.literal
115115
? item.literal.type
@@ -123,12 +123,6 @@ class TypeScriptParser implements Parser {
123123
return [...new Set(membersTypes.map(remapLiteral))];
124124
}
125125

126-
getStringLiteralUnionTypeAnnotationStringLiterals(
127-
membersTypes: Array<$FlowFixMe>,
128-
): Array<string> {
129-
return membersTypes.map((item: $FlowFixMe) => item.literal.value);
130-
}
131-
132126
parseFile(filename: string): SchemaType {
133127
const contents = fs.readFileSync(filename, 'utf8');
134128

0 commit comments

Comments
 (0)