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

When using for+let, the loop variable isn't available in the when clause #992

Closed
vendethiel opened this issue Jan 10, 2018 · 2 comments
Closed
Assignees
Labels
bug

Comments

@vendethiel
Copy link
Contributor

@vendethiel vendethiel commented Jan 10, 2018

exemple:

for let k in v when k
  ...

result:

var i$, ref$, len$;
for (i$ = 0, len$ = (ref$ = v).length; i$ < len$; ++i$) {
  if (k) {
    (fn$.call(this, ref$[i$]));
  }
}
function fn$(k){
  throw Error('unimplemented');
}

expected:

var i$, ref$, len$;
for (i$ = 0, len$ = (ref$ = v).length; i$ < len$; ++i$) {
  var k = ref$[i$];
  if (k) {
    (fn$.call(this, k));
  }
}
function fn$(k){
  throw Error('unimplemented');
}
@rhendric rhendric added the bug label Jan 10, 2018
@rhendric rhendric self-assigned this Jan 10, 2018
@rhendric
Copy link
Collaborator

@rhendric rhendric commented Jan 10, 2018

Turns out this is slightly narrower; the actual issue only occurs when the loop variable is the entirety of the when clause. for let k in v when k > 0 works as expected.

@vendethiel
Copy link
Contributor Author

@vendethiel vendethiel commented Jan 10, 2018

Actually there's another bug underneath:

for let {}:k in v when k > 0
  ...

gives

var i$, ref$, len$;
for (i$ = 0, len$ = (ref$ = v).length; i$ < len$; ++i$) {
  if (k > 0) {
    (fn$.call(this, ref$[i$]));
  }
}
function fn$(){
  throw Error('unimplemented');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants