SyntaxError: unknown: Binding 'arguments' in strict mode (2:6)
See original GitHub issueHi I follow the instructions in this doc to transform arrow functions.
I find an error SyntaxError: unknown: Binding 'arguments' in strict mode (2:5)
is thrown every time when a variable is named “arguments”. For example,
var foo = () => {
var arguments = 1;
};
The instruction I use is require('@babel/core').transform(code, {plugins: ['@babel/plugin-transform-arrow-functions']})
where code
is the input program like the above example.
So how can I fix it? Is there any options I miss to set?
Issue Analytics
- State:
- Created 3 years ago
- Comments:18 (14 by maintainers)
Top Results From Across the Web
Strict Mode Issue with Binding Arguments - Stack Overflow
I have an issue with running a test on my files. Would love if someone more experienced could help me out here. the...
Read more >Strict mode - JavaScript - MDN Web Docs
No syncing between parameters and arguments indices. Strict mode code doesn't sync indices of the arguments object with each parameter binding.
Read more >JavaScript Mistakes — Strict Mode | by John Au-Yeung
With strict mode on, the this value passed into call , apply , or bind aren't boxed into an object. Therefore, the original...
Read more >JavaScript Strict Mode
Attempting to perform an update on a property when its property definition defines otherwise will throw a TypeError in Strict Mode.
Read more >ECMA-262-5 in detail. Chapter 2. Strict Mode.
In strict mode these names — eval and arguments are treated as kind of “keywords” (while they are not) and not allowed in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@RichardHoOoOo If you are interested in fixing this issue you are welcome to help, otherwise it’s open for anyone who wants to work on it!
The problem is in the utility we have to convert arrow functions to ES5 function expressions. In the
hoistFunctionEnvironment
function, we “extract”this
,arguments
,super
andnew.target
to the outer scope, to preserve the correct semantics in cases like this one:However, when there is a
var arguments;
declaration,arguments
shouldn’t refer to the outer function’sarguments
anymore. When replacingarguments
, we need to check if it was defined as a variable in the local scope usingargumentsChild.scope.hasOwnBinding("arguments")
.Note that we also need to check
argumentsChild.scope.parent
,argumentsChild.scope.parent.parent
and so on: we should stop when we reach a non-arrow function scope, which defines the implicitarguments
binding.A few test cases:
If it is the first time that you contribute to Babel, follow these steps: (you need to have
make
andyarn
available on your machine)git clone https://github.com/<YOUR_USERNAME>/babel.git && cd babel
yarn && make bootstrap
make watch
(ormake build
whenever you change a file)input.js
;output.js
will be automatically generated)yarn jest plugin-transform-arrow-functions
to run the testsoutput.js
files and run the tests againOVERWRITE=true yarn jest plugin-transform-arrow-functions
and they will be automatically updated.make test
to run all the testsgit push
and open a PR!I have started working on the issue!