Skip to content

Commit 27948b1

Browse files
committed
Add test for class+namespace merging
1 parent c7008df commit 27948b1

4 files changed

+140
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//// [esDecorators-classDeclaration-commonjs-classNamespaceMerge.ts]
2+
declare var deco: any;
3+
4+
@deco
5+
export class Example {
6+
static foo() {}
7+
}
8+
9+
export namespace Example {
10+
export const x = 1;
11+
}
12+
13+
Example.foo();
14+
15+
//// [esDecorators-classDeclaration-commonjs-classNamespaceMerge.js]
16+
"use strict";
17+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
18+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
19+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
20+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
21+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
22+
var _, done = false;
23+
for (var i = decorators.length - 1; i >= 0; i--) {
24+
var context = {};
25+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
26+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
27+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
28+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
29+
if (kind === "accessor") {
30+
if (result === void 0) continue;
31+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
32+
if (_ = accept(result.get)) descriptor.get = _;
33+
if (_ = accept(result.set)) descriptor.set = _;
34+
if (_ = accept(result.init)) initializers.push(_);
35+
}
36+
else if (_ = accept(result)) {
37+
if (kind === "field") initializers.push(_);
38+
else descriptor[key] = _;
39+
}
40+
}
41+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
42+
done = true;
43+
};
44+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
45+
var useValue = arguments.length > 2;
46+
for (var i = 0; i < initializers.length; i++) {
47+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
48+
}
49+
return useValue ? value : void 0;
50+
};
51+
Object.defineProperty(exports, "__esModule", { value: true });
52+
exports.Example = void 0;
53+
let Example = exports.Example = (() => {
54+
let _classDecorators = [deco];
55+
let _classDescriptor;
56+
let _classExtraInitializers = [];
57+
let _classThis;
58+
var Example = class {
59+
static {
60+
__esDecorate(null, _classDescriptor = { value: this }, _classDecorators, { kind: "class", name: this.name }, null, _classExtraInitializers);
61+
Example = _classThis = _classDescriptor.value;
62+
__runInitializers(_classThis, _classExtraInitializers);
63+
}
64+
static foo() { }
65+
};
66+
return Example = _classThis;
67+
})();
68+
(function (Example) {
69+
Example.x = 1;
70+
})(Example = exports.Example || (exports.Example = {}));
71+
Example.foo();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=== tests/cases/conformance/esDecorators/classDeclaration/esDecorators-classDeclaration-commonjs-classNamespaceMerge.ts ===
2+
declare var deco: any;
3+
>deco : Symbol(deco, Decl(esDecorators-classDeclaration-commonjs-classNamespaceMerge.ts, 0, 11))
4+
5+
@deco
6+
>deco : Symbol(deco, Decl(esDecorators-classDeclaration-commonjs-classNamespaceMerge.ts, 0, 11))
7+
8+
export class Example {
9+
>Example : Symbol(Example, Decl(esDecorators-classDeclaration-commonjs-classNamespaceMerge.ts, 0, 22), Decl(esDecorators-classDeclaration-commonjs-classNamespaceMerge.ts, 5, 1))
10+
11+
static foo() {}
12+
>foo : Symbol(Example.foo, Decl(esDecorators-classDeclaration-commonjs-classNamespaceMerge.ts, 3, 22))
13+
}
14+
15+
export namespace Example {
16+
>Example : Symbol(Example, Decl(esDecorators-classDeclaration-commonjs-classNamespaceMerge.ts, 0, 22), Decl(esDecorators-classDeclaration-commonjs-classNamespaceMerge.ts, 5, 1))
17+
18+
export const x = 1;
19+
>x : Symbol(x, Decl(esDecorators-classDeclaration-commonjs-classNamespaceMerge.ts, 8, 16))
20+
}
21+
22+
Example.foo();
23+
>Example.foo : Symbol(Example.foo, Decl(esDecorators-classDeclaration-commonjs-classNamespaceMerge.ts, 3, 22))
24+
>Example : Symbol(Example, Decl(esDecorators-classDeclaration-commonjs-classNamespaceMerge.ts, 0, 22), Decl(esDecorators-classDeclaration-commonjs-classNamespaceMerge.ts, 5, 1))
25+
>foo : Symbol(Example.foo, Decl(esDecorators-classDeclaration-commonjs-classNamespaceMerge.ts, 3, 22))
26+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
=== tests/cases/conformance/esDecorators/classDeclaration/esDecorators-classDeclaration-commonjs-classNamespaceMerge.ts ===
2+
declare var deco: any;
3+
>deco : any
4+
5+
@deco
6+
>deco : any
7+
8+
export class Example {
9+
>Example : Example
10+
11+
static foo() {}
12+
>foo : () => void
13+
}
14+
15+
export namespace Example {
16+
>Example : typeof Example
17+
18+
export const x = 1;
19+
>x : 1
20+
>1 : 1
21+
}
22+
23+
Example.foo();
24+
>Example.foo() : void
25+
>Example.foo : () => void
26+
>Example : typeof Example
27+
>foo : () => void
28+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @target: es2022
2+
// @module: commonjs
3+
4+
declare var deco: any;
5+
6+
@deco
7+
export class Example {
8+
static foo() {}
9+
}
10+
11+
export namespace Example {
12+
export const x = 1;
13+
}
14+
15+
Example.foo();

0 commit comments

Comments
 (0)