Merge pull request #3203 from samwgoldman/flow-mixins-6.x

Add support for mixins to Babel 6.x
This commit is contained in:
Sebastian McKenzie 2015-12-27 21:04:40 +00:00
commit 5ca1cf0506
10 changed files with 240 additions and 0 deletions

View File

@ -104,6 +104,10 @@ export function _interfaceish(node: Object) {
this.push(" extends ");
this.printJoin(node.extends, node, { separator: ", " });
}
if (node.mixins && node.mixins.length) {
this.push(" mixins ");
this.printJoin(node.mixins, node, { separator: ", " });
}
this.space();
this.print(node.body, node);
}

View File

@ -9,3 +9,4 @@ declare class A<T> extends B<T> { x: number }
declare class A { static foo(): number; static x : string }
declare class A { static [ indexer: number]: string }
declare class A { static () : number }
declare class A mixins B<T>, C {}

View File

@ -9,3 +9,4 @@ declare class A<T> extends B<T> { x: number }
declare class A { static foo(): number; static x: string; }
declare class A { static [indexer: number]: string }
declare class A { static (): number }
declare class A mixins B<T>, C {}

View File

@ -0,0 +1,12 @@
declare var foo
declare var foo;
declare function foo(): void
declare function foo(): void;
declare function foo<T>(): void;
declare function foo(x: number, y: string): void;
declare class A {}
declare class A<T> extends B<T> { x: number }
declare class A { static foo(): number; static x : string }
declare class A { static [ indexer: number]: string }
declare class A { static () : number }
declare class A mixins B<T>, C {}

View File

@ -0,0 +1,12 @@
/*:: declare var foo*/
/*:: declare var foo;*/
/*:: declare function foo(): void*/
/*:: declare function foo(): void;*/
/*:: declare function foo<T>(): void;*/
/*:: declare function foo(x: number, y: string): void;*/
/*:: declare class A {}*/
/*:: declare class A<T> extends B<T> { x: number }*/
/*:: declare class A { static foo(): number; static x : string }*/
/*:: declare class A { static [ indexer: number]: string }*/
/*:: declare class A { static () : number }*/
/*:: declare class A mixins B<T>, C {}*/

View File

@ -9,3 +9,4 @@ declare class A<T> extends B<T> { x: number }
declare class A { static foo(): number; static x : string }
declare class A { static [ indexer: number]: string }
declare class A { static () : number }
declare class A mixins B<T>, C {}

View File

@ -64,6 +64,7 @@ defineType("ClassDeclaration", {
"id",
"body",
"superClass",
"mixins",
"typeParameters",
"superTypeParameters",
"implements",

View File

@ -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);
};

View File

@ -0,0 +1 @@
declare class A mixins B<T>, C {}

View File

@ -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": []
}
}