rename colliding let bindings with for loop init (#8937)
* rename colliding let bindings with for loop init * added complex test case to check if loop init collisions were handled correctly * updated test files
This commit is contained in:
parent
c82750a48a
commit
0d9e77f559
@ -460,7 +460,9 @@ class BlockScoping {
|
|||||||
|
|
||||||
remap() {
|
remap() {
|
||||||
const letRefs = this.letReferences;
|
const letRefs = this.letReferences;
|
||||||
|
const outsideLetRefs = this.outsideLetReferences;
|
||||||
const scope = this.scope;
|
const scope = this.scope;
|
||||||
|
const blockPathScope = this.blockPath.scope;
|
||||||
|
|
||||||
// alright, so since we aren't wrapping this block in a closure
|
// alright, so since we aren't wrapping this block in a closure
|
||||||
// we have to check if any of our let variables collide with
|
// we have to check if any of our let variables collide with
|
||||||
@ -481,11 +483,20 @@ class BlockScoping {
|
|||||||
scope.rename(ref.name);
|
scope.rename(ref.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.blockPath.scope.hasOwnBinding(key)) {
|
if (blockPathScope.hasOwnBinding(key)) {
|
||||||
this.blockPath.scope.rename(ref.name);
|
blockPathScope.rename(ref.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const key in outsideLetRefs) {
|
||||||
|
const ref = letRefs[key];
|
||||||
|
// check for collisions with a for loop's init variable and the enclosing scope's bindings
|
||||||
|
// https://github.com/babel/babel/issues/8498
|
||||||
|
if (isInLoop(this.blockPath) && blockPathScope.hasOwnBinding(key)) {
|
||||||
|
blockPathScope.rename(ref.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wrapClosure() {
|
wrapClosure() {
|
||||||
|
|||||||
@ -0,0 +1,7 @@
|
|||||||
|
for (let a, { b } = {};;) {
|
||||||
|
let a, { b } = {};
|
||||||
|
|
||||||
|
{
|
||||||
|
let a, { b } = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["transform-destructuring", "transform-block-scoping"]
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
for (var a, _ref = {}, b = _ref.b;;) {
|
||||||
|
var _a = void 0,
|
||||||
|
_ref2 = {},
|
||||||
|
_b = _ref2.b;
|
||||||
|
|
||||||
|
{
|
||||||
|
var _a2 = void 0,
|
||||||
|
_ref3 = {},
|
||||||
|
_b2 = _ref3.b;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
for (let i = 0; i < 3; i++) {
|
||||||
|
let i = 'abc';
|
||||||
|
console.log(i);
|
||||||
|
|
||||||
|
{
|
||||||
|
let i = "hello";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
for (var i = 0; i < 3; i++) {
|
||||||
|
var _i = 'abc';
|
||||||
|
console.log(_i);
|
||||||
|
{
|
||||||
|
var _i2 = "hello";
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user