Skip to content

Commit 921d5f8

Browse files
committed
Fix == typo and add object literal 'this' test
1 parent 2a9f39b commit 921d5f8

File tree

5 files changed

+220
-1
lines changed

5 files changed

+220
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4252,7 +4252,7 @@ namespace ts {
42524252
const resolvedSymbol = resolveName(param, paramSymbol.name, SymbolFlags.Value, undefined, undefined);
42534253
paramSymbol = resolvedSymbol;
42544254
}
4255-
if (i == 0 && paramSymbol.name === "this") {
4255+
if (i === 0 && paramSymbol.name === "this") {
42564256
hasThisParameter = true;
42574257
thisType = param.type ? getTypeFromTypeNode(param.type) : unknownType;
42584258
}

tests/baselines/reference/thisTypeInObjectLiterals.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,29 @@ let o = {
55
return this.d.length;
66
}
77
}
8+
let mutuallyRecursive = {
9+
a: 100,
10+
start() {
11+
return this.passthrough(this.a);
12+
},
13+
passthrough(n: number) {
14+
return this.sub1(n);
15+
},
16+
sub1(n: number): number {
17+
if (n > 0) {
18+
return this.passthrough(n - 1);
19+
}
20+
return n;
21+
}
22+
}
23+
var i: number = mutuallyRecursive.start();
24+
interface I {
25+
a: number;
26+
start(): number;
27+
passthrough(n: number): number;
28+
sub1(n: number): number;
29+
}
30+
var impl: I = mutuallyRecursive;
831

932

1033
//// [thisTypeInObjectLiterals.js]
@@ -14,3 +37,20 @@ var o = {
1437
return this.d.length;
1538
}
1639
};
40+
var mutuallyRecursive = {
41+
a: 100,
42+
start: function () {
43+
return this.passthrough(this.a);
44+
},
45+
passthrough: function (n) {
46+
return this.sub1(n);
47+
},
48+
sub1: function (n) {
49+
if (n > 0) {
50+
return this.passthrough(n - 1);
51+
}
52+
return n;
53+
}
54+
};
55+
var i = mutuallyRecursive.start();
56+
var impl = mutuallyRecursive;

tests/baselines/reference/thisTypeInObjectLiterals.symbols

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,77 @@ let o = {
1616
>length : Symbol(String.length, Decl(lib.d.ts, --, --))
1717
}
1818
}
19+
let mutuallyRecursive = {
20+
>mutuallyRecursive : Symbol(mutuallyRecursive, Decl(thisTypeInObjectLiterals.ts, 6, 3))
21+
22+
a: 100,
23+
>a : Symbol(a, Decl(thisTypeInObjectLiterals.ts, 6, 25))
24+
25+
start() {
26+
>start : Symbol(start, Decl(thisTypeInObjectLiterals.ts, 7, 11))
27+
28+
return this.passthrough(this.a);
29+
>this.passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 10, 6))
30+
>this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 6, 23))
31+
>passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 10, 6))
32+
>this.a : Symbol(a, Decl(thisTypeInObjectLiterals.ts, 6, 25))
33+
>this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 6, 23))
34+
>a : Symbol(a, Decl(thisTypeInObjectLiterals.ts, 6, 25))
35+
36+
},
37+
passthrough(n: number) {
38+
>passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 10, 6))
39+
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 11, 16))
40+
41+
return this.sub1(n);
42+
>this.sub1 : Symbol(sub1, Decl(thisTypeInObjectLiterals.ts, 13, 6))
43+
>this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 6, 23))
44+
>sub1 : Symbol(sub1, Decl(thisTypeInObjectLiterals.ts, 13, 6))
45+
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 11, 16))
46+
47+
},
48+
sub1(n: number): number {
49+
>sub1 : Symbol(sub1, Decl(thisTypeInObjectLiterals.ts, 13, 6))
50+
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 14, 9))
51+
52+
if (n > 0) {
53+
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 14, 9))
54+
55+
return this.passthrough(n - 1);
56+
>this.passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 10, 6))
57+
>this : Symbol(, Decl(thisTypeInObjectLiterals.ts, 6, 23))
58+
>passthrough : Symbol(passthrough, Decl(thisTypeInObjectLiterals.ts, 10, 6))
59+
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 14, 9))
60+
}
61+
return n;
62+
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 14, 9))
63+
}
64+
}
65+
var i: number = mutuallyRecursive.start();
66+
>i : Symbol(i, Decl(thisTypeInObjectLiterals.ts, 21, 3))
67+
>mutuallyRecursive.start : Symbol(start, Decl(thisTypeInObjectLiterals.ts, 7, 11))
68+
>mutuallyRecursive : Symbol(mutuallyRecursive, Decl(thisTypeInObjectLiterals.ts, 6, 3))
69+
>start : Symbol(start, Decl(thisTypeInObjectLiterals.ts, 7, 11))
70+
71+
interface I {
72+
>I : Symbol(I, Decl(thisTypeInObjectLiterals.ts, 21, 42))
73+
74+
a: number;
75+
>a : Symbol(I.a, Decl(thisTypeInObjectLiterals.ts, 22, 13))
76+
77+
start(): number;
78+
>start : Symbol(I.start, Decl(thisTypeInObjectLiterals.ts, 23, 14))
79+
80+
passthrough(n: number): number;
81+
>passthrough : Symbol(I.passthrough, Decl(thisTypeInObjectLiterals.ts, 24, 20))
82+
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 25, 16))
83+
84+
sub1(n: number): number;
85+
>sub1 : Symbol(I.sub1, Decl(thisTypeInObjectLiterals.ts, 25, 35))
86+
>n : Symbol(n, Decl(thisTypeInObjectLiterals.ts, 26, 9))
87+
}
88+
var impl: I = mutuallyRecursive;
89+
>impl : Symbol(impl, Decl(thisTypeInObjectLiterals.ts, 28, 3))
90+
>I : Symbol(I, Decl(thisTypeInObjectLiterals.ts, 21, 42))
91+
>mutuallyRecursive : Symbol(mutuallyRecursive, Decl(thisTypeInObjectLiterals.ts, 6, 3))
1992

