Skip to content

Commit 635780d

Browse files
committed
ArrowFunction has no own 'arguments'
Fixes: microsoft#28621
1 parent 94d7e30 commit 635780d

File tree

34 files changed

+155
-73
lines changed

34 files changed

+155
-73
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,12 +1419,18 @@ namespace ts {
14191419
}
14201420
}
14211421
break;
1422+
case SyntaxKind.ArrowFunction:
1423+
// when targeting ES6 or higher there is no 'arguments' in an arrow function
1424+
// for lower compile targets the resolved symbol is used to emit an error
1425+
if (compilerOptions.target! >= ScriptTarget.ES2015) {
1426+
break;
1427+
}
1428+
// falls through
14221429
case SyntaxKind.MethodDeclaration:
14231430
case SyntaxKind.Constructor:
14241431
case SyntaxKind.GetAccessor:
14251432
case SyntaxKind.SetAccessor:
14261433
case SyntaxKind.FunctionDeclaration:
1427-
case SyntaxKind.ArrowFunction:
14281434
if (meaning & SymbolFlags.Variable && name === "arguments") {
14291435
result = argumentsSymbol;
14301436
break loop;

tests/baselines/reference/arguments.errors.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
tests/cases/compiler/arguments.ts(6,25): error TS2304: Cannot find name 'arguments'.
2-
tests/cases/compiler/arguments.ts(7,23): error TS2304: Cannot find name 'arguments'.
3-
tests/cases/compiler/arguments.ts(8,19): error TS2304: Cannot find name 'arguments'.
4-
tests/cases/compiler/arguments.ts(9,23): error TS2304: Cannot find name 'arguments'.
5-
tests/cases/compiler/arguments.ts(10,34): error TS2304: Cannot find name 'arguments'.
1+
tests/cases/compiler/arguments.ts(6,8): error TS2304: Cannot find name 'arguments'.
2+
tests/cases/compiler/arguments.ts(9,25): error TS2304: Cannot find name 'arguments'.
3+
tests/cases/compiler/arguments.ts(10,23): error TS2304: Cannot find name 'arguments'.
4+
tests/cases/compiler/arguments.ts(11,19): error TS2304: Cannot find name 'arguments'.
5+
tests/cases/compiler/arguments.ts(12,23): error TS2304: Cannot find name 'arguments'.
6+
tests/cases/compiler/arguments.ts(13,34): error TS2304: Cannot find name 'arguments'.
67

78

8-
==== tests/cases/compiler/arguments.ts (5 errors) ====
9+
==== tests/cases/compiler/arguments.ts (6 errors) ====
910
function f() {
1011
var x=arguments[12];
12+
(() => arguments)();
1113
}
1214

15+
(() => arguments)();
16+
~~~~~~~~~
17+
!!! error TS2304: Cannot find name 'arguments'.
18+
1319
interface I {
1420
method(args: typeof arguments): void;
1521
~~~~~~~~~

tests/baselines/reference/arguments.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
//// [arguments.ts]
22
function f() {
33
var x=arguments[12];
4+
(() => arguments)();
45
}
56

7+
(() => arguments)();
8+
69
interface I {
710
method(args: typeof arguments): void;
811
fn: (args: typeof arguments) => void;
@@ -14,4 +17,6 @@ interface I {
1417
//// [arguments.js]
1518
function f() {
1619
var x = arguments[12];
20+
(() => arguments)();
1721
}
22+
(() => arguments)();

tests/baselines/reference/arguments.symbols

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,32 @@ function f() {
44

55
var x=arguments[12];
66
>x : Symbol(x, Decl(arguments.ts, 1, 7))
7+
>arguments : Symbol(arguments)
8+
9+
(() => arguments)();
710
>arguments : Symbol(arguments)
811
}
912

13+
(() => arguments)();
14+
1015
interface I {
11-
>I : Symbol(I, Decl(arguments.ts, 2, 1))
16+
>I : Symbol(I, Decl(arguments.ts, 5, 20))
1217

1318
method(args: typeof arguments): void;
14-
>method : Symbol(I.method, Decl(arguments.ts, 4, 13))
15-
>args : Symbol(args, Decl(arguments.ts, 5, 11))
19+
>method : Symbol(I.method, Decl(arguments.ts, 7, 13))
20+
>args : Symbol(args, Decl(arguments.ts, 8, 11))
1621

1722
fn: (args: typeof arguments) => void;
18-
>fn : Symbol(I.fn, Decl(arguments.ts, 5, 41))
19-
>args : Symbol(args, Decl(arguments.ts, 6, 9))
23+
>fn : Symbol(I.fn, Decl(arguments.ts, 8, 41))
24+
>args : Symbol(args, Decl(arguments.ts, 9, 9))
2025

2126
(args: typeof arguments): void;
22-
>args : Symbol(args, Decl(arguments.ts, 7, 5))
27+
>args : Symbol(args, Decl(arguments.ts, 10, 5))
2328

2429
new (args: typeof arguments): void;
25-
>args : Symbol(args, Decl(arguments.ts, 8, 9))
30+
>args : Symbol(args, Decl(arguments.ts, 11, 9))
2631

2732
construct: new (args: typeof arguments) => void;
28-
>construct : Symbol(I.construct, Decl(arguments.ts, 8, 39))
29-
>args : Symbol(args, Decl(arguments.ts, 9, 20))
33+
>construct : Symbol(I.construct, Decl(arguments.ts, 11, 39))
34+
>args : Symbol(args, Decl(arguments.ts, 12, 20))
3035
}

tests/baselines/reference/arguments.types

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,20 @@ function f() {
77
>arguments[12] : any
88
>arguments : IArguments
99
>12 : 12
10+
11+
(() => arguments)();
12+
>(() => arguments)() : IArguments
13+
>(() => arguments) : () => IArguments
14+
>() => arguments : () => IArguments
15+
>arguments : IArguments
1016
}
1117

18+
(() => arguments)();
19+
>(() => arguments)() : any
20+
>(() => arguments) : () => any
21+
>() => arguments : () => any
22+
>arguments : any
23+
1224
interface I {
1325
method(args: typeof arguments): void;
1426
>method : (args: any) => void
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments01_ES6.ts(2,15): error TS2304: Cannot find name 'arguments'.
2+
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments01_ES6.ts(19,15): error TS2304: Cannot find name 'arguments'.
3+
4+
5+
==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments01_ES6.ts (2 errors) ====
6+
var a = () => {
7+
var arg = arguments[0]; // error
8+
~~~~~~~~~
9+
!!! error TS2304: Cannot find name 'arguments'.
10+
}
11+
12+
var b = function () {
13+
var a = () => {
14+
var arg = arguments[0]; // error
15+
}
16+
}
17+
18+
function baz() {
19+
() => {
20+
var arg = arguments[0];
21+
}
22+
}
23+
24+
function foo(inputFunc: () => void) { }
25+
foo(() => {
26+
var arg = arguments[0]; // error
27+
~~~~~~~~~
28+
!!! error TS2304: Cannot find name 'arguments'.
29+
});
30+
31+
function bar() {
32+
var arg = arguments[0]; // no error
33+
}
34+
35+
36+
() => {
37+
function foo() {
38+
var arg = arguments[0]; // no error
39+
}
40+
}

tests/baselines/reference/emitArrowFunctionWhenUsingArguments01_ES6.symbols

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ var a = () => {
44

55
var arg = arguments[0]; // error
66
>arg : Symbol(arg, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 1, 7))
7-
>arguments : Symbol(arguments)
87
}
98

109
var b = function () {
@@ -38,7 +37,6 @@ foo(() => {
3837

3938
var arg = arguments[0]; // error
4039
>arg : Symbol(arg, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 18, 7))
41-
>arguments : Symbol(arguments)
4240

4341
});
4442

tests/baselines/reference/emitArrowFunctionWhenUsingArguments01_ES6.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var a = () => {
66
var arg = arguments[0]; // error
77
>arg : any
88
>arguments[0] : any
9-
>arguments : IArguments
9+
>arguments : any
1010
>0 : 0
1111
}
1212

@@ -52,7 +52,7 @@ foo(() => {
5252
var arg = arguments[0]; // error
5353
>arg : any
5454
>arguments[0] : any
55-
>arguments : IArguments
55+
>arguments : any
5656
>0 : 0
5757

5858
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments02_ES6.ts(1,15): error TS2304: Cannot find name 'arguments'.
2+
3+
4+
==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments02_ES6.ts (1 errors) ====
5+
var a = () => arguments;
6+
~~~~~~~~~
7+
!!! error TS2304: Cannot find name 'arguments'.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments02_ES6.ts ===
22
var a = () => arguments;
33
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments02_ES6.ts, 0, 3))
4-
>arguments : Symbol(arguments)
54

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments02_ES6.ts ===
22
var a = () => arguments;
3-
>a : () => IArguments
4-
>() => arguments : () => IArguments
5-
>arguments : IArguments
3+
>a : () => any
4+
>() => arguments : () => any
5+
>arguments : any
66

tests/baselines/reference/emitArrowFunctionWhenUsingArguments03_ES6.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ var arguments;
44

55
var a = () => arguments;
66
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments03_ES6.ts, 1, 3))
7-
>arguments : Symbol(arguments)
7+
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments03_ES6.ts, 0, 3))
88

