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
Fix for #4943 "Calling an async function with default parameter as function for arguments checking handled synchonous" #5688
Conversation
@hulkish, thanks for your PR! By analyzing the history of the files in this pull request, we identified @loganfsmyth, @spicyj and @hzoo to be potential reviewers. |
Codecov Report
@@ Coverage Diff @@
## 7.0 #5688 +/- ##
=======================================
Coverage 84.56% 84.56%
=======================================
Files 283 283
Lines 9742 9742
Branches 2735 2735
=======================================
Hits 8238 8238
- Misses 991 992 +1
+ Partials 513 512 -1
Continue to review full report at Codecov.
|
This seems simple enough to me. Can you write a test for this? |
@spicyj sure, is there an area i should focus on for this test? Like... should I look for if the arguments are being applied outside of the promise block? |
I think testing for the original issue – something that throws immediately upon execution – and verifying the correct behavior at runtime would be the best test here. |
@spicyj gotcha, ill work on that now |
@spicyj hows that? |
Sorry, I should have been clearer. Can you add an exec.js test as described in https://github.com/babel/babel/blob/7.0/CONTRIBUTING.md#writing-tests that verifies the code actually works at runtime? That is, not just checking the compiled output. That way, if someone changes this in the future, it will be obvious why the function call needs to be inside the Also, not sure it makes sense to have this test in packages/babel-core – any reason you didn't put both in the async-to-generator folder? |
@spicyj no reason, ill move it |
@spicyj better? |
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 seems all right although the test case could likely be as simple as:
assert.doesNotThrow(async function() {
throw new Error('should be thrown after a tick');
});
I'll let someone else review too.
@spicyj agree the test can be simpler, but i think its good to check for doesNotThrow & also a check to see that the asynchronously thrown error is caught properly. |
@@ -216,8 +216,10 @@ helpers.asyncGeneratorDelegate = template(` | |||
helpers.asyncToGenerator = template(` | |||
(function (fn) { | |||
return function () { | |||
var gen = fn.apply(this, arguments); | |||
var _args = arguments; | |||
var _promiseWrapper = this; | |||
return new Promise(function (resolve, 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.
If you want to change this to an arrow function, that's fine with me. Seems like it would be worth it.
if (err instanceof AssertionError) { | ||
throw err; | ||
} | ||
}); |
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.
I believe the runner expects a promise to be returned if it is going to have async operations that need to be waited for. As it is, this will queue up a bunch of async operations, but not wait for them to complete before moving on to a new test.
I guess the easiest solution might be to wrap this whole test in return (async function(){ ... })();
?
@spicyj @loganfsmyth ok:
function _asyncToGenerator(fn) { return function () { var _this = this, _arguments = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(_this, _arguments); [...] Also, this part is necessary to avoid the .then(() => {
throw new Error('should not occcur');
})
.catch(() => true); The |
core-js@2.4.1 node_modules/core-js
make[1]: Leaving directory `/home/travis/build/babel/babel'
make test-only
make[1]: Entering directory `/home/travis/build/babel/babel'
./scripts/test.sh
undefined:233
return new Promise((resolve, reject) => {
^^
SyntaxError: Unexpected token =>
at Object.<anonymous> (/home/travis/build/babel/babel/packages/babel-helper-transform-fixture-test-runner/lib/index.js:186:61) hmm.. im guessing this fails in ci builds (and not locally) because of node version differences.... should i revert my arrow function change back to final output as pasted in my last comment? This is the line it dies on:
Could be wrong, but although the Maybe Unrelated to this issue, but possible solution:
./node_modules/.bin/lerna bootstrap --hoist |
Went ahead and removed the arrow function and just put the expected output in the helper template. That ok? |
Thanks for your PR 👍 The PR is against master (Babel 6) which still support Node < 0.12 and doesn't support arrow functions syntax. I would like to port this to Babel 7 using an arrowFunction, ok for you @loganfsmyth ? |
Yes, let's target to 7.0 |
Ok, as said by @loganfsmyth, would be great to change it to an arrowFunction then. |
@xtuc do i need to do this? If so, can I get some advice on where to apply the change in order to add support for this per the issue explained here. |
@hzoo so I made these changes, resolved the conflicts and pushed... but it's not being reflected here for some reason...what do? |
Do I need to move my changes to the corresponding 7.0 branch in my forked repo? |
ok now im a little confused.... i put the base to 7.0, but then there were conflicts... how do i fix this? |
nvm, got it. |
@hulkish are you fine with the arrowFunction change? The issue was from Node < 0.12. You need to correct the old tests fixtures which still use the function. |
@xtuc yea im good with it.. I just fixed the test for it. |
Ok, so back to this on the ci builds, lol: make[1]: Leaving directory `/home/ubuntu/babel'
make test-only
make[1]: Entering directory `/home/ubuntu/babel'
./scripts/test.sh
undefined:233
return new Promise((resolve, reject) => {
^
SyntaxError: Unexpected token >
at Object.<anonymous> (/home/ubuntu/babel/packages/babel-helper-transform-fixture-test-runner/lib/index.js:186:61)
at Module._compile (module.js:456:26)
at Module._extensions..js (module.js:474:10) |
…mrproved change to self/arguments refs by using arrow function on returned promise
@loganfsmyth anything else i need to do here? |
@@ -0,0 +1,7 @@ | |||
{ | |||
"presets": ["es2015"], |
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.
Still needed post move to 7.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.
I didn't realize this should be moved out for 7.0 branch, ill go ahead and do that.
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.
how's that?
The easiest fix for those failures would be to add |
By the way, thanks so much for this, I know it's been a lot of back and forth, hope it's not too bad of an experience. |
@loganfsmyth no no, its cool... its far more important that the outcome is desired than to rush this anyway |
@loganfsmyth im kinda stuck now though...travis build fails but circlici build works haha |
Node 4 doesn't support destructuring, you'll have to enable the transform to run the exec test. |
@jridgewell @loganfsmyth ok i think this is the one!! |
Thanks so much! |
This change reflects this suggestion: #4943 (comment)