From 1435d654d787ef312f24abcd24f1cf6b2dbf03d7 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Tue, 29 Sep 2020 14:33:06 -0700 Subject: [PATCH] Restructure getTypes function Summary: There are two types of types we care about: - Type aliases - Interface Declarations These types can be exported. I think we should build the types dictionary from only those types. Everything else should be ignored. Changelog: [Internal] Reviewed By: fkgozali Differential Revision: D23120241 fbshipit-source-id: 9f023081d0f9c85b45407b180ae7c3e7391eb725 --- .../src/parsers/flow/index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/react-native-codegen/src/parsers/flow/index.js b/packages/react-native-codegen/src/parsers/flow/index.js index 4de02b00943..47342b8d87f 100644 --- a/packages/react-native-codegen/src/parsers/flow/index.js +++ b/packages/react-native-codegen/src/parsers/flow/index.js @@ -20,10 +20,19 @@ const {buildComponentSchema} = require('./components/schema'); const {processComponent} = require('./components'); const {processModule} = require('./modules'); -function getTypes(ast) { +/** + * This FlowFixMe is supposed to refer to an InterfaceDeclaration or TypeAlias + * declaration type. Unfortunately, we don't have those types, because flow-parser + * generates them, and flow-parser is not type-safe. In the future, we should find + * a way to get these types from our flow parser library. + */ +function getTypes(ast): {[declarationName: string]: $FlowFixMe} { return ast.body.reduce((types, node) => { - if (node.type === 'ExportNamedDeclaration') { - if (node.declaration && node.declaration.type !== 'VariableDeclaration') { + if (node.type === 'ExportNamedDeclaration' && node.exportKind === 'type') { + if ( + node.declaration.type === 'TypeAlias' || + node.declaration.type === 'InterfaceDeclaration' + ) { types[node.declaration.id.name] = node.declaration; } } else if (