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
Changes from 2 commits
45f4c1f
8199f31
69c067b
a312fe2
15714de
6fe46d8
14e9cfd
aa5593e
aeb81ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,12 @@ const visitor = { | |
|
||
for (const declar of declarations) { | ||
firstId = declar.node.id; | ||
if ( | ||
declar.parentPath.parentPath.isBlockStatement() && | ||
declar.parent.kind !== "var" | ||
) { | ||
declar.scope.rename(declar.node.id.name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 if (needsRename) {
for (const name of Object.keys(declar.getBindingIdentifiers()) {
declar.scope.rename(name);
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I will do that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also add a test for this! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I will add the test There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ expect( | |
bar; | ||
} | ||
).toBe("foo"); | ||
expect(bar).toBe("foo"); | ||
// expect(bar).toBe("foo"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This behavior should not change. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { x } from './x.js'; | ||
|
||
if (true) { | ||
const x = 1; | ||
console.log(x); | ||
} | ||
|
||
new (class extends x {})(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 {}(); | ||
} | ||
}; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: we can hoist this check outside of the
for
loop:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think we can just edit the
Scope
visitor above to checkkind === "let" || kind === "const"
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I will change that.