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
Preserve empty for...of loops #3132
Merged
Merged
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b1997b1
Add test based on #3126
imatlopez 2c9ad8f
Placeholder fix
imatlopez df3666e
comment out options
imatlopez 4897ae0
remove solo
imatlopez efc1226
Merge branch 'master' into for-of
imatlopez 57bce51
get rid of comments
imatlopez ca23f1b
leap of faith on export let;
imatlopez 2aab256
"Fix" two for...of tests
imatlopez 116016f
fix for-of-scpes "fix"
imatlopez 5119221
Merge branch 'master' into for-of
imatlopez b0a5c02
fix effect-in-for-of-loop test
imatlopez e23354a
fix for effect-in-for-of-loop-in-functions
imatlopez c2b48af
Merge branch 'master' into for-of
imatlopez File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
description: 'preserves for...of loops' | ||
}; |
18 changes: 18 additions & 0 deletions
18
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,18 @@ | ||
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 | ||
global.foo = this.current; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A cooler way than mutating a global and testing our test isolation would be to export a mutable |
||
|
||
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 } from './iterables'; | ||
import { iterate } from './loops'; | ||
|
||
assert.equal(global.foo, undefined); | ||
iterate(zeroToFive); | ||
assert.equal(global.foo, 5); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could you get rid of the commented code and commented import?