Test that emitter skips this with rest parameter

Also test that it's skipped when emitting decorator metadata
This commit is contained in:
Nathan Shively-Sanders 2016-07-13 11:43:28 -07:00
parent 5768b42bfa
commit 97e4578b74
8 changed files with 85 additions and 6 deletions

View File

@ -14,7 +14,7 @@ class A {
class B {
constructor(...args: number[]) {}
@MyMethodDecorator
method(...args: string[]) {}
method(this: this, ...args: string[]) {}
}

View File

@ -37,8 +37,9 @@ class B {
@MyMethodDecorator
>MyMethodDecorator : Symbol(MyMethodDecorator, Decl(emitDecoratorMetadata_restArgs.ts, 2, 13))
method(...args: string[]) {}
method(this: this, ...args: string[]) {}
>method : Symbol(B.method, Decl(emitDecoratorMetadata_restArgs.ts, 13, 37))
>args : Symbol(args, Decl(emitDecoratorMetadata_restArgs.ts, 15, 11))
>this : Symbol(this, Decl(emitDecoratorMetadata_restArgs.ts, 15, 11))
>args : Symbol(args, Decl(emitDecoratorMetadata_restArgs.ts, 15, 22))
}

View File

@ -37,8 +37,9 @@ class B {
@MyMethodDecorator
>MyMethodDecorator : <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void
method(...args: string[]) {}
>method : (...args: string[]) => void
method(this: this, ...args: string[]) {}
>method : (this: this, ...args: string[]) => void
>this : this
>args : string[]
}

View File

@ -0,0 +1,18 @@
//// [emitSkipsThisWithRestParameter.ts]
function rebase(fn: (base: any, ...args: any[]) => any): (...args: any[]) => any {
return function(this: any, ...args: any[]) {
return fn.apply(this, [ this ].concat(args));
};
}
//// [emitSkipsThisWithRestParameter.js]
function rebase(fn) {
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
return fn.apply(this, [this].concat(args));
};
}

View File

@ -0,0 +1,25 @@
=== tests/cases/compiler/emitSkipsThisWithRestParameter.ts ===
function rebase(fn: (base: any, ...args: any[]) => any): (...args: any[]) => any {
>rebase : Symbol(rebase, Decl(emitSkipsThisWithRestParameter.ts, 0, 0))
>fn : Symbol(fn, Decl(emitSkipsThisWithRestParameter.ts, 0, 16))
>base : Symbol(base, Decl(emitSkipsThisWithRestParameter.ts, 0, 21))
>args : Symbol(args, Decl(emitSkipsThisWithRestParameter.ts, 0, 31))
>args : Symbol(args, Decl(emitSkipsThisWithRestParameter.ts, 0, 58))
return function(this: any, ...args: any[]) {
>this : Symbol(this, Decl(emitSkipsThisWithRestParameter.ts, 1, 20))
>args : Symbol(args, Decl(emitSkipsThisWithRestParameter.ts, 1, 30))
return fn.apply(this, [ this ].concat(args));
>fn.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --))
>fn : Symbol(fn, Decl(emitSkipsThisWithRestParameter.ts, 0, 16))
>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --))
>this : Symbol(this, Decl(emitSkipsThisWithRestParameter.ts, 1, 20))
>[ this ].concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
>this : Symbol(this, Decl(emitSkipsThisWithRestParameter.ts, 1, 20))
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
>args : Symbol(args, Decl(emitSkipsThisWithRestParameter.ts, 1, 30))
};
}

View File

@ -0,0 +1,29 @@
=== tests/cases/compiler/emitSkipsThisWithRestParameter.ts ===
function rebase(fn: (base: any, ...args: any[]) => any): (...args: any[]) => any {
>rebase : (fn: (base: any, ...args: any[]) => any) => (...args: any[]) => any
>fn : (base: any, ...args: any[]) => any
>base : any
>args : any[]
>args : any[]
return function(this: any, ...args: any[]) {
>function(this: any, ...args: any[]) { return fn.apply(this, [ this ].concat(args)); } : (this: any, ...args: any[]) => any
>this : any
>args : any[]
return fn.apply(this, [ this ].concat(args));
>fn.apply(this, [ this ].concat(args)) : any
>fn.apply : (this: Function, thisArg: any, argArray?: any) => any
>fn : (base: any, ...args: any[]) => any
>apply : (this: Function, thisArg: any, argArray?: any) => any
>this : any
>[ this ].concat(args) : any[]
>[ this ].concat : (...items: any[]) => any[]
>[ this ] : any[]
>this : any
>concat : (...items: any[]) => any[]
>args : any[]
};
}

View File

@ -16,5 +16,5 @@ class A {
class B {
constructor(...args: number[]) {}
@MyMethodDecorator
method(...args: string[]) {}
method(this: this, ...args: string[]) {}
}

View File

@ -0,0 +1,5 @@
function rebase(fn: (base: any, ...args: any[]) => any): (...args: any[]) => any {
return function(this: any, ...args: any[]) {
return fn.apply(this, [ this ].concat(args));
};
}