-
Notifications
You must be signed in to change notification settings - Fork 463
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
Dynamic import in expression #6310
Conversation
Side note: I have to go now, I'll fix the formatting part couple of hours later 😓 |
Not to handle the case of // no need
await Belt.List |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thanks!
Just some code style comments.
Remember to add a changelog before merging.
@@ -214,6 +221,19 @@ let expr_mapper ~async_context ~in_function_def (self : mapper) | |||
the attribute to the whole expression, in general, when shuffuling the ast | |||
it is very hard to place attributes correctly | |||
*) | |||
| Pexp_letmodule | |||
(lid, ({pmod_desc = Pmod_ident {txt}; pmod_attributes} as me), expr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need this too, or are the use cases of this kind more rare?
| Pmod_constraint of module_expr * module_type
(* (ME : MT) *)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, correct! I'll add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added the case of Pmod_constraint ({pmod_desc = Pmod_ident _}, {pmty_desc = Pmty_ident mtyp_lid})
additionally, e.g. ME: MT
. In other cases, for example, I don't think Pmty_alias
or Pmty_with are applicable
for dynamic import. Any thought?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree
jscomp/frontend/bs_builtin_ppx.ml
Outdated
match has_local_module_name with | ||
| Some _ -> None | ||
| None -> | ||
let open Ast_helper in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove the open, just makes the code more indirect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand what the indirect means correctly:
1ed974f
jscomp/frontend/bs_builtin_ppx.ml
Outdated
(* [ module __Belt_List__ = module type of Belt.List ] *) | ||
let module_type_decls = | ||
module_exprs | ||
|> List.filter_map (fun ({pmod_desc} as me : Parsetree.module_expr) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: instead of filter-map twice and compose, why not compose the functions inside directly, and do only 1 filter-map.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last changes look good.
How about adding 1 more example whith 2 module awaits in the same function.
@@ -214,6 +221,19 @@ let expr_mapper ~async_context ~in_function_def (self : mapper) | |||
the attribute to the whole expression, in general, when shuffuling the ast | |||
it is very hard to place attributes correctly | |||
*) | |||
| Pexp_letmodule | |||
(lid, ({pmod_desc = Pmod_ident {txt}; pmod_attributes} as me), expr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree
Good catch, thanks. There an issue in that case. I'll fix it. |
jscomp/frontend/bs_builtin_ppx.ml
Outdated
~module_type_lid:safe_module_type_lid me, | ||
expr ); | ||
} | ||
self.expr self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little dangerous.
One never applies the recursion to the whole expression, but to the subparts.
The danger is to create infinite loops.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, agree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Final comments
jscomp/frontend/bs_builtin_ppx.ml
Outdated
me, | ||
expr ); | ||
} | ||
self.expr self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
Left comments for some final changes before merging. |
Thanks! f3ebaff |
Ready to merge? |
Fixes #6300
This PR fixes the issue #6300 that is formatting removes
await
keyword. This is not just a formatting issue, it's an issue because there is no transformation for when dynamic imports are used in expressions in addition to one of the structure_items,Pstr_module
.This PR add the transformation for
andPstr_eval
Pstr_value
.await
in the expression