Skip to content

Commit ecaf44d

Browse files
committed
Add more tests and update baselines
1 parent 860e8e8 commit ecaf44d

5 files changed

+157
-23
lines changed

tests/baselines/reference/emitClassExpressionInDeclarationFile.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,12 @@ export declare var simpleExample: {
9595
new (): {
9696
tags(): void;
9797
};
98-
prototype: {
99-
tags(): void;
100-
};
10198
getTags(): void;
10299
};
103100
export declare var circularReference: {
104101
new (): {
105102
tags(c: any): any;
106103
};
107-
prototype: {
108-
tags(c: any): any;
109-
};
110104
getTags(c: {
111105
tags(c: any): any;
112106
}): {
@@ -124,11 +118,6 @@ export declare function WithTags<T extends Constructor<FooItem>>(Base: T): {
124118
foo(): void;
125119
name?: string;
126120
};
127-
prototype: {
128-
tags(): void;
129-
foo(): void;
130-
name?: string;
131-
};
132121
getTags(): void;
133122
} & T;
134123
declare const Test_base: {
@@ -137,11 +126,6 @@ declare const Test_base: {
137126
foo(): void;
138127
name?: string;
139128
};
140-
prototype: {
141-
tags(): void;
142-
foo(): void;
143-
name?: string;
144-
};
145129
getTags(): void;
146130
} & typeof FooItem;
147131
export declare class Test extends Test_base {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
tests/cases/compiler/emitClassExpressionInDeclarationFile2.ts(1,12): error TS4094: Property 'p' of exported class expression may not be private or protected.
2+
tests/cases/compiler/emitClassExpressionInDeclarationFile2.ts(1,12): error TS4094: Property 'ps' of exported class expression may not be private or protected.
3+
tests/cases/compiler/emitClassExpressionInDeclarationFile2.ts(16,17): error TS4094: Property 'property' of exported class expression may not be private or protected.
4+
5+
6+
==== tests/cases/compiler/emitClassExpressionInDeclarationFile2.ts (3 errors) ====
7+
export var noPrivates = class {
8+
~~~~~~~~~~
9+
!!! error TS4094: Property 'p' of exported class expression may not be private or protected.
10+
~~~~~~~~~~
11+
!!! error TS4094: Property 'ps' of exported class expression may not be private or protected.
12+
static getTags() { }
13+
tags() { }
14+
private static ps = -1
15+
private p = 12
16+
}
17+
18+
// altered repro from #15066 to add private property
19+
export class FooItem {
20+
foo(): void { }
21+
name?: string;
22+
private property = "capitalism"
23+
}
24+
25+
export type Constructor<T> = new(...args: any[]) => T;
26+
export function WithTags<T extends Constructor<FooItem>>(Base: T) {
27+
~~~~~~~~
28+
!!! error TS4094: Property 'property' of exported class expression may not be private or protected.
29+
return class extends Base {
30+
static getTags(): void { }
31+
tags(): void { }
32+
}
33+
}
34+
35+
export class Test extends WithTags(FooItem) {}
36+
37+
const test = new Test();
38+
39+
Test.getTags()
40+
test.tags();
41+
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//// [emitClassExpressionInDeclarationFile2.ts]
2+
export var noPrivates = class {
3+
static getTags() { }
4+
tags() { }
5+
private static ps = -1
6+
private p = 12
7+
}
8+
9+
// altered repro from #15066 to add private property
10+
export class FooItem {
11+
foo(): void { }
12+
name?: string;
13+
private property = "capitalism"
14+
}
15+
16+
export type Constructor<T> = new(...args: any[]) => T;
17+
export function WithTags<T extends Constructor<FooItem>>(Base: T) {
18+
return class extends Base {
19+
static getTags(): void { }
20+
tags(): void { }
21+
}
22+
}
23+
24+
export class Test extends WithTags(FooItem) {}
25+
26+
const test = new Test();
27+
28+
Test.getTags()
29+
test.tags();
30+
31+
32+
//// [emitClassExpressionInDeclarationFile2.js]
33+
"use strict";
34+
var __extends = (this && this.__extends) || (function () {
35+
var extendStatics = Object.setPrototypeOf ||
36+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
37+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
38+
return function (d, b) {
39+
extendStatics(d, b);
40+
function __() { this.constructor = d; }
41+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
42+
};
43+
})();
44+
exports.__esModule = true;
45+
exports.noPrivates = (_a = (function () {
46+
function class_1() {
47+
this.p = 12;
48+
}
49+
class_1.getTags = function () { };
50+
class_1.prototype.tags = function () { };
51+
return class_1;
52+
}()),
53+
_a.ps = -1,
54+
_a);
55+
// altered repro from #15066 to add private property
56+
var FooItem = (function () {
57+
function FooItem() {
58+
this.property = "capitalism";
59+
}
60+
FooItem.prototype.foo = function () { };
61+
return FooItem;
62+
}());
63+
exports.FooItem = FooItem;
64+
function WithTags(Base) {
65+
return (function (_super) {
66+
__extends(class_2, _super);
67+
function class_2() {
68+
return _super !== null && _super.apply(this, arguments) || this;
69+
}
70+
class_2.getTags = function () { };
71+
class_2.prototype.tags = function () { };
72+
return class_2;
73+
}(Base));
74+
}
75+
exports.WithTags = WithTags;
76+
var Test = (function (_super) {
77+
__extends(Test, _super);
78+
function Test() {
79+
return _super !== null && _super.apply(this, arguments) || this;
80+
}
81+
return Test;
82+
}(WithTags(FooItem)));
83+
exports.Test = Test;
84+
var test = new Test();
85+
Test.getTags();
86+
test.tags();
87+
var _a;

tests/cases/compiler/emitClassExpressionInDeclarationFile.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,12 @@
22
export var simpleExample = class {
33
static getTags() { }
44
tags() { }
5-
private static ps = -1
6-
private p = 12
75
}
86
export var circularReference = class C {
97
static getTags(c: C): C { return c }
108
tags(c: C): C { return c }
119
}
1210

13-
class Base { }
14-
export function foo() {
15-
return class extends Base { }
16-
}
17-
1811
// repro from #15066
1912
export class FooItem {
2013
foo(): void { }
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// @declaration: true
2+
export var noPrivates = class {
3+
static getTags() { }
4+
tags() { }
5+
private static ps = -1
6+
private p = 12
7+
}
8+
9+
// altered repro from #15066 to add private property
10+
export class FooItem {
11+
foo(): void { }
12+
name?: string;
13+
private property = "capitalism"
14+
}
15+
16+
export type Constructor<T> = new(...args: any[]) => T;
17+
export function WithTags<T extends Constructor<FooItem>>(Base: T) {
18+
return class extends Base {
19+
static getTags(): void { }
20+
tags(): void { }
21+
}
22+
}
23+
24+
export class Test extends WithTags(FooItem) {}
25+
26+
const test = new Test();
27+
28+
Test.getTags()
29+
test.tags();

0 commit comments

Comments
 (0)