Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve empty for...of loops (#3132)
* Add test based on #3126 * Placeholder fix * comment out options * remove solo * get rid of comments * leap of faith on export let; * "Fix" two for...of tests * fix for-of-scpes "fix" * fix effect-in-for-of-loop test * fix for effect-in-for-of-loop-in-functions
- Loading branch information
1 parent
bc5b98d
commit a92d09d
Showing
12 changed files
with
54 additions
and
54 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
description: 'preserves for...of loops' | ||
}; |
20 changes: 20 additions & 0 deletions
20
test/function/samples/preserve-for-of-iterable/iterables.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export let dirty; | ||
|
||
export const zeroToFive = { | ||
[Symbol.iterator]() { | ||
return { | ||
current: 0, | ||
last: 5, | ||
next() { | ||
const ret = this.current < this.last | ||
? { done: false, value: this.current++ } | ||
: { done: true }; | ||
|
||
// assert later | ||
dirty = this.current; | ||
|
||
return ret; | ||
} | ||
}; | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export const awaitable = async (iterable) => { | ||
for await (const value of iterable) { | ||
} | ||
} | ||
|
||
// This is equivalent to the above 'awaitable' function. | ||
export const equivalent = async (iterable) => { | ||
const iterator = iterable[Symbol.asyncIterator]() | ||
let { done } = await iterator.next() | ||
while (!done) { | ||
({ done } = await iterator.next()) | ||
} | ||
|
||
} | ||
|
||
export const iterate = iterable => { | ||
for (const value of iterable) { | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { zeroToFive, dirty } from './iterables'; | ||
import { iterate } from './loops'; | ||
|
||
assert.equal(dirty, undefined); | ||
iterate(zeroToFive); | ||
assert.equal(dirty, 5); |