Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Transform
for await
with shadowed variables (#15235)
* fix * review * Update packages/babel-preset-env/test/fixtures/plugins-integration/issue-11610/options.json Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com> * fix * Update packages/babel-plugin-proposal-async-generator-functions/src/index.ts Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>
- Loading branch information
1 parent
0e86d38
commit 382d284
Showing
5 changed files
with
51 additions
and
5 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
11 changes: 11 additions & 0 deletions
11
packages/babel-preset-env/test/fixtures/plugins-integration/issue-11610/exec.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const arr = []; | ||
async function v(source = 2) { | ||
for await (source of [1]) { | ||
arr.push(source); | ||
} | ||
expect(source).toEqual(1); | ||
} | ||
return v().then(() => { | ||
expect(arr).toEqual([1]); | ||
}); | ||
|
4 changes: 4 additions & 0 deletions
4
packages/babel-preset-env/test/fixtures/plugins-integration/issue-11610/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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
async function v(source = 2) { | ||
for await (source of [1]) { | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/babel-preset-env/test/fixtures/plugins-integration/issue-11610/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,7 @@ | ||
{ | ||
"plugins": ["transform-parameters", "proposal-async-generator-functions"], | ||
"parserOpts": { | ||
"allowReturnOutsideFunction": true | ||
}, | ||
"minNodeVersion": "8.0.0" | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/babel-preset-env/test/fixtures/plugins-integration/issue-11610/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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
async function v() { | ||
let source = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2; | ||
var _iteratorAbruptCompletion = false; | ||
var _didIteratorError = false; | ||
var _iteratorError; | ||
try { | ||
for (var _iterator = babelHelpers.asyncIterator([1]), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) { | ||
source = _step.value; | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (_iteratorAbruptCompletion && _iterator.return != null) { | ||
await _iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
} |