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 5 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { x } from './x.js'; | ||
|
||
if (true) { | ||
const { x } = { x: 1 }; | ||
console.log(x); | ||
} | ||
|
||
new (class extends x {})(); |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,23 @@ | ||||||||||||||||||||||
System.register(["./x.js"], function (_export, _context) { | ||||||||||||||||||||||
"use strict"; | ||||||||||||||||||||||
|
||||||||||||||||||||||
var x, _x; | ||||||||||||||||||||||
|
||||||||||||||||||||||
return { | ||||||||||||||||||||||
setters: [function (_xJs) { | ||||||||||||||||||||||
x = _xJs.x; | ||||||||||||||||||||||
}], | ||||||||||||||||||||||
execute: function () { | ||||||||||||||||||||||
if (true) { | ||||||||||||||||||||||
({ | ||||||||||||||||||||||
x: _x | ||||||||||||||||||||||
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. Why if (true) {
const { x: _x } = { x: 1 };
console.log(_x);
} 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. Hoisted vars are renamed, So I think that's the reason 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. What should we change in 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. I have been thinking about this, and the proper fix probably is in the We should not hoist all variables (
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. For (1), be careful because 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. If third parameter is removed from the 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. Yeah we will still need to hoist these export bindings and set up the metadata from which the 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'm surprised that the current helper doesn't work, because we only need 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 don't have a working branch. We can infer the behaviour of babel/packages/babel-helper-hoist-variables/src/index.ts Lines 23 to 32 in dacaab1
The third variable In systemjs transform, what we want to achieve is to hoist
Therefore we still need to extend the hoistVariable helper behaviour. 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-x-Theorist I hope you don't mind, I pushed two commits to your branch.
The updated tests look good, but it probably needs a few new tests to make sure that both |
||||||||||||||||||||||
} = { | ||||||||||||||||||||||
x: 1 | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
console.log(_x); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
new class extends x {}(); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
}); |
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.
The hoistVariable visitor should be merged with
environmentVisitor
, too.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.
Lets do it in another PR since it's separate from this bug 👍