Skip to content

Commit

Permalink
Merge explicit and inferred param defaults (#1230)
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett authored and tmcw committed Apr 18, 2019
1 parent 03e721f commit d1ee0f3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
15 changes: 15 additions & 0 deletions __tests__/lib/infer/__snapshots__/params.js.snap
Expand Up @@ -217,6 +217,21 @@ Array [
]
`;

exports[`inferParams 8`] = `
Array [
Object {
"default": "4",
"lineNumber": 1,
"name": "x",
"title": "param",
"type": Object {
"name": "number",
"type": "NameExpression",
},
},
]
`;

exports[`mergeTrees 1`] = `
Object {
"errors": Array [
Expand Down
11 changes: 11 additions & 0 deletions __tests__/lib/infer/params.js
Expand Up @@ -191,4 +191,15 @@ test('inferParams', function() {
}
`).params
).toEqual([]);

expect(
evaluate(
`
/** Test
* @param x
*/
function f(x: number = 4) {}
`
).params
).toMatchSnapshot();
});
4 changes: 3 additions & 1 deletion src/infer/params.js
Expand Up @@ -338,7 +338,9 @@ function combineTags(inferredTag, explicitTag) {
let defaultValue;
if (!explicitTag.type) {
type = inferredTag.type;
} else if (!explicitTag.default && inferredTag.default) {
}

if (!explicitTag.default && inferredTag.default) {
defaultValue = inferredTag.default;
}

Expand Down

0 comments on commit d1ee0f3

Please sign in to comment.