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

Mutated variables in pseudo-block-scope loops aren't written back when using continue #264

Open
marijnh opened this issue Sep 2, 2020 · 0 comments

Comments

@marijnh
Copy link
Contributor

marijnh commented Sep 2, 2020

For this code...

for (let i = 0; i < 5; i++) {
  console.log(i++, [2].every(x => x != i))
  continue
}

Bublé creates this:

var loop = function ( i$1 ) {
  console.log(i$1++, [2].every(function (x) { return x != i$1; }))
  return
};

for (var i = 0; i < 5; i++) loop( i );

It'd normally add an i = i$1 to the end of the function, because it noticed that i$1 is mutated, but for some reason it doesn't do that when the end of the loop isn't reachable. I originally observed a case where the assignment was generated, but not reached because of a continue (compiled to a return).

In any case, this generated code produces different output than the original, because the mutations to i are dropped at the end of the loop body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant