@@ -50,8 +50,8 @@ let splice_obj_apply obj name args =
5050 bundle *)
5151
5252let external_var
53- ({ bundle; module_bind_name; import_attributes } : External_ffi_types.external_module_name ) =
54- let id = Lam_compile_env. add_js_module ?import_attributes module_bind_name bundle false in
53+ ({ bundle; module_bind_name; import_attributes } : External_ffi_types.external_module_name ) ~ dynamic_import =
54+ let id = Lam_compile_env. add_js_module ?import_attributes module_bind_name bundle false ~dynamic_import in
5555 E. external_var ?import_attributes ~external_name: bundle id
5656
5757(* let handle_external_opt
@@ -216,21 +216,22 @@ let assemble_args_has_splice (arg_types : specs) (args : exprs) :
216216
217217let translate_scoped_module_val
218218 (module_name : External_ffi_types.external_module_name option ) (fn : string )
219- (scopes : string list ) =
219+ (scopes : string list )
220+ ~dynamic_import =
220221 match module_name with
221222 | Some { bundle; module_bind_name; import_attributes } -> (
222223 match scopes with
223224 | [] ->
224225 let default = fn = " default" in
225226 let id =
226- Lam_compile_env. add_js_module ?import_attributes module_bind_name bundle default
227+ Lam_compile_env. add_js_module ?import_attributes module_bind_name bundle default ~dynamic_import
227228 in
228229 E. external_var_field ?import_attributes ~external_name: bundle ~field: fn ~default id
229230 | x :: rest ->
230231 (* TODO: what happens when scope contains "default" ?*)
231232 let default = false in
232233 let id =
233- Lam_compile_env. add_js_module ?import_attributes module_bind_name bundle default
234+ Lam_compile_env. add_js_module ?import_attributes module_bind_name bundle default ~dynamic_import
234235 in
235236 let start =
236237 E. external_var_field ?import_attributes ~external_name: bundle ~field: x ~default id
@@ -250,10 +251,10 @@ let translate_scoped_access scopes obj =
250251 | x :: xs -> Ext_list. fold_left xs (E. dot obj x) E. dot
251252
252253let translate_ffi (cxt : Lam_compile_context.t ) arg_types
253- (ffi : External_ffi_types.external_spec ) (args : J.expression list ) =
254+ (ffi : External_ffi_types.external_spec ) (args : J.expression list ) ~ dynamic_import =
254255 match ffi with
255256 | Js_call { external_module_name; name; splice: _; scopes; tagged_template = true } ->
256- let fn = translate_scoped_module_val external_module_name name scopes in
257+ let fn = translate_scoped_module_val external_module_name name scopes ~dynamic_import in
257258 (match args with
258259 | [ {expression_desc = Array (strings, _); _}; {expression_desc = Array (values, _); _} ] ->
259260 E. tagged_template fn strings values
@@ -262,7 +263,7 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types
262263 (if dynamic then splice_apply fn args
263264 else E. call ~info: { arity = Full ; call_info = Call_na } fn args))
264265 | Js_call { external_module_name = module_name ; name = fn ; splice; scopes; tagged_template = false } ->
265- let fn = translate_scoped_module_val module_name fn scopes in
266+ let fn = translate_scoped_module_val module_name fn scopes ~dynamic_import in
266267 if splice then
267268 let args, eff, dynamic = assemble_args_has_splice arg_types args in
268269 add_eff eff
@@ -283,7 +284,7 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types
283284 add_eff eff
284285 @@ E. call ~info: { arity = Full ; call_info = Call_na } fn args
285286 | Js_module_as_fn { external_module_name; splice } ->
286- let fn = external_var external_module_name in
287+ let fn = external_var external_module_name ~dynamic_import in
287288 if splice then
288289 let args, eff, dynamic = assemble_args_has_splice arg_types args in
289290 (* TODO: fix in rest calling convention *)
@@ -313,14 +314,14 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types
313314 in
314315 if splice then
315316 let args, eff, dynamic = assemble_args_has_splice arg_types args in
316- let fn = translate_scoped_module_val module_name fn scopes in
317+ let fn = translate_scoped_module_val module_name fn scopes ~dynamic_import in
317318 add_eff eff
318319 (mark () ;
319320 if dynamic then splice_new_apply fn args
320321 else E. new_ fn args)
321322 else
322323 let args, eff = assemble_args_no_splice arg_types args in
323- let fn = translate_scoped_module_val module_name fn scopes in
324+ let fn = translate_scoped_module_val module_name fn scopes ~dynamic_import in
324325 add_eff eff
325326 (mark () ; E. new_ fn args)
326327 | Js_send { splice; name; js_send_scopes } -> (
@@ -346,16 +347,16 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types
346347 ~info: { arity = Full ; call_info = Call_na }
347348 (E. dot self name) args)
348349 | _ -> assert false )
349- | Js_module_as_var module_name -> external_var module_name
350+ | Js_module_as_var module_name -> external_var module_name ~dynamic_import
350351 | Js_var { name; external_module_name; scopes } ->
351352 (* TODO #11
352353 1. check args -- error checking
353354 2. support [@@scope "window"]
354355 we need know whether we should call [add_js_module] or not
355356 *)
356- translate_scoped_module_val external_module_name name scopes
357+ translate_scoped_module_val external_module_name name scopes ~dynamic_import
357358 | Js_module_as_class module_name ->
358- let fn = external_var module_name in
359+ let fn = external_var module_name ~dynamic_import in
359360 let args, eff = assemble_args_no_splice arg_types args in
360361 (* TODO: fix in rest calling convention *)
361362 add_eff eff
0 commit comments