diff --git a/tests/baselines/reference/emitDecoratorMetadata_restArgs.js b/tests/baselines/reference/emitDecoratorMetadata_restArgs.js index 35350c54e0a..6ca7e40d413 100644 --- a/tests/baselines/reference/emitDecoratorMetadata_restArgs.js +++ b/tests/baselines/reference/emitDecoratorMetadata_restArgs.js @@ -14,7 +14,7 @@ class A { class B { constructor(...args: number[]) {} @MyMethodDecorator - method(...args: string[]) {} + method(this: this, ...args: string[]) {} } diff --git a/tests/baselines/reference/emitDecoratorMetadata_restArgs.symbols b/tests/baselines/reference/emitDecoratorMetadata_restArgs.symbols index b665b778f86..29ccb8b2711 100644 --- a/tests/baselines/reference/emitDecoratorMetadata_restArgs.symbols +++ b/tests/baselines/reference/emitDecoratorMetadata_restArgs.symbols @@ -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)) } diff --git a/tests/baselines/reference/emitDecoratorMetadata_restArgs.types b/tests/baselines/reference/emitDecoratorMetadata_restArgs.types index 4820d3a7d8d..e08261e4503 100644 --- a/tests/baselines/reference/emitDecoratorMetadata_restArgs.types +++ b/tests/baselines/reference/emitDecoratorMetadata_restArgs.types @@ -37,8 +37,9 @@ class B { @MyMethodDecorator >MyMethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void - method(...args: string[]) {} ->method : (...args: string[]) => void + method(this: this, ...args: string[]) {} +>method : (this: this, ...args: string[]) => void +>this : this >args : string[] } diff --git a/tests/baselines/reference/emitSkipsThisWithRestParameter.js b/tests/baselines/reference/emitSkipsThisWithRestParameter.js new file mode 100644 index 00000000000..d1e99f9409d --- /dev/null +++ b/tests/baselines/reference/emitSkipsThisWithRestParameter.js @@ -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)); + }; +} diff --git a/tests/baselines/reference/emitSkipsThisWithRestParameter.symbols b/tests/baselines/reference/emitSkipsThisWithRestParameter.symbols new file mode 100644 index 00000000000..4f1e2bc1aec --- /dev/null +++ b/tests/baselines/reference/emitSkipsThisWithRestParameter.symbols @@ -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)) + + }; +} + diff --git a/tests/baselines/reference/emitSkipsThisWithRestParameter.types b/tests/baselines/reference/emitSkipsThisWithRestParameter.types new file mode 100644 index 00000000000..97276fa117d --- /dev/null +++ b/tests/baselines/reference/emitSkipsThisWithRestParameter.types @@ -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[] + + }; +} + diff --git a/tests/cases/compiler/emitDecoratorMetadata_restArgs.ts b/tests/cases/compiler/emitDecoratorMetadata_restArgs.ts index 6b0741e2205..f58e9b704d4 100644 --- a/tests/cases/compiler/emitDecoratorMetadata_restArgs.ts +++ b/tests/cases/compiler/emitDecoratorMetadata_restArgs.ts @@ -16,5 +16,5 @@ class A { class B { constructor(...args: number[]) {} @MyMethodDecorator - method(...args: string[]) {} + method(this: this, ...args: string[]) {} } diff --git a/tests/cases/compiler/emitSkipsThisWithRestParameter.ts b/tests/cases/compiler/emitSkipsThisWithRestParameter.ts new file mode 100644 index 00000000000..09411a28cd2 --- /dev/null +++ b/tests/cases/compiler/emitSkipsThisWithRestParameter.ts @@ -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)); + }; +}