@@ -1625,6 +1625,60 @@ and compile_prim (prim_info : Lam.prim_info)
16251625      Js_output. output_of_block_and_expression lambda_cxt.continuation 
16261626        (Ext_list. concat_append args_block block) 
16271627        exp 
1628+   |  { primitive  = Pimport ; args  = []  | _  :: _  :: _ ; loc }  ->  
1629+     Location. raise_errorf ~loc  
1630+       " Missing argument: Dynamic import requires a module or \ 
1631+       module value that is a file as argument."  
1632+   |  { primitive  = Pimport  as  primitive ; args  = [ mod_ ]; loc}  -> 
1633+       (match  mod_ with  
1634+       |  Lglobal_module  _ |  Lvar  _ 
1635+       |  Lprim  { primitive  = Pfield  _  | Pjs_call  _  ; _ }  -> 
1636+         let  args_block, args_expr =  
1637+           let  new_cxt =  
1638+             { lambda_cxt with  continuation =  NeedValue  Not_tail  } 
1639+           in  
1640+           match  compile_lambda new_cxt mod_ with  
1641+           |  { block; value  = Some  b ; _ }  -> ([ block ], b) 
1642+           |  { value  = None ; _ }  -> assert  false  
1643+         in  
1644+         let  args_code  : J.block  =  List. concat args_block in  
1645+         let  exp =  
1646+           Lam_compile_primitive. translate output_prefix loc lambda_cxt primitive [args_expr] 
1647+         in  
1648+         Js_output. output_of_block_and_expression lambda_cxt.continuation args_code 
1649+         exp 
1650+       |  Lfunction  { 
1651+           body =  
1652+             ( (Lprim  _ as  body) 
1653+             |  Lsequence  ((Lprim  _ as  body), Lconst  Const_js_undefined  _) ); 
1654+           _; 
1655+         } -> 
1656+         let  body =  match  body with  
1657+           |  Lprim  ({ primitive  = Pjs_call  prim_info ; args; loc } ) ->  
1658+             Lam. prim  
1659+               ~primitive: (Lam_primitive. Pjs_call  { prim_info with  dynamic_import =  true  })  
1660+               ~args  
1661+               loc 
1662+           |  _  -> body 
1663+         in  
1664+         let  args_block, args_expr =  
1665+           let  new_cxt =  
1666+             { lambda_cxt with  continuation =  NeedValue  Not_tail  } 
1667+           in  
1668+           match  compile_lambda new_cxt body with  
1669+           |  { block; value  = Some  b ; _ }  -> ([ block ], b) 
1670+           |  { value  = None ; _ }  -> assert  false  
1671+         in  
1672+         let  args_code  : J.block  =  List. concat args_block in  
1673+         let  exp =  
1674+           Lam_compile_primitive. translate output_prefix loc lambda_cxt primitive [args_expr] 
1675+         in  
1676+         Js_output. output_of_block_and_expression lambda_cxt.continuation args_code 
1677+           exp 
1678+       |  _  -> 
1679+         Location. raise_errorf ~loc  
1680+           " Invalid argument: unsupported argument to dynamic import. If \ 
1681+             you believe this should be supported, please open an issue."  )
16281682  |  { primitive; args; loc }  -> 
16291683      let  args_block, args_expr =  
16301684        if  args =  []  then  ([] , [] ) 
0 commit comments