diff --git a/jscomp/core/lam_compile_external_call.ml b/jscomp/core/lam_compile_external_call.ml index 617996b7e2..db03d15a2a 100644 --- a/jscomp/core/lam_compile_external_call.ml +++ b/jscomp/core/lam_compile_external_call.ml @@ -252,16 +252,15 @@ let translate_scoped_access scopes obj = let translate_ffi (cxt : Lam_compile_context.t) arg_types (ffi : External_ffi_types.external_spec) (args : J.expression list) = match ffi with - | Js_call { external_module_name; name; splice; scopes; tagged_template = true } -> + | Js_call { external_module_name; name; splice: _; scopes; tagged_template = true } -> let fn = translate_scoped_module_val external_module_name name scopes in (match args with - | [ stringArgs; valueArgs ] -> ( - match (stringArgs, valueArgs) with - | ({expression_desc = Array (strings, _); _}, {expression_desc = Array (values, _); _}) -> - E.tagged_template fn strings values - | _ -> assert false - ) - | _ -> assert false) + | [ {expression_desc = Array (strings, _); _}; {expression_desc = Array (values, _); _} ] -> + E.tagged_template fn strings values + | _ -> let args, eff, dynamic = assemble_args_has_splice arg_types args in + add_eff eff + (if dynamic then splice_apply fn args + else E.call ~info:{ arity = Full; call_info = Call_na } fn args)) | Js_call { external_module_name = module_name; name = fn; splice; scopes; tagged_template = false } -> let fn = translate_scoped_module_val module_name fn scopes in if splice then diff --git a/jscomp/test/build.ninja b/jscomp/test/build.ninja index b1ce7ef10a..aabc9c0e57 100644 --- a/jscomp/test/build.ninja +++ b/jscomp/test/build.ninja @@ -569,8 +569,7 @@ o test/submodule.cmi test/submodule.cmj : cc test/submodule.res | $bsc $stdlib r o test/submodule_call.cmi test/submodule_call.cmj : cc test/submodule_call.res | test/submodule.cmj $bsc $stdlib runtime o test/switch_case_test.cmi test/switch_case_test.cmj : cc test/switch_case_test.res | test/mt.cmj $bsc $stdlib runtime o test/switch_string.cmi test/switch_string.cmj : cc test/switch_string.res | $bsc $stdlib runtime -o test/tagged_template_test.cmj : cc_cmi test/tagged_template_test.res | test/mt.cmj test/tagged_template_test.cmi $bsc $stdlib runtime -o test/tagged_template_test.cmi : cc test/tagged_template_test.resi | $bsc $stdlib runtime +o test/tagged_template_test.cmi test/tagged_template_test.cmj : cc test/tagged_template_test.res | test/mt.cmj $bsc $stdlib runtime o test/tailcall_inline_test.cmi test/tailcall_inline_test.cmj : cc test/tailcall_inline_test.res | test/mt.cmj $bsc $stdlib runtime o test/template.cmi test/template.cmj : cc test/template.res | $bsc $stdlib runtime o test/test.cmi test/test.cmj : cc test/test.res | $bsc $stdlib runtime diff --git a/jscomp/test/tagged_template_test.js b/jscomp/test/tagged_template_test.js index c0a4687743..331ac706d9 100644 --- a/jscomp/test/tagged_template_test.js +++ b/jscomp/test/tagged_template_test.js @@ -3,9 +3,21 @@ var Mt = require("./mt.js"); var Caml_array = require("../../lib/js/caml_array.js"); +var Caml_splice_call = require("../../lib/js/caml_splice_call.js"); var Tagged_template_libJs = require("./tagged_template_lib.js"); -var query = Tagged_template_libJs.sql`SELECT * FROM ${"users"} WHERE id = ${"5"}`; +function sql(prim0, prim1) { + return Caml_splice_call.spliceApply(Tagged_template_libJs.sql, [ + prim0, + prim1 + ]); +} + +var table = "users"; + +var id = "5"; + +var query = Tagged_template_libJs.sql`SELECT * FROM ${table} WHERE id = ${id}`; var length = Tagged_template_libJs.length`hello ${10} what's the total length? Is it ${3}?`; @@ -73,4 +85,14 @@ Mt.from_pair_suites("tagged templates", { } }); +var extraLength = 10; + +exports.sql = sql; +exports.table = table; +exports.id = id; +exports.query = query; +exports.extraLength = extraLength; +exports.length = length; +exports.foo = foo; +exports.res = res; /* query Not a pure module */ diff --git a/jscomp/test/tagged_template_test.resi b/jscomp/test/tagged_template_test.resi deleted file mode 100644 index e69de29bb2..0000000000