support block scoped vars captured in closures inside loops#5208
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? |
There was a problem hiding this comment.
Can you use JSDoc for these?
|
I don't see an example of |
There was a problem hiding this comment.
It seems like this line should have a period at the end of it.
|
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? |
|
👍 |
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 |
Fixes #3915