Skip to content

Commit

Permalink
fix: πŸ› Error with flow opaque type and readme command
Browse files Browse the repository at this point in the history
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
  • Loading branch information
andrewdelprete authored and tmcw committed Jun 4, 2020
1 parent 35359ab commit 78db9a4
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 1 deletion.
179 changes: 179 additions & 0 deletions __tests__/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18930,6 +18930,185 @@ Object {
}
`;

exports[`outputs flow-exported-opaque-type.input.js JSON 1`] = `
Array [
Object {
"augments": Array [],
"context": Object {
"loc": Object {
"end": Object {
"column": 48,
"line": 4,
},
"start": Object {
"column": 0,
"line": 4,
},
},
},
"description": Object {
"children": Array [
Object {
"children": Array [
Object {
"position": Object {
"end": Object {
"column": 30,
"line": 1,
"offset": 29,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "text",
"value": "MyOpaqueType Description Here",
},
],
"position": Object {
"end": Object {
"column": 30,
"line": 1,
"offset": 29,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "paragraph",
},
],
"position": Object {
"end": Object {
"column": 30,
"line": 1,
"offset": 29,
},
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "root",
},
"errors": Array [],
"examples": Array [],
"implements": Array [],
"loc": Object {
"end": Object {
"column": 36,
"line": 3,
},
"start": Object {
"column": 0,
"line": 3,
},
},
"members": Object {
"events": Array [],
"global": Array [],
"inner": Array [],
"instance": Array [],
"static": Array [],
},
"name": "MyOpaqueType",
"namespace": "MyOpaqueType",
"params": Array [],
"path": Array [
Object {
"name": "MyOpaqueType",
},
],
"properties": Array [],
"returns": Array [],
"sees": Array [],
"tags": Array [],
"throws": Array [],
"todos": Array [],
"yields": Array [],
},
]
`;

exports[`outputs flow-exported-opaque-type.input.js markdown 1`] = `
"<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents

- [MyOpaqueType][1]

## MyOpaqueType

MyOpaqueType Description Here

[1]: #myopaquetype
"
`;

exports[`outputs flow-exported-opaque-type.input.js markdown AST 1`] = `
Object {
"children": Array [
Object {
"type": "html",
"value": "<!-- Generated by documentation.js. Update this documentation by updating the source code. -->",
},
Object {
"children": Array [
Object {
"type": "text",
"value": "MyOpaqueType",
},
],
"depth": 2,
"type": "heading",
},
Object {
"children": Array [
Object {
"position": Position {
"end": Object {
"column": 30,
"line": 1,
"offset": 29,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "text",
"value": "MyOpaqueType Description Here",
},
],
"position": Position {
"end": Object {
"column": 30,
"line": 1,
"offset": 29,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"type": "paragraph",
},
],
"type": "root",
}
`;

exports[`outputs flow-optional-chaining.input.js JSON 1`] = `
Array [
Object {
Expand Down
4 changes: 4 additions & 0 deletions __tests__/fixture/flow-exported-opaque-type.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @flow

/** MyOpaqueType Description Here */
export opaque type MyOpaqueType: string = string
3 changes: 2 additions & 1 deletion src/extractors/exported.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ function findExportDeclaration(
if (
declaration.isFunctionDeclaration() ||
declaration.isClassDeclaration() ||
declaration.isTypeAlias()
declaration.isTypeAlias() ||
declaration.isOpaqueType()
) {
bindingName = declaration.node.id.name;
} else if (declaration.isVariableDeclaration()) {
Expand Down

0 comments on commit 78db9a4

Please sign in to comment.