GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||
GeezerVison is showing github.com — Let and const support by mhegazy · Pull Request #904 · microsoft/TypeScript Conversation
Contributor
This change adds support for ES6-style block-scoped variable declarations. these are only available when targeting ES6. the change also adds a new target for ES6. There are two variants, let and const. Generaly let and const behave like a var declarations with the following exceptions:
let a = 0; a = 1; let a; // Error: redeclaration
let a = 0; { var a; // Error: redeclaration, as var is hoisted to the top of the scope, and re-declares a }
if (true) { let a = 0; // OK } if (false) let b = 0; // Error for (let i = 0; i< 10; i++) // OK console.log(i);
let a = 0; { let a = "local"; console.log(a) // local } console.log(a); // 0
v = 2; // ok var v; a = 2; let a; // Error, used before initialization
const c = 0; console.log(c); // OK: 0 c = 2; // Error c++; // Error { const c2 = 0; var c2 = 0; // not a redeclaration, as the var is hoisted out, but still a write to c2 }
What is left:
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions…ations to align with local declarations Conflicts: src/compiler/types.ts
Contributor
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 thought we would not allow 'let' here as we're not in a block scope. or do you check for that later?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
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 you are correct. the ES6 spec makes it clear that lexical scopes do not include switch, try or finally blocks, section 8.1:
I will follow up to see if this is intentional or just an error in the spec and update this accordingly.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
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. They say "such as", which I normally interpret as "including but not limited to".
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
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. checked with Brian Terlson (@bterlson) and he confirmed that that is not the intention. so keeping Switch, try and finally blocks as valid lexical scopes
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. …earch for any variable instead of only a blockScoped one to ensure we are not picking it up from a wrong scope. …re that const module elements are not used as references. …t comes to symbol flags, instead of compining BlockScoped and Variable …flag is set. Set the flag by default on all let and const errors to ensure we are not emitting invalid JS code. Conflicts: src/compiler/types.ts
Mohamed Hegazy (mhegazy)
added a commit
that referenced
this pull request
Let and const support
This was referenced
Closed
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
ReviewersNo reviewsUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later. | |||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |