Skip to content

Commit 06c2fae

Browse files
authored
Only check identifiers in getMemberExpressionValuePath (#993)
1 parent e01cbcb commit 06c2fae

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

.changeset/late-numbers-raise.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'react-docgen': patch
3+
---
4+
5+
Fixed crash when classes with private fields are used

packages/react-docgen/src/utils/__tests__/getMemberExpressionValuePath-test.ts

+21
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@ describe('getMemberExpressionValuePath', () => {
1515
);
1616
});
1717

18+
test('ignores unrelated private field', () => {
19+
const def = parse.statement(
20+
`
21+
class Foo {
22+
#isprivate = {};
23+
24+
classMethod() {
25+
this.#isprivate = {};
26+
}
27+
}
28+
const Boo = () => {};
29+
Boo.propTypes = {};
30+
`,
31+
1,
32+
);
33+
34+
expect(getMemberExpressionValuePath(def, 'propTypes')).toBe(
35+
def.parentPath.get('body')[2].get('expression').get('right'),
36+
);
37+
});
38+
1839
test('takes the correct property definitions', () => {
1940
const def = parse.statement(`
2041
var Foo = () => {};

packages/react-docgen/src/utils/getMemberExpressionValuePath.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const explodedVisitors = visitors.explode<TraverseState>({
8787
const property = memberPath.get('property');
8888

8989
if (
90-
(!memberPath.node.computed ||
90+
((!memberPath.node.computed && property.isIdentifier()) ||
9191
property.isStringLiteral() ||
9292
property.isNumericLiteral()) &&
9393
getNameOrValue(property) === state.memberName &&

0 commit comments

Comments
 (0)