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

babili made variable lose #412

Closed
lin-chao opened this issue Feb 9, 2017 · 1 comment
Closed

babili made variable lose #412

lin-chao opened this issue Feb 9, 2017 · 1 comment
Labels
bug Confirmed bug with es2015 The bug is caused when used with es2015-block-scoping plugin

Comments

@lin-chao
Copy link

lin-chao commented Feb 9, 2017

Babili 0.0.11

Input:

let tabs = [1,2,3,4,5]
let tabIdx = 0

for (let i = 0; i < tabs.length; i++) {
  // do something
}

console.log({
  tabIdx: tabIdx
})

Output:

"use strict";
for (var tabs = [1, 2, 3, 4, 5], i = 0; i < tabs.length; i++);
console.log({
  tabIdx: tabIdx
});

can not find variable: tabIdx

@boopathi
Copy link
Member

boopathi commented Feb 9, 2017

This happens when using with es2015 preset.

let is converted to var and brought inside

for(var tabs = [], tabId = 0, i = 0; ; ) {} // tabId becomes deadcode 
use(tabId); // still treated as let binding 

@kangax I guess this is another binding issue

@boopathi boopathi added the bug Confirmed bug label Feb 9, 2017
@boopathi boopathi added the with es2015 The bug is caused when used with es2015-block-scoping plugin label Feb 20, 2017
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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