Skip to content

Commit

Permalink
Fix block scoped vars shadowing globals
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Dec 6, 2022
1 parent 174b311 commit 8e38136
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/babel-plugin-transform-block-scoping/src/index.ts
Expand Up @@ -202,6 +202,7 @@ function transformBlockScopedVariable(
// a nested scope and thus we don't need to assume that it
// may be declared (but not registered yet) in an upper one.
blockScope.parent.hasBinding(name, { noUids: true }) ||
blockScope.parent.hasGlobal(name) ||
(isProgramScope && varScope.hasGlobal(name))
) {
newName = blockScope.generateUid(name);
Expand Down
@@ -0,0 +1,15 @@
{ a; }
{ let a; }

(function () {
{ b; }
{ let b; }
})();

{ c = 0; }
{ let c; }

(function () {
{ d = 0; }
{ let d; }
})
@@ -0,0 +1,28 @@
{
a;
}
{
var _a;
}
(function () {
{
b;
}
{
var _b;
}
})();
{
c = 0;
}
{
var _c;
}
(function () {
{
d = 0;
}
{
var _d;
}
});

0 comments on commit 8e38136

Please sign in to comment.