Incorrect scope after transform-es2015-block-scoping (T7429)
- Dominant language
- TypeScript
- Stars
- 44k
- Forks
- 6k
- Avg merge
- 5d 15h
- Merged PRs (30d)
- 23
Description
> Issue originally made by Juriy Zaytsev (kangax)
### Options
```
{ plugins: ['transform-es2015-block-scoping', {
visitor: {
CallExpression: function(path) {
console.log(`
${path.node.callee.name} ---
own: ${Object.keys(path.scope.bindings)}
parent: ${Object.keys(path.scope.parent.bindings)}
`.replace(/\s+/g, ' '));
}
}
}] },
```
### Input code
```
function f(x) {
let smth = x.foo;
for (let i = 0; i; i++) {
let n;
if (n) return;
g(() => n);
}
}
```
Transformed with block-scoping to:
```
function f(x) {
var smth = x.foo;
var _loop = function (i) {
var n = void 0;
if (n) return {
v: void 0
};
g(() => n);
};
for (var i = 0; i; i++) {
var _ret = _loop(i);
if (typeof _ret === "object") return _ret.v;
}
}
```
### Description
This outputs:
```
g --- own: i,n parent: x,smth,_loop,_ret
_loop --- own: parent: i
```
When encountering CallExpression within a loop, the scope doesn't look correct. Current scope should have `_ret`, `i`, `_loop`, and `x` bindings.
Contributor guide
Research direction
Start by reproducing the shown input with the transform-es2015-block-scoping plugin and its visitor option. Inspect the scope bindings reported for the CallExpression inside the loop and compare them with the expected bindings listed in the issue; done means the reported current scope includes _ret, i, _loop, and x.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100