Skip to content
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

Is ES6 parameter scope not supported? #130

getify opened this Issue Mar 13, 2019 · 0 comments


None yet
1 participant
Copy link

getify commented Mar 13, 2019

Apologies if this is a known problem. I couldn't quite tell from my review of existing issue threads.

My problem is related to the scopes set up by this code:

var x = (a,b = () => a) => { var a = 2; return [a, b()]; }
x(5);  // [2,5]

As you can see from the result output, the parameter list peculiarly has its own scope which is distinguishable when there's a closure in the parameter list. The a of value 5 is different from the a of value 2.

So, I would expect to get 4 scopes here from escopes:

  1. The outer scope
  2. The main function (x()) scope
  3. The intermediate parameter scope (where the parameter a and b comes from)
  4. The scope of the b() function

However, (3) is missing from the escopes output. Moreover, the a (parameter) and b (parameter) are recorded as belonging to the function (x()) scope. Usually that wouldn't matter and would be OK, but when there's a parameter list closure, it matters. There should be 3 variables (both as and the b) in the function, but there's only 2.

This inaccuracy is affecting my usage in ESLint, which I believe uses escopes. I can't fully accurately detect that a parameter is used or not if I cannot distinguish between the two as in that above code snippet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.