Skip to content

Commit 2cc040c

Browse files
committed
Test that emitter skips this with rest parameter
Also test that it's skipped when emitting decorator metadata
1 parent 5efbf61 commit 2cc040c

8 files changed

+85
-6
lines changed

tests/baselines/reference/emitDecoratorMetadata_restArgs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class A {
1414
class B {
1515
constructor(...args: number[]) {}
1616
@MyMethodDecorator
17-
method(...args: string[]) {}
17+
method(this: this, ...args: string[]) {}
1818
}
1919

2020

tests/baselines/reference/emitDecoratorMetadata_restArgs.symbols

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ class B {
3737
@MyMethodDecorator
3838
>MyMethodDecorator : Symbol(MyMethodDecorator, Decl(emitDecoratorMetadata_restArgs.ts, 2, 13))
3939

40-
method(...args: string[]) {}
40+
method(this: this, ...args: string[]) {}
4141
>method : Symbol(B.method, Decl(emitDecoratorMetadata_restArgs.ts, 13, 37))
42-
>args : Symbol(args, Decl(emitDecoratorMetadata_restArgs.ts, 15, 11))
42+
>this : Symbol(this, Decl(emitDecoratorMetadata_restArgs.ts, 15, 11))
43+
>args : Symbol(args, Decl(emitDecoratorMetadata_restArgs.ts, 15, 22))
4344
}
4445

tests/baselines/reference/emitDecoratorMetadata_restArgs.types

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ class B {
3737
@MyMethodDecorator
3838
>MyMethodDecorator : <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void
3939

40-
method(...args: string[]) {}
41-
>method : (...args: string[]) => void
40+
method(this: this, ...args: string[]) {}
41+
>method : (this: this, ...args: string[]) => void
42+
>this : this
4243
>args : string[]
4344
}
4445

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [emitSkipsThisWithRestParameter.ts]
2+
function rebase(fn: (base: any, ...args: any[]) => any): (...args: any[]) => any {
3+
return function(this: any, ...args: any[]) {
4+
return fn.apply(this, [ this ].concat(args));
5+
};
6+
}
7+
8+
9+
//// [emitSkipsThisWithRestParameter.js]
10+
function rebase(fn) {
11+
return function () {
12+
var args = [];
13+
for (var _i = 0; _i < arguments.length; _i++) {
14+
args[_i - 0] = arguments[_i];
15+
}
16+
return fn.apply(this, [this].concat(args));
17+
};
18+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== tests/cases/compiler/emitSkipsThisWithRestParameter.ts ===
2+
function rebase(fn: (base: any, ...args: any[]) => any): (...args: any[]) => any {
3+
>rebase : Symbol(rebase, Decl(emitSkipsThisWithRestParameter.ts, 0, 0))
4+
>fn : Symbol(fn, Decl(emitSkipsThisWithRestParameter.ts, 0, 16))
5+
>base : Symbol(base, Decl(emitSkipsThisWithRestParameter.ts, 0, 21))
6+
>args : Symbol(args, Decl(emitSkipsThisWithRestParameter.ts, 0, 31))
7+
>args : Symbol(args, Decl(emitSkipsThisWithRestParameter.ts, 0, 58))
8+
9+
return function(this: any, ...args: any[]) {
10+
>this : Symbol(this, Decl(emitSkipsThisWithRestParameter.ts, 1, 20))
11+
>args : Symbol(args, Decl(emitSkipsThisWithRestParameter.ts, 1, 30))
12+
13+
return fn.apply(this, [ this ].concat(args));
14+
>fn.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --))
15+
>fn : Symbol(fn, Decl(emitSkipsThisWithRestParameter.ts, 0, 16))
16+
>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --))
17+
>this : Symbol(this, Decl(emitSkipsThisWithRestParameter.ts, 1, 20))
18+
>[ this ].concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
19+
>this : Symbol(this, Decl(emitSkipsThisWithRestParameter.ts, 1, 20))
20+
>concat : Symbol(Array.concat, Decl(lib.d.ts, --, --))
21+
>args : Symbol(args, Decl(emitSkipsThisWithRestParameter.ts, 1, 30))
22+
23+
};
24+
}
25+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/compiler/emitSkipsThisWithRestParameter.ts ===
2+
function rebase(fn: (base: any, ...args: any[]) => any): (...args: any[]) => any {
3+
>rebase : (fn: (base: any, ...args: any[]) => any) => (...args: any[]) => any
4+
>fn : (base: any, ...args: any[]) => any
5+
>base : any
6+
>args : any[]
7+
>args : any[]
8+
9+
return function(this: any, ...args: any[]) {
10+
>function(this: any, ...args: any[]) { return fn.apply(this, [ this ].concat(args)); } : (this: any, ...args: any[]) => any
11+
>this : any
12+
>args : any[]
13+
14+
return fn.apply(this, [ this ].concat(args));
15+
>fn.apply(this, [ this ].concat(args)) : any
16+
>fn.apply : (this: Function, thisArg: any, argArray?: any) => any
17+
>fn : (base: any, ...args: any[]) => any
18+
>apply : (this: Function, thisArg: any, argArray?: any) => any
19+
>this : any
20+
>[ this ].concat(args) : any[]
21+
>[ this ].concat : (...items: any[]) => any[]
22+
>[ this ] : any[]
23+
>this : any
24+
>concat : (...items: any[]) => any[]
25+
>args : any[]
26+
27+
};
28+
}
29+

tests/cases/compiler/emitDecoratorMetadata_restArgs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ class A {
1616
class B {
1717
constructor(...args: number[]) {}
1818
@MyMethodDecorator
19-
method(...args: string[]) {}
19+
method(this: this, ...args: string[]) {}
2020
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function rebase(fn: (base: any, ...args: any[]) => any): (...args: any[]) => any {
2+
return function(this: any, ...args: any[]) {
3+
return fn.apply(this, [ this ].concat(args));
4+
};
5+
}

0 commit comments

Comments
 (0)