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
Zenparsing async generator functions #4576
Conversation
@@ -54,6 +54,7 @@ export default class File extends Store { | |||
sourceType: this.opts.sourceType, | |||
filename: this.opts.filename, | |||
sourceFileName:this.opts.filename, | |||
allowReturnOutsideFunction: true, |
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.
This is temporary until #3561 is ready and merged
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.
The lets wait for #3561. I wouldn't add that now, as removing it again would be a breaking change if we are careful.
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.
Definitely - this was just to make it pass in this pr
if (task.exec.code) { | ||
let result = run(task); | ||
if (result && typeof result.then === "function") { | ||
return result; |
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.
Basically just returning the result of the runExec(execOpts, execCode);
if it's a promise. We could also just always return
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.
Do we need the .then
check? I'd have thought we could return it without worrying to let Mocha worry about whether it is a promise.
@@ -1,5 +1,5 @@ | |||
let f = (() => { | |||
var ref = babelHelpers.asyncToGenerator(function* () { | |||
var _ref = babelHelpers.asyncToGenerator(function* () { |
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.
Not sure why this happened but some other code changed in the time between the original PR and now
var output = 0; | ||
return forEach(genAnswers(), function(val) { output += val.value }) | ||
.then(function () { | ||
assert.equal(output, 42); |
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.
assert.equal(output, 42);
in a promise. Needs to use the allowReturnOutsideFunction
parser option
2d39e11
to
23ee7ce
Compare
Current coverage is 88.72% (diff: 100%)@@ master #4576 diff @@
==========================================
Files 192 195 +3
Lines 13646 13751 +105
Methods 1413 1423 +10
Messages 0 0
Branches 3153 3169 +16
==========================================
+ Hits 12102 12200 +98
- Misses 1544 1551 +7
Partials 0 0
|
/cc @zenparsing @domenic if you want to review, since you probably know the proposal best. |
23ee7ce
to
0766976
Compare
0766976
to
b3bca86
Compare
@@ -151,7 +156,14 @@ export default function ( | |||
return throwMsg === true || err.message.indexOf(throwMsg) >= 0; | |||
}); |
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.
Should we try to handle the promise case here too, to allow async tests to reject.
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.
We should, do you want to do that in another pr if you want to and with an example test?
Ref #3473
Added an async exec test (had to modify the testing code to support async) from https://github.com/leebyron/async-to-gen
last commit: b3bca86
exec: https://github.com/babel/babel/tree/b3bca86ef1f9019d563af4bb5c814faf3045cc54/packages/babel-plugin-transform-async-generator-functions/test/fixtures/for-await/async-generator-exec
cc @leebyron