Skip to content

Commit e770249

Browse files
committed
Test:decl emit for class expressions as type lits
Add test and update baselines
1 parent 5a5fee3 commit e770249

7 files changed

+357
-10
lines changed

tests/baselines/reference/declarationEmitExpressionInExtends4.errors.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
1-
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(1,10): error TS4060: Return type of exported function has or is using private name 'D'.
21
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(5,17): error TS2315: Type 'D' is not generic.
3-
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(5,17): error TS4020: 'extends' clause of exported class 'C' has or is using private name 'D'.
42
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(9,18): error TS2304: Cannot find name 'SomeUndefinedFunction'.
53
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(14,18): error TS2304: Cannot find name 'SomeUndefinedFunction'.
64
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(14,18): error TS4020: 'extends' clause of exported class 'C3' has or is using private name 'SomeUndefinedFunction'.
75

86

9-
==== tests/cases/compiler/declarationEmitExpressionInExtends4.ts (6 errors) ====
7+
==== tests/cases/compiler/declarationEmitExpressionInExtends4.ts (4 errors) ====
108
function getSomething() {
11-
~~~~~~~~~~~~
12-
!!! error TS4060: Return type of exported function has or is using private name 'D'.
139
return class D { }
1410
}
1511

1612
class C extends getSomething()<number, string> {
1713
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1814
!!! error TS2315: Type 'D' is not generic.
19-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20-
!!! error TS4020: 'extends' clause of exported class 'C' has or is using private name 'D'.
2115

2216
}
2317

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
//// [emitClassExpressionInDeclarationFile.ts]
2+
export var simpleExample = class {
3+
static getTags() { }
4+
tags() { }
5+
}
6+
export var circularReference = class C {
7+
static getTags(c: C): C { return c }
8+
tags(c: C): C { return c }
9+
}
10+
11+
// repro from #15066
12+
export class FooItem {
13+
foo(): void { }
14+
name?: string;
15+
}
16+
17+
export type Constructor<T> = new(...args: any[]) => T;
18+
export function WithTags<T extends Constructor<FooItem>>(Base: T) {
19+
return class extends Base {
20+
static getTags(): void { }
21+
tags(): void { }
22+
}
23+
}
24+
25+
export class Test extends WithTags(FooItem) {}
26+
27+
const test = new Test();
28+
29+
Test.getTags()
30+
test.tags();
31+
32+
33+
//// [emitClassExpressionInDeclarationFile.js]
34+
"use strict";
35+
var __extends = (this && this.__extends) || (function () {
36+
var extendStatics = Object.setPrototypeOf ||
37+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
38+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
39+
return function (d, b) {
40+
extendStatics(d, b);
41+
function __() { this.constructor = d; }
42+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
43+
};
44+
})();
45+
exports.__esModule = true;
46+
exports.simpleExample = (function () {
47+
function class_1() {
48+
}
49+
class_1.getTags = function () { };
50+
class_1.prototype.tags = function () { };
51+
return class_1;
52+
}());
53+
exports.circularReference = (function () {
54+
function C() {
55+
}
56+
C.getTags = function (c) { return c; };
57+
C.prototype.tags = function (c) { return c; };
58+
return C;
59+
}());
60+
// repro from #15066
61+
var FooItem = (function () {
62+
function FooItem() {
63+
}
64+
FooItem.prototype.foo = function () { };
65+
return FooItem;
66+
}());
67+
exports.FooItem = FooItem;
68+
function WithTags(Base) {
69+
return (function (_super) {
70+
__extends(class_2, _super);
71+
function class_2() {
72+
return _super !== null && _super.apply(this, arguments) || this;
73+
}
74+
class_2.getTags = function () { };
75+
class_2.prototype.tags = function () { };
76+
return class_2;
77+
}(Base));
78+
}
79+
exports.WithTags = WithTags;
80+
var Test = (function (_super) {
81+
__extends(Test, _super);
82+
function Test() {
83+
return _super !== null && _super.apply(this, arguments) || this;
84+
}
85+
return Test;
86+
}(WithTags(FooItem)));
87+
exports.Test = Test;
88+
var test = new Test();
89+
Test.getTags();
90+
test.tags();
91+
92+
93+
//// [emitClassExpressionInDeclarationFile.d.ts]
94+
export declare var simpleExample: {
95+
new (): {
96+
tags(): void;
97+
};
98+
prototype: {
99+
tags(): void;
100+
};
101+
getTags(): void;
102+
};
103+
export declare var circularReference: {
104+
new (): {
105+
tags(c: any): any;
106+
};
107+
prototype: {
108+
tags(c: any): any;
109+
};
110+
getTags(c: {
111+
tags(c: any): any;
112+
}): {
113+
tags(c: any): any;
114+
};
115+
};
116+
export declare class FooItem {
117+
foo(): void;
118+
name?: string;
119+
}
120+
export declare type Constructor<T> = new (...args: any[]) => T;
121+
export declare function WithTags<T extends Constructor<FooItem>>(Base: T): {
122+
new (...args: any[]): {
123+
tags(): void;
124+
foo(): void;
125+
name?: string;
126+
};
127+
prototype: {
128+
tags(): void;
129+
foo(): void;
130+
name?: string;
131+
};
132+
getTags(): void;
133+
} & T;
134+
declare const Test_base: {
135+
new (...args: any[]): {
136+
tags(): void;
137+
foo(): void;
138+
name?: string;
139+
};
140+
prototype: {
141+
tags(): void;
142+
foo(): void;
143+
name?: string;
144+
};
145+
getTags(): void;
146+
} & typeof FooItem;
147+
export declare class Test extends Test_base {
148+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
=== tests/cases/compiler/emitClassExpressionInDeclarationFile.ts ===
2+
export var simpleExample = class {
3+
>simpleExample : Symbol(simpleExample, Decl(emitClassExpressionInDeclarationFile.ts, 0, 10))
4+
5+
static getTags() { }
6+
>getTags : Symbol(simpleExample.getTags, Decl(emitClassExpressionInDeclarationFile.ts, 0, 34))
7+
8+
tags() { }
9+
>tags : Symbol(simpleExample.tags, Decl(emitClassExpressionInDeclarationFile.ts, 1, 24))
10+
}
11+
export var circularReference = class C {
12+
>circularReference : Symbol(circularReference, Decl(emitClassExpressionInDeclarationFile.ts, 4, 10))
13+
>C : Symbol(C, Decl(emitClassExpressionInDeclarationFile.ts, 4, 30))
14+
15+
static getTags(c: C): C { return c }
16+
>getTags : Symbol(C.getTags, Decl(emitClassExpressionInDeclarationFile.ts, 4, 40))
17+
>c : Symbol(c, Decl(emitClassExpressionInDeclarationFile.ts, 5, 19))
18+
>C : Symbol(C, Decl(emitClassExpressionInDeclarationFile.ts, 4, 30))
19+
>C : Symbol(C, Decl(emitClassExpressionInDeclarationFile.ts, 4, 30))
20+
>c : Symbol(c, Decl(emitClassExpressionInDeclarationFile.ts, 5, 19))
21+
22+
tags(c: C): C { return c }
23+
>tags : Symbol(C.tags, Decl(emitClassExpressionInDeclarationFile.ts, 5, 40))
24+
>c : Symbol(c, Decl(emitClassExpressionInDeclarationFile.ts, 6, 9))
25+
>C : Symbol(C, Decl(emitClassExpressionInDeclarationFile.ts, 4, 30))
26+
>C : Symbol(C, Decl(emitClassExpressionInDeclarationFile.ts, 4, 30))
27+
>c : Symbol(c, Decl(emitClassExpressionInDeclarationFile.ts, 6, 9))
28+
}
29+
30+
// repro from #15066
31+
export class FooItem {
32+
>FooItem : Symbol(FooItem, Decl(emitClassExpressionInDeclarationFile.ts, 7, 1))
33+
34+
foo(): void { }
35+
>foo : Symbol(FooItem.foo, Decl(emitClassExpressionInDeclarationFile.ts, 10, 22))
36+
37+
name?: string;
38+
>name : Symbol(FooItem.name, Decl(emitClassExpressionInDeclarationFile.ts, 11, 19))
39+
}
40+
41+
export type Constructor<T> = new(...args: any[]) => T;
42+
>Constructor : Symbol(Constructor, Decl(emitClassExpressionInDeclarationFile.ts, 13, 1))
43+
>T : Symbol(T, Decl(emitClassExpressionInDeclarationFile.ts, 15, 24))
44+
>args : Symbol(args, Decl(emitClassExpressionInDeclarationFile.ts, 15, 33))
45+
>T : Symbol(T, Decl(emitClassExpressionInDeclarationFile.ts, 15, 24))
46+
47+
export function WithTags<T extends Constructor<FooItem>>(Base: T) {
48+
>WithTags : Symbol(WithTags, Decl(emitClassExpressionInDeclarationFile.ts, 15, 54))
49+
>T : Symbol(T, Decl(emitClassExpressionInDeclarationFile.ts, 16, 25))
50+
>Constructor : Symbol(Constructor, Decl(emitClassExpressionInDeclarationFile.ts, 13, 1))
51+
>FooItem : Symbol(FooItem, Decl(emitClassExpressionInDeclarationFile.ts, 7, 1))
52+
>Base : Symbol(Base, Decl(emitClassExpressionInDeclarationFile.ts, 16, 57))
53+
>T : Symbol(T, Decl(emitClassExpressionInDeclarationFile.ts, 16, 25))
54+
55+
return class extends Base {
56+
>Base : Symbol(Base, Decl(emitClassExpressionInDeclarationFile.ts, 16, 57))
57+
58+
static getTags(): void { }
59+
>getTags : Symbol((Anonymous class).getTags, Decl(emitClassExpressionInDeclarationFile.ts, 17, 31))
60+
61+
tags(): void { }
62+
>tags : Symbol((Anonymous class).tags, Decl(emitClassExpressionInDeclarationFile.ts, 18, 34))
63+
}
64+
}
65+
66+
export class Test extends WithTags(FooItem) {}
67+
>Test : Symbol(Test, Decl(emitClassExpressionInDeclarationFile.ts, 21, 1))
68+
>WithTags : Symbol(WithTags, Decl(emitClassExpressionInDeclarationFile.ts, 15, 54))
69+
>FooItem : Symbol(FooItem, Decl(emitClassExpressionInDeclarationFile.ts, 7, 1))
70+
71+
const test = new Test();
72+
>test : Symbol(test, Decl(emitClassExpressionInDeclarationFile.ts, 25, 5))
73+
>Test : Symbol(Test, Decl(emitClassExpressionInDeclarationFile.ts, 21, 1))
74+
75+
Test.getTags()
76+
>Test.getTags : Symbol((Anonymous class).getTags, Decl(emitClassExpressionInDeclarationFile.ts, 17, 31))
77+
>Test : Symbol(Test, Decl(emitClassExpressionInDeclarationFile.ts, 21, 1))
78+
>getTags : Symbol((Anonymous class).getTags, Decl(emitClassExpressionInDeclarationFile.ts, 17, 31))
79+
80+
test.tags();
81+
>test.tags : Symbol((Anonymous class).tags, Decl(emitClassExpressionInDeclarationFile.ts, 18, 34))
82+
>test : Symbol(test, Decl(emitClassExpressionInDeclarationFile.ts, 25, 5))
83+
>tags : Symbol((Anonymous class).tags, Decl(emitClassExpressionInDeclarationFile.ts, 18, 34))
84+
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
=== tests/cases/compiler/emitClassExpressionInDeclarationFile.ts ===
2+
export var simpleExample = class {
3+
>simpleExample : typeof simpleExample
4+
>class { static getTags() { } tags() { }} : typeof simpleExample
5+
6+
static getTags() { }
7+
>getTags : () => void
8+
9+
tags() { }
10+
>tags : () => void
11+
}
12+
export var circularReference = class C {
13+
>circularReference : typeof C
14+
>class C { static getTags(c: C): C { return c } tags(c: C): C { return c }} : typeof C
15+
>C : typeof C
16+
17+
static getTags(c: C): C { return c }
18+
>getTags : (c: C) => C
19+
>c : C
20+
>C : C
21+
>C : C
22+
>c : C
23+
24+
tags(c: C): C { return c }
25+
>tags : (c: C) => C
26+
>c : C
27+
>C : C
28+
>C : C
29+
>c : C
30+
}
31+
32+
// repro from #15066
33+
export class FooItem {
34+
>FooItem : FooItem
35+
36+
foo(): void { }
37+
>foo : () => void
38+
39+
name?: string;
40+
>name : string
41+
}
42+
43+
export type Constructor<T> = new(...args: any[]) => T;
44+
>Constructor : Constructor<T>
45+
>T : T
46+
>args : any[]
47+
>T : T
48+
49+
export function WithTags<T extends Constructor<FooItem>>(Base: T) {
50+
>WithTags : <T extends Constructor<FooItem>>(Base: T) => { new (...args: any[]): (Anonymous class); prototype: WithTags<any>.(Anonymous class); getTags(): void; } & T
51+
>T : T
52+
>Constructor : Constructor<T>
53+
>FooItem : FooItem
54+
>Base : T
55+
>T : T
56+
57+
return class extends Base {
58+
>class extends Base { static getTags(): void { } tags(): void { } } : { new (...args: any[]): (Anonymous class); prototype: WithTags<any>.(Anonymous class); getTags(): void; } & T
59+
>Base : FooItem
60+
61+
static getTags(): void { }
62+
>getTags : () => void
63+
64+
tags(): void { }
65+
>tags : () => void
66+
}
67+
}
68+
69+
export class Test extends WithTags(FooItem) {}
70+
>Test : Test
71+
>WithTags(FooItem) : WithTags<typeof FooItem>.(Anonymous class) & FooItem
72+
>WithTags : <T extends Constructor<FooItem>>(Base: T) => { new (...args: any[]): (Anonymous class); prototype: WithTags<any>.(Anonymous class); getTags(): void; } & T
73+
>FooItem : typeof FooItem
74+
75+
const test = new Test();
76+
>test : Test
77+
>new Test() : Test
78+
>Test : typeof Test
79+
80+
Test.getTags()
81+
>Test.getTags() : void
82+
>Test.getTags : () => void
83+
>Test : typeof Test
84+
>getTags : () => void
85+
86+
test.tags();
87+
>test.tags() : void
88+
>test.tags : () => void
89+
>test : Test
90+
>tags : () => void
91+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// @declaration: true
2+
export var simpleExample = class {
3+
static getTags() { }
4+
tags() { }
5+
}
6+
export var circularReference = class C {
7+
static getTags(c: C): C { return c }
8+
tags(c: C): C { return c }
9+
}
10+
11+
// repro from #15066
12+
export class FooItem {
13+
foo(): void { }
14+
name?: string;
15+
}
16+
17+
export type Constructor<T> = new(...args: any[]) => T;
18+
export function WithTags<T extends Constructor<FooItem>>(Base: T) {
19+
return class extends Base {
20+
static getTags(): void { }
21+
tags(): void { }
22+
}
23+
}
24+
25+
export class Test extends WithTags(FooItem) {}
26+
27+
const test = new Test();
28+
29+
Test.getTags()
30+
test.tags();

tests/cases/fourslash/findAllRefsForVariableInExtendsClause01.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
////var [|{| "isWriteAccess": true, "isDefinition": true |}Base|] = class { };
44
////class C extends [|Base|] { }
55

6-
verify.singleReferenceGroup("var Base: typeof Base");
6+
verify.singleReferenceGroup("var Base: {\n new (): {};\n prototype: {};\n}");

tests/cases/fourslash/renameJsExports02.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
const [r0, r1] = test.ranges();
1111
verify.referenceGroups(r0, [
1212
{ definition: "(local class) A", ranges: [r0] },
13-
{ definition: "const A: typeof A", ranges: [r1] }
13+
{ definition: "const A: {\n new (): {};\n prototype: {};\n}", ranges: [r1] }
1414
]);
1515

16-
verify.singleReferenceGroup("const A: typeof A", [r1]);
16+
verify.singleReferenceGroup("const A: {\n new (): {};\n prototype: {};\n}", [r1]);

0 commit comments

Comments
 (0)