Skip to content

Commit 116cfff

Browse files
committed
guard infinite loop against chained, static methods
* Add `isValidCalleeType()` check for CallExpresion and ArrayExpression and Literal * Fixes #136
1 parent e036dc2 commit 116cfff

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/__tests__/fixtures/component_2.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,11 @@ export class Button extends React.Component {
2121
};
2222
}
2323
}
24+
25+
export function foo() {
26+
return [].join();
27+
}
28+
29+
export function chained() {
30+
return foo.bar().join();
31+
}

src/utils/isStatelessComponent.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ const validPossibleStatelessComponentTypes = [
2727
'ArrowFunctionExpression',
2828
];
2929

30+
function isValidCalleeType(type) {
31+
return [
32+
'Identifier',
33+
'CallExpression',
34+
'ArrayExpression',
35+
'Literal'
36+
].indexOf(type) < 0;
37+
}
38+
3039
function isJSXElementOrReactCreateElement(path) {
3140
return (
3241
path.node.type === 'JSXElement' ||
@@ -92,7 +101,7 @@ function returnsJSXElementOrReactCreateElementCall(path) {
92101
resolvedValue = resolveToValue(calleeValue.get('object'));
93102
}
94103
else {
95-
while (calleeValue.get('object').node.type !== 'Identifier') {
104+
while (isValidCalleeType(calleeValue.get('object').node.type)) {
96105
calleeValue = calleeValue.get('object');
97106
namesToResolve.unshift(calleeValue.get('property'));
98107
}

0 commit comments

Comments
 (0)