Skip to content

Commit 363a108

Browse files
authored
fix(extractors): Document export default value (#623)
With `--document-exported` we used to only support ```js export default Declaration ``` and ```js export default IdentifierExpression ``` With this change we generate a comment for all default exports. Fixes #543
1 parent 381ef48 commit 363a108

9 files changed

+185
-4
lines changed

lib/extractors/exported.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,14 @@ function walkExported(ast, data, addComment) {
6666
}
6767

6868
if (path.isExportDefaultDeclaration()) {
69-
if (declaration.isDeclaration()) {
70-
traverseExportedSubtree(declaration, data, addComments);
71-
return path.skip();
72-
}
7369
if (declaration.isIdentifier()) {
7470
var binding = declaration.scope.getBinding(declaration.node.name);
7571
traverseExportedSubtree(binding.path, data, addComments);
7672
return path.skip();
7773
}
74+
75+
traverseExportedSubtree(declaration, data, addComments);
76+
return path.skip();
7877
}
7978

8079
if (t.isExportNamedDeclaration(path)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Options: {"documentExported": true}
2+
3+
export default {
4+
x: 42,
5+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
[
2+
{
3+
"description": "",
4+
"tags": [],
5+
"loc": {
6+
"start": {
7+
"line": 3,
8+
"column": 0
9+
},
10+
"end": {
11+
"line": 5,
12+
"column": 2
13+
}
14+
},
15+
"context": {
16+
"loc": {
17+
"start": {
18+
"line": 3,
19+
"column": 0
20+
},
21+
"end": {
22+
"line": 5,
23+
"column": 2
24+
}
25+
}
26+
},
27+
"errors": [],
28+
"name": "document-exported-export-default-object.input",
29+
"members": {
30+
"instance": [],
31+
"static": []
32+
},
33+
"path": [
34+
{
35+
"name": "document-exported-export-default-object.input"
36+
}
37+
],
38+
"namespace": "document-exported-export-default-object.input"
39+
},
40+
{
41+
"description": "",
42+
"tags": [],
43+
"loc": {
44+
"start": {
45+
"line": 4,
46+
"column": 2
47+
},
48+
"end": {
49+
"line": 4,
50+
"column": 7
51+
}
52+
},
53+
"context": {
54+
"loc": {
55+
"start": {
56+
"line": 4,
57+
"column": 2
58+
},
59+
"end": {
60+
"line": 4,
61+
"column": 7
62+
}
63+
}
64+
},
65+
"errors": [],
66+
"name": "x",
67+
"members": {
68+
"instance": [],
69+
"static": []
70+
},
71+
"path": [
72+
{
73+
"name": "x"
74+
}
75+
],
76+
"namespace": "x"
77+
}
78+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
2+
3+
# document-exported-export-default-object.input
4+
5+
# x
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"type": "root",
3+
"children": [
4+
{
5+
"type": "html",
6+
"value": "<!-- Generated by documentation.js. Update this documentation by updating the source code. -->"
7+
},
8+
{
9+
"depth": 1,
10+
"type": "heading",
11+
"children": [
12+
{
13+
"type": "text",
14+
"value": "document-exported-export-default-object.input"
15+
}
16+
]
17+
},
18+
{
19+
"depth": 1,
20+
"type": "heading",
21+
"children": [
22+
{
23+
"type": "text",
24+
"value": "x"
25+
}
26+
]
27+
}
28+
]
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Options: {"documentExported": true}
2+
3+
export default 42;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[
2+
{
3+
"description": "",
4+
"tags": [],
5+
"loc": {
6+
"start": {
7+
"line": 3,
8+
"column": 0
9+
},
10+
"end": {
11+
"line": 3,
12+
"column": 18
13+
}
14+
},
15+
"context": {
16+
"loc": {
17+
"start": {
18+
"line": 3,
19+
"column": 0
20+
},
21+
"end": {
22+
"line": 3,
23+
"column": 18
24+
}
25+
}
26+
},
27+
"errors": [],
28+
"name": "document-exported-export-default-value.input",
29+
"members": {
30+
"instance": [],
31+
"static": []
32+
},
33+
"path": [
34+
{
35+
"name": "document-exported-export-default-value.input"
36+
}
37+
],
38+
"namespace": "document-exported-export-default-value.input"
39+
}
40+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
2+
3+
# document-exported-export-default-value.input
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"type": "root",
3+
"children": [
4+
{
5+
"type": "html",
6+
"value": "<!-- Generated by documentation.js. Update this documentation by updating the source code. -->"
7+
},
8+
{
9+
"depth": 1,
10+
"type": "heading",
11+
"children": [
12+
{
13+
"type": "text",
14+
"value": "document-exported-export-default-value.input"
15+
}
16+
]
17+
}
18+
]
19+
}

0 commit comments

Comments
 (0)