-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add basic support for await with the pipeline operator #7154
Changes from 2 commits
5d539fd
016784a
9c78ae8
834ad9c
cc95f94
176c038
3c5b19a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var incPromise = (x) => Promise.resolve(x + 1); | ||
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. i'd prefer to have the same code in actual / exec if they are in the same directory, exec differs slightly right now and it makes it hard to compare those files (assert ofc should stay just in exec) 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. I made them match now. I think I may have saved the file with Prettier on at some point. 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. Oh, I didnt mean that they do not match in sense of formatting - i think there was some differenc in how 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. Oh, got it. I also changed the usage of that variable down below. Either way, they're the same now. 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. Cool! |
||
var double = (x) => x * 2; | ||
|
||
var result = async () => 10 |> await incPromise; | ||
var result2 = async () => 10 |> await incPromise |> double; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var incPromise = x => Promise.resolve(x + 1); | ||
var double = x => x * 2; | ||
|
||
var result = async () => 10 |> await incPromise; | ||
var result2 = async () => 10 |> await incPromise |> double; | ||
|
||
return Promise.all([result(), result2()]).then(([r, r2]) => { | ||
assert.equal(r, 11); | ||
assert.equal(r2, 22); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var incPromise = x => Promise.resolve(x + 1); | ||
|
||
var double = x => x * 2; | ||
|
||
var result = | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref = babelHelpers.asyncToGenerator(function* () { | ||
var _; | ||
|
||
return _ = 10, yield (0, incPromise)(_); | ||
}); | ||
|
||
return function result() { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
|
||
var result2 = | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref2 = babelHelpers.asyncToGenerator(function* () { | ||
var _ref3, _2; | ||
|
||
return _ref3 = (_2 = 10, yield (0, incPromise)(_2)), double(_ref3); | ||
}); | ||
|
||
return function result2() { | ||
return _ref2.apply(this, arguments); | ||
}; | ||
}(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": ["proposal-pipeline-operator", "external-helpers", "transform-async-to-generator"], | ||
"parserOpts": { | ||
"allowReturnOutsideFunction": true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var incPromise = (x) => Promise.resolve(x + 1); | ||
var double = (x) => x * 2; | ||
|
||
var result = async () => 10 |> await incPromise; | ||
var result2 = async () => 10 |> await incPromise |> double; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var incPromise = x => Promise.resolve(x + 1); | ||
var double = x => x * 2; | ||
|
||
var result = async () => 10 |> await incPromise; | ||
var result2 = async () => 10 |> await incPromise |> double; | ||
|
||
return Promise.all([result(), result2()]).then(([r, r2]) => { | ||
assert.equal(r, 11); | ||
assert.equal(r2, 22); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
var incPromise = x => Promise.resolve(x + 1); | ||
|
||
var double = x => x * 2; | ||
|
||
var result = async () => { | ||
var _; | ||
|
||
return _ = 10, await (0, incPromise)(_); | ||
}; | ||
|
||
var result2 = async () => { | ||
var _ref, _2; | ||
|
||
return _ref = (_2 = 10, await (0, incPromise)(_2)), double(_ref); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"minNodeVersion": "7.6.0", | ||
"parserOpts": { | ||
"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.
foo |> yield bar
shouldn't be transfrmed; it should become something like (_temp = yield bar, _temp(foo)
).If there isn't a way of transforming
|> await foo
before transforming the async function, you can workaround the problem by addingnode.__wasAwait
to yield expressions generated by the async functions plugin and then do