-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add support for captured block scoped bindings #7693
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
Conversation
@@ -62,10 +195,19 @@ namespace ts { | |||
const savedEnclosingBlockScopeContainer = enclosingBlockScopeContainer; | |||
const savedEnclosingBlockScopeContainerParent = enclosingBlockScopeContainerParent; | |||
|
|||
const savedConvertedLoopState = convertedLoopState; | |||
if (nodeStartsNewLexicalEnvironment(node) || isClassLike(node)) { |
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.
What about an arrow function in a computed property name or extends clause of a class?
Good point |
onBeforeVisitNode(node); | ||
const savedConvertedLoopState = convertedLoopState; | ||
if (nodeStartsNewLexicalEnvironment(node)) { | ||
// don't treat content of nodes that start new lexical environment or class-like nodes as part of converted loop copy |
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.
This comment may now be incorrect.
How do we want to handle captured block scope bindings for initializers?
let ar = [];
for (let i = 0; i < 2; i++) {
ar.push(class { x = i; });
}
console.log(new ar[0]().x); // should this be 0 or 2?
console.log(new ar[1]().x); // should this be 1 or 2?
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.
comment is fixed. Re initializers, I think this code should be equivalent to
"use strict"
let ar = [];
for (let i = 0; i < 2; i++) {
ar.push(class { x: number; constructor() { this.x=i }; });
}
console.log(new ar[0]().x); // should be 0
console.log(new ar[1]().x); // should be 1
old emitter does not support this either so I'll file it as a separate issue that should be fixed
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.
filed #7714 to track it
👍 |
nodeIsSynthesized(statements[0]) || | ||
rangeStartPositionsAreOnSameLine(parentNode, statements[0], currentSourceFile) | ||
); | ||
if (emitAsSingleStatement) { |
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.
Nit: Newline above
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.
✅
// cc @rbuckton