-
Notifications
You must be signed in to change notification settings - Fork 12.9k
support block scoped vars captured in closures inside loops #5208
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
I noticed that there isn't a flag to enable this. We should consider having a flag to warn when block-scoped variables are captured, or create a TSLint rule for it that we can use ourselves. |
Don't think we should hide it under the flag:
Adding TSLint rule for it sounds reasonable |
pinging @mhegazy: can you have a look at this PR when you have time? |
|
||
interface ConvertedLoopState { | ||
// set of labels that occured inside the converted loop | ||
// used to determine if labeled jump can be emitted as is or it should be dispatched to calling code |
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.
Can you use JSDoc for these?
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.
done
I don't see an example of |
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.
It seems like this line should have a period at the end of it.
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.
done
Can you add a test for class C {
constructor(private N: number) { }
foo() {
for (let i = 0; i < 100; i++) {
let f = () => this.N * i;
}
}
} |
@DanielRosenwasser any other comments? |
emit(node.label); | ||
write(": "); | ||
} | ||
|
||
function emitLabelledStatement(node: LabeledStatement) { |
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.
Spelling
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.
oops, thanks
👍 |
support block scoped vars captured in closures inside loops
This is awesome!!! |
With version class C {
constructor(private N: number) {}
foo() {
for (let i of [0]) {
let f = () => i;
this.N = f();
}
}
} is not correctly transformed. (The |
Glad to help! :) |
Fixes #3915