Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[systemjs] Fix nested let/const shadowing imported bindings #14057

Merged
6 changes: 6 additions & 0 deletions packages/babel-helper-hoist-variables/src/index.ts
Expand Up @@ -38,8 +38,14 @@ const visitor = {
> = path.get("declarations");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hoistVariable visitor should be merged with environmentVisitor, too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets do it in another PR since it's separate from this bug 👍

let firstId;

const needsRename =
path.node.kind !== "var" && path.parentPath.isBlockStatement();

for (const declar of declarations) {
firstId = declar.node.id;
if (needsRename) {
declar.scope.rename(declar.node.id.name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TS warning here is correct; I think this breaks, for example, with const { x } = {}. You probably need to do

if (needsRename) {
  for (const name of Object.keys(declar.getBindingIdentifiers()) {
    declar.scope.rename(name);
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will do that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add a test for this!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will add the test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it's working now.

}

if (declar.node.init) {
nodes.push(
Expand Down
Expand Up @@ -15,4 +15,4 @@ System.register([], function (_export, _context) {
_export("testProp", testProp = 'test property');
}
};
});
});
@@ -0,0 +1,8 @@
import { x } from './x.js';

if (true) {
const x = 1;
console.log(x);
}

new (class extends x {})();
@@ -0,0 +1,19 @@
System.register(["./x.js"], function (_export, _context) {
"use strict";

var x, _x;

return {
setters: [function (_xJs) {
x = _xJs.x;
}],
execute: function () {
if (true) {
_x = 1;
console.log(_x);
}

new class extends x {}();
}
};
});