Skip to content

ArrowFunction has no own 'arguments' #28627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 10, 2018
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
8 changes: 7 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1419,12 +1419,18 @@ namespace ts {
}
}
break;
case SyntaxKind.ArrowFunction:
// when targeting ES6 or higher there is no 'arguments' in an arrow function
// for lower compile targets the resolved symbol is used to emit an error
if (compilerOptions.target! >= ScriptTarget.ES2015) {
break;
}
// falls through
case SyntaxKind.MethodDeclaration:
case SyntaxKind.Constructor:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.ArrowFunction:
if (meaning & SymbolFlags.Variable && name === "arguments") {
result = argumentsSymbol;
break loop;
Expand Down
18 changes: 12 additions & 6 deletions tests/baselines/reference/arguments.errors.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
tests/cases/compiler/arguments.ts(6,25): error TS2304: Cannot find name 'arguments'.
tests/cases/compiler/arguments.ts(7,23): error TS2304: Cannot find name 'arguments'.
tests/cases/compiler/arguments.ts(8,19): error TS2304: Cannot find name 'arguments'.
tests/cases/compiler/arguments.ts(9,23): error TS2304: Cannot find name 'arguments'.
tests/cases/compiler/arguments.ts(10,34): error TS2304: Cannot find name 'arguments'.
tests/cases/compiler/arguments.ts(6,8): error TS2304: Cannot find name 'arguments'.
tests/cases/compiler/arguments.ts(9,25): error TS2304: Cannot find name 'arguments'.
tests/cases/compiler/arguments.ts(10,23): error TS2304: Cannot find name 'arguments'.
tests/cases/compiler/arguments.ts(11,19): error TS2304: Cannot find name 'arguments'.
tests/cases/compiler/arguments.ts(12,23): error TS2304: Cannot find name 'arguments'.
tests/cases/compiler/arguments.ts(13,34): error TS2304: Cannot find name 'arguments'.


==== tests/cases/compiler/arguments.ts (5 errors) ====
==== tests/cases/compiler/arguments.ts (6 errors) ====
function f() {
var x=arguments[12];
(() => arguments)();
}

(() => arguments)();
~~~~~~~~~
!!! error TS2304: Cannot find name 'arguments'.

interface I {
method(args: typeof arguments): void;
~~~~~~~~~
Expand Down
5 changes: 5 additions & 0 deletions tests/baselines/reference/arguments.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//// [arguments.ts]
function f() {
var x=arguments[12];
(() => arguments)();
}

(() => arguments)();

interface I {
method(args: typeof arguments): void;
fn: (args: typeof arguments) => void;
Expand All @@ -14,4 +17,6 @@ interface I {
//// [arguments.js]
function f() {
var x = arguments[12];
(() => arguments)();
}
(() => arguments)();
23 changes: 14 additions & 9 deletions tests/baselines/reference/arguments.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,32 @@ function f() {

var x=arguments[12];
>x : Symbol(x, Decl(arguments.ts, 1, 7))
>arguments : Symbol(arguments)

(() => arguments)();
>arguments : Symbol(arguments)
}

(() => arguments)();

interface I {
>I : Symbol(I, Decl(arguments.ts, 2, 1))
>I : Symbol(I, Decl(arguments.ts, 5, 20))

method(args: typeof arguments): void;
>method : Symbol(I.method, Decl(arguments.ts, 4, 13))
>args : Symbol(args, Decl(arguments.ts, 5, 11))
>method : Symbol(I.method, Decl(arguments.ts, 7, 13))
>args : Symbol(args, Decl(arguments.ts, 8, 11))

fn: (args: typeof arguments) => void;
>fn : Symbol(I.fn, Decl(arguments.ts, 5, 41))
>args : Symbol(args, Decl(arguments.ts, 6, 9))
>fn : Symbol(I.fn, Decl(arguments.ts, 8, 41))
>args : Symbol(args, Decl(arguments.ts, 9, 9))

(args: typeof arguments): void;
>args : Symbol(args, Decl(arguments.ts, 7, 5))
>args : Symbol(args, Decl(arguments.ts, 10, 5))

new (args: typeof arguments): void;
>args : Symbol(args, Decl(arguments.ts, 8, 9))
>args : Symbol(args, Decl(arguments.ts, 11, 9))

construct: new (args: typeof arguments) => void;
>construct : Symbol(I.construct, Decl(arguments.ts, 8, 39))
>args : Symbol(args, Decl(arguments.ts, 9, 20))
>construct : Symbol(I.construct, Decl(arguments.ts, 11, 39))
>args : Symbol(args, Decl(arguments.ts, 12, 20))
}
12 changes: 12 additions & 0 deletions tests/baselines/reference/arguments.types
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@ function f() {
>arguments[12] : any
>arguments : IArguments
>12 : 12

(() => arguments)();
>(() => arguments)() : IArguments
>(() => arguments) : () => IArguments
>() => arguments : () => IArguments
>arguments : IArguments
}

(() => arguments)();
>(() => arguments)() : any
>(() => arguments) : () => any
>() => arguments : () => any
>arguments : any

interface I {
method(args: typeof arguments): void;
>method : (args: any) => void
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments01_ES6.ts(2,15): error TS2304: Cannot find name 'arguments'.
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments01_ES6.ts(19,15): error TS2304: Cannot find name 'arguments'.


==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments01_ES6.ts (2 errors) ====
var a = () => {
var arg = arguments[0]; // error
~~~~~~~~~
!!! error TS2304: Cannot find name 'arguments'.
}

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

function baz() {
() => {
var arg = arguments[0];
}
}

function foo(inputFunc: () => void) { }
foo(() => {
var arg = arguments[0]; // error
~~~~~~~~~
!!! error TS2304: Cannot find name 'arguments'.
});

function bar() {
var arg = arguments[0]; // no error
}


() => {
function foo() {
var arg = arguments[0]; // no error
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var a = () => {

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

var b = function () {
Expand Down Expand Up @@ -38,7 +37,6 @@ foo(() => {

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

});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var a = () => {
var arg = arguments[0]; // error
>arg : any
>arguments[0] : any
>arguments : IArguments
>arguments : any
>0 : 0
}

Expand Down Expand Up @@ -52,7 +52,7 @@ foo(() => {
var arg = arguments[0]; // error
>arg : any
>arguments[0] : any
>arguments : IArguments
>arguments : any
>0 : 0

});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments02_ES6.ts(1,15): error TS2304: Cannot find name 'arguments'.


==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments02_ES6.ts (1 errors) ====
var a = () => arguments;
~~~~~~~~~
!!! error TS2304: Cannot find name 'arguments'.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments02_ES6.ts ===
var a = () => arguments;
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments02_ES6.ts, 0, 3))
>arguments : Symbol(arguments)

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

Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ var arguments;

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

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var arguments;
>arguments : any

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

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ function f() {

var a = () => arguments;
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments04_ES6.ts, 2, 7))
>arguments : Symbol(arguments)
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments04_ES6.ts, 1, 7))
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function f() {
>arguments : any

var a = () => arguments;
>a : () => IArguments
>() => arguments : () => IArguments
>arguments : IArguments
>a : () => any
>() => arguments : () => any
>arguments : any
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ function f(arguments) {

var a = () => arguments;
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments05_ES6.ts, 1, 7))
>arguments : Symbol(arguments)
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments05_ES6.ts, 0, 11))
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function f(arguments) {
>arguments : any

var a = () => arguments;
>a : () => IArguments
>() => arguments : () => IArguments
>arguments : IArguments
>a : () => any
>() => arguments : () => any
>arguments : any
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ function f(arguments) {

var a = () => () => arguments;
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments06_ES6.ts, 1, 7))
>arguments : Symbol(arguments)
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments06_ES6.ts, 0, 11))
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ function f(arguments) {
>arguments : any

var a = () => () => arguments;
>a : () => () => IArguments
>() => () => arguments : () => () => IArguments
>() => arguments : () => IArguments
>arguments : IArguments
>a : () => () => any
>() => () => arguments : () => () => any
>() => arguments : () => any
>arguments : any
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ function f(arguments) {
var a = (arguments) => () => arguments;
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments07_ES6.ts, 1, 7))
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments07_ES6.ts, 1, 13))
>arguments : Symbol(arguments)
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments07_ES6.ts, 1, 13))
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ function f(arguments) {
>arguments : any

var a = (arguments) => () => arguments;
>a : (arguments: any) => () => IArguments
>(arguments) => () => arguments : (arguments: any) => () => IArguments
>a : (arguments: any) => () => any
>(arguments) => () => arguments : (arguments: any) => () => any
>arguments : any
>() => arguments : () => any
>arguments : any
>() => arguments : () => IArguments
>arguments : IArguments
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ function f(arguments) {

var a = () => () => arguments;
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments11_ES6.ts, 2, 7))
>arguments : Symbol(arguments)
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments11_ES6.ts, 0, 11))
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ function f(arguments) {
>10 : 10

var a = () => () => arguments;
>a : () => () => IArguments
>() => () => arguments : () => () => IArguments
>() => arguments : () => IArguments
>arguments : IArguments
>a : () => () => any
>() => () => arguments : () => () => any
>() => arguments : () => any
>arguments : any
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class C {

var a = () => arguments;
>a : Symbol(a, Decl(emitArrowFunctionWhenUsingArguments12_ES6.ts, 2, 11))
>arguments : Symbol(arguments)
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments12_ES6.ts, 1, 6))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class C {
>arguments : any

var a = () => arguments;
>a : () => IArguments
>() => arguments : () => IArguments
>arguments : IArguments
>a : () => any
>() => arguments : () => any
>arguments : any
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ function f() {
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments14_ES6.ts, 2, 11))

return () => arguments;
>arguments : Symbol(arguments)
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments14_ES6.ts, 2, 11))
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments14_ES6.ts ===
function f() {
>f : () => () => IArguments
>f : () => () => number

if (Math.random()) {
>Math.random() : number
Expand All @@ -13,7 +13,7 @@ function f() {
>100 : 100

return () => arguments;
>() => arguments : () => IArguments
>arguments : IArguments
>() => arguments : () => number
>arguments : number
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ function f() {
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments15_ES6.ts, 3, 13))

return () => arguments;
>arguments : Symbol(arguments)
>arguments : Symbol(arguments, Decl(emitArrowFunctionWhenUsingArguments15_ES6.ts, 3, 13))
}
}
Loading