@@ -50,8 +50,8 @@ let splice_obj_apply obj name args =
50
50
bundle *)
51
51
52
52
let 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
55
55
E. external_var ?import_attributes ~external_name: bundle id
56
56
57
57
(* let handle_external_opt
@@ -216,21 +216,22 @@ let assemble_args_has_splice (arg_types : specs) (args : exprs) :
216
216
217
217
let translate_scoped_module_val
218
218
(module_name : External_ffi_types.external_module_name option ) (fn : string )
219
- (scopes : string list ) =
219
+ (scopes : string list )
220
+ ~dynamic_import =
220
221
match module_name with
221
222
| Some { bundle; module_bind_name; import_attributes } -> (
222
223
match scopes with
223
224
| [] ->
224
225
let default = fn = " default" in
225
226
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
227
228
in
228
229
E. external_var_field ?import_attributes ~external_name: bundle ~field: fn ~default id
229
230
| x :: rest ->
230
231
(* TODO: what happens when scope contains "default" ?*)
231
232
let default = false in
232
233
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
234
235
in
235
236
let start =
236
237
E. external_var_field ?import_attributes ~external_name: bundle ~field: x ~default id
@@ -250,10 +251,10 @@ let translate_scoped_access scopes obj =
250
251
| x :: xs -> Ext_list. fold_left xs (E. dot obj x) E. dot
251
252
252
253
let 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 =
254
255
match ffi with
255
256
| 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
257
258
(match args with
258
259
| [ {expression_desc = Array (strings, _); _}; {expression_desc = Array (values, _); _} ] ->
259
260
E. tagged_template fn strings values
@@ -262,7 +263,7 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types
262
263
(if dynamic then splice_apply fn args
263
264
else E. call ~info: { arity = Full ; call_info = Call_na } fn args))
264
265
| 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
266
267
if splice then
267
268
let args, eff, dynamic = assemble_args_has_splice arg_types args in
268
269
add_eff eff
@@ -283,7 +284,7 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types
283
284
add_eff eff
284
285
@@ E. call ~info: { arity = Full ; call_info = Call_na } fn args
285
286
| 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
287
288
if splice then
288
289
let args, eff, dynamic = assemble_args_has_splice arg_types args in
289
290
(* TODO: fix in rest calling convention *)
@@ -313,14 +314,14 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types
313
314
in
314
315
if splice then
315
316
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
317
318
add_eff eff
318
319
(mark () ;
319
320
if dynamic then splice_new_apply fn args
320
321
else E. new_ fn args)
321
322
else
322
323
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
324
325
add_eff eff
325
326
(mark () ; E. new_ fn args)
326
327
| Js_send { splice; name; js_send_scopes } -> (
@@ -346,16 +347,16 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types
346
347
~info: { arity = Full ; call_info = Call_na }
347
348
(E. dot self name) args)
348
349
| _ -> 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
350
351
| Js_var { name; external_module_name; scopes } ->
351
352
(* TODO #11
352
353
1. check args -- error checking
353
354
2. support [@@scope "window"]
354
355
we need know whether we should call [add_js_module] or not
355
356
*)
356
- translate_scoped_module_val external_module_name name scopes
357
+ translate_scoped_module_val external_module_name name scopes ~dynamic_import
357
358
| Js_module_as_class module_name ->
358
- let fn = external_var module_name in
359
+ let fn = external_var module_name ~dynamic_import in
359
360
let args, eff = assemble_args_no_splice arg_types args in
360
361
(* TODO: fix in rest calling convention *)
361
362
add_eff eff
0 commit comments