Skip to content

Commit eccff4f

Browse files
committed
More cases of attributes not handled.
The module constraint can originate from `module M: MT = await N` or from `module M = await (N: MT)` and the attributes go to the module id in the first case, but on the constraint in the second.
1 parent 99240c1 commit eccff4f

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

compiler/frontend/bs_builtin_ppx.ml

+13-5
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,13 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
196196
({
197197
pmod_desc =
198198
Pmod_constraint
199-
({pmod_desc = Pmod_ident _}, {pmty_desc = Pmty_ident mtyp_lid});
200-
pmod_attributes;
199+
( {pmod_desc = Pmod_ident _; pmod_attributes = attrs1},
200+
{pmty_desc = Pmty_ident mtyp_lid} );
201+
pmod_attributes = attrs2;
201202
} as me),
202203
expr )
203-
when Res_parsetree_viewer.has_await_attribute pmod_attributes ->
204+
when Res_parsetree_viewer.has_await_attribute attrs1
205+
|| Res_parsetree_viewer.has_await_attribute attrs2 ->
204206
{
205207
e with
206208
pexp_desc =
@@ -224,14 +226,20 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
224226
in
225227
match e.pexp_desc with
226228
| Pexp_letmodule (_, {pmod_desc = Pmod_ident _; pmod_attributes}, _)
229+
when Ast_attributes.has_await_payload pmod_attributes ->
230+
check_await ();
231+
result
227232
| Pexp_letmodule
228233
( _,
229234
{
230235
pmod_desc =
231-
Pmod_constraint ({pmod_desc = Pmod_ident _; pmod_attributes}, _);
236+
Pmod_constraint
237+
({pmod_desc = Pmod_ident _; pmod_attributes = attrs1}, _);
238+
pmod_attributes = attrs2;
232239
},
233240
_ )
234-
when Ast_attributes.has_await_payload pmod_attributes ->
241+
when Ast_attributes.has_await_payload attrs1
242+
|| Ast_attributes.has_await_payload attrs2 ->
235243
check_await ();
236244
result
237245
| _ when Ast_attributes.has_await_payload e.pexp_attributes ->

tests/tests/src/async_await.mjs

+10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ async function f(value) {
3434
return await Promise.resolve(1);
3535
}
3636

37+
async function f0() {
38+
return (await import("rescript/lib/es6/Belt_Option.js")).forEach;
39+
}
40+
41+
async function f1() {
42+
return (await import("rescript/lib/es6/Belt_Option.js")).forEach;
43+
}
44+
3745
export {
3846
next,
3947
useNext,
@@ -43,5 +51,7 @@ export {
4351
toplevelAwait,
4452
toplevelAwait2,
4553
f,
54+
f0,
55+
f1,
4656
}
4757
/* toplevelAwait Not a pure module */

tests/tests/src/async_await.res

+12
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,15 @@ let toplevelAwait2 = arr[await topFoo()]
1818
let f = async (type input, value: input) => {
1919
await Js.Promise.resolve(1)
2020
}
21+
22+
module type MT = module type of Belt.Option
23+
24+
let f0 = async () => {
25+
module O = await Belt.Option
26+
O.forEach
27+
}
28+
29+
let f1 = async () => {
30+
module O: MT = await Belt.Option
31+
O.forEach
32+
}

0 commit comments

Comments
 (0)