Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize
transform-async-to-generator
output (#14122)
* Optimize `transform-async-to-generator` output - remove wrapper if the function length is zero. - remove wrapper if the `assumptions.ignoreFunctionLength` is `true`. * chore: update test case and code style * chore: add test
- Loading branch information
1 parent
213397b
commit 910ece5
Showing
11 changed files
with
102 additions
and
21 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
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
16 changes: 16 additions & 0 deletions
16
...orm-async-to-generator/test/fixtures/assumption-ignoreFunctionLength-true/basic/input.mjs
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,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]) => {}; | ||
|
6 changes: 6 additions & 0 deletions
6
...-async-to-generator/test/fixtures/assumption-ignoreFunctionLength-true/basic/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,6 @@ | ||
{ | ||
"plugins": ["transform-async-to-generator"], | ||
"assumptions": { | ||
"ignoreFunctionLength": true | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...rm-async-to-generator/test/fixtures/assumption-ignoreFunctionLength-true/basic/output.mjs
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,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]) {}); |
1 change: 1 addition & 0 deletions
1
...ator/test/fixtures/assumption-ignoreFunctionLength-true/export-default-function/input.mjs
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 @@ | ||
export default async function (x) {} |
6 changes: 6 additions & 0 deletions
6
...r/test/fixtures/assumption-ignoreFunctionLength-true/export-default-function/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,6 @@ | ||
{ | ||
"plugins": ["transform-async-to-generator"], | ||
"assumptions": { | ||
"ignoreFunctionLength": true | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...tor/test/fixtures/assumption-ignoreFunctionLength-true/export-default-function/output.mjs
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,8 @@ | ||
export default function (_x) { | ||
return _ref.apply(this, arguments); | ||
} | ||
|
||
function _ref() { | ||
_ref = babelHelpers.asyncToGenerator(function* (x) {}); | ||
return _ref.apply(this, arguments); | ||
} |
8 changes: 8 additions & 0 deletions
8
...form-async-to-generator/test/fixtures/async-to-generator/no-parameters-and-no-id/input.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 |
---|---|---|
@@ -1,3 +1,11 @@ | ||
foo(async function () { | ||
|
||
}); | ||
|
||
bar(async function (x = 1) { | ||
|
||
}); | ||
|
||
baz(async function (...y) { | ||
|
||
}); |
4 changes: 4 additions & 0 deletions
4
...orm-async-to-generator/test/fixtures/async-to-generator/no-parameters-and-no-id/output.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 |
---|---|---|
@@ -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* () {})); |