Skip to content

Disallow let\const declarations in the same scope with var declarations. #2027

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

Merged
merged 5 commits into from
Feb 13, 2015

Conversation

vladima
Copy link
Contributor

@vladima vladima commented Feb 13, 2015

Prevent nested let\const to shadow hoisted variables Fixes #1910.

// Do not consider let and const declarations, as duplicate block-scoped declarations
// are handled by the binder.
// We are only looking for var declarations that step on const declarations from a
// are handled by the binder.
Copy link
Member

Choose a reason for hiding this comment

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

Trim this trailing whitespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@mhegazy
Copy link
Contributor

mhegazy commented Feb 13, 2015

👍

// let x;
// var x;
// }
// 'var x' will be placed into the function locals and 'let x' - into the locals of the block
Copy link
Contributor

Choose a reason for hiding this comment

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

So you are saying that you want vars and lets to go to one place, because you want them to collide. The choice of function locals as opposed to block locals is arbitrary, it just has to be the same for both declaration kinds. Correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, i'd add a comment to that effect. I think using hte function as the location makes sense though, as that's where we put parameters. (we should also add tests for parameters/locals/lets (if they collide or not))

@JsonFreeman
Copy link
Contributor

👍

vladima added a commit that referenced this pull request Feb 13, 2015
Disallow let\const declarations in the same scope with var declarations.
@vladima vladima merged commit 9f7c252 into master Feb 13, 2015
@vladima vladima deleted the redefinedLetConst branch February 13, 2015 23:14
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redeclaring 'let' by 'var' or 'var' by 'let' is an error according to ES6 spec, should be a TS compiler error
6 participants