Support Flow this parameter annotations (#12234)
This commit is contained in:
@@ -289,6 +289,18 @@ export function FunctionTypeAnnotation(
|
||||
) {
|
||||
this.print(node.typeParameters, node);
|
||||
this.token("(");
|
||||
|
||||
if (node.this) {
|
||||
this.word("this");
|
||||
this.token(":");
|
||||
this.space();
|
||||
this.print(node.this.typeAnnotation, node);
|
||||
if (node.params.length || node.rest) {
|
||||
this.token(",");
|
||||
this.space();
|
||||
}
|
||||
}
|
||||
|
||||
this.printList(node.params, node);
|
||||
|
||||
if (node.rest) {
|
||||
|
||||
45
packages/babel-generator/test/fixtures/flow/this-param/input.js
vendored
Normal file
45
packages/babel-generator/test/fixtures/flow/this-param/input.js
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
function one (this : number) {}
|
||||
function two (this : number, a) {}
|
||||
function three (this : number, ...a) {}
|
||||
function four (this : number, a, b, ...c) {}
|
||||
function five<T> (this : T) {}
|
||||
|
||||
type six = (this : number) => void
|
||||
type seven = (this : number, a : number) => void
|
||||
type eight = (this : number, ...a : any) => void
|
||||
type nine = <T>(this : T) => void
|
||||
|
||||
type ten = {
|
||||
m1(this : string) : void,
|
||||
m2(this : string, a : number) : void,
|
||||
m3(this : string, ...a : any) : void,
|
||||
m4<T>(this : T) : void
|
||||
}
|
||||
|
||||
declare function eleven (this : number) : void
|
||||
declare function twelve (this : string, a : number) : void
|
||||
declare function thirteen (this : string, ...a : any) : void
|
||||
declare function fourteen<T>(this : T) : void
|
||||
|
||||
declare class Fifteen {
|
||||
m1(this : string) : void,
|
||||
m2(this : string, a : number) : void,
|
||||
m3(this : string, ...a : any) : void,
|
||||
m4<T>(this : T) : void
|
||||
}
|
||||
|
||||
class Sixteen {
|
||||
m1 (this : number) {}
|
||||
m2 (this : number, a) {}
|
||||
m3 (this : number, ...a) {}
|
||||
m4 (this : number, a, b, ...c) {}
|
||||
m5<T> (this : T) {}
|
||||
}
|
||||
|
||||
let seventeen = {
|
||||
m1 (this : number) {},
|
||||
m2 (this : number, a) {},
|
||||
m3 (this : number, ...a) {},
|
||||
m4 (this : number, a, b, ...c) {},
|
||||
m5<T> (this : T) {}
|
||||
}
|
||||
56
packages/babel-generator/test/fixtures/flow/this-param/output.js
vendored
Normal file
56
packages/babel-generator/test/fixtures/flow/this-param/output.js
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
function one(this: number) {}
|
||||
|
||||
function two(this: number, a) {}
|
||||
|
||||
function three(this: number, ...a) {}
|
||||
|
||||
function four(this: number, a, b, ...c) {}
|
||||
|
||||
function five<T>(this: T) {}
|
||||
|
||||
type six = (this: number) => void;
|
||||
type seven = (this: number, a: number) => void;
|
||||
type eight = (this: number, ...a: any) => void;
|
||||
type nine = <T>(this: T) => void;
|
||||
type ten = {
|
||||
m1(this: string): void,
|
||||
m2(this: string, a: number): void,
|
||||
m3(this: string, ...a: any): void,
|
||||
m4<T>(this: T): void,
|
||||
};
|
||||
declare function eleven(this: number): void;
|
||||
declare function twelve(this: string, a: number): void;
|
||||
declare function thirteen(this: string, ...a: any): void;
|
||||
declare function fourteen<T>(this: T): void;
|
||||
declare class Fifteen {
|
||||
m1(this: string): void,
|
||||
m2(this: string, a: number): void,
|
||||
m3(this: string, ...a: any): void,
|
||||
m4<T>(this: T): void,
|
||||
}
|
||||
|
||||
class Sixteen {
|
||||
m1(this: number) {}
|
||||
|
||||
m2(this: number, a) {}
|
||||
|
||||
m3(this: number, ...a) {}
|
||||
|
||||
m4(this: number, a, b, ...c) {}
|
||||
|
||||
m5<T>(this: T) {}
|
||||
|
||||
}
|
||||
|
||||
let seventeen = {
|
||||
m1(this: number) {},
|
||||
|
||||
m2(this: number, a) {},
|
||||
|
||||
m3(this: number, ...a) {},
|
||||
|
||||
m4(this: number, a, b, ...c) {},
|
||||
|
||||
m5<T>(this: T) {}
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user