-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Let and const support #904
Conversation
…ations to align with local declarations
Conflicts: src/compiler/types.ts
@@ -2827,7 +2848,7 @@ module ts { | |||
parseExpected(SyntaxKind.CaseKeyword); | |||
node.expression = parseExpression(); | |||
parseExpected(SyntaxKind.ColonToken); | |||
node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatement); | |||
node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatementAllowingLetDeclaration); |
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.
i thought we would not allow 'let' here as we're not in a block scope. or do you check for that later?
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.
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:
A Lexical Environment is a specification type used to define the association of Identifiers to specific variables and functions based upon the lexical nesting structure of ECMAScript code. A Lexical Environment consists of an Environment Record and a possibly null reference to an outer Lexical Environment. Usually a Lexical Environment is associated with some specific syntactic structure of ECMAScript code such as a FunctionDeclaration, a BlockStatement, or a Catch clause of a TryStatement and a new Lexical Environment is created each time such code is evaluated.
I will follow up to see if this is intentional or just an error in the spec and update this accordingly.
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.
They say "such as", which I normally interpret as "including but not limited to".
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.
yeah. checked with @bterlson and he confirmed that that is not the intention. so keeping Switch, try and finally blocks as valid lexical scopes
Overall looks great! |
…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
TypeScript's specification seems to allow a missing initializer for destructuring lexical bindings, whereas the EC262 specification does not. Is this intentional? In that case, I believe it should only be allowed in the case that a type annotation is present, e.g., in |
@nickie, can you report a new bug for this, with the label Spec? |
@sandersn FYI only Owners (i.e. us) can add Labels |
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:
What is left: