Support Flow this parameter annotations (#12234)

This commit is contained in:
Daniel Sainati
2021-02-21 11:44:27 -05:00
committed by GitHub
parent 407e8b5c7b
commit 16e9f1c8e5
149 changed files with 3010 additions and 83 deletions

View File

@@ -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) {

View 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) {}
}

View 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) {}
};