Skip to content

Commit 5f7d9d9

Browse files
committed
Fix endless loop by detecting end of MemberExpression chain
1 parent d36ff81 commit 5f7d9d9

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

src/__tests__/fixtures/component_2.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,11 @@ export function chained() {
3333
export function templateLiteral() {
3434
return `foo bar`.split(' ');
3535
}
36+
37+
export default function withThis() {
38+
return this.foo();
39+
}
40+
41+
export default function withNestedMemberExpressions() {
42+
return this.blub.blob.foo();
43+
}

src/utils/isStatelessComponent.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,6 @@ const validPossibleStatelessComponentTypes = [
2727
'ArrowFunctionExpression',
2828
];
2929

30-
function isValidCalleeType(type) {
31-
return [
32-
'Identifier',
33-
'CallExpression',
34-
'ArrayExpression',
35-
'TemplateLiteral',
36-
'Literal'
37-
].indexOf(type) < 0;
38-
}
39-
4030
function isJSXElementOrReactCreateElement(path) {
4131
return (
4232
path.node.type === 'JSXElement' ||
@@ -100,12 +90,11 @@ function returnsJSXElementOrReactCreateElementCall(path) {
10090
if (calleeValue.node.type === 'MemberExpression') {
10191
if (calleeValue.get('object').node.type === 'Identifier') {
10292
resolvedValue = resolveToValue(calleeValue.get('object'));
103-
}
104-
else {
105-
while (isValidCalleeType(calleeValue.get('object').node.type)) {
93+
} else if (types.MemberExpression.check(calleeValue.node)) {
94+
do {
10695
calleeValue = calleeValue.get('object');
10796
namesToResolve.unshift(calleeValue.get('property'));
108-
}
97+
} while (types.MemberExpression.check(calleeValue.node));
10998

11099
resolvedValue = resolveToValue(calleeValue.get('object'));
111100
}

0 commit comments

Comments
 (0)