-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[T6933] Rename any shadowing Symbol binding #3250
Conversation
👍 |
Current coverage is
|
return; | ||
} | ||
|
||
scope.rename("Symbol"); |
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.
Should this just be a feature of Babel Core? This fixes this specific case, but this'll happen anywhere any global is shadowed. For instance
var Symbol = undefined;
var a;
a = [1, 2, 3];
for (var i of a){
console.log(i);
}
would also throw for this reason.
I assume this same issue would happen with our use of Object
and Promise
, not sure if there are other globals we use in the helpers.
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.
Good point, but are there times when it is expected that we use the
shadowed global? Like if someone wants to use their own promise library?
On Thursday, January 7, 2016, Logan Smyth notifications@github.com wrote:
In packages/babel-plugin-transform-es2015-typeof-symbol/src/index.js
#3250 (comment):@@ -3,6 +3,14 @@ export default function ({ types: t }) {
return {
visitor: {
Scope({ scope }) {
if (!scope.getBinding("Symbol")) {
return;
}
scope.rename("Symbol");
Should this just be a feature of Babel Core? This fixes this specific
case, but this'll happen anywhere any global is shadowed. For instancevar Symbol = undefined;
var a;
a = [1, 2, 3];
for (var i of a){
console.log(i);
}would also throw for this reason.
I assume this same issue would happen with our use of Object and Promise,
not sure if there are other globals we use in the helpers.—
Reply to this email directly or view it on GitHub
https://github.com/babel/babel/pull/3250/files#r49159082.
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.
@amasad
If someone imported their Promise lib as Promise
it would cause the same error Lodash was seeing with its Symbol
module.
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.
Valid point. If we want to only do Symbol for now, that's fine.
As @jdalton says, Promise
is the one case that comes to mind. I don't think I'd say that's what I expect imported Promise
to be used by helpers, but it's possible people are using this behavior and assuming it is correct. I guess if we were going to change Promise, we'd at least want to do it in a non-patch release. It definitely seems like a terrible idea if anyone is relying on that, since their code would break immediately if they used transform-runtime
or external-helpers
, which you could potentially want to introduce at any time.
Ok, let's ship this for now and open a task to track the larger issue. |
[T6933] Rename any shadowing Symbol binding
🚀 |
No description provided.