From 78db9a443a65bbe8ff202083351655e0cfa60004 Mon Sep 17 00:00:00 2001 From: Andrew Del Prete Date: Mon, 1 Jun 2020 20:10:21 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Error=20with=20flow=20opa?= =?UTF-8?q?que=20type=20and=20readme=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- __tests__/__snapshots__/test.js.snap | 179 ++++++++++++++++++ .../flow-exported-opaque-type.input.js | 4 + src/extractors/exported.js | 3 +- 3 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 __tests__/fixture/flow-exported-opaque-type.input.js diff --git a/__tests__/__snapshots__/test.js.snap b/__tests__/__snapshots__/test.js.snap index 0ad23c1b9..b026bacc1 100644 --- a/__tests__/__snapshots__/test.js.snap +++ b/__tests__/__snapshots__/test.js.snap @@ -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`] = ` +" + +### 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": "", + }, + 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 { diff --git a/__tests__/fixture/flow-exported-opaque-type.input.js b/__tests__/fixture/flow-exported-opaque-type.input.js new file mode 100644 index 000000000..9bcf2e647 --- /dev/null +++ b/__tests__/fixture/flow-exported-opaque-type.input.js @@ -0,0 +1,4 @@ +// @flow + +/** MyOpaqueType Description Here */ +export opaque type MyOpaqueType: string = string \ No newline at end of file diff --git a/src/extractors/exported.js b/src/extractors/exported.js index 9a11323af..bd0191026 100644 --- a/src/extractors/exported.js +++ b/src/extractors/exported.js @@ -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()) {