@@ -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
@@ -273,7 +274,7 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types
273
274
add_eff eff
274
275
@@ E. call ~info: { arity = Full ; call_info = Call_na } fn args
275
276
| Js_module_as_fn { external_module_name; splice } ->
276
- let fn = external_var external_module_name in
277
+ let fn = external_var external_module_name ~dynamic_import in
277
278
if splice then
278
279
let args, eff, dynamic = assemble_args_has_splice arg_types args in
279
280
(* TODO: fix in rest calling convention *)
@@ -303,14 +304,14 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types
303
304
in
304
305
if splice then
305
306
let args, eff, dynamic = assemble_args_has_splice arg_types args in
306
- let fn = translate_scoped_module_val module_name fn scopes in
307
+ let fn = translate_scoped_module_val module_name fn scopes ~dynamic_import in
307
308
add_eff eff
308
309
(mark () ;
309
310
if dynamic then splice_new_apply fn args
310
311
else E. new_ fn args)
311
312
else
312
313
let args, eff = assemble_args_no_splice arg_types args in
313
- let fn = translate_scoped_module_val module_name fn scopes in
314
+ let fn = translate_scoped_module_val module_name fn scopes ~dynamic_import in
314
315
add_eff eff
315
316
(mark () ; E. new_ fn args)
316
317
| Js_send { splice; name; js_send_scopes } -> (
@@ -336,16 +337,16 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types
336
337
~info: { arity = Full ; call_info = Call_na }
337
338
(E. dot self name) args)
338
339
| _ -> assert false )
339
- | Js_module_as_var module_name -> external_var module_name
340
+ | Js_module_as_var module_name -> external_var module_name ~dynamic_import
340
341
| Js_var { name; external_module_name; scopes } ->
341
342
(* TODO #11
342
343
1. check args -- error checking
343
344
2. support [@@scope "window"]
344
345
we need know whether we should call [add_js_module] or not
345
346
*)
346
- translate_scoped_module_val external_module_name name scopes
347
+ translate_scoped_module_val external_module_name name scopes ~dynamic_import
347
348
| Js_module_as_class module_name ->
348
- let fn = external_var module_name in
349
+ let fn = external_var module_name ~dynamic_import in
349
350
let args, eff = assemble_args_no_splice arg_types args in
350
351
(* TODO: fix in rest calling convention *)
351
352
add_eff eff
0 commit comments