diff --git a/src/plugins/flow.js b/src/plugins/flow.js index 6a72187df1..117ad2e5d5 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -687,7 +687,9 @@ export default function (instance) { // export type instance.extend("shouldParseExportDeclaration", function (inner) { return function () { - return this.isContextual("type") || inner.call(this); + return this.isContextual("type") + || this.isContextual("interface") + || inner.call(this); }; }); @@ -745,6 +747,11 @@ export default function (instance) { // export type Foo = Bar; return this.flowParseTypeAlias(declarationNode); } + } else if (this.isContextual("interface")) { + node.exportKind = "type"; + let declarationNode = this.startNode(); + this.next(); + return this.flowParseInterface(declarationNode); } else { return inner.call(this, node); } diff --git a/test/fixtures/flow/type-exports/interface/actual.js b/test/fixtures/flow/type-exports/interface/actual.js new file mode 100644 index 0000000000..b3512f17ab --- /dev/null +++ b/test/fixtures/flow/type-exports/interface/actual.js @@ -0,0 +1,2 @@ +export interface foo { p: number }; +export interface foo { p: T }; diff --git a/test/fixtures/flow/type-exports/interface/expected.json b/test/fixtures/flow/type-exports/interface/expected.json new file mode 100644 index 0000000000..6e0eca1d53 --- /dev/null +++ b/test/fixtures/flow/type-exports/interface/expected.json @@ -0,0 +1,349 @@ +{ + "type": "File", + "start": 0, + "end": 69, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 69, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "specifiers": [], + "source": null, + "exportKind": "type", + "declaration": { + "type": "InterfaceDeclaration", + "start": 7, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "name": "foo" + }, + "typeParameters": null, + "extends": [], + "mixins": [], + "body": { + "type": "ObjectTypeAnnotation", + "start": 21, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 23, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "key": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "name": "p" + }, + "value": { + "type": "NumberTypeAnnotation", + "start": 26, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 32 + } + } + }, + "optional": false + } + ], + "indexers": [] + } + } + }, + { + "type": "EmptyStatement", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 35 + } + } + }, + { + "type": "ExportNamedDeclaration", + "start": 36, + "end": 68, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "specifiers": [], + "source": null, + "exportKind": "type", + "declaration": { + "type": "InterfaceDeclaration", + "start": 43, + "end": 68, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "id": { + "type": "Identifier", + "start": 53, + "end": 56, + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "name": "foo" + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 56, + "end": 59, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "params": [ + { + "type": "Identifier", + "start": 57, + "end": 58, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "name": "T" + } + ] + }, + "extends": [], + "mixins": [], + "body": { + "type": "ObjectTypeAnnotation", + "start": 60, + "end": 68, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 62, + "end": 66, + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "key": { + "type": "Identifier", + "start": 62, + "end": 63, + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "name": "p" + }, + "value": { + "type": "GenericTypeAnnotation", + "start": 65, + "end": 66, + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 65, + "end": 66, + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "name": "T" + } + }, + "optional": false + } + ], + "indexers": [] + } + } + }, + { + "type": "EmptyStatement", + "start": 68, + "end": 69, + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 2, + "column": 33 + } + } + } + ], + "directives": [] + } +}