Merge pull request #6156 from jridgewell/pr/5502

Fix overshadowing local binding
This commit is contained in:
Henry Zhu
2017-08-28 13:38:21 -06:00
committed by GitHub
9 changed files with 38 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
function B() {
const B = 1;
}

View File

@@ -0,0 +1,3 @@
function B() {
var B = 1;
}

View File

@@ -0,0 +1,3 @@
(function B() {
const B = 1;
});

View File

@@ -0,0 +1,3 @@
(function B() {
var B = 1;
});

View File

@@ -0,0 +1,3 @@
(function foo() {
let foo = true;
});

View File

@@ -0,0 +1,3 @@
(function foo() {
var foo = true;
});

View File

@@ -346,6 +346,10 @@ export default class Scope {
// ignore parameters
if (kind === "param") return;
// Ignore existing binding if it's the name of the current function or
// class expression
if (local.kind === "local") return;
// ignore hoisted functions if there's also a local let
if (kind === "hoisted" && local.kind === "let") return;
@@ -519,6 +523,7 @@ export default class Scope {
for (const name in ids) {
for (const id of (ids[name]: Array<Object>)) {
let local = this.getOwnBinding(name);
if (local) {
// same identifier so continue safely as we're likely trying to register it
// multiple times

View File

@@ -0,0 +1,8 @@
let obj = {
foo: function foo() {
let foo = true;
console.log('foo ran');
}
};
obj.foo();

View File

@@ -0,0 +1,7 @@
let obj = {
foo: function foo() {
let foo = true;
console.log('foo ran');
}
};
obj.foo();