Skip to content

Commit 8d4d7df

Browse files
Merge pull request #2802 from Microsoft/allowArrowArgumentsES6
Only error in ES3 and ES5 when using 'arguments' in an arrow function
2 parents 3b74503 + ce00997 commit 8d4d7df

File tree

138 files changed

+1687
-69
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+1687
-69
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5404,8 +5404,8 @@ module ts {
54045404
// will be bound to non-arrow function that contain this arrow function. This results in inconsistent behavior.
54055405
// To avoid that we will give an error to users if they use arguments objects in arrow function so that they
54065406
// can explicitly bound arguments objects
5407-
if (symbol === argumentsSymbol && getContainingFunction(node).kind === SyntaxKind.ArrowFunction) {
5408-
error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression);
5407+
if (symbol === argumentsSymbol && getContainingFunction(node).kind === SyntaxKind.ArrowFunction && languageVersion < ScriptTarget.ES6) {
5408+
error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression);
54095409
}
54105410

54115411
if (symbol.flags & SymbolFlags.Alias && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) {

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// <auto-generated />
22
/// <reference path="types.ts" />
3+
/* @internal */
34
module ts {
45
export var Diagnostics = {
56
Unterminated_string_literal: { code: 1002, category: DiagnosticCategory.Error, key: "Unterminated string literal." },
@@ -357,7 +358,7 @@ module ts {
357358
Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2: { code: 2493, category: DiagnosticCategory.Error, key: "Tuple type '{0}' with length '{1}' cannot be assigned to tuple with length '{2}'." },
358359
Using_a_string_in_a_for_of_statement_is_only_supported_in_ECMAScript_5_and_higher: { code: 2494, category: DiagnosticCategory.Error, key: "Using a string in a 'for...of' statement is only supported in ECMAScript 5 and higher." },
359360
Type_0_is_not_an_array_type_or_a_string_type: { code: 2495, category: DiagnosticCategory.Error, key: "Type '{0}' is not an array type or a string type." },
360-
The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 2496, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." },
361+
The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression: { code: 2496, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression." },
361362
External_module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct: { code: 2497, category: DiagnosticCategory.Error, key: "External module '{0}' resolves to a non-module entity and cannot be imported using this construct." },
362363
External_module_0_uses_export_and_cannot_be_used_with_export_Asterisk: { code: 2498, category: DiagnosticCategory.Error, key: "External module '{0}' uses 'export =' and cannot be used with 'export *'." },
363364
An_interface_can_only_extend_an_identifier_Slashqualified_name_with_optional_type_arguments: { code: 2499, category: DiagnosticCategory.Error, key: "An interface can only extend an identifier/qualified-name with optional type arguments." },

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@
14191419
"category": "Error",
14201420
"code": 2495
14211421
},
1422-
"The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.": {
1422+
"The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.": {
14231423
"category": "Error",
14241424
"code": 2496
14251425
},

tests/baselines/reference/emitArrowFunctionWhenUsingArguments.errors.txt renamed to tests/baselines/reference/emitArrowFunctionWhenUsingArguments01.errors.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(2,15): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
2-
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(7,19): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
3-
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(13,13): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
4-
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(19,15): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
1+
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments01.ts(2,15): error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
2+
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments01.ts(7,19): error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
3+
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments01.ts(13,13): error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
4+
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments01.ts(19,15): error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
55

66

7-
==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts (4 errors) ====
7+
==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments01.ts (4 errors) ====
88
var a = () => {
99
var arg = arguments[0]; // error
1010
~~~~~~~~~
11-
!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
11+
!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
1212
}
1313

1414
var b = function () {
1515
var a = () => {
1616
var arg = arguments[0]; // error
1717
~~~~~~~~~
18-
!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
18+
!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
1919
}
2020
}
2121

2222
function baz() {
2323
() => {
2424
var arg = arguments[0];
2525
~~~~~~~~~
26-
!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
26+
!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
2727
}
2828
}
2929

3030
function foo(inputFunc: () => void) { }
3131
foo(() => {
3232
var arg = arguments[0]; // error
3333
~~~~~~~~~
34-
!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
34+
!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
3535
});
3636

3737
function bar() {

tests/baselines/reference/emitArrowFunctionWhenUsingArgumentsES6.js renamed to tests/baselines/reference/emitArrowFunctionWhenUsingArguments01.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//// [emitArrowFunctionWhenUsingArgumentsES6.ts]
1+
//// [emitArrowFunctionWhenUsingArguments01.ts]
22
var a = () => {
33
var arg = arguments[0]; // error
44
}
@@ -31,28 +31,28 @@ function bar() {
3131
}
3232
}
3333

34-
//// [emitArrowFunctionWhenUsingArgumentsES6.js]
35-
var a = () => {
34+
//// [emitArrowFunctionWhenUsingArguments01.js]
35+
var a = function () {
3636
var arg = arguments[0]; // error
3737
};
3838
var b = function () {
39-
var a = () => {
39+
var a = function () {
4040
var arg = arguments[0]; // error
4141
};
4242
};
4343
function baz() {
44-
(() => {
44+
(function () {
4545
var arg = arguments[0];
4646
});
4747
}
4848
function foo(inputFunc) { }
49-
foo(() => {
49+
foo(function () {
5050
var arg = arguments[0]; // error
5151
});
5252
function bar() {
5353
var arg = arguments[0]; // no error
5454
}
55-
(() => {
55+
(function () {
5656
function foo() {
5757
var arg = arguments[0]; // no error
5858
}

tests/baselines/reference/emitArrowFunctionWhenUsingArguments.js renamed to tests/baselines/reference/emitArrowFunctionWhenUsingArguments01_ES6.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//// [emitArrowFunctionWhenUsingArguments.ts]
1+
//// [emitArrowFunctionWhenUsingArguments01_ES6.ts]
22
var a = () => {
33
var arg = arguments[0]; // error
44
}
@@ -31,7 +31,7 @@ function bar() {
3131
}
3232
}
3333

34-
//// [emitArrowFunctionWhenUsingArguments.js]
34+
//// [emitArrowFunctionWhenUsingArguments01_ES6.js]
3535
var a = () => {
3636
var arg = arguments[0]; // error
3737
};
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments01_ES6.ts ===
2+
var a = () => {
3+
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 0, 3))
4+
5+
var arg = arguments[0]; // error
6+
>arg : Symbol(arg, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 1, 7))
7+
>arguments : Symbol(arguments)
8+
}
9+
10+
var b = function () {
11+
>b : Symbol(b, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 4, 3))
12+
13+
var a = () => {
14+
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 5, 7))
15+
16+
var arg = arguments[0]; // error
17+
>arg : Symbol(arg, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 6, 11))
18+
>arguments : Symbol(arguments)
19+
}
20+
}
21+
22+
function baz() {
23+
>baz : Symbol(baz, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 8, 1))
24+
25+
() => {
26+
var arg = arguments[0];
27+
>arg : Symbol(arg, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 12, 5))
28+
>arguments : Symbol(arguments)
29+
}
30+
}
31+
32+
function foo(inputFunc: () => void) { }
33+
>foo : Symbol(foo, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 14, 1))
34+
>inputFunc : Symbol(inputFunc, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 16, 13))
35+
36+
foo(() => {
37+
>foo : Symbol(foo, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 14, 1))
38+
39+
var arg = arguments[0]; // error
40+
>arg : Symbol(arg, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 18, 7))
41+
>arguments : Symbol(arguments)
42+
43+
});
44+
45+
function bar() {
46+
>bar : Symbol(bar, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 19, 3))
47+
48+
var arg = arguments[0]; // no error
49+
>arg : Symbol(arg, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 22, 7))
50+
>arguments : Symbol(arguments)
51+
}
52+
53+
54+
() => {
55+
function foo() {
56+
>foo : Symbol(foo, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 26, 7))
57+
58+
var arg = arguments[0]; // no error
59+
>arg : Symbol(arg, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 28, 5))
60+
>arguments : Symbol(arguments)
61+
}
62+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments01_ES6.ts ===
2+
var a = () => {
3+
>a : () => void
4+
>() => { var arg = arguments[0]; // error} : () => void
5+
6+
var arg = arguments[0]; // error
7+
>arg : any
8+
>arguments[0] : any
9+
>arguments : IArguments
10+
>0 : number
11+
}
12+
13+
var b = function () {
14+
>b : () => void
15+
>function () { var a = () => { var arg = arguments[0]; // error }} : () => void
16+
17+
var a = () => {
18+
>a : () => void
19+
>() => { var arg = arguments[0]; // error } : () => void
20+
21+
var arg = arguments[0]; // error
22+
>arg : any
23+
>arguments[0] : any
24+
>arguments : IArguments
25+
>0 : number
26+
}
27+
}
28+
29+
function baz() {
30+
>baz : () => void
31+
32+
() => {
33+
>() => { var arg = arguments[0]; } : () => void
34+
35+
var arg = arguments[0];
36+
>arg : any
37+
>arguments[0] : any
38+
>arguments : IArguments
39+
>0 : number
40+
}
41+
}
42+
43+
function foo(inputFunc: () => void) { }
44+
>foo : (inputFunc: () => void) => void
45+
>inputFunc : () => void
46+
47+
foo(() => {
48+
>foo(() => { var arg = arguments[0]; // error}) : void
49+
>foo : (inputFunc: () => void) => void
50+
>() => { var arg = arguments[0]; // error} : () => void
51+
52+
var arg = arguments[0]; // error
53+
>arg : any
54+
>arguments[0] : any
55+
>arguments : IArguments
56+
>0 : number
57+
58+
});
59+
60+
function bar() {
61+
>bar : () => void
62+
63+
var arg = arguments[0]; // no error
64+
>arg : any
65+
>arguments[0] : any
66+
>arguments : IArguments
67+
>0 : number
68+
}
69+
70+
71+
() => {
72+
>() => { function foo() { var arg = arguments[0]; // no error }} : () => void
73+
74+
function foo() {
75+
>foo : () => void
76+
77+
var arg = arguments[0]; // no error
78+
>arg : any
79+
>arguments[0] : any
80+
>arguments : IArguments
81+
>0 : number
82+
}
83+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments02.ts(2,15): error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
2+
3+
4+
==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments02.ts (1 errors) ====
5+
6+
var a = () => arguments;
7+
~~~~~~~~~
8+
!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [emitArrowFunctionWhenUsingArguments02.ts]
2+
3+
var a = () => arguments;
4+
5+
//// [emitArrowFunctionWhenUsingArguments02.js]
6+
var a = function () { return arguments; };
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [emitArrowFunctionWhenUsingArguments02_ES6.ts]
2+
3+
var a = () => arguments;
4+
5+
//// [emitArrowFunctionWhenUsingArguments02_ES6.js]
6+
var a = () => arguments;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments02_ES6.ts ===
2+
3+
var a = () => arguments;
4+
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments02_ES6.ts, 1, 3))
5+
>arguments : Symbol(arguments)
6+
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 ===
2+
3+
var a = () => arguments;
4+
>a : () => IArguments
5+
>() => arguments : () => IArguments
6+
>arguments : IArguments
7+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments03.ts(3,15): error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
2+
3+
4+
==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments03.ts (1 errors) ====
5+
6+
var arguments;
7+
var a = () => arguments;
8+
~~~~~~~~~
9+
!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [emitArrowFunctionWhenUsingArguments03.ts]
2+
3+
var arguments;
4+
var a = () => arguments;
5+
6+
//// [emitArrowFunctionWhenUsingArguments03.js]
7+
var arguments;
8+
var a = function () { return arguments; };
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [emitArrowFunctionWhenUsingArguments03_ES6.ts]
2+
3+
var arguments;
4+
var a = () => arguments;
5+
6+
//// [emitArrowFunctionWhenUsingArguments03_ES6.js]
7+
var arguments;
8+
var a = () => arguments;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments03_ES6.ts ===
2+
3+
var arguments;
4+
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments03_ES6.ts, 1, 3))
5+
6+
var a = () => arguments;
7+
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments03_ES6.ts, 2, 3))
8+
>arguments : Symbol(arguments)
9+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments03_ES6.ts ===
2+
3+
var arguments;
4+
>arguments : any
5+
6+
var a = () => arguments;
7+
>a : () => IArguments
8+
>() => arguments : () => IArguments
9+
>arguments : IArguments
10+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments04.ts(4,19): error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
2+
3+
4+
==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments04.ts (1 errors) ====
5+
6+
function f() {
7+
var arguments;
8+
var a = () => arguments;
9+
~~~~~~~~~
10+
!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
11+
}

0 commit comments

Comments
 (0)