Skip to content

Commit

Permalink
Don't output empty properties, reduce diff noise
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Apr 17, 2017
1 parent 03242f3 commit 1f99f9c
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 51 deletions.
20 changes: 13 additions & 7 deletions lib/infer/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,21 @@ function combineTags(inferredTag, explicitTag) {
defaultValue = inferredTag.default;
}

const hasProperties = (inferredTag.properties &&
inferredTag.properties.length) ||
(explicitTag.properties && explicitTag.properties.length);

return _.assign(
explicitTag,
{
properties: mergeNodes(
inferredTag.properties || [],
explicitTag.properties || []
),
type
},
hasProperties
? {
properties: mergeNodes(
inferredTag.properties || [],
explicitTag.properties || []
)
}
: {},
{ type },
defaultValue ? { default: defaultValue } : {}
);
}
Expand Down
3 changes: 1 addition & 2 deletions test/fixture/_multi-file-input.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@
"type": {
"type": "NameExpression",
"name": "Number"
},
"properties": []
}
}
],
"properties": [],
Expand Down
3 changes: 1 addition & 2 deletions test/fixture/class.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@
"type": {
"type": "NameExpression",
"name": "boolean"
},
"properties": []
}
}
],
"properties": [],
Expand Down
3 changes: 1 addition & 2 deletions test/fixture/es6-class.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,7 @@
"type": {
"type": "NameExpression",
"name": "string"
},
"properties": []
}
}
],
"properties": [],
Expand Down
9 changes: 3 additions & 6 deletions test/fixture/es6.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,7 @@
"name": "Number"
}
]
},
"properties": []
}
},
{
"title": "param",
Expand Down Expand Up @@ -1085,8 +1084,7 @@
"type": {
"type": "NameExpression",
"name": "number"
},
"properties": []
}
},
{
"title": "param",
Expand Down Expand Up @@ -1147,8 +1145,7 @@
"type": {
"type": "NameExpression",
"name": "number"
},
"properties": []
}
}
],
"properties": [],
Expand Down
6 changes: 2 additions & 4 deletions test/fixture/inline-link.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@
"type": {
"type": "NameExpression",
"name": "number"
},
"properties": []
}
}
],
"properties": [],
Expand Down Expand Up @@ -582,8 +581,7 @@
"type": {
"type": "NameExpression",
"name": "number"
},
"properties": []
}
}
],
"properties": [],
Expand Down
6 changes: 2 additions & 4 deletions test/fixture/lends.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@
"type": {
"type": "NameExpression",
"name": "string"
},
"properties": []
}
}
],
"properties": [],
Expand Down Expand Up @@ -524,8 +523,7 @@
"type": {
"type": "NameExpression",
"name": "string"
},
"properties": []
}
}
],
"properties": [],
Expand Down
3 changes: 1 addition & 2 deletions test/fixture/literal_types.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@
"value": 3.14
}
]
},
"properties": []
}
}
],
"properties": [],
Expand Down
3 changes: 1 addition & 2 deletions test/fixture/memberedclass.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,7 @@
"type": {
"type": "NameExpression",
"name": "boolean"
},
"properties": []
}
}
],
"properties": [],
Expand Down
1 change: 0 additions & 1 deletion test/fixture/merge-infered-type.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@
}
}
},
"properties": [],
"type": {
"type": "NameExpression",
"name": "number"
Expand Down
3 changes: 1 addition & 2 deletions test/fixture/multisignature.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,7 @@
"type": {
"type": "NameExpression",
"name": "Date"
},
"properties": []
}
}
],
"properties": [],
Expand Down
3 changes: 1 addition & 2 deletions test/fixture/nest_params.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,7 @@
"name": "string"
}
},
"default": "minion",
"properties": []
"default": "minion"
}
],
"properties": [],
Expand Down
17 changes: 5 additions & 12 deletions test/fixture/params.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@
"type": {
"type": "NameExpression",
"name": "number"
},
"properties": []
}
},
{
"title": "param",
Expand Down Expand Up @@ -380,8 +379,7 @@
"type": {
"type": "NameExpression",
"name": "String"
},
"properties": []
}
},
{
"title": "param",
Expand Down Expand Up @@ -515,7 +513,6 @@
"name": "number"
}
},
"properties": [],
"default": "2"
}
],
Expand Down Expand Up @@ -782,8 +779,7 @@
"type": {
"type": "NameExpression",
"name": "number"
},
"properties": []
}
}
],
"properties": [],
Expand Down Expand Up @@ -2223,7 +2219,6 @@
"name": "number"
}
},
"properties": [],
"default": "123"
}
],
Expand Down Expand Up @@ -2456,8 +2451,7 @@
"offset": 22
}
}
},
"properties": []
}
}
],
"properties": [],
Expand Down Expand Up @@ -2699,8 +2693,7 @@
"type": {
"type": "NameExpression",
"name": "any"
},
"properties": []
}
},
{
"title": "param",
Expand Down
3 changes: 1 addition & 2 deletions test/fixture/simple-two.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@
"type": {
"type": "NameExpression",
"name": "Number"
},
"properties": []
}
}
],
"properties": [],
Expand Down
1 change: 0 additions & 1 deletion test/lib/infer/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ test('inferParams', function(t) {
name: 'x',
title: 'param',
lineNumber: 1,
properties: [],
type: {
expression: {
type: 'NameExpression',
Expand Down

0 comments on commit 1f99f9c

Please sign in to comment.