tests/baselines/reference/emitArrowFunctionWhenUsingArguments03_ES6.types

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var arguments;
33
>arguments : any
44

55
var a = () => arguments;
6-
>a : () => IArguments
7-
>() => arguments : () => IArguments
8-
>arguments : IArguments
6+
>a : () => any
7+
>() => arguments : () => any
8+
>arguments : any
99

tests/baselines/reference/emitArrowFunctionWhenUsingArguments04_ES6.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ function f() {
77

88
var a = () => arguments;
99
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments04_ES6.ts, 2, 7))
10-
>arguments : Symbol(arguments)
10+
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments04_ES6.ts, 1, 7))
1111
}

tests/baselines/reference/emitArrowFunctionWhenUsingArguments04_ES6.types

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function f() {
66
>arguments : any
77

88
var a = () => arguments;
9-
>a : () => IArguments
10-
>() => arguments : () => IArguments
11-
>arguments : IArguments
9+
>a : () => any
10+
>() => arguments : () => any
11+
>arguments : any
1212
}

tests/baselines/reference/emitArrowFunctionWhenUsingArguments05_ES6.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ function f(arguments) {
55

66
var a = () => arguments;
77
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments05_ES6.ts, 1, 7))
8-
>arguments : Symbol(arguments)
8+
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments05_ES6.ts, 0, 11))
99
}

