Skip to content

Commit 6e87078

Browse files
committed
Added tests and improve type of new expression
1 parent 8cb5333 commit 6e87078

File tree

7 files changed

+228
-161
lines changed

7 files changed

+228
-161
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16142,7 +16142,7 @@ namespace ts {
1614216142
function getInferredClassType(symbol: Symbol) {
1614316143
const links = getSymbolLinks(symbol);
1614416144
if (!links.inferredClassType) {
16145-
links.inferredClassType = createAnonymousType(symbol, symbol.members, emptyArray, emptyArray, /*stringIndexType*/ undefined, /*numberIndexType*/ undefined);
16145+
links.inferredClassType = createAnonymousType(symbol, symbol.members || emptySymbols, emptyArray, emptyArray, /*stringIndexType*/ undefined, /*numberIndexType*/ undefined);
1614616146
}
1614716147
return links.inferredClassType;
1614816148
}
@@ -16182,7 +16182,7 @@ namespace ts {
1618216182
if (funcSymbol && isDeclarationOfFunctionOrClassExpression(funcSymbol)) {
1618316183
funcSymbol = getSymbolOfNode((<VariableDeclaration>funcSymbol.valueDeclaration).initializer);
1618416184
}
16185-
if (funcSymbol && funcSymbol.members && funcSymbol.flags & SymbolFlags.Function) {
16185+
if (funcSymbol && funcSymbol.flags & SymbolFlags.Function && (funcSymbol.members || getJSDocClassTag(funcSymbol.valueDeclaration))) {
1618616186
return getInferredClassType(funcSymbol);
1618716187
}
1618816188
else if (noImplicitAny) {
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
=== tests/cases/conformance/salsa/index.js ===
2+
function C1() {
3+
>C1 : Symbol(C1, Decl(index.js, 0, 0))
4+
5+
if (!(this instanceof C1)) return new C1();
6+
>C1 : Symbol(C1, Decl(index.js, 0, 0))
7+
>C1 : Symbol(C1, Decl(index.js, 0, 0))
8+
9+
this.x = 1;
10+
>x : Symbol(C1.x, Decl(index.js, 1, 47))
11+
}
12+
13+
const c1_v1 = C1();
14+
>c1_v1 : Symbol(c1_v1, Decl(index.js, 5, 5))
15+
>C1 : Symbol(C1, Decl(index.js, 0, 0))
16+
17+
const c1_v2 = new C1();
18+
>c1_v2 : Symbol(c1_v2, Decl(index.js, 6, 5))
19+
>C1 : Symbol(C1, Decl(index.js, 0, 0))
20+
21+
var C2 = function () {
22+
>C2 : Symbol(C2, Decl(index.js, 8, 3))
23+
24+
if (!(this instanceof C2)) return new C2();
25+
>C2 : Symbol(C2, Decl(index.js, 8, 3))
26+
>C2 : Symbol(C2, Decl(index.js, 8, 3))
27+
28+
this.x = 1;
29+
>x : Symbol(C2.x, Decl(index.js, 9, 47))
30+
31+
};
32+
33+
const c2_v1 = C2();
34+
>c2_v1 : Symbol(c2_v1, Decl(index.js, 13, 5))
35+
>C2 : Symbol(C2, Decl(index.js, 8, 3))
36+
37+
const c2_v2 = new C2();
38+
>c2_v2 : Symbol(c2_v2, Decl(index.js, 14, 5))
39+
>C2 : Symbol(C2, Decl(index.js, 8, 3))
40+
41+
/** @class */
42+
function C3() {
43+
>C3 : Symbol(C3, Decl(index.js, 14, 23))
44+
45+
if (!(this instanceof C3)) return new C3();
46+
>C3 : Symbol(C3, Decl(index.js, 14, 23))
47+
>C3 : Symbol(C3, Decl(index.js, 14, 23))
48+
49+
};
50+
51+
const c3_v1 = C3();
52+
>c3_v1 : Symbol(c3_v1, Decl(index.js, 21, 5))
53+
>C3 : Symbol(C3, Decl(index.js, 14, 23))
54+
55+
const c3_v2 = new C3();
56+
>c3_v2 : Symbol(c3_v2, Decl(index.js, 22, 5))
57+
>C3 : Symbol(C3, Decl(index.js, 14, 23))
58+
59+
/** @class */
60+
var C4 = function () {
61+
>C4 : Symbol(C4, Decl(index.js, 25, 3))
62+
63+
if (!(this instanceof C4)) return new C4();
64+
>C4 : Symbol(C4, Decl(index.js, 25, 3))
65+
>C4 : Symbol(C4, Decl(index.js, 25, 3))
66+
67+
};
68+
69+
const c4_v1 = C4();
70+
>c4_v1 : Symbol(c4_v1, Decl(index.js, 29, 5))
71+
>C4 : Symbol(C4, Decl(index.js, 25, 3))
72+
73+
const c4_v2 = new C4();
74+
>c4_v2 : Symbol(c4_v2, Decl(index.js, 30, 5))
75+
>C4 : Symbol(C4, Decl(index.js, 25, 3))
76+
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
=== tests/cases/conformance/salsa/index.js ===
2+
function C1() {
3+
>C1 : () => typeof C1
4+
5+
if (!(this instanceof C1)) return new C1();
6+
>!(this instanceof C1) : boolean
7+
>(this instanceof C1) : boolean
8+
>this instanceof C1 : boolean
9+
>this : any
10+
>C1 : () => typeof C1
11+
>new C1() : { x: number; }
12+
>C1 : () => typeof C1
13+
14+
this.x = 1;
15+
>this.x = 1 : 1
16+
>this.x : any
17+
>this : any
18+
>x : any
19+
>1 : 1
20+
}
21+
22+
const c1_v1 = C1();
23+
>c1_v1 : { x: number; }
24+
>C1() : { x: number; }
25+
>C1 : () => typeof C1
26+
27+
const c1_v2 = new C1();
28+
>c1_v2 : { x: number; }
29+
>new C1() : { x: number; }
30+
>C1 : () => typeof C1
31+
32+
var C2 = function () {
33+
>C2 : () => any
34+
>function () { if (!(this instanceof C2)) return new C2(); this.x = 1;} : () => any
35+
36+
if (!(this instanceof C2)) return new C2();
37+
>!(this instanceof C2) : boolean
38+
>(this instanceof C2) : boolean
39+
>this instanceof C2 : boolean
40+
>this : any
41+
>C2 : () => any
42+
>new C2() : { x: number; }
43+
>C2 : () => any
44+
45+
this.x = 1;
46+
>this.x = 1 : 1
47+
>this.x : any
48+
>this : any
49+
>x : any
50+
>1 : 1
51+
52+
};
53+
54+
const c2_v1 = C2();
55+
>c2_v1 : { x: number; }
56+
>C2() : { x: number; }
57+
>C2 : () => any
58+
59+
const c2_v2 = new C2();
60+
>c2_v2 : { x: number; }
61+
>new C2() : { x: number; }
62+
>C2 : () => any
63+
64+
/** @class */
65+
function C3() {
66+
>C3 : () => typeof C3
67+
68+
if (!(this instanceof C3)) return new C3();
69+
>!(this instanceof C3) : boolean
70+
>(this instanceof C3) : boolean
71+
>this instanceof C3 : boolean
72+
>this : any
73+
>C3 : () => typeof C3
74+
>new C3() : {}
75+
>C3 : () => typeof C3
76+
77+
};
78+
79+
const c3_v1 = C3();
80+
>c3_v1 : {}
81+
>C3() : {}
82+
>C3 : () => typeof C3
83+
84+
const c3_v2 = new C3();
85+
>c3_v2 : {}
86+
>new C3() : {}
87+
>C3 : () => typeof C3
88+
89+
/** @class */
90+
var C4 = function () {
91+
>C4 : () => any
92+
>function () { if (!(this instanceof C4)) return new C4();} : () => any
93+
94+
if (!(this instanceof C4)) return new C4();
95+
>!(this instanceof C4) : boolean
96+
>(this instanceof C4) : boolean
97+
>this instanceof C4 : boolean
98+
>this : any
99+
>C4 : () => any
100+
>new C4() : {}
101+
>C4 : () => any
102+
103+
};
104+
105+
const c4_v1 = C4();
106+
>c4_v1 : {}
107+
>C4() : {}
108+
>C4 : () => any
109+
110+
const c4_v2 = new C4();
111+
>c4_v2 : {}
112+
>new C4() : {}
113+
>C4 : () => any
114+

tests/baselines/reference/jsConstructorFunction.symbols

Lines changed: 0 additions & 56 deletions
This file was deleted.

tests/baselines/reference/jsConstructorFunction.types

Lines changed: 0 additions & 81 deletions
This file was deleted.

tests/cases/compiler/jsConstructorFunction.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)