Skip to content

Commit c64ddbb

Browse files
committed
Unwind getReactElementDisplayName to a cascade of if statements
1 parent 6f44721 commit c64ddbb

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/parser/parseReactElement.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ import type { TreeNode } from './../tree';
1212

1313
const supportFragment = Boolean(Fragment);
1414

15-
const getReactElementDisplayName = (element: ReactElement<*>): string =>
16-
element.type.displayName ||
17-
(element.type.name !== '_default' ? element.type.name : null) || // function name
18-
(typeof element.type === 'function' // function without a name, you should provide one
19-
? 'No Display Name'
20-
: element.type);
15+
const getReactElementDisplayName = ({ type }: ReactElement<*>): string => {
16+
if (type.displayName) {
17+
return type.displayName;
18+
}
19+
if (type.name && type.name !== '_default') {
20+
return type.name;
21+
}
22+
if (typeof type === 'function') {
23+
return 'No Display Name';
24+
}
25+
return type;
26+
};
2127

2228
const noChildren = (propsValue, propName) => propName !== 'children';
2329

0 commit comments

Comments
 (0)