Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix allowing using dyanmic import of module instead of async function #6434

Merged
merged 4 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

#### :bug: Bug Fix

- Fix issue with Dynamic import of module in nested expressions https://github.com/rescript-lang/rescript-compiler/pull/6431
- Fix issue with dynamic import of module in nested expressions https://github.com/rescript-lang/rescript-compiler/pull/6431
- Fix issue where GenType was not supporting `@tag` on ordinary variatns https://github.com/rescript-lang/rescript-compiler/pull/6437
- Fix using dynamic import of module in block instead of async function https://github.com/rescript-lang/rescript-compiler/pull/6434
- Fix issue with using dynamic import of module in uncurried mode https://github.com/rescript-lang/rescript-compiler/pull/6434

#### :nail_care: Polish

Expand Down
21 changes: 19 additions & 2 deletions jscomp/frontend/bs_builtin_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,29 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
let async_saved = !async_context in
let result = expr_mapper ~async_context ~in_function_def self e in
async_context := async_saved;
match Ast_attributes.has_await_payload e.pexp_attributes with
let is_module, has_await =
match e.pexp_desc with
| Pexp_letmodule (_, {pmod_desc = Pmod_ident _; pmod_attributes}, _)
| Pexp_letmodule
( _,
{
pmod_desc =
Pmod_constraint
({pmod_desc = Pmod_ident _}, {pmty_desc = Pmty_ident _});
pmod_attributes;
},
_ ) ->
(true, Ast_attributes.has_await_payload pmod_attributes)
| _ -> (false, Ast_attributes.has_await_payload e.pexp_attributes)
in
match has_await with
| None -> result
| Some _ ->
if !async_context = false then
Location.raise_errorf ~loc:e.pexp_loc
"Await on expression not in an async context";
Ast_await.create_await_expression result
if is_module = false then Ast_await.create_await_expression result
else result

let typ_mapper (self : mapper) (typ : Parsetree.core_type) =
Ast_core_type_class_type.typ_mapper self typ
Expand Down Expand Up @@ -604,6 +620,7 @@ let rec structure_mapper ~await_context (self : mapper) (stru : Ast_structure.t)
| Pexp_let (_, vbs, expr) -> aux expr @ spelunk_vbs acc vbs
| Pexp_ifthenelse (_, then_expr, Some else_expr) ->
aux then_expr @ aux else_expr
| Pexp_construct (_, Some expr) -> aux expr
| Pexp_fun (_, _, _, expr) | Pexp_newtype (_, expr) -> aux expr
| _ -> acc
in
Expand Down
Loading