Adding test for declaration files

This commit is contained in:
Anders Hejlsberg 2015-09-26 15:56:00 -07:00
parent 29f6036176
commit 19319b2208
4 changed files with 447 additions and 0 deletions

View File

@ -0,0 +1,135 @@
//// [declarationFiles.ts]
class C1 {
x: this;
f(x: this): this { return undefined; }
constructor(x: this) { }
}
class C2 {
[x: string]: this;
}
interface Foo<T> {
x: T;
y: this;
}
class C3 {
a: this[];
b: [this, this];
c: this | Date;
d: this & Date;
e: (((this)));
f: (x: this) => this;
g: new (x: this) => this;
h: Foo<this>;
i: Foo<this | (() => this)>;
j: (x: any) => x is this;
}
class C4 {
x1 = { a: this };
x2 = [this];
x3 = [{ a: this }];
x4 = () => this;
f1() {
return { a: this };
}
f2() {
return [this];
}
f3() {
return [{ a: this }];
}
f4() {
return () => this;
}
}
//// [declarationFiles.js]
var C1 = (function () {
function C1(x) {
}
C1.prototype.f = function (x) { return undefined; };
return C1;
})();
var C2 = (function () {
function C2() {
}
return C2;
})();
var C3 = (function () {
function C3() {
}
return C3;
})();
var C4 = (function () {
function C4() {
var _this = this;
this.x1 = { a: this };
this.x2 = [this];
this.x3 = [{ a: this }];
this.x4 = function () { return _this; };
}
C4.prototype.f1 = function () {
return { a: this };
};
C4.prototype.f2 = function () {
return [this];
};
C4.prototype.f3 = function () {
return [{ a: this }];
};
C4.prototype.f4 = function () {
var _this = this;
return function () { return _this; };
};
return C4;
})();
//// [declarationFiles.d.ts]
declare class C1 {
x: this;
f(x: this): this;
constructor(x: this);
}
declare class C2 {
[x: string]: this;
}
interface Foo<T> {
x: T;
y: this;
}
declare class C3 {
a: this[];
b: [this, this];
c: this | Date;
d: this & Date;
e: (((this)));
f: (x: this) => this;
g: new (x: this) => this;
h: Foo<this>;
i: Foo<this | (() => this)>;
j: (x: any) => x is this;
}
declare class C4 {
x1: {
a: C4;
};
x2: this[];
x3: {
a: C4;
}[];
x4: () => this;
f1(): {
a: C4;
};
f2(): this[];
f3(): {
a: C4;
}[];
f4(): () => this;
}

View File

@ -0,0 +1,127 @@
=== tests/cases/conformance/types/thisType/declarationFiles.ts ===
class C1 {
>C1 : Symbol(C1, Decl(declarationFiles.ts, 0, 0))
x: this;
>x : Symbol(x, Decl(declarationFiles.ts, 1, 10))
f(x: this): this { return undefined; }
>f : Symbol(f, Decl(declarationFiles.ts, 2, 12))
>x : Symbol(x, Decl(declarationFiles.ts, 3, 6))
>undefined : Symbol(undefined)
constructor(x: this) { }
>x : Symbol(x, Decl(declarationFiles.ts, 4, 16))
}
class C2 {
>C2 : Symbol(C2, Decl(declarationFiles.ts, 5, 1))
[x: string]: this;
>x : Symbol(x, Decl(declarationFiles.ts, 8, 5))
}
interface Foo<T> {
>Foo : Symbol(Foo, Decl(declarationFiles.ts, 9, 1))
>T : Symbol(T, Decl(declarationFiles.ts, 11, 14))
x: T;
>x : Symbol(x, Decl(declarationFiles.ts, 11, 18))
>T : Symbol(T, Decl(declarationFiles.ts, 11, 14))
y: this;
>y : Symbol(y, Decl(declarationFiles.ts, 12, 9))
}
class C3 {
>C3 : Symbol(C3, Decl(declarationFiles.ts, 14, 1))
a: this[];
>a : Symbol(a, Decl(declarationFiles.ts, 16, 10))
b: [this, this];
>b : Symbol(b, Decl(declarationFiles.ts, 17, 14))
c: this | Date;
>c : Symbol(c, Decl(declarationFiles.ts, 18, 20))
>Date : Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11))
d: this & Date;
>d : Symbol(d, Decl(declarationFiles.ts, 19, 19))
>Date : Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11))
e: (((this)));
>e : Symbol(e, Decl(declarationFiles.ts, 20, 19))
f: (x: this) => this;
>f : Symbol(f, Decl(declarationFiles.ts, 21, 18))
>x : Symbol(x, Decl(declarationFiles.ts, 22, 8))
g: new (x: this) => this;
>g : Symbol(g, Decl(declarationFiles.ts, 22, 25))
>x : Symbol(x, Decl(declarationFiles.ts, 23, 12))
h: Foo<this>;
>h : Symbol(h, Decl(declarationFiles.ts, 23, 29))
>Foo : Symbol(Foo, Decl(declarationFiles.ts, 9, 1))
i: Foo<this | (() => this)>;
>i : Symbol(i, Decl(declarationFiles.ts, 24, 17))
>Foo : Symbol(Foo, Decl(declarationFiles.ts, 9, 1))
j: (x: any) => x is this;
>j : Symbol(j, Decl(declarationFiles.ts, 25, 32))
>x : Symbol(x, Decl(declarationFiles.ts, 26, 8))
>x : Symbol(x, Decl(declarationFiles.ts, 26, 8))
}
class C4 {
>C4 : Symbol(C4, Decl(declarationFiles.ts, 27, 1))
x1 = { a: this };
>x1 : Symbol(x1, Decl(declarationFiles.ts, 29, 10))
>a : Symbol(a, Decl(declarationFiles.ts, 30, 10))
>this : Symbol(C4, Decl(declarationFiles.ts, 27, 1))
x2 = [this];
>x2 : Symbol(x2, Decl(declarationFiles.ts, 30, 21))
>this : Symbol(C4, Decl(declarationFiles.ts, 27, 1))
x3 = [{ a: this }];
>x3 : Symbol(x3, Decl(declarationFiles.ts, 31, 16))
>a : Symbol(a, Decl(declarationFiles.ts, 32, 11))
>this : Symbol(C4, Decl(declarationFiles.ts, 27, 1))
x4 = () => this;
>x4 : Symbol(x4, Decl(declarationFiles.ts, 32, 23))
>this : Symbol(C4, Decl(declarationFiles.ts, 27, 1))
f1() {
>f1 : Symbol(f1, Decl(declarationFiles.ts, 33, 20))
return { a: this };
>a : Symbol(a, Decl(declarationFiles.ts, 35, 16))
>this : Symbol(C4, Decl(declarationFiles.ts, 27, 1))
}
f2() {
>f2 : Symbol(f2, Decl(declarationFiles.ts, 36, 5))
return [this];
>this : Symbol(C4, Decl(declarationFiles.ts, 27, 1))
}
f3() {
>f3 : Symbol(f3, Decl(declarationFiles.ts, 39, 5))
return [{ a: this }];
>a : Symbol(a, Decl(declarationFiles.ts, 41, 17))
>this : Symbol(C4, Decl(declarationFiles.ts, 27, 1))
}
f4() {
>f4 : Symbol(f4, Decl(declarationFiles.ts, 42, 5))
return () => this;
>this : Symbol(C4, Decl(declarationFiles.ts, 27, 1))
}
}

