-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change assumes loop blocks have scope (they do in ES6), which means it "fixes" (i.e. changes) the pre-ES6 behaviour of `const` declarations within loops. Whilst this is "correct", it differs from the previous behaviour and so early JS engines that previously returned "incorrect" results will now return "correct" results: specifically `const` in a loop is local and can be deferenced in a callback with it's loop value rather than it's terminal value. This change affects NodeJS versions before 6.x, Chrome until approx v48, Safari 9 and possibly 10 (I've not verified which browser versions are actually affected). These engine will run generate "correct" ES6 results for loops like: ``` async function nop(x) { return x } var resolve,p = new Promise(function(r){resolve = r}) ; var i = 0, x = 0, s = 1 ; while (i<5) { const j = i+1 ; await nop() ; setTimeout(function(){ x += 1 ; s *= j ; // REFERS to "j" if (x===5) { resolve(s) ; } }, 0); i++ ; } return await p ; ```
- Loading branch information
Showing
2 changed files
with
21 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters