Skip to content

Commit d1ee0f3

Browse files
devongovetttmcw
authored andcommitted
Merge explicit and inferred param defaults (#1230)
1 parent 03e721f commit d1ee0f3

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

__tests__/lib/infer/__snapshots__/params.js.snap

+15
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,21 @@ Array [
217217
]
218218
`;
219219

220+
exports[`inferParams 8`] = `
221+
Array [
222+
Object {
223+
"default": "4",
224+
"lineNumber": 1,
225+
"name": "x",
226+
"title": "param",
227+
"type": Object {
228+
"name": "number",
229+
"type": "NameExpression",
230+
},
231+
},
232+
]
233+
`;
234+
220235
exports[`mergeTrees 1`] = `
221236
Object {
222237
"errors": Array [

__tests__/lib/infer/params.js

+11
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,15 @@ test('inferParams', function() {
191191
}
192192
`).params
193193
).toEqual([]);
194+
195+
expect(
196+
evaluate(
197+
`
198+
/** Test
199+
* @param x
200+
*/
201+
function f(x: number = 4) {}
202+
`
203+
).params
204+
).toMatchSnapshot();
194205
});

src/infer/params.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,9 @@ function combineTags(inferredTag, explicitTag) {
338338
let defaultValue;
339339
if (!explicitTag.type) {
340340
type = inferredTag.type;
341-
} else if (!explicitTag.default && inferredTag.default) {
341+
}
342+
343+
if (!explicitTag.default && inferredTag.default) {
342344
defaultValue = inferredTag.default;
343345
}
344346

0 commit comments

Comments
 (0)