Skip to content

Commit 940ae38

Browse files
author
Aditya Vohra
committed
[WIP] Added post-processing step for documentation
1 parent f198733 commit 940ae38

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/__tests__/__snapshots__/main-test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Object {
3838
"computed": false,
3939
"value": "\\"primary\\"",
4040
},
41+
"required": false,
4142
},
4243
},
4344
}

src/parse.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
import Documentation from './Documentation';
14+
import postProcessDocumentation from './utils/postProcessDocumentation';
1415

1516
import babylon from './babylon';
1617
import recast from 'recast';
@@ -21,7 +22,7 @@ function executeHandlers(handlers, componentDefinitions) {
2122
return componentDefinitions.map(componentDefinition => {
2223
var documentation = new Documentation();
2324
handlers.forEach(handler => handler(documentation, componentDefinition));
24-
return documentation.toObject();
25+
return postProcessDocumentation(documentation.toObject());
2526
});
2627
}
2728

src/utils/postProcessDocumentation.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function postProcessProps(props) {
2+
// props with default values should not be required
3+
Object.keys(props).forEach(prop => {
4+
const propInfo = props[prop];
5+
6+
if (propInfo.defaultValue) {
7+
propInfo.required = false;
8+
}
9+
});
10+
}
11+
12+
export default function (documentation) {
13+
const props = documentation.props;
14+
15+
if (props) {
16+
postProcessProps(props);
17+
}
18+
19+
return documentation;
20+
};

0 commit comments

Comments
 (0)