tests/baselines/reference/emitArrowFunctionWhenUsingArguments05_ES6.types

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function f(arguments) {
44
>arguments : any
55

66
var a = () => arguments;
7-
>a : () => IArguments
8-
>() => arguments : () => IArguments
9-
>arguments : IArguments
7+
>a : () => any
8+
>() => arguments : () => any
9+
>arguments : any
1010
}

tests/baselines/reference/emitArrowFunctionWhenUsingArguments06_ES6.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ function f(arguments) {
55

66
var a = () => () => arguments;
77
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments06_ES6.ts, 1, 7))
8-
>arguments : Symbol(arguments)
8+
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments06_ES6.ts, 0, 11))
99
}

tests/baselines/reference/emitArrowFunctionWhenUsingArguments06_ES6.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ function f(arguments) {
44
>arguments : any
55

66
var a = () => () => arguments;
7-
>a : () => () => IArguments
8-
>() => () => arguments : () => () => IArguments
9-
>() => arguments : () => IArguments
10-
>arguments : IArguments
7+
>a : () => () => any
8+
>() => () => arguments : () => () => any
9+
>() => arguments : () => any
10+
>arguments : any
1111
}

tests/baselines/reference/emitArrowFunctionWhenUsingArguments07_ES6.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ function f(arguments) {
66
var a = (arguments) => () => arguments;
77
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments07_ES6.ts, 1, 7))
88
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments07_ES6.ts, 1, 13))
9-
>arguments : Symbol(arguments)
9+
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments07_ES6.ts, 1, 13))
1010
}

