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

[T6933] Rename any shadowing Symbol binding #3250

Merged
merged 1 commit into from
Jan 13, 2016
Merged

[T6933] Rename any shadowing Symbol binding #3250

merged 1 commit into from
Jan 13, 2016

Conversation

amasad
Copy link
Member

@amasad amasad commented Jan 8, 2016

No description provided.

@hzoo
Copy link
Member

hzoo commented Jan 8, 2016

👍

@codecov-io
Copy link

Current coverage is 85.21%

Merging #3250 into master will decrease coverage by -0.03% as of 635a066

@@            master   #3250   diff @@
======================================
  Files          215     215       
  Stmts        15699   15703     +4
  Branches      3360    3361     +1
  Methods          0       0       
======================================
- Hit          13383   13382     -1
- Partial        674     679     +5
  Missed        1642    1642       

Review entire Coverage Diff as of 635a066

Powered by Codecov. Updated on successful CI builds.

return;
}

scope.rename("Symbol");
Copy link
Member

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.

Copy link
Member Author

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 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.


Reply to this email directly or view it on GitHub
https://github.com/babel/babel/pull/3250/files#r49159082.

Copy link
Member

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.

Copy link
Member

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.

@amasad
Copy link
Member Author

amasad commented Jan 8, 2016

Ok, let's ship this for now and open a task to track the larger issue.

amasad added a commit that referenced this pull request Jan 13, 2016
[T6933] Rename any shadowing Symbol binding
@amasad amasad merged commit b7aa49d into master Jan 13, 2016
@amasad amasad deleted the symbol-rename branch January 13, 2016 01:02
@jdalton
Copy link
Member

jdalton commented Jan 13, 2016

🚀

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 7, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants