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
This commit is contained in:
Ramanpreet Nara
2020-09-29 14:39:37 -07:00
committed by Facebook GitHub Bot
parent 5142e99437
commit 1435d654d7
+12 -3
View File
@@ -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 (