tests/baselines/reference/thisTypeInObjectLiterals.types

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,87 @@ let o = {
1818
>length : number
1919
}
2020
}
21+
let mutuallyRecursive = {
22+
>mutuallyRecursive : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; }
23+
>{ a: 100, start() { return this.passthrough(this.a); }, passthrough(n: number) { return this.sub1(n); }, sub1(n: number): number { if (n > 0) { return this.passthrough(n - 1); } return n; }} : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; }
24+
25+
a: 100,
26+
>a : number
27+
>100 : number
28+
29+
start() {
30+
>start : () => number
31+
32+
return this.passthrough(this.a);
33+
>this.passthrough(this.a) : number
34+
>this.passthrough : (n: number) => number
35+
>this : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; }
36+
>passthrough : (n: number) => number
37+
>this.a : number
38+
>this : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; }
39+
>a : number
40+
41+
},
42+
passthrough(n: number) {
43+
>passthrough : (n: number) => number
44+
>n : number
45+
46+
return this.sub1(n);
47+
>this.sub1(n) : number
48+
>this.sub1 : (n: number) => number
49+
>this : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; }
50+
>sub1 : (n: number) => number
51+
>n : number
52+
53+
},
54+
sub1(n: number): number {
55+
>sub1 : (n: number) => number
56+
>n : number
57+
58+
if (n > 0) {
59+
>n > 0 : boolean
60+
>n : number
61+
>0 : number
62+
63+
return this.passthrough(n - 1);
64+
>this.passthrough(n - 1) : number
65+
>this.passthrough : (n: number) => number
66+
>this : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; }
67+
>passthrough : (n: number) => number
68+
>n - 1 : number
69+
>n : number
70+
>1 : number
71+
}
72+
return n;
73+
>n : number
74+
}
75+
}
76+
var i: number = mutuallyRecursive.start();
77+
>i : number
78+
>mutuallyRecursive.start() : number
79+
>mutuallyRecursive.start : () => number
80+
>mutuallyRecursive : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; }
81+
>start : () => number
82+
83+
interface I {
84+
>I : I
85+
86+
a: number;
87+
>a : number
88+
89+
start(): number;
90+
>start : () => number
91+
92+
passthrough(n: number): number;
93+
>passthrough : (n: number) => number
94+
>n : number
95+
96+
sub1(n: number): number;
97+
>sub1 : (n: number) => number
98+
>n : number
99+
}
100+
var impl: I = mutuallyRecursive;
101+
>impl : I
102+
>I : I
103+
>mutuallyRecursive : { a: number; start(): number; passthrough(n: number): number; sub1(n: number): number; }
21104

tests/cases/conformance/types/thisType/thisTypeInObjectLiterals.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,26 @@ let o = {
44
return this.d.length;
55
}
66
}
7+
let mutuallyRecursive = {
8+
a: 100,
9+
start() {
10+
return this.passthrough(this.a);
11+
},
12+
passthrough(n: number) {
13+
return this.sub1(n);
14+
},
15+
sub1(n: number): number {
16+
if (n > 0) {
17+
return this.passthrough(n - 1);
18+
}
19+
return n;
20+
}
21+
}
22+
var i: number = mutuallyRecursive.start();
23+
interface I {
24+
a: number;
25+
start(): number;
26+
passthrough(n: number): number;
27+
sub1(n: number): number;
28+
}
29+
var impl: I = mutuallyRecursive;

0 commit comments

Comments
 (0)