Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit beced3b

Browse files
committed
fix: handle named export specifiers
fixes #368
1 parent 22eba90 commit beced3b

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

Diff for: src/typings.ts

+3
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,9 @@ function getComponentExportType(ast: AstQuery, componentName: string): dom.Decla
442442
// VariableDeclaration
443443
/ VariableDeclarator
444444
/:id Identifier[@name == '${componentName}']
445+
||
446+
// ExportSpecifier
447+
/:exported Identifier[@name == '${componentName}']
445448
]
446449
`);
447450
if (res.length > 0) {

Diff for: tests/named-export-specifiers.d.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
declare module 'component' {
2+
export interface ComponentProps {
3+
optionalAny?: any;
4+
}
5+
6+
export function Component(props: ComponentProps): JSX.Element;
7+
8+
export function Component2(): JSX.Element;
9+
}

Diff for: tests/named-export-specifiers.jsx

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as React from 'react';
2+
3+
const Component = ({optionalAny}) => <div />;
4+
Component.propTypes = {
5+
optionalAny: React.PropTypes.any,
6+
};
7+
8+
const Component2 = () => <div />;
9+
10+
export { Component, Component2 };

Diff for: tests/parsing-test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ test('Parsing should create definition from file with references in propTypes',
8787
test('Parsing should create definition from file with unnamed default export', t => {
8888
compare(t, 'path', 'unnamed-default-export.jsx', 'unnamed-default-export.d.ts');
8989
});
90+
test('Parsing should create definition from file with named export specifiers', t => {
91+
compare(t, 'component', 'named-export-specifiers.jsx', 'named-export-specifiers.d.ts');
92+
});
9093
test('Parsing should create preact definition', t => {
9194
compare(t, 'path', 'preact-definition.jsx', 'preact-definition.d.ts', {}, 'preact');
9295
});

0 commit comments

Comments
 (0)