Skip to content

Commit aa6c0c6

Browse files
authored
Merge pull request #15194 from Microsoft/serializeTypeNode-handles-object
serializeTypeNode handles `object`
2 parents b5f37a1 + 9591876 commit aa6c0c6

File tree

5 files changed

+106
-0
lines changed

5 files changed

+106
-0
lines changed

src/compiler/transformers/ts.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,9 @@ namespace ts {
17071707
case SyntaxKind.StringKeyword:
17081708
return createIdentifier("String");
17091709

1710+
case SyntaxKind.ObjectKeyword:
1711+
return createIdentifier("Object");
1712+
17101713
case SyntaxKind.LiteralType:
17111714
switch ((<LiteralTypeNode>node).literal.kind) {
17121715
case SyntaxKind.StringLiteral:
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//// [emitDecoratorMetadata_object.ts]
2+
declare const MyClassDecorator: ClassDecorator;
3+
declare const MyMethodDecorator: MethodDecorator;
4+
5+
@MyClassDecorator
6+
class A {
7+
constructor(hi: object) {}
8+
@MyMethodDecorator
9+
method(there: object) {}
10+
}
11+
12+
13+
//// [emitDecoratorMetadata_object.js]
14+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
15+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
18+
return c > 3 && r && Object.defineProperty(target, key, r), r;
19+
};
20+
var __metadata = (this && this.__metadata) || function (k, v) {
21+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
22+
};
23+
var A = (function () {
24+
function A(hi) {
25+
}
26+
A.prototype.method = function (there) { };
27+
return A;
28+
}());
29+
__decorate([
30+
MyMethodDecorator,
31+
__metadata("design:type", Function),
32+
__metadata("design:paramtypes", [Object]),
33+
__metadata("design:returntype", void 0)
34+
], A.prototype, "method", null);
35+
A = __decorate([
36+
MyClassDecorator,
37+
__metadata("design:paramtypes", [Object])
38+
], A);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=== tests/cases/compiler/emitDecoratorMetadata_object.ts ===
2+
declare const MyClassDecorator: ClassDecorator;
3+
>MyClassDecorator : Symbol(MyClassDecorator, Decl(emitDecoratorMetadata_object.ts, 0, 13))
4+
>ClassDecorator : Symbol(ClassDecorator, Decl(lib.d.ts, --, --))
5+
6+
declare const MyMethodDecorator: MethodDecorator;
7+
>MyMethodDecorator : Symbol(MyMethodDecorator, Decl(emitDecoratorMetadata_object.ts, 1, 13))
8+
>MethodDecorator : Symbol(MethodDecorator, Decl(lib.d.ts, --, --))
9+
10+
@MyClassDecorator
11+
>MyClassDecorator : Symbol(MyClassDecorator, Decl(emitDecoratorMetadata_object.ts, 0, 13))
12+
13+
class A {
14+
>A : Symbol(A, Decl(emitDecoratorMetadata_object.ts, 1, 49))
15+
16+
constructor(hi: object) {}
17+
>hi : Symbol(hi, Decl(emitDecoratorMetadata_object.ts, 5, 16))
18+
19+
@MyMethodDecorator
20+
>MyMethodDecorator : Symbol(MyMethodDecorator, Decl(emitDecoratorMetadata_object.ts, 1, 13))
21+
22+
method(there: object) {}
23+
>method : Symbol(A.method, Decl(emitDecoratorMetadata_object.ts, 5, 30))
24+
>there : Symbol(there, Decl(emitDecoratorMetadata_object.ts, 7, 11))
25+
}
26+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=== tests/cases/compiler/emitDecoratorMetadata_object.ts ===
2+
declare const MyClassDecorator: ClassDecorator;
3+
>MyClassDecorator : ClassDecorator
4+
>ClassDecorator : ClassDecorator
5+
6+
declare const MyMethodDecorator: MethodDecorator;
7+
>MyMethodDecorator : MethodDecorator
8+
>MethodDecorator : MethodDecorator
9+
10+
@MyClassDecorator
11+
>MyClassDecorator : ClassDecorator
12+
13+
class A {
14+
>A : A
15+
16+
constructor(hi: object) {}
17+
>hi : object
18+
19+
@MyMethodDecorator
20+
>MyMethodDecorator : MethodDecorator
21+
22+
method(there: object) {}
23+
>method : (there: object) => void
24+
>there : object
25+
}
26+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @experimentaldecorators: true
2+
// @emitdecoratormetadata: true
3+
// @target: ES5
4+
5+
declare const MyClassDecorator: ClassDecorator;
6+
declare const MyMethodDecorator: MethodDecorator;
7+
8+
@MyClassDecorator
9+
class A {
10+
constructor(hi: object) {}
11+
@MyMethodDecorator
12+
method(there: object) {}
13+
}

0 commit comments

Comments
 (0)