Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5404,8 +5404,8 @@ module ts {
// will be bound to non-arrow function that contain this arrow function. This results in inconsistent behavior.
// To avoid that we will give an error to users if they use arguments objects in arrow function so that they
// can explicitly bound arguments objects
if (symbol === argumentsSymbol && getContainingFunction(node).kind === SyntaxKind.ArrowFunction) {
error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression);
if (symbol === argumentsSymbol && getContainingFunction(node).kind === SyntaxKind.ArrowFunction && languageVersion < ScriptTarget.ES6) {
error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_in_ES3_and_ES5_Consider_using_a_standard_function_expression);
}

if (symbol.flags & SymbolFlags.Alias && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) {
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/diagnosticInformationMap.generated.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// <auto-generated />
/// <reference path="types.ts" />
/* @internal */
module ts {
export var Diagnostics = {
Unterminated_string_literal: { code: 1002, category: DiagnosticCategory.Error, key: "Unterminated string literal." },
Expand Down Expand Up @@ -357,7 +358,7 @@ module ts {
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}'." },
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." },
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." },
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." },
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." },
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." },
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 *'." },
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." },
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@
"category": "Error",
"code": 2495
},
"The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.": {
"The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.": {
"category": "Error",
"code": 2496
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
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.
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.
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.
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.
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.
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.
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.
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.


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

var b = function () {
var a = () => {
var arg = arguments[0]; // error
~~~~~~~~~
!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
}
}

function baz() {
() => {
var arg = arguments[0];
~~~~~~~~~
!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.
!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
}
}

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

function bar() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//// [emitArrowFunctionWhenUsingArgumentsES6.ts]
//// [emitArrowFunctionWhenUsingArguments01.ts]
var a = () => {
var arg = arguments[0]; // error
}
Expand Down Expand Up @@ -31,28 +31,28 @@ function bar() {
}
}

//// [emitArrowFunctionWhenUsingArgumentsES6.js]
var a = () => {
//// [emitArrowFunctionWhenUsingArguments01.js]
var a = function () {
var arg = arguments[0]; // error
};
var b = function () {
var a = () => {
var a = function () {
var arg = arguments[0]; // error
};
};
function baz() {
(() => {
(function () {
var arg = arguments[0];
});
}
function foo(inputFunc) { }
foo(() => {
foo(function () {
var arg = arguments[0]; // error
});
function bar() {
var arg = arguments[0]; // no error
}
(() => {
(function () {
function foo() {
var arg = arguments[0]; // no error
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//// [emitArrowFunctionWhenUsingArguments.ts]
//// [emitArrowFunctionWhenUsingArguments01_ES6.ts]
var a = () => {
var arg = arguments[0]; // error
}
Expand Down Expand Up @@ -31,7 +31,7 @@ function bar() {
}
}

//// [emitArrowFunctionWhenUsingArguments.js]
//// [emitArrowFunctionWhenUsingArguments01_ES6.js]
var a = () => {
var arg = arguments[0]; // error
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments01_ES6.ts ===
var a = () => {
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 0, 3))

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

var b = function () {
>b : Symbol(b, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 4, 3))

var a = () => {
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 5, 7))

var arg = arguments[0]; // error
>arg : Symbol(arg, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 6, 11))
>arguments : Symbol(arguments)
}
}

function baz() {
>baz : Symbol(baz, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 8, 1))

() => {
var arg = arguments[0];
>arg : Symbol(arg, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 12, 5))
>arguments : Symbol(arguments)
}
}

function foo(inputFunc: () => void) { }
>foo : Symbol(foo, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 14, 1))
>inputFunc : Symbol(inputFunc, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 16, 13))

foo(() => {
>foo : Symbol(foo, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 14, 1))

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

});

function bar() {
>bar : Symbol(bar, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 19, 3))

var arg = arguments[0]; // no error
>arg : Symbol(arg, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 22, 7))
>arguments : Symbol(arguments)
}


() => {
function foo() {
>foo : Symbol(foo, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 26, 7))

var arg = arguments[0]; // no error
>arg : Symbol(arg, Decl(emitArrowFunctionWhenUsingArguments01_ES6.ts, 28, 5))
>arguments : Symbol(arguments)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments01_ES6.ts ===
var a = () => {
>a : () => void
>() => { var arg = arguments[0]; // error} : () => void

var arg = arguments[0]; // error
>arg : any
>arguments[0] : any
>arguments : IArguments
>0 : number
}

var b = function () {
>b : () => void
>function () { var a = () => { var arg = arguments[0]; // error }} : () => void

var a = () => {
>a : () => void
>() => { var arg = arguments[0]; // error } : () => void

var arg = arguments[0]; // error
>arg : any
>arguments[0] : any
>arguments : IArguments
>0 : number
}
}

function baz() {
>baz : () => void

() => {
>() => { var arg = arguments[0]; } : () => void

var arg = arguments[0];
>arg : any
>arguments[0] : any
>arguments : IArguments
>0 : number
}
}

function foo(inputFunc: () => void) { }
>foo : (inputFunc: () => void) => void
>inputFunc : () => void

foo(() => {
>foo(() => { var arg = arguments[0]; // error}) : void
>foo : (inputFunc: () => void) => void
>() => { var arg = arguments[0]; // error} : () => void

var arg = arguments[0]; // error
>arg : any
>arguments[0] : any
>arguments : IArguments
>0 : number

});

function bar() {
>bar : () => void

var arg = arguments[0]; // no error
>arg : any
>arguments[0] : any
>arguments : IArguments
>0 : number
}


() => {
>() => { function foo() { var arg = arguments[0]; // no error }} : () => void

function foo() {
>foo : () => void

var arg = arguments[0]; // no error
>arg : any
>arguments[0] : any
>arguments : IArguments
>0 : number
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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.


==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments02.ts (1 errors) ====

var a = () => arguments;
~~~~~~~~~
!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [emitArrowFunctionWhenUsingArguments02.ts]

var a = () => arguments;

//// [emitArrowFunctionWhenUsingArguments02.js]
var a = function () { return arguments; };
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [emitArrowFunctionWhenUsingArguments02_ES6.ts]

var a = () => arguments;

//// [emitArrowFunctionWhenUsingArguments02_ES6.js]
var a = () => arguments;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments02_ES6.ts ===

var a = () => arguments;
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments02_ES6.ts, 1, 3))
>arguments : Symbol(arguments)

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments02_ES6.ts ===

var a = () => arguments;
>a : () => IArguments
>() => arguments : () => IArguments
>arguments : IArguments

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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.


==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments03.ts (1 errors) ====

var arguments;
var a = () => arguments;
~~~~~~~~~
!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//// [emitArrowFunctionWhenUsingArguments03.ts]

var arguments;
var a = () => arguments;

//// [emitArrowFunctionWhenUsingArguments03.js]
var arguments;
var a = function () { return arguments; };
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//// [emitArrowFunctionWhenUsingArguments03_ES6.ts]

var arguments;
var a = () => arguments;

//// [emitArrowFunctionWhenUsingArguments03_ES6.js]
var arguments;
var a = () => arguments;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments03_ES6.ts ===

var arguments;
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments03_ES6.ts, 1, 3))

var a = () => arguments;
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments03_ES6.ts, 2, 3))
>arguments : Symbol(arguments)

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments03_ES6.ts ===

var arguments;
>arguments : any

var a = () => arguments;
>a : () => IArguments
>() => arguments : () => IArguments
>arguments : IArguments

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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.


==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments04.ts (1 errors) ====

function f() {
var arguments;
var a = () => arguments;
~~~~~~~~~
!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
}
Loading