Skip to content

Commit 635780d

Browse files
committed
ArrowFunction has no own 'arguments'
Fixes: #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

0 commit comments

Comments
 (0)