Skip to content

Commit b92a8f2

Browse files
author
Andy
authored
Merge pull request #9144 from Microsoft/decorator_metadata_rest_parameter
Fix decorator metadata emit for rest arg with no type
2 parents 6eaf7fa + c0c707c commit b92a8f2

File tree

5 files changed

+190
-2
lines changed

5 files changed

+190
-2
lines changed

src/compiler/emitter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6133,10 +6133,10 @@ const _super = (function (geti, seti) {
61336133

61346134
if (parameters[i].dotDotDotToken) {
61356135
let parameterType = parameters[i].type;
6136-
if (parameterType.kind === SyntaxKind.ArrayType) {
6136+
if (parameterType && parameterType.kind === SyntaxKind.ArrayType) {
61376137
parameterType = (<ArrayTypeNode>parameterType).elementType;
61386138
}
6139-
else if (parameterType.kind === SyntaxKind.TypeReference && (<TypeReferenceNode>parameterType).typeArguments && (<TypeReferenceNode>parameterType).typeArguments.length === 1) {
6139+
else if (parameterType && parameterType.kind === SyntaxKind.TypeReference && (<TypeReferenceNode>parameterType).typeArguments && (<TypeReferenceNode>parameterType).typeArguments.length === 1) {
61406140
parameterType = (<TypeReferenceNode>parameterType).typeArguments[0];
61416141
}
61426142
else {
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//// [emitDecoratorMetadata_restArgs.ts]
2+
3+
declare const MyClassDecorator: ClassDecorator;
4+
declare const MyMethodDecorator: MethodDecorator;
5+
6+
@MyClassDecorator
7+
class A {
8+
constructor(...args) {}
9+
@MyMethodDecorator
10+
method(...args) {}
11+
}
12+
13+
@MyClassDecorator
14+
class B {
15+
constructor(...args: number[]) {}
16+
@MyMethodDecorator
17+
method(...args: string[]) {}
18+
}
19+
20+
21+
//// [emitDecoratorMetadata_restArgs.js]
22+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
23+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
24+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
25+
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;
26+
return c > 3 && r && Object.defineProperty(target, key, r), r;
27+
};
28+
var __metadata = (this && this.__metadata) || function (k, v) {
29+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
30+
};
31+
var A = (function () {
32+
function A() {
33+
var args = [];
34+
for (var _i = 0; _i < arguments.length; _i++) {
35+
args[_i - 0] = arguments[_i];
36+
}
37+
}
38+
A.prototype.method = function () {
39+
var args = [];
40+
for (var _i = 0; _i < arguments.length; _i++) {
41+
args[_i - 0] = arguments[_i];
42+
}
43+
};
44+
__decorate([
45+
MyMethodDecorator,
46+
__metadata('design:type', Function),
47+
__metadata('design:paramtypes', [Object]),
48+
__metadata('design:returntype', void 0)
49+
], A.prototype, "method", null);
50+
A = __decorate([
51+
MyClassDecorator,
52+
__metadata('design:paramtypes', [Object])
53+
], A);
54+
return A;
55+
}());
56+
var B = (function () {
57+
function B() {
58+
var args = [];
59+
for (var _i = 0; _i < arguments.length; _i++) {
60+
args[_i - 0] = arguments[_i];
61+
}
62+
}
63+
B.prototype.method = function () {
64+
var args = [];
65+
for (var _i = 0; _i < arguments.length; _i++) {
66+
args[_i - 0] = arguments[_i];
67+
}
68+
};
69+
__decorate([
70+
MyMethodDecorator,
71+
__metadata('design:type', Function),
72+
__metadata('design:paramtypes', [String]),
73+
__metadata('design:returntype', void 0)
74+
], B.prototype, "method", null);
75+
B = __decorate([
76+
MyClassDecorator,
77+
__metadata('design:paramtypes', [Number])
78+
], B);
79+
return B;
80+
}());
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
=== tests/cases/compiler/emitDecoratorMetadata_restArgs.ts ===
2+
3+
declare const MyClassDecorator: ClassDecorator;
4+
>MyClassDecorator : Symbol(MyClassDecorator, Decl(emitDecoratorMetadata_restArgs.ts, 1, 13))
5+
>ClassDecorator : Symbol(ClassDecorator, Decl(lib.d.ts, --, --))
6+
7+
declare const MyMethodDecorator: MethodDecorator;
8+
>MyMethodDecorator : Symbol(MyMethodDecorator, Decl(emitDecoratorMetadata_restArgs.ts, 2, 13))
9+
>MethodDecorator : Symbol(MethodDecorator, Decl(lib.d.ts, --, --))
10+
11+
@MyClassDecorator
12+
>MyClassDecorator : Symbol(MyClassDecorator, Decl(emitDecoratorMetadata_restArgs.ts, 1, 13))
13+
14+
class A {
15+
>A : Symbol(A, Decl(emitDecoratorMetadata_restArgs.ts, 2, 49))
16+
17+
constructor(...args) {}
18+
>args : Symbol(args, Decl(emitDecoratorMetadata_restArgs.ts, 6, 16))
19+
20+
@MyMethodDecorator
21+
>MyMethodDecorator : Symbol(MyMethodDecorator, Decl(emitDecoratorMetadata_restArgs.ts, 2, 13))
22+
23+
method(...args) {}
24+
>method : Symbol(A.method, Decl(emitDecoratorMetadata_restArgs.ts, 6, 27))
25+
>args : Symbol(args, Decl(emitDecoratorMetadata_restArgs.ts, 8, 11))
26+
}
27+
28+
@MyClassDecorator
29+
>MyClassDecorator : Symbol(MyClassDecorator, Decl(emitDecoratorMetadata_restArgs.ts, 1, 13))
30+
31+
class B {
32+
>B : Symbol(B, Decl(emitDecoratorMetadata_restArgs.ts, 9, 1))
33+
34+
constructor(...args: number[]) {}
35+
>args : Symbol(args, Decl(emitDecoratorMetadata_restArgs.ts, 13, 16))
36+
37+
@MyMethodDecorator
38+
>MyMethodDecorator : Symbol(MyMethodDecorator, Decl(emitDecoratorMetadata_restArgs.ts, 2, 13))
39+
40+
method(...args: string[]) {}
41+
>method : Symbol(B.method, Decl(emitDecoratorMetadata_restArgs.ts, 13, 37))
42+
>args : Symbol(args, Decl(emitDecoratorMetadata_restArgs.ts, 15, 11))
43+
}
44+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
=== tests/cases/compiler/emitDecoratorMetadata_restArgs.ts ===
2+
3+
declare const MyClassDecorator: ClassDecorator;
4+
>MyClassDecorator : <TFunction extends Function>(target: TFunction) => TFunction | void
5+
>ClassDecorator : <TFunction extends Function>(target: TFunction) => TFunction | void
6+
7+
declare const MyMethodDecorator: MethodDecorator;
8+
>MyMethodDecorator : <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void
9+
>MethodDecorator : <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void
10+
11+
@MyClassDecorator
12+
>MyClassDecorator : <TFunction extends Function>(target: TFunction) => TFunction | void
13+
14+
class A {
15+
>A : A
16+
17+
constructor(...args) {}
18+
>args : any[]
19+
20+
@MyMethodDecorator
21+
>MyMethodDecorator : <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void
22+
23+
method(...args) {}
24+
>method : (...args: any[]) => void
25+
>args : any[]
26+
}
27+
28+
@MyClassDecorator
29+
>MyClassDecorator : <TFunction extends Function>(target: TFunction) => TFunction | void
30+
31+
class B {
32+
>B : B
33+
34+
constructor(...args: number[]) {}
35+
>args : number[]
36+
37+
@MyMethodDecorator
38+
>MyMethodDecorator : <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void
39+
40+
method(...args: string[]) {}
41+
>method : (...args: string[]) => void
42+
>args : string[]
43+
}
44+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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(...args) {}
11+
@MyMethodDecorator
12+
method(...args) {}
13+
}
14+
15+
@MyClassDecorator
16+
class B {
17+
constructor(...args: number[]) {}
18+
@MyMethodDecorator
19+
method(...args: string[]) {}
20+
}

0 commit comments

Comments
 (0)