Skip to content

Commit e3cc5e9

Browse files
committed
Double the test, double the fun
1 parent 4cb867b commit e3cc5e9

File tree

4 files changed

+207
-6
lines changed

4 files changed

+207
-6
lines changed

tests/baselines/reference/anonClassDeclarationEmitIsAnon.js

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,47 @@ export function wrapClass(param: any) {
88
}
99
}
1010
}
11+
12+
export type Constructor<T = {}> = new (...args: any[]) => T;
13+
14+
export function Timestamped<TBase extends Constructor>(Base: TBase) {
15+
return class extends Base {
16+
timestamp = Date.now();
17+
};
18+
}
1119

1220
//// [index.ts]
13-
import { wrapClass } from "./wrapClass";
21+
import { wrapClass, Timestamped } from "./wrapClass";
1422

15-
export default wrapClass(0);
23+
export default wrapClass(0);
24+
25+
// Simple class
26+
export class User {
27+
name = '';
28+
}
29+
30+
// User that is Timestamped
31+
export class TimestampedUser extends Timestamped(User) {
32+
constructor() {
33+
super();
34+
}
35+
}
1636

1737
//// [wrapClass.js]
1838
"use strict";
39+
var __extends = (this && this.__extends) || (function () {
40+
var extendStatics = function (d, b) {
41+
extendStatics = Object.setPrototypeOf ||
42+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
43+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
44+
return extendStatics(d, b);
45+
};
46+
return function (d, b) {
47+
extendStatics(d, b);
48+
function __() { this.constructor = d; }
49+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
50+
};
51+
})();
1952
exports.__esModule = true;
2053
function wrapClass(param) {
2154
return /** @class */ (function () {
@@ -28,11 +61,53 @@ function wrapClass(param) {
2861
}());
2962
}
3063
exports.wrapClass = wrapClass;
64+
function Timestamped(Base) {
65+
return /** @class */ (function (_super) {
66+
__extends(class_1, _super);
67+
function class_1() {
68+
var _this = _super !== null && _super.apply(this, arguments) || this;
69+
_this.timestamp = Date.now();
70+
return _this;
71+
}
72+
return class_1;
73+
}(Base));
74+
}
75+
exports.Timestamped = Timestamped;
3176
//// [index.js]
3277
"use strict";
78+
var __extends = (this && this.__extends) || (function () {
79+
var extendStatics = function (d, b) {
80+
extendStatics = Object.setPrototypeOf ||
81+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
82+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
83+
return extendStatics(d, b);
84+
};
85+
return function (d, b) {
86+
extendStatics(d, b);
87+
function __() { this.constructor = d; }
88+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
89+
};
90+
})();
3391
exports.__esModule = true;
3492
var wrapClass_1 = require("./wrapClass");
3593
exports["default"] = wrapClass_1.wrapClass(0);
94+
// Simple class
95+
var User = /** @class */ (function () {
96+
function User() {
97+
this.name = '';
98+
}
99+
return User;
100+
}());
101+
exports.User = User;
102+
// User that is Timestamped
103+
var TimestampedUser = /** @class */ (function (_super) {
104+
__extends(TimestampedUser, _super);
105+
function TimestampedUser() {
106+
return _super.call(this) || this;
107+
}
108+
return TimestampedUser;
109+
}(wrapClass_1.Timestamped(User)));
110+
exports.TimestampedUser = TimestampedUser;
36111

37112

38113
//// [wrapClass.d.ts]
@@ -41,10 +116,27 @@ export declare function wrapClass(param: any): {
41116
foo(): any;
42117
};
43118
};
119+
export declare type Constructor<T = {}> = new (...args: any[]) => T;
120+
export declare function Timestamped<TBase extends Constructor>(Base: TBase): {
121+
new (...args: any[]): {
122+
timestamp: number;
123+
};
124+
} & TBase;
44125
//// [index.d.ts]
45126
declare const _default: {
46127
new (): {
47128
foo(): any;
48129
};
49130
};
50131
export default _default;
132+
export declare class User {
133+
name: string;
134+
}
135+
declare const TimestampedUser_base: {
136+
new (...args: any[]): {
137+
timestamp: number;
138+
};
139+
} & typeof User;
140+
export declare class TimestampedUser extends TimestampedUser_base {
141+
constructor();
142+
}

tests/baselines/reference/anonClassDeclarationEmitIsAnon.symbols

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,54 @@ export function wrapClass(param: any) {
1515
}
1616
}
1717

