Skip to content
New issue

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

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

Already on GitHub? # to your account

Some for loops cause incorrect output #430

Closed
cpetrov opened this issue Feb 17, 2017 · 1 comment
Closed

Some for loops cause incorrect output #430

cpetrov opened this issue Feb 17, 2017 · 1 comment
Labels
bug Confirmed bug with es2015 The bug is caused when used with es2015-block-scoping plugin
Milestone

Comments

@cpetrov
Copy link

cpetrov commented Feb 17, 2017

Using let in the initialization part of the for loop used in the function foo() leads to incorrect output.

Input:

function foo() {
  let len = 0;
  for (let i = 0; i < 2; i++) {}
  return len;
}

Output:

"use strict";function foo(){for(var b=0;2>b;b++);return a}

The returned variable a is not defined. The function foo() must always return 0.

Demo: https://babeljs.io/repl/#?babili=true&evaluate=true&lineWrap=false&presets=es2015%2Creact%2Cstage-2&targets=&browsers=&builtIns=false&code=function foo() { let len %3D 0%3B for (let i %3D 0%3B i < 2%3B i%2B%2B) {} return len%3B}

@boopathi boopathi added the bug Confirmed bug label Feb 20, 2017
@boopathi
Copy link
Member

Another let to var binding issue.

Related #412, babel/babel#4818

@boopathi boopathi added the with es2015 The bug is caused when used with es2015-block-scoping plugin label Feb 20, 2017
review-squirrel pushed a commit to eclipsesource/tabris-js that referenced this issue Feb 20, 2017
The function getStringByteSize() refers to an undefined variable in the
minified output. This works around this problem.

See babel/minify#430

Add a verify test for WebSocket.send() to make sure the private
getStringByteSize() can be called without an error being thrown.

Change-Id: I5513e53cc262d13fdc7434601c9557d0814655fc
boopathi pushed a commit that referenced this issue Nov 12, 2017
…) (#713)

* Fix(merge-sibling-var): force recalc ref when concat for-loop var (#485)

Fix #594
Fix #430
Fix #412

* Add test cases of es2015 scoping issue (#713)

* Use babel path API instead of mutating node
@boopathi boopathi added this to the 1.0 milestone Nov 19, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Confirmed bug with es2015 The bug is caused when used with es2015-block-scoping plugin
Projects
None yet
Development

No branches or pull requests

2 participants