From b9a03ce197865ec333c3dccfc7a4dcf1206b9064 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 3 Oct 2022 04:15:04 -0700 Subject: [PATCH] Fix crash when exporting type of existing variable Summary: When using flow syntax like this, the parser would throw an error. ``` const foo = new ClassInstance(); export type {foo}; ``` Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D39850098 fbshipit-source-id: 28a7748892559c2c4a0fb8afa8612cbeb5568058 --- packages/react-native-codegen/src/parsers/flow/utils.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/react-native-codegen/src/parsers/flow/utils.js b/packages/react-native-codegen/src/parsers/flow/utils.js index c337570c060..e2ca547678a 100644 --- a/packages/react-native-codegen/src/parsers/flow/utils.js +++ b/packages/react-native-codegen/src/parsers/flow/utils.js @@ -26,8 +26,9 @@ function getTypes(ast: $FlowFixMe): TypeDeclarationMap { return ast.body.reduce((types, node) => { if (node.type === 'ExportNamedDeclaration' && node.exportKind === 'type') { if ( - node.declaration.type === 'TypeAlias' || - node.declaration.type === 'InterfaceDeclaration' + node.declaration != null && + (node.declaration.type === 'TypeAlias' || + node.declaration.type === 'InterfaceDeclaration') ) { types[node.declaration.id.name] = node.declaration; }