Skip to content

Commit 193499b

Browse files
tchonfkling
authored andcommitted
guard infinite loop against chained, static methods
* Add `isValidCalleeType()` check for CallExpresion and ArrayExpression and Literal * Fixes #136
1 parent ab37d8b commit 193499b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/__tests__/fixtures/component_2.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,15 @@ 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+
}
32+
33+
export function templateLiteral() {
34+
return `foo bar`.split(' ');
35+
}

src/utils/isStatelessComponent.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ const validPossibleStatelessComponentTypes = [
2828
'ArrowFunctionExpression',
2929
];
3030

31+
function isValidCalleeType(type) {
32+
return [
33+
'Identifier',
34+
'CallExpression',
35+
'ArrayExpression',
36+
'TemplateLiteral',
37+
'Literal'
38+
].indexOf(type) < 0;
39+
}
40+
3141
function isJSXElementOrReactCreateElement(path) {
3242
return (
3343
path.node.type === 'JSXElement' ||
@@ -94,7 +104,7 @@ function returnsJSXElementOrReactCreateElementCall(path) {
94104
resolvedValue = resolveToValue(calleeValue.get('object'));
95105
}
96106
else {
97-
while (calleeValue.get('object').node.type !== 'Identifier') {
107+
while (isValidCalleeType(calleeValue.get('object').node.type)) {
98108
calleeValue = calleeValue.get('object');
99109
namesToResolve.unshift(calleeValue.get('property'));
100110
}

0 commit comments

Comments
 (0)