View File

@ -0,0 +1,137 @@
=== tests/cases/conformance/types/thisType/declarationFiles.ts ===
class C1 {
>C1 : C1
x: this;
>x : this
f(x: this): this { return undefined; }
>f : (x: this) => this
>x : this
>undefined : undefined
constructor(x: this) { }
>x : this
}
class C2 {
>C2 : C2
[x: string]: this;
>x : string
}
interface Foo<T> {
>Foo : Foo<T>
>T : T
x: T;
>x : T
>T : T
y: this;
>y : this
}
class C3 {
>C3 : C3
a: this[];
>a : this[]
b: [this, this];
>b : [this, this]
c: this | Date;
>c : this | Date
>Date : Date
d: this & Date;
>d : this & Date
>Date : Date
e: (((this)));
>e : this
f: (x: this) => this;
>f : (x: this) => this
>x : this
g: new (x: this) => this;
>g : new (x: this) => this
>x : this
h: Foo<this>;
>h : Foo<this>
>Foo : Foo<T>
i: Foo<this | (() => this)>;
>i : Foo<this | (() => this)>
>Foo : Foo<T>
j: (x: any) => x is this;
>j : (x: any) => x is this
>x : any
>x : any
}
class C4 {
>C4 : C4
x1 = { a: this };
>x1 : { a: this; }
>{ a: this } : { a: this; }
>a : this
>this : this
x2 = [this];
>x2 : this[]
>[this] : this[]
>this : this
x3 = [{ a: this }];
>x3 : { a: this; }[]
>[{ a: this }] : { a: this; }[]
>{ a: this } : { a: this; }
>a : this
>this : this
x4 = () => this;
>x4 : () => this
>() => this : () => this
>this : this
f1() {
>f1 : () => { a: this; }
return { a: this };
>{ a: this } : { a: this; }
>a : this
>this : this
}
f2() {
>f2 : () => this[]
return [this];
>[this] : this[]
>this : this
}
f3() {
>f3 : () => { a: this; }[]
return [{ a: this }];
>[{ a: this }] : { a: this; }[]
>{ a: this } : { a: this; }
>a : this
>this : this
}
f4() {
>f4 : () => () => this
return () => this;
>() => this : () => this
>this : this
}
}

View File

@ -0,0 +1,48 @@
// @declaration: true
class C1 {
x: this;
f(x: this): this { return undefined; }
constructor(x: this) { }
}
class C2 {
[x: string]: this;
}
interface Foo<T> {
x: T;
y: this;
}
class C3 {
a: this[];
b: [this, this];
c: this | Date;
d: this & Date;
e: (((this)));
f: (x: this) => this;
g: new (x: this) => this;
h: Foo<this>;
i: Foo<this | (() => this)>;
j: (x: any) => x is this;
}
class C4 {
x1 = { a: this };
x2 = [this];
x3 = [{ a: this }];
x4 = () => this;
f1() {
return { a: this };
}
f2() {
return [this];
}
f3() {
return [{ a: this }];
}
f4() {
return () => this;
}
}