Skip to content

Commit 52a75fb

Browse files
committed
move logic to lam_compile_external_call
1 parent 0052e08 commit 52a75fb

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

jscomp/core/lam_compile_external_call.ml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,19 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types
381381
| [ obj; v; value ] ->
382382
Js_arr.set_array (translate_scoped_access scopes obj) v value
383383
| _ -> assert false)
384+
385+
let translate_tagged_template (cxt : Lam_compile_context.t)
386+
(ffi : External_ffi_types.external_spec) (args : J.expression list) =
387+
let fn = match ffi with
388+
| Js_call { external_module_name; name; scopes; _ } ->
389+
translate_scoped_module_val external_module_name name scopes
390+
| _ -> assert false
391+
in
392+
match args with
393+
| [ stringArgs; valueArgs ] -> (
394+
match (stringArgs, valueArgs) with
395+
| ({expression_desc = Array (strings, _); _}, {expression_desc = Array (values, _); _}) ->
396+
E.tagged_template fn strings values
397+
| _ -> assert false
398+
)
399+
| _ -> assert false

jscomp/core/lam_compile_external_call.mli

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ val translate_ffi :
3636
J.expression list ->
3737
J.expression
3838

39-
val translate_scoped_module_val :
40-
External_ffi_types.external_module_name option ->
41-
string ->
42-
string list ->
43-
J.expression
39+
val translate_tagged_template :
40+
Lam_compile_context.t ->
41+
External_ffi_types.external_spec ->
42+
J.expression list ->
43+
J.expression
4444

4545
(** TODO: document supported attributes
4646
Attributes starting with `js` are reserved

jscomp/core/lam_compile_primitive.ml

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -339,21 +339,7 @@ let translate output_prefix loc (cxt : Lam_compile_context.t)
339339
| Pjs_object_create _ -> assert false
340340
| Pjs_call { arg_types; ffi } ->
341341
Lam_compile_external_call.translate_ffi cxt arg_types ffi args
342-
| Pjs_tagged_template { ffi } -> (
343-
(* TODO: extract this into lam_compile_external_call.ml *)
344-
let fn = match ffi with
345-
| Js_call { external_module_name; name; scopes } ->
346-
Lam_compile_external_call.translate_scoped_module_val external_module_name name scopes
347-
| _ -> assert false
348-
in
349-
match args with
350-
| [ stringArgs; valueArgs ] -> (
351-
match (stringArgs, valueArgs) with
352-
| ({expression_desc = Array (strings, _)}, {expression_desc = Array (values, _)}) ->
353-
E.tagged_template fn strings values
354-
| _ -> assert false
355-
)
356-
| _ -> assert false)
342+
| Pjs_tagged_template { ffi } -> Lam_compile_external_call.translate_tagged_template cxt ffi args
357343
(* FIXME, this can be removed later *)
358344
| Pisint -> E.is_type_number (Ext_list.singleton_exn args)
359345
| Pis_poly_var_block -> E.is_type_object (Ext_list.singleton_exn args)

0 commit comments

Comments
 (0)