Skip to content

Commit 18f387a

Browse files
committed
Refactor getReactElementDisplayName to switch statement
1 parent c64ddbb commit 18f387a

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/parser/parseReactElement.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ import type { TreeNode } from './../tree';
1313
const supportFragment = Boolean(Fragment);
1414

1515
const getReactElementDisplayName = ({ type }: ReactElement<*>): string => {
16-
if (type.displayName) {
17-
return type.displayName;
16+
switch (true) {
17+
case Boolean(type.displayName):
18+
return type.displayName;
19+
case typeof type === 'function':
20+
if (!type.name || type.name === '_default') {
21+
return 'No Display Name';
22+
}
23+
return type.name;
24+
default:
25+
return type;
1826
}
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;
2627
};
2728

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

0 commit comments

Comments
 (0)