bublejs / bublejs/buble

[bug] variable name mangling not working as expected with destructuring in for..of

Open
#182 5 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
874
Forks
62
PR merge metrics
No merged PRs in 30d

Description

As described in https://github.com/Rich-Harris/buble/issues/181#issuecomment-458631107, the first way doesn't work, the second way does work.

In practice, I have this code:

```js
for (const [target, weights] of Array.from(weightsPerTarget)) {
console.log( target, weights )
debugger
```

which I see is compiled to the following erroneous output:

```js
for (var i$4 = 0, list$1 = _babel_runtime_core_js_array_from__WEBPACK_IMPORTED_MODULE_1___default()(weightsPerTarget); i$4 < list$1.length; i$4 += 1) {
var ref = list$1[i$4];
var target = ref[0];
var weights = ref[1]; // HERE! "weights" should be "weights$1"

console.log(target, weights$1); // and it is used here
debugger;
```

so if I change my source code to

```js
for (const entry of Array.from(weightsPerTarget)) {
const [target, weights] = entry
console.log( target, weights )
debugger
```

then I get an output that works:

```js
for (var i$4 = 0, list$1 = _babel_runtime_core_js_array_from__WEBPACK_IMPORTED_MODULE_1___default()(weightsPerTarget); i$4 < list$1.length; i$4 += 1) {
var entry = list$1[i$4];

var target = entry[0];
var weights$1 = entry[1];
console.log(target, weights$1);
debugger;
```

I'm on Buble 0.19.0, and haven't updated yet, so I'm not yet sure if this still happens in a newer version.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.