From 137abcaf7a43bc46417a79c8ab40e49aa45e4add Mon Sep 17 00:00:00 2001 From: Sam Goldman Date: Wed, 23 Dec 2015 16:09:12 -0500 Subject: [PATCH] Add support for mixins to Babel 6.x --- src/plugins/flow.js | 8 + .../flow/declare-statements/13/actual.js | 1 + .../flow/declare-statements/13/expected.json | 199 ++++++++++++++++++ 3 files changed, 208 insertions(+) create mode 100644 test/fixtures/flow/declare-statements/13/actual.js create mode 100644 test/fixtures/flow/declare-statements/13/expected.json diff --git a/src/plugins/flow.js b/src/plugins/flow.js index a0f32f550c..f25595058e 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -109,6 +109,7 @@ pp.flowParseInterfaceish = function (node, allowStatic) { } node.extends = []; + node.mixins = []; if (this.eat(tt._extends)) { do { @@ -116,6 +117,13 @@ pp.flowParseInterfaceish = function (node, allowStatic) { } while (this.eat(tt.comma)); } + if (this.isContextual("mixins")) { + this.next(); + do { + node.mixins.push(this.flowParseInterfaceExtends()); + } while (this.eat(tt.comma)); + } + node.body = this.flowParseObjectType(allowStatic); }; diff --git a/test/fixtures/flow/declare-statements/13/actual.js b/test/fixtures/flow/declare-statements/13/actual.js new file mode 100644 index 0000000000..c397cf82f9 --- /dev/null +++ b/test/fixtures/flow/declare-statements/13/actual.js @@ -0,0 +1 @@ +declare class A mixins B, C {} diff --git a/test/fixtures/flow/declare-statements/13/expected.json b/test/fixtures/flow/declare-statements/13/expected.json new file mode 100644 index 0000000000..28eabe6252 --- /dev/null +++ b/test/fixtures/flow/declare-statements/13/expected.json @@ -0,0 +1,199 @@ +{ + "type": "File", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "sourceType": "module", + "body": [ + { + "type": "DeclareClass", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "id": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "name": "A" + }, + "typeParameters": null, + "extends": [], + "mixins": [ + { + "type": "InterfaceExtends", + "start": 23, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "id": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "name": "B" + }, + "typeParameters": { + "type": "TypeParameterInstantiation", + "start": 24, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "params": [ + { + "type": "GenericTypeAnnotation", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "name": "T" + } + } + ] + } + }, + { + "type": "InterfaceExtends", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "id": { + "type": "Identifier", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "name": "C" + }, + "typeParameters": null + } + ], + "body": { + "type": "ObjectTypeAnnotation", + "start": 31, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "callProperties": [], + "properties": [], + "indexers": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file