Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly delegate .return() in async generator (#10422)
* Correctly delegate .return() in async generator * Add catch param * minNodeVersion * Add another test
- Loading branch information
1 parent
8618447
commit d25262e
Showing
17 changed files
with
264 additions
and
5 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
20 changes: 20 additions & 0 deletions
20
...bel-plugin-proposal-async-generator-functions/test/fixtures/yield-star/issue-9905/exec.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 @@ | ||
const log = []; | ||
|
||
async function* func1() { | ||
log.push(1); | ||
yield "a"; | ||
log.push(2); | ||
} | ||
|
||
async function* func2() { | ||
yield* func1(); | ||
log.push(3); | ||
} | ||
|
||
return (async () => { | ||
const iterator = func2(); | ||
await iterator.next(); | ||
await iterator.return(); | ||
|
||
expect(log).toEqual([1]); | ||
})(); |
3 changes: 3 additions & 0 deletions
3
...lugin-proposal-async-generator-functions/test/fixtures/yield-star/issue-9905/options.json
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 @@ | ||
{ | ||
"minNodeVersion": "8.0.0" | ||
} |
10 changes: 10 additions & 0 deletions
10
...ges/babel-plugin-proposal-async-generator-functions/test/fixtures/yield-star/options.json
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,10 @@ | ||
{ | ||
"parserOpts": { | ||
"allowReturnOutsideFunction": true | ||
}, | ||
"plugins": [ | ||
"external-helpers", | ||
"transform-async-to-generator", | ||
"proposal-async-generator-functions" | ||
] | ||
} |
34 changes: 34 additions & 0 deletions
34
...r-functions/test/fixtures/yield-star/return-method-with-finally-multiple-parallel/exec.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,34 @@ | ||
const log = []; | ||
|
||
async function* inner() { | ||
try { | ||
log.push(1); | ||
yield "a"; | ||
log.push(2); | ||
yield "b"; | ||
log.push(3); | ||
} finally { | ||
log.push(4); | ||
yield "c"; | ||
log.push(5); | ||
} | ||
} | ||
|
||
async function* outer() { | ||
log.push(6); | ||
yield* inner(); | ||
log.push(7); | ||
} | ||
|
||
return (async () => { | ||
const iterator = outer(); | ||
|
||
let res = await iterator.next(); | ||
expect(res).toEqual({ value: "a", done: false }); | ||
expect(log).toEqual([6, 1]); | ||
|
||
const [res1, res2] = await Promise.all([ iterator.return("x"), iterator.return("y") ]); | ||
expect(res1).toEqual({ value: "c", done: false }); | ||
expect(res2).toEqual({ value: "y", done: true }); | ||
expect(log).toEqual([6, 1, 4]); | ||
})(); |
3 changes: 3 additions & 0 deletions
3
...ctions/test/fixtures/yield-star/return-method-with-finally-multiple-parallel/options.json
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 @@ | ||
{ | ||
"minNodeVersion": "8.0.0" | ||
} |
37 changes: 37 additions & 0 deletions
37
...tor-functions/test/fixtures/yield-star/return-method-with-finally-multiple-serial/exec.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,37 @@ | ||
const log = []; | ||
|
||
async function* inner() { | ||
try { | ||
log.push(1); | ||
yield "a"; | ||
log.push(2); | ||
yield "b"; | ||
log.push(3); | ||
} finally { | ||
log.push(4); | ||
yield "c"; | ||
log.push(5); | ||
} | ||
} | ||
|
||
async function* outer() { | ||
log.push(6); | ||
yield* inner(); | ||
log.push(7); | ||
} | ||
|
||
return (async () => { | ||
const iterator = outer(); | ||
|
||
let res = await iterator.next(); | ||
expect(res).toEqual({ value: "a", done: false }); | ||
expect(log).toEqual([6, 1]); | ||
|
||
res = await iterator.return("x"); | ||
expect(res).toEqual({ value: "c", done: false }); | ||
expect(log).toEqual([6, 1, 4]); | ||
|
||
res = await iterator.return("y"); | ||
expect(res).toEqual({ value: "y", done: true }); | ||
expect(log).toEqual([6, 1, 4]); | ||
})(); |
3 changes: 3 additions & 0 deletions
3
...unctions/test/fixtures/yield-star/return-method-with-finally-multiple-serial/options.json
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 @@ | ||
{ | ||
"minNodeVersion": "8.0.0" | ||
} |
37 changes: 37 additions & 0 deletions
37
...sal-async-generator-functions/test/fixtures/yield-star/return-method-with-finally/exec.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,37 @@ | ||
const log = []; | ||
|
||
async function* inner() { | ||
try { | ||
log.push(1); | ||
yield "a"; | ||
log.push(2); | ||
yield "b"; | ||
log.push(3); | ||
} finally { | ||
log.push(4); | ||
yield "c"; | ||
log.push(5); | ||
} | ||
} | ||
|
||
async function* outer() { | ||
log.push(6); | ||
yield* inner(); | ||
log.push(7); | ||
} | ||
|
||
return (async () => { | ||
const iterator = outer(); | ||
|
||
let res = await iterator.next(); | ||
expect(res).toEqual({ value: "a", done: false }); | ||
expect(log).toEqual([6, 1]); | ||
|
||
res = await iterator.return(); | ||
expect(res).toEqual({ value: "c", done: false }); | ||
expect(log).toEqual([6, 1, 4]); | ||
|
||
res = await iterator.next(); | ||
expect(res).toEqual({ value: undefined, done: true }); | ||
expect(log).toEqual([6, 1, 4, 5, 7]); | ||
})(); |
31 changes: 31 additions & 0 deletions
31
...-plugin-proposal-async-generator-functions/test/fixtures/yield-star/return-method/exec.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,31 @@ | ||
const log = []; | ||
|
||
async function* inner() { | ||
log.push(1); | ||
yield "a"; | ||
log.push(2); | ||
yield "b"; | ||
log.push(3); | ||
} | ||
|
||
async function* outer() { | ||
log.push(4); | ||
yield* inner(); | ||
log.push(5); | ||
} | ||
|
||
return (async () => { | ||
const iterator = outer(); | ||
|
||
let res = await iterator.next(); | ||
expect(res).toEqual({ value: "a", done: false }); | ||
expect(log).toEqual([4, 1]); | ||
|
||
res = await iterator.return(); | ||
expect(res).toEqual({ value: undefined, done: true }); | ||
expect(log).toEqual([4, 1]); | ||
|
||
res = await iterator.next(); | ||
expect(res).toEqual({ value: undefined, done: true }); | ||
expect(log).toEqual([4, 1]); | ||
})(); |
3 changes: 3 additions & 0 deletions
3
...in-proposal-async-generator-functions/test/fixtures/yield-star/return-method/options.json
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 @@ | ||
{ | ||
"minNodeVersion": "8.0.0" | ||
} |
37 changes: 37 additions & 0 deletions
37
...oposal-async-generator-functions/test/fixtures/yield-star/throw-method-with-catch/exec.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,37 @@ | ||
const log = []; | ||
|
||
async function* inner() { | ||
try { | ||
log.push(1); | ||
yield "a"; | ||
log.push(2); | ||
yield "b"; | ||
log.push(3); | ||
} catch (e) { | ||
log.push(4); | ||
yield "c"; | ||
log.push(5); | ||
} | ||
} | ||
|
||
async function* outer() { | ||
log.push(6); | ||
yield* inner(); | ||
log.push(7); | ||
} | ||
|
||
return (async () => { | ||
const iterator = outer(); | ||
|
||
let res = await iterator.next(); | ||
expect(res).toEqual({ value: "a", done: false }); | ||
expect(log).toEqual([6, 1]); | ||
|
||
res = await iterator.throw(new Error("TEST")); | ||
expect(res).toEqual({ value: "c", done: false }); | ||
expect(log).toEqual([6, 1, 4]); | ||
|
||
res = await iterator.next(); | ||
expect(res).toEqual({ value: undefined, done: true }); | ||
expect(log).toEqual([6, 1, 4, 5, 7]); | ||
})(); |
37 changes: 37 additions & 0 deletions
37
...osal-async-generator-functions/test/fixtures/yield-star/throw-method-with-finally/exec.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,37 @@ | ||
const log = []; | ||
|
||
async function* inner() { | ||
try { | ||
log.push(1); | ||
yield "a"; | ||
log.push(2); | ||
yield "b"; | ||
log.push(3); | ||
} finally { | ||
log.push(4); | ||
yield "c"; | ||
log.push(5); | ||
} | ||
} | ||
|
||
async function* outer() { | ||
log.push(6); | ||
yield* inner(); | ||
log.push(7); | ||
} | ||
|
||
return (async () => { | ||
const iterator = outer(); | ||
|
||
let res = await iterator.next(); | ||
expect(res).toEqual({ value: "a", done: false }); | ||
expect(log).toEqual([6, 1]); | ||
|
||
res = await iterator.throw(new Error("TEST")); | ||
expect(res).toEqual({ value: "c", done: false }); | ||
expect(log).toEqual([6, 1, 4]); | ||
|
||
// "yield" in finally suspended the exception for one turn | ||
await expect(iterator.next()).rejects.toThrow(/TEST/); | ||
expect(log).toEqual([6, 1, 4, 5]); | ||
})(); |
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 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