Skip to content

Commit 7edaaa3

Browse files
committed
Add support for toplevel await.
Fixes #5925
1 parent d598b04 commit 7edaaa3

File tree

6 files changed

+45
-3
lines changed

6 files changed

+45
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ subset of the arguments, and return a curried type with the remaining ones https
2323
- Parser/Printer: unify uncurried functions of arity 0, and of arity 1 taking unit. There's now only arity 1 in the source language. https://github.com/rescript-lang/rescript-compiler/pull/5825
2424
- Add support for default arguments in uncurried functions https://github.com/rescript-lang/rescript-compiler/pull/5835
2525
- Inline uncurried application when it is safe https://github.com/rescript-lang/rescript-compiler/pull/5847
26+
- Add support for toplevel `await`
2627

2728
#### :boom: Breaking Change
2829

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/await.res:4:9-17
4+
5+
2 │ let foo = async () => {
6+
3 │ let _ = ()
7+
4 │ () => await a()
8+
5 │ }
9+
6 │
10+
11+
Await on expression not in an async context
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let a = async () => 3
2+
let foo = async () => {
3+
let _ = ()
4+
() => await a()
5+
}

jscomp/frontend/bs_builtin_ppx.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ let rec structure_mapper (self : mapper) (stru : Ast_structure.t) =
502502
let mapper : mapper =
503503
{
504504
default_mapper with
505-
expr = expr_mapper ~async_context:(ref false) ~in_function_def:(ref false);
505+
expr = expr_mapper ~async_context:(ref true) ~in_function_def:(ref false);
506506
pat = pat_mapper;
507507
typ = typ_mapper;
508508
signature_item = signature_item_mapper;

jscomp/test/async_await.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var Caml_array = require("../../lib/js/caml_array.js");
34

45
function next(n) {
56
return n + 1 | 0;
@@ -18,7 +19,25 @@ function Make(I) {
1819
};
1920
}
2021

22+
async function topFoo(param) {
23+
return 1;
24+
}
25+
26+
var arr = [
27+
1,
28+
2,
29+
3
30+
];
31+
32+
var toplevelAwait = await topFoo(undefined);
33+
34+
var toplevelAwait2 = Caml_array.get(arr, await topFoo(undefined));
35+
2136
exports.next = next;
2237
exports.useNext = useNext;
2338
exports.Make = Make;
24-
/* No side effect */
39+
exports.topFoo = topFoo;
40+
exports.arr = arr;
41+
exports.toplevelAwait = toplevelAwait;
42+
exports.toplevelAwait2 = toplevelAwait2;
43+
/* toplevelAwait Not a pure module */

jscomp/test/async_await.res

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,11 @@ module type Impl = {
88
}
99

1010
module Make = (I: Impl) => {
11-
let get = async key => await I.get(key)
11+
let get = async (key) => await I.get(key)
1212
}
13+
14+
let topFoo = async () => 1
15+
let arr = [1, 2, 3]
16+
17+
let toplevelAwait = await topFoo()
18+
let toplevelAwait2 = arr[await topFoo()]

0 commit comments

Comments
 (0)