Skip to content

Commit 13d664f

Browse files
committed
Improve logic and add new tests
1 parent 9f272a3 commit 13d664f

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,27 @@ describe('findFunctionReturn', () => {
152152
expect(findFunctionReturn(def, predicate)).toBeUndefined();
153153
});
154154

155+
test('handles direct prop return', () => {
156+
const def = parse.statement(`
157+
function Foo ({ children }) {
158+
return children;
159+
}
160+
`);
161+
162+
expect(findFunctionReturn(def, predicate)).toBeDefined();
163+
});
164+
165+
test('handles null return', () => {
166+
const def = parse.statement(`
167+
function Foo (props) {
168+
return null;
169+
}
170+
`);
171+
172+
const received = findFunctionReturn(def, predicate);
173+
expect(received).toBeDefined();
174+
});
175+
155176
testReturnValues(
156177
'does not see ifs as separate block',
157178
`

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ function resolvesToFinalValue<T extends NodePath>(
9494
}
9595
}
9696

97-
return resolvedPath as T;
97+
if (resolvedPath.isObjectProperty()) {
98+
return resolvedPath as T;
99+
}
100+
101+
return;
98102
}
99103

100104
/**

0 commit comments

Comments
 (0)