18+
export type Constructor<T = {}> = new (...args: any[]) => T;
19+
>Constructor : Symbol(Constructor, Decl(wrapClass.ts, 6, 1))
20+
>T : Symbol(T, Decl(wrapClass.ts, 8, 24))
21+
>args : Symbol(args, Decl(wrapClass.ts, 8, 39))
22+
>T : Symbol(T, Decl(wrapClass.ts, 8, 24))
23+
24+
export function Timestamped<TBase extends Constructor>(Base: TBase) {
25+
>Timestamped : Symbol(Timestamped, Decl(wrapClass.ts, 8, 60))
26+
>TBase : Symbol(TBase, Decl(wrapClass.ts, 10, 28))
27+
>Constructor : Symbol(Constructor, Decl(wrapClass.ts, 6, 1))
28+
>Base : Symbol(Base, Decl(wrapClass.ts, 10, 55))
29+
>TBase : Symbol(TBase, Decl(wrapClass.ts, 10, 28))
30+
31+
return class extends Base {
32+
>Base : Symbol(Base, Decl(wrapClass.ts, 10, 55))
33+
34+
timestamp = Date.now();
35+
>timestamp : Symbol((Anonymous class).timestamp, Decl(wrapClass.ts, 11, 31))
36+
>Date.now : Symbol(DateConstructor.now, Decl(lib.es5.d.ts, --, --))
37+
>Date : Symbol(Date, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.scripthost.d.ts, --, --))
38+
>now : Symbol(DateConstructor.now, Decl(lib.es5.d.ts, --, --))
39+
40+
};
41+
}
42+
1843
=== tests/cases/compiler/index.ts ===
19-
import { wrapClass } from "./wrapClass";
44+
import { wrapClass, Timestamped } from "./wrapClass";
2045
>wrapClass : Symbol(wrapClass, Decl(index.ts, 0, 8))
46+
>Timestamped : Symbol(Timestamped, Decl(index.ts, 0, 19))
2147

2248
export default wrapClass(0);
2349
>wrapClass : Symbol(wrapClass, Decl(index.ts, 0, 8))
2450

51+
// Simple class
52+
export class User {
53+
>User : Symbol(User, Decl(index.ts, 2, 28))
54+
55+
name = '';
56+
>name : Symbol(User.name, Decl(index.ts, 5, 19))
57+
}
58+
59+
// User that is Timestamped
60+
export class TimestampedUser extends Timestamped(User) {
61+
>TimestampedUser : Symbol(TimestampedUser, Decl(index.ts, 7, 1))
62+
>Timestamped : Symbol(Timestamped, Decl(index.ts, 0, 19))
63+
>User : Symbol(User, Decl(index.ts, 2, 28))
64+
65+
constructor() {
66+
super();
67+
}
68+
}

tests/baselines/reference/anonClassDeclarationEmitIsAnon.types

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,57 @@ export function wrapClass(param: any) {
1616
}
1717
}
1818

19+
export type Constructor<T = {}> = new (...args: any[]) => T;
20+
>Constructor : Constructor<T>
21+
>args : any[]
22+
23+
export function Timestamped<TBase extends Constructor>(Base: TBase) {
24+
>Timestamped : <TBase extends Constructor<{}>>(Base: TBase) => { new (...args: any[]): (Anonymous class); prototype: Timestamped<any>.(Anonymous class); } & TBase
25+
>Base : TBase
26+
27+
return class extends Base {
28+
>class extends Base { timestamp = Date.now(); } : { new (...args: any[]): (Anonymous class); prototype: Timestamped<any>.(Anonymous class); } & TBase
29+
>Base : {}
30+
31+
timestamp = Date.now();
32+
>timestamp : number
33+
>Date.now() : number
34+
>Date.now : () => number
35+
>Date : DateConstructor
36+
>now : () => number
37+
38+
};
39+
}
40+
1941
=== tests/cases/compiler/index.ts ===
20-
import { wrapClass } from "./wrapClass";
42+
import { wrapClass, Timestamped } from "./wrapClass";
2143
>wrapClass : (param: any) => typeof Wrapped
44+
>Timestamped : <TBase extends import("tests/cases/compiler/wrapClass").Constructor<{}>>(Base: TBase) => { new (...args: any[]): (Anonymous class); prototype: Timestamped<any>.(Anonymous class); } & TBase
2245

2346
export default wrapClass(0);
2447
>wrapClass(0) : typeof Wrapped
2548
>wrapClass : (param: any) => typeof Wrapped
2649
>0 : 0
2750

51+
// Simple class
52+
export class User {
53+
>User : User
54+
55+
name = '';
56+
>name : string
57+
>'' : ""
58+
}
59+
60+
// User that is Timestamped
61+
export class TimestampedUser extends Timestamped(User) {
62+
>TimestampedUser : TimestampedUser
63+
>Timestamped(User) : Timestamped<typeof User>.(Anonymous class) & User
64+
>Timestamped : <TBase extends import("tests/cases/compiler/wrapClass").Constructor<{}>>(Base: TBase) => { new (...args: any[]): (Anonymous class); prototype: Timestamped<any>.(Anonymous class); } & TBase
65+
>User : typeof User
66+
67+
constructor() {
68+
super();
69+
>super() : void
70+
>super : { new (...args: any[]): Timestamped<typeof User>.(Anonymous class); prototype: Timestamped<any>.(Anonymous class); } & typeof User
71+
}
72+
}

tests/cases/compiler/anonClassDeclarationEmitIsAnon.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,27 @@ export function wrapClass(param: any) {
88
}
99
}
1010

11+
export type Constructor<T = {}> = new (...args: any[]) => T;
12+
13+
export function Timestamped<TBase extends Constructor>(Base: TBase) {
14+
return class extends Base {
15+
timestamp = Date.now();
16+
};
17+
}
18+
1119
// @filename: index.ts
12-
import { wrapClass } from "./wrapClass";
20+
import { wrapClass, Timestamped } from "./wrapClass";
21+
22+
export default wrapClass(0);
1323

14-
export default wrapClass(0);
24+
// Simple class
25+
export class User {
26+
name = '';
27+
}
28+
29+
// User that is Timestamped
30+
export class TimestampedUser extends Timestamped(User) {
31+
constructor() {
32+
super();
33+
}
34+
}

0 commit comments

Comments
 (0)