Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tired-ideas-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-docgen': patch
---

Do not fail when resolving inside ObjectMethod nodes
26 changes: 26 additions & 0 deletions packages/react-docgen/src/utils/__tests__/resolveToValue-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,30 @@ describe('resolveToValue', () => {
expect(resolveToValue(path)).toBe(path);
});
});

describe('ObjectMethod', () => {
test('does not throw', () => {
const def = parse.statement(
`const slice = createSlice({
example(state, action) {
state.images[action.payload.id] = action.payload.content;
},
});`,
);

// path to `action.payload.id`
const path = def
.get('declarations')[0]
.get('init')
.get('arguments')[0]
.get('properties')[0]
.get('body')
.get('body')[0]
.get('expression')
.get('left')
.get('property');

expect(() => resolveToValue(path)).not.toThrow();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function resolveName(path: NodePath): string | undefined {
path.isArrowFunctionExpression() ||
path.isTaggedTemplateExpression() ||
path.isCallExpression() ||
path.isObjectMethod() ||
isReactForwardRefCall(path)
) {
let currentPath: NodePath = path;
Expand Down