Skip to content

Fix decorator metadata emit for rest arg with no type #9144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Jun 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6133,10 +6133,10 @@ const _super = (function (geti, seti) {

if (parameters[i].dotDotDotToken) {
let parameterType = parameters[i].type;
if (parameterType.kind === SyntaxKind.ArrayType) {
if (parameterType && parameterType.kind === SyntaxKind.ArrayType) {
parameterType = (<ArrayTypeNode>parameterType).elementType;
}
else if (parameterType.kind === SyntaxKind.TypeReference && (<TypeReferenceNode>parameterType).typeArguments && (<TypeReferenceNode>parameterType).typeArguments.length === 1) {
else if (parameterType && parameterType.kind === SyntaxKind.TypeReference && (<TypeReferenceNode>parameterType).typeArguments && (<TypeReferenceNode>parameterType).typeArguments.length === 1) {
parameterType = (<TypeReferenceNode>parameterType).typeArguments[0];
}
else {
Expand Down
80 changes: 80 additions & 0 deletions tests/baselines/reference/emitDecoratorMetadata_restArgs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//// [emitDecoratorMetadata_restArgs.ts]

declare const MyClassDecorator: ClassDecorator;
declare const MyMethodDecorator: MethodDecorator;

@MyClassDecorator
class A {
constructor(...args) {}
@MyMethodDecorator
method(...args) {}
}

@MyClassDecorator
class B {
constructor(...args: number[]) {}
@MyMethodDecorator
method(...args: string[]) {}
}


//// [emitDecoratorMetadata_restArgs.js]
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var A = (function () {
function A() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
}
A.prototype.method = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
};
__decorate([
MyMethodDecorator,
__metadata('design:type', Function),
__metadata('design:paramtypes', [Object]),
__metadata('design:returntype', void 0)
], A.prototype, "method", null);
A = __decorate([
MyClassDecorator,
__metadata('design:paramtypes', [Object])
], A);
return A;
}());
var B = (function () {
function B() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
}
B.prototype.method = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
};
__decorate([
MyMethodDecorator,
__metadata('design:type', Function),
__metadata('design:paramtypes', [String]),
__metadata('design:returntype', void 0)
], B.prototype, "method", null);
B = __decorate([
MyClassDecorator,
__metadata('design:paramtypes', [Number])
], B);
return B;
}());
44 changes: 44 additions & 0 deletions tests/baselines/reference/emitDecoratorMetadata_restArgs.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
=== tests/cases/compiler/emitDecoratorMetadata_restArgs.ts ===

declare const MyClassDecorator: ClassDecorator;
>MyClassDecorator : Symbol(MyClassDecorator, Decl(emitDecoratorMetadata_restArgs.ts, 1, 13))
>ClassDecorator : Symbol(ClassDecorator, Decl(lib.d.ts, --, --))

declare const MyMethodDecorator: MethodDecorator;
>MyMethodDecorator : Symbol(MyMethodDecorator, Decl(emitDecoratorMetadata_restArgs.ts, 2, 13))
>MethodDecorator : Symbol(MethodDecorator, Decl(lib.d.ts, --, --))

@MyClassDecorator
>MyClassDecorator : Symbol(MyClassDecorator, Decl(emitDecoratorMetadata_restArgs.ts, 1, 13))

class A {
>A : Symbol(A, Decl(emitDecoratorMetadata_restArgs.ts, 2, 49))

constructor(...args) {}
>args : Symbol(args, Decl(emitDecoratorMetadata_restArgs.ts, 6, 16))

@MyMethodDecorator
>MyMethodDecorator : Symbol(MyMethodDecorator, Decl(emitDecoratorMetadata_restArgs.ts, 2, 13))

method(...args) {}
>method : Symbol(A.method, Decl(emitDecoratorMetadata_restArgs.ts, 6, 27))
>args : Symbol(args, Decl(emitDecoratorMetadata_restArgs.ts, 8, 11))
}

@MyClassDecorator
>MyClassDecorator : Symbol(MyClassDecorator, Decl(emitDecoratorMetadata_restArgs.ts, 1, 13))

class B {
>B : Symbol(B, Decl(emitDecoratorMetadata_restArgs.ts, 9, 1))

constructor(...args: number[]) {}
>args : Symbol(args, Decl(emitDecoratorMetadata_restArgs.ts, 13, 16))

@MyMethodDecorator
>MyMethodDecorator : Symbol(MyMethodDecorator, Decl(emitDecoratorMetadata_restArgs.ts, 2, 13))

method(...args: string[]) {}
>method : Symbol(B.method, Decl(emitDecoratorMetadata_restArgs.ts, 13, 37))
>args : Symbol(args, Decl(emitDecoratorMetadata_restArgs.ts, 15, 11))
}

44 changes: 44 additions & 0 deletions tests/baselines/reference/emitDecoratorMetadata_restArgs.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
=== tests/cases/compiler/emitDecoratorMetadata_restArgs.ts ===

declare const MyClassDecorator: ClassDecorator;
>MyClassDecorator : <TFunction extends Function>(target: TFunction) => TFunction | void
>ClassDecorator : <TFunction extends Function>(target: TFunction) => TFunction | void

declare const MyMethodDecorator: MethodDecorator;
>MyMethodDecorator : <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void
>MethodDecorator : <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void

@MyClassDecorator
>MyClassDecorator : <TFunction extends Function>(target: TFunction) => TFunction | void

class A {
>A : A

constructor(...args) {}
>args : any[]

@MyMethodDecorator
>MyMethodDecorator : <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void

method(...args) {}
>method : (...args: any[]) => void
>args : any[]
}

@MyClassDecorator
>MyClassDecorator : <TFunction extends Function>(target: TFunction) => TFunction | void

class B {
>B : B

constructor(...args: number[]) {}
>args : number[]

@MyMethodDecorator
>MyMethodDecorator : <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void

method(...args: string[]) {}
>method : (...args: string[]) => void
>args : string[]
}

20 changes: 20 additions & 0 deletions tests/cases/compiler/emitDecoratorMetadata_restArgs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @experimentaldecorators: true
// @emitdecoratormetadata: true
// @target: ES5

declare const MyClassDecorator: ClassDecorator;
declare const MyMethodDecorator: MethodDecorator;

@MyClassDecorator
class A {
constructor(...args) {}
@MyMethodDecorator
method(...args) {}
}

@MyClassDecorator
class B {
constructor(...args: number[]) {}
@MyMethodDecorator
method(...args: string[]) {}
}