tests/baselines/reference/emitArrowFunctionWhenUsingArguments07_ES6.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ function f(arguments) {
44
>arguments : any
55

66
var a = (arguments) => () => arguments;
7-
>a : (arguments: any) => () => IArguments
8-
>(arguments) => () => arguments : (arguments: any) => () => IArguments
7+
>a : (arguments: any) => () => any
8+
>(arguments) => () => arguments : (arguments: any) => () => any
9+
>arguments : any
10+
>() => arguments : () => any
911
>arguments : any
10-
>() => arguments : () => IArguments
11-
>arguments : IArguments
1212
}

tests/baselines/reference/emitArrowFunctionWhenUsingArguments11_ES6.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ function f(arguments) {
88

99
var a = () => () => arguments;
1010
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments11_ES6.ts, 2, 7))
11-
>arguments : Symbol(arguments)
11+
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments11_ES6.ts, 0, 11))
1212
}

tests/baselines/reference/emitArrowFunctionWhenUsingArguments11_ES6.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ function f(arguments) {
88
>10 : 10
99

1010
var a = () => () => arguments;
11-
>a : () => () => IArguments
12-
>() => () => arguments : () => () => IArguments
13-
>() => arguments : () => IArguments
14-
>arguments : IArguments
11+
>a : () => () => any
12+
>() => () => arguments : () => () => any
13+
>() => arguments : () => any
14+
>arguments : any
1515
}

tests/baselines/reference/emitArrowFunctionWhenUsingArguments12_ES6.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ class C {
88

99
var a = () => arguments;
1010
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments12_ES6.ts, 2, 11))
11-
>arguments : Symbol(arguments)
11+
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments12_ES6.ts, 1, 6))
1212
}
1313
}

tests/baselines/reference/emitArrowFunctionWhenUsingArguments12_ES6.types

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class C {
77
>arguments : any
88

99
var a = () => arguments;
10-
>a : () => IArguments
11-
>() => arguments : () => IArguments
12-
>arguments : IArguments
10+
>a : () => any
11+
>() => arguments : () => any
12+
>arguments : any
1313
}
1414
}

tests/baselines/reference/emitArrowFunctionWhenUsingArguments14_ES6.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ function f() {
1111
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments14_ES6.ts, 2, 11))
1212

1313
return () => arguments;
14-
>arguments : Symbol(arguments)
14+
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments14_ES6.ts, 2, 11))
1515
}
1616
}

tests/baselines/reference/emitArrowFunctionWhenUsingArguments14_ES6.types

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments14_ES6.ts ===
22
function f() {
3-
>f : () => () => IArguments
3+
>f : () => () => number
44

55
if (Math.random()) {
66
>Math.random() : number
@@ -13,7 +13,7 @@ function f() {
1313
>100 : 100
1414

1515
return () => arguments;
16-
>() => arguments : () => IArguments
17-
>arguments : IArguments
16+
>() => arguments : () => number
17+
>arguments : number
1818
}
1919
}

tests/baselines/reference/emitArrowFunctionWhenUsingArguments15_ES6.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ function f() {
1414
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments15_ES6.ts, 3, 13))
1515

1616
return () => arguments;
17-
>arguments : Symbol(arguments)
17+
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments15_ES6.ts, 3, 13))
1818
}
1919
}

0 commit comments

Comments
 (0)