Skip to content

Commit da381ba

Browse files
committed
import Pmod_constraint
1 parent aff0726 commit da381ba

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

jscomp/frontend/ast_await.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let create_await_expression (e : Parsetree.expression) =
77
Ast_helper.Exp.apply ~loc unsafe_await [(Nolabel, e)]
88

99
(* Transform `@res.await M` to unpack(@res.await Js.import(module(M: __M0__))) *)
10-
let create_await_module_expression ~module_type_name (e : Parsetree.module_expr)
10+
let create_await_module_expression ~module_type_lid (e : Parsetree.module_expr)
1111
=
1212
let open Ast_helper in
1313
let remove_await_attribute =
@@ -33,8 +33,6 @@ let create_await_module_expression ~module_type_name (e : Parsetree.module_expr)
3333
pmod_attributes =
3434
remove_await_attribute e.pmod_attributes;
3535
})
36-
(Typ.package ~loc:e.pmod_loc
37-
{txt = Lident module_type_name; loc = e.pmod_loc}
38-
[]) );
36+
(Typ.package ~loc:e.pmod_loc module_type_lid []) );
3937
]));
4038
}

jscomp/frontend/bs_builtin_ppx.ml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,17 +221,40 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
221221
the attribute to the whole expression, in general, when shuffuling the ast
222222
it is very hard to place attributes correctly
223223
*)
224+
(* module M = await Belt.List *)
224225
| Pexp_letmodule
225226
(lid, ({pmod_desc = Pmod_ident {txt}; pmod_attributes} as me), expr)
226227
when Res_parsetree_viewer.hasAwaitAttribute pmod_attributes ->
227-
let safe_module_type_name = local_module_type_name txt in
228+
let safe_module_type_lid : Ast_helper.lid =
229+
{txt = Lident (local_module_type_name txt); loc = me.pmod_loc}
230+
in
228231
{
229232
e with
230233
pexp_desc =
231234
Pexp_letmodule
232235
( lid,
233236
Ast_await.create_await_module_expression
234-
~module_type_name:safe_module_type_name me,
237+
~module_type_lid:safe_module_type_lid me,
238+
expr );
239+
}
240+
(* module M = await (Belt.List: BeltList) *)
241+
| Pexp_letmodule
242+
( lid,
243+
({
244+
pmod_desc =
245+
Pmod_constraint
246+
({pmod_desc = Pmod_ident _}, {pmty_desc = Pmty_ident mtyp_lid});
247+
pmod_attributes;
248+
} as me),
249+
expr )
250+
when Res_parsetree_viewer.hasAwaitAttribute pmod_attributes ->
251+
{
252+
e with
253+
pexp_desc =
254+
Pexp_letmodule
255+
( lid,
256+
Ast_await.create_await_module_expression ~module_type_lid:mtyp_lid
257+
me,
235258
expr );
236259
}
237260
| _ -> default_expr_mapper self e
@@ -531,6 +554,9 @@ let rec structure_mapper ~await_context (self : mapper) (stru : Ast_structure.t)
531554
~typ:(Mty.typeof_ ~loc me));
532555
]
533556
in
557+
let safe_module_type_lid : Ast_helper.lid =
558+
{txt = Lident safe_module_type_name; loc = mb.pmb_expr.pmod_loc}
559+
in
534560
module_type_decl
535561
@ (* module M = @res.await Belt.List *)
536562
{
@@ -541,7 +567,7 @@ let rec structure_mapper ~await_context (self : mapper) (stru : Ast_structure.t)
541567
mb with
542568
pmb_expr =
543569
Ast_await.create_await_module_expression
544-
~module_type_name:safe_module_type_name mb.pmb_expr;
570+
~module_type_lid:safe_module_type_lid mb.pmb_expr;
545571
};
546572
}
547573
:: structure_mapper ~await_context self rest

jscomp/test/Import.js

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)