From a495d7f65d69c0bfb30bdc1e4ef1fe30131df1b1 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Thu, 23 Mar 2017 16:10:07 -0500 Subject: [PATCH] Allow statics in flow interfaces (#427) --- src/plugins/flow.js | 8 +- .../interfaces-module-and-script/10/actual.js | 5 + .../10/expected.json | 239 ++++++++++++++++++ 3 files changed, 248 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/flow/interfaces-module-and-script/10/actual.js create mode 100644 test/fixtures/flow/interfaces-module-and-script/10/expected.json diff --git a/src/plugins/flow.js b/src/plugins/flow.js index 9592064400..fed1934731 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -69,7 +69,7 @@ pp.flowParseTypeAndPredicateInitialiser = function () { pp.flowParseDeclareClass = function (node) { this.next(); - this.flowParseInterfaceish(node, true); + this.flowParseInterfaceish(node); return this.finishNode(node, "DeclareClass"); }; @@ -194,7 +194,7 @@ pp.flowParseDeclareInterface = function (node) { // Interfaces -pp.flowParseInterfaceish = function (node, allowStatic) { +pp.flowParseInterfaceish = function (node) { node.id = this.parseIdentifier(); if (this.isRelational("<")) { @@ -219,7 +219,7 @@ pp.flowParseInterfaceish = function (node, allowStatic) { } while (this.eat(tt.comma)); } - node.body = this.flowParseObjectType(allowStatic); + node.body = this.flowParseObjectType(true); }; pp.flowParseInterfaceExtends = function () { @@ -236,7 +236,7 @@ pp.flowParseInterfaceExtends = function () { }; pp.flowParseInterface = function (node) { - this.flowParseInterfaceish(node, false); + this.flowParseInterfaceish(node); return this.finishNode(node, "InterfaceDeclaration"); }; diff --git a/test/fixtures/flow/interfaces-module-and-script/10/actual.js b/test/fixtures/flow/interfaces-module-and-script/10/actual.js new file mode 100644 index 0000000000..c12feec022 --- /dev/null +++ b/test/fixtures/flow/interfaces-module-and-script/10/actual.js @@ -0,0 +1,5 @@ +interface IFoo { + x: boolean; + static (): void; + static y: boolean; +} diff --git a/test/fixtures/flow/interfaces-module-and-script/10/expected.json b/test/fixtures/flow/interfaces-module-and-script/10/expected.json new file mode 100644 index 0000000000..ea68f99b99 --- /dev/null +++ b/test/fixtures/flow/interfaces-module-and-script/10/expected.json @@ -0,0 +1,239 @@ +{ + "type": "File", + "start": 0, + "end": 72, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 72, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "sourceType": "module", + "body": [ + { + "type": "InterfaceDeclaration", + "start": 0, + "end": 72, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "IFoo" + }, + "name": "IFoo" + }, + "typeParameters": null, + "extends": [], + "mixins": [], + "body": { + "type": "ObjectTypeAnnotation", + "start": 15, + "end": 72, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "callProperties": [ + { + "type": "ObjectTypeCallProperty", + "start": 33, + "end": 49, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "static": true, + "value": { + "type": "FunctionTypeAnnotation", + "start": 40, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "params": [], + "rest": null, + "typeParameters": null, + "returnType": { + "type": "VoidTypeAnnotation", + "start": 44, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 17 + } + } + } + } + } + ], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 19, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "key": { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "x" + }, + "name": "x" + }, + "value": { + "type": "BooleanTypeAnnotation", + "start": 22, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "optional": false, + "static": false, + "variance": null + }, + { + "type": "ObjectTypeProperty", + "start": 52, + "end": 70, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 20 + } + }, + "key": { + "type": "Identifier", + "start": 59, + "end": 60, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 10 + }, + "identifierName": "y" + }, + "name": "y" + }, + "value": { + "type": "BooleanTypeAnnotation", + "start": 62, + "end": 69, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 19 + } + } + }, + "optional": false, + "static": true, + "variance": null + } + ], + "indexers": [], + "exact": false + } + } + ], + "directives": [] + } +} \ No newline at end of file