Skip to content

Commit cc079c5

Browse files
committed
Fix issue with generating async functions inside loops.
Fixes #6444
1 parent 4755d4a commit cc079c5

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

jscomp/core/js_dump.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,13 @@ and pp_function ~return_unit ~async ~is_method cxt (f : P.t) ~fn_state
421421
| No_name _ -> ()
422422
| Name_non_top name | Name_top name ->
423423
ignore (pp_var_assign inner_cxt f name : cxt));
424+
if async then P.string f L.await;
424425
P.string f L.lparen;
425426
P.string f (L.function_async ~async);
426427
pp_paren_params inner_cxt f lexical;
427428
P.brace_vgroup f 0 (fun _ ->
428429
return_sp f;
429-
P.string f L.function_;
430+
P.string f (L.function_async ~async);
430431
P.space f;
431432
(match fn_state with
432433
| Is_return | No_name _ -> ()

jscomp/core/js_dump_lit.ml

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25+
26+
let await = "await"
27+
2528
let function_ = "function"
2629

2730
let function_async ~async = if async then "async function" else "function"

jscomp/test/async_inside_loop.js

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/async_inside_loop.res

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
let topLevelAsyncFunction = async () => {
2+
for innerScopeVal in 0 to 3 {
3+
let asyncClosureAccessingScopedVal = async () => {
4+
Js.log2("Accessing scoped var inside loop", innerScopeVal)
5+
await Js.Promise.resolve()
6+
}
7+
8+
await asyncClosureAccessingScopedVal()
9+
}
10+
}
11+
12+
let _ = topLevelAsyncFunction()

jscomp/test/build.ninja

+2-1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)