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
Optimize transform-async-to-generator
output
#14122
Changes from all commits
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,16 @@ | ||
foo(async (x) => {}); | ||
foo(async ([x]) => {}); | ||
foo(async ({ x }) => {}); | ||
|
||
foo(async function (x) {}); | ||
foo(async function ([x]) {}); | ||
foo(async function ({ x }) {}); | ||
|
||
foo(async ([]) => {}); | ||
foo(async ({}) => {}); | ||
|
||
foo(async function ([]) {}); | ||
foo(async function ({}) {}); | ||
|
||
export default async ([...x]) => {}; | ||
|
||
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. There is one more case that we should test: export default async function (x) {} The function should still be wrapped, because it is a function declaration and it needs to be hoisted. Why?Otherwise this code doesn't work, when // a.js
import x from "./b.js";
x.then(console.log);
export default async function () { return 1 } // b.js
import f from "./a.js";
export default f(); 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. Done. test added. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": ["transform-async-to-generator"], | ||
"assumptions": { | ||
"ignoreFunctionLength": true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
foo( /*#__PURE__*/babelHelpers.asyncToGenerator(function* (x) {})); | ||
foo( /*#__PURE__*/babelHelpers.asyncToGenerator(function* ([x]) {})); | ||
foo( /*#__PURE__*/babelHelpers.asyncToGenerator(function* ({ | ||
x | ||
}) {})); | ||
foo( /*#__PURE__*/babelHelpers.asyncToGenerator(function* (x) {})); | ||
foo( /*#__PURE__*/babelHelpers.asyncToGenerator(function* ([x]) {})); | ||
foo( /*#__PURE__*/babelHelpers.asyncToGenerator(function* ({ | ||
x | ||
}) {})); | ||
foo( /*#__PURE__*/babelHelpers.asyncToGenerator(function* ([]) {})); | ||
foo( /*#__PURE__*/babelHelpers.asyncToGenerator(function* ({}) {})); | ||
foo( /*#__PURE__*/babelHelpers.asyncToGenerator(function* ([]) {})); | ||
foo( /*#__PURE__*/babelHelpers.asyncToGenerator(function* ({}) {})); | ||
export default /*#__PURE__*/babelHelpers.asyncToGenerator(function* ([...x]) {}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default async function (x) {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": ["transform-async-to-generator"], | ||
"assumptions": { | ||
"ignoreFunctionLength": true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default function (_x) { | ||
return _ref.apply(this, arguments); | ||
} | ||
|
||
function _ref() { | ||
_ref = babelHelpers.asyncToGenerator(function* (x) {}); | ||
return _ref.apply(this, arguments); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
foo(async function () { | ||
|
||
}); | ||
|
||
bar(async function (x = 1) { | ||
|
||
}); | ||
|
||
baz(async function (...y) { | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
foo( /*#__PURE__*/babelHelpers.asyncToGenerator(function* () {})); | ||
bar( /*#__PURE__*/babelHelpers.asyncToGenerator(function* () { | ||
let x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; | ||
})); | ||
baz( /*#__PURE__*/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.
Probably we can do it by adding
|| isFunctionDeclaration(retFunction)
here.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 don't need to change it.
default export use a different template builder.
The wrapper is in another function.
You can check the test case.
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.
Oh awesome, thanks for the test!