Skip to content

Commit 58c2e23

Browse files
committed
Allow functions to return, yield, and await within comprehensions
1 parent cbfa795 commit 58c2e23

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ export default function (babel) {
214214

215215
function validateComprehensionLoopBody(loopBodyPath) {
216216
loopBodyPath.traverse({
217+
Function(fnPath) {
218+
fnPath.skip();
219+
},
217220
AwaitExpression(awaitPath) {
218221
throw awaitPath.buildCodeFrameError(
219222
"`await` is not allowed within Comprehensions; " +
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
f() ->
2+
c = [for const x of arr:
3+
g() -> return x
4+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function f() {
2+
const c = (() => {
3+
const _arr = [];
4+
for (const x of arr) {
5+
function g() {
6+
return x;
7+
}
8+
9+
_arr.push(g);
10+
}return _arr;
11+
})();
12+
return c;
13+
}

0 commit comments

Comments
 (0)