diff --git a/src/plugins/flow.js b/src/plugins/flow.js index d3332907bf..6a72187df1 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -60,6 +60,8 @@ pp.flowParseDeclare = function (node) { return this.flowParseDeclareModule(node); } else if (this.isContextual("type")) { return this.flowParseDeclareTypeAlias(node); + } else if (this.isContextual("interface")) { + return this.flowParseDeclareInterface(node); } else { this.unexpected(); } @@ -104,6 +106,12 @@ pp.flowParseDeclareTypeAlias = function (node) { return this.finishNode(node, "DeclareTypeAlias"); }; +pp.flowParseDeclareInterface = function (node) { + this.next(); + this.flowParseInterfaceish(node); + return this.finishNode(node, "DeclareInterface"); +} + // Interfaces diff --git a/test/fixtures/flow/declare-statements/15/actual.js b/test/fixtures/flow/declare-statements/15/actual.js new file mode 100644 index 0000000000..e5d2353e55 --- /dev/null +++ b/test/fixtures/flow/declare-statements/15/actual.js @@ -0,0 +1,2 @@ +declare interface I { foo: string } +declare interface I { foo: T } diff --git a/test/fixtures/flow/declare-statements/15/expected.json b/test/fixtures/flow/declare-statements/15/expected.json new file mode 100644 index 0000000000..d888583822 --- /dev/null +++ b/test/fixtures/flow/declare-statements/15/expected.json @@ -0,0 +1,283 @@ +{ + "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": "DeclareInterface", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "id": { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "name": "I" + }, + "typeParameters": null, + "extends": [], + "mixins": [], + "body": { + "type": "ObjectTypeAnnotation", + "start": 20, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 22, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "key": { + "type": "Identifier", + "start": 22, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "name": "foo" + }, + "value": { + "type": "StringTypeAnnotation", + "start": 27, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 33 + } + } + }, + "optional": false + } + ], + "indexers": [] + } + }, + { + "type": "DeclareInterface", + "start": 36, + "end": 69, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "id": { + "type": "Identifier", + "start": 54, + "end": 55, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "name": "I" + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 55, + "end": 58, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "params": [ + { + "type": "Identifier", + "start": 56, + "end": 57, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "name": "T" + } + ] + }, + "extends": [], + "mixins": [], + "body": { + "type": "ObjectTypeAnnotation", + "start": 59, + "end": 69, + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 61, + "end": 67, + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "key": { + "type": "Identifier", + "start": 61, + "end": 64, + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "name": "foo" + }, + "value": { + "type": "GenericTypeAnnotation", + "start": 66, + "end": 67, + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 66, + "end": 67, + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "name": "T" + } + }, + "optional": false + } + ], + "indexers": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file