Skip to content

Commit 78db9a4

Browse files
andrewdelpretetmcw
authored andcommittedJun 4, 2020
fix: 🐛 Error with flow opaque type and readme command
When exporting an opaque Flow type and importing it into an entry file for documentation to consume, the CLI throws an error when using the readme command. ✅ Closes: #1322
1 parent 35359ab commit 78db9a4

File tree

3 files changed

+185
-1
lines changed

3 files changed

+185
-1
lines changed
 

‎__tests__/__snapshots__/test.js.snap

+179
Original file line numberDiff line numberDiff line change
@@ -18930,6 +18930,185 @@ Object {
1893018930
}
1893118931
`;
1893218932

18933+
exports[`outputs flow-exported-opaque-type.input.js JSON 1`] = `
18934+
Array [
18935+
Object {
18936+
"augments": Array [],
18937+
"context": Object {
18938+
"loc": Object {
18939+
"end": Object {
18940+
"column": 48,
18941+
"line": 4,
18942+
},
18943+
"start": Object {
18944+
"column": 0,
18945+
"line": 4,
18946+
},
18947+
},
18948+
},
18949+
"description": Object {
18950+
"children": Array [
18951+
Object {
18952+
"children": Array [
18953+
Object {
18954+
"position": Object {
18955+
"end": Object {
18956+
"column": 30,
18957+
"line": 1,
18958+
"offset": 29,
18959+
},
18960+
"indent": Array [],
18961+
"start": Object {
18962+
"column": 1,
18963+
"line": 1,
18964+
"offset": 0,
18965+
},
18966+
},
18967+
"type": "text",
18968+
"value": "MyOpaqueType Description Here",
18969+
},
18970+
],
18971+
"position": Object {
18972+
"end": Object {
18973+
"column": 30,
18974+
"line": 1,
18975+
"offset": 29,
18976+
},
18977+
"indent": Array [],
18978+
"start": Object {
18979+
"column": 1,
18980+
"line": 1,
18981+
"offset": 0,
18982+
},
18983+
},
18984+
"type": "paragraph",
18985+
},
18986+
],
18987+
"position": Object {
18988+
"end": Object {
18989+
"column": 30,
18990+
"line": 1,
18991+
"offset": 29,
18992+
},
18993+
"start": Object {
18994+
"column": 1,
18995+
"line": 1,
18996+
"offset": 0,
18997+
},
18998+
},
18999+
"type": "root",
19000+
},
19001+
"errors": Array [],
19002+
"examples": Array [],
19003+
"implements": Array [],
19004+
"loc": Object {
19005+
"end": Object {
19006+
"column": 36,
19007+
"line": 3,
19008+
},
19009+
"start": Object {
19010+
"column": 0,
19011+
"line": 3,
19012+
},
19013+
},
19014+
"members": Object {
19015+
"events": Array [],
19016+
"global": Array [],
19017+
"inner": Array [],
19018+
"instance": Array [],
19019+
"static": Array [],
19020+
},
19021+
"name": "MyOpaqueType",
19022+
"namespace": "MyOpaqueType",
19023+
"params": Array [],
19024+
"path": Array [
19025+
Object {
19026+
"name": "MyOpaqueType",
19027+
},
19028+
],
19029+
"properties": Array [],
19030+
"returns": Array [],
19031+
"sees": Array [],
19032+
"tags": Array [],
19033+
"throws": Array [],
19034+
"todos": Array [],
19035+
"yields": Array [],
19036+
},
19037+
]
19038+
`;
19039+
19040+
exports[`outputs flow-exported-opaque-type.input.js markdown 1`] = `
19041+
"<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
19042+
19043+
### Table of Contents
19044+
19045+
- [MyOpaqueType][1]
19046+
19047+
## MyOpaqueType
19048+
19049+
MyOpaqueType Description Here
19050+
19051+
[1]: #myopaquetype
19052+
"
19053+
`;
19054+
19055+
exports[`outputs flow-exported-opaque-type.input.js markdown AST 1`] = `
19056+
Object {
19057+
"children": Array [
19058+
Object {
19059+
"type": "html",
19060+
"value": "<!-- Generated by documentation.js. Update this documentation by updating the source code. -->",
19061+
},
19062+
Object {
19063+
"children": Array [
19064+
Object {
19065+
"type": "text",
19066+
"value": "MyOpaqueType",
19067+
},
19068+
],
19069+
"depth": 2,
19070+
"type": "heading",
19071+
},
19072+
Object {
19073+
"children": Array [
19074+
Object {
19075+
"position": Position {
19076+
"end": Object {
19077+
"column": 30,
19078+
"line": 1,
19079+
"offset": 29,
19080+
},
19081+
"indent": Array [],
19082+
"start": Object {
19083+
"column": 1,
19084+
"line": 1,
19085+
"offset": 0,
19086+
},
19087+
},
19088+
"type": "text",
19089+
"value": "MyOpaqueType Description Here",
19090+
},
19091+
],
19092+
"position": Position {
19093+
"end": Object {
19094+
"column": 30,
19095+
"line": 1,
19096+
"offset": 29,
19097+
},
19098+
"indent": Array [],
19099+
"start": Object {
19100+
"column": 1,
19101+
"line": 1,
19102+
"offset": 0,
19103+
},
19104+
},
19105+
"type": "paragraph",
19106+
},
19107+
],
19108+
"type": "root",
19109+
}
19110+
`;
19111+
1893319112
exports[`outputs flow-optional-chaining.input.js JSON 1`] = `
1893419113
Array [
1893519114
Object {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @flow
2+
3+
/** MyOpaqueType Description Here */
4+
export opaque type MyOpaqueType: string = string

‎src/extractors/exported.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ function findExportDeclaration(
224224
if (
225225
declaration.isFunctionDeclaration() ||
226226
declaration.isClassDeclaration() ||
227-
declaration.isTypeAlias()
227+
declaration.isTypeAlias() ||
228+
declaration.isOpaqueType()
228229
) {
229230
bindingName = declaration.node.id.name;
230231
} else if (declaration.isVariableDeclaration()) {

0 commit comments

Comments
 (0)
Please sign in to comment.