diff --git a/CHANGELOG.md b/CHANGELOG.md index 66de9f1385..8713c31953 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - Fix generation of interfaces for module types containing multiple type constraints. https://github.com/rescript-lang/rescript/pull/7825 - JSX preserve mode: fix "make is not a valid component name". https://github.com/rescript-lang/rescript/pull/7831 - Rewatch: include parser arguments of experimental features. https://github.com/rescript-lang/rescript/pull/7836 +- Stop mangling tagged templates and backquoted strings. https://github.com/rescript-lang/rescript/pull/7841 #### :memo: Documentation diff --git a/compiler/core/j.ml b/compiler/core/j.ml index 7465226ab9..dc5aa2514d 100644 --- a/compiler/core/j.ml +++ b/compiler/core/j.ml @@ -75,7 +75,7 @@ and for_ident = ident and for_direction = Js_op.direction_flag and property_map = (property_name * expression) list and length_object = Js_op.length_object -and delim = External_arg_spec.delim = DNone | DStarJ | DNoQuotes +and delim = External_arg_spec.delim = DNone | DStarJ | DNoQuotes | DBackQuotes and expression_desc = | Length of expression * length_object diff --git a/compiler/core/js_dump.ml b/compiler/core/js_dump.ml index 44820298f6..49ace5fa6c 100644 --- a/compiler/core/js_dump.ml +++ b/compiler/core/js_dump.ml @@ -729,6 +729,7 @@ and expression_desc cxt ~(level : int) f x : cxt = | DStarJ -> P.string f ("\"" ^ txt ^ "\"") | DNoQuotes -> P.string f txt | DNone -> Js_dump_string.pp_string f txt + | DBackQuotes -> P.string f ("`" ^ txt ^ "`") in cxt | Raw_js_code {code = s; code_info = info} -> ( diff --git a/compiler/core/lam.ml b/compiler/core/lam.ml index d7c6d6c6cc..51b8bb3e38 100644 --- a/compiler/core/lam.ml +++ b/compiler/core/lam.ml @@ -430,7 +430,7 @@ let switch lam (lam_switch : lambda_switch) : t = let stringswitch (lam : t) cases default : t = match lam with - | Lconst (Const_string {s; unicode = false}) -> + | Lconst (Const_string {s; delim = None | Some DNoQuotes}) -> Ext_list.assoc_by_string cases s default | _ -> Lstringswitch (lam, cases, default) @@ -471,7 +471,7 @@ module Lift = struct let bool b = if b then true_ else false_ - let string s : t = Lconst (Const_string {s; unicode = false}) + let string s : t = Lconst (Const_string {s; delim = None}) let char b : t = Lconst (Const_char b) end @@ -488,7 +488,7 @@ let prim ~primitive:(prim : Lam_primitive.t) ~args loc : t = Lift.int (Int32.of_float (float_of_string a)) (* | Pnegfloat -> Lift.float (-. a) *) (* | Pabsfloat -> Lift.float (abs_float a) *) - | Pstringlength, Const_string {s; unicode = false} -> + | Pstringlength, Const_string {s; delim = None} -> Lift.int (Int32.of_int (String.length s)) (* | Pnegbint Pnativeint, ( (Const_nativeint i)) *) (* -> *) @@ -537,11 +537,11 @@ let prim ~primitive:(prim : Lam_primitive.t) ~args loc : t = | Psequor, Const_js_false, Const_js_true -> true_ | Psequor, Const_js_false, Const_js_false -> false_ | ( Pstringadd, - Const_string {s = a; unicode = false}, - Const_string {s = b; unicode = false} ) -> + Const_string {s = a; delim = None}, + Const_string {s = b; delim = None} ) -> Lift.string (a ^ b) | ( (Pstringrefs | Pstringrefu), - Const_string {s = a; unicode = false}, + Const_string {s = a; delim = None}, Const_int {i = b} ) -> ( try Lift.char (Char.code (String.get a (Int32.to_int b))) with _ -> default ()) diff --git a/compiler/core/lam_compile_const.ml b/compiler/core/lam_compile_const.ml index 58603472dd..4b50f55618 100644 --- a/compiler/core/lam_compile_const.ml +++ b/compiler/core/lam_compile_const.ml @@ -61,8 +61,8 @@ and translate (x : Lam_constant.t) : J.expression = | Const_char i -> Js_of_lam_string.const_char i | Const_bigint (sign, i) -> E.bigint sign i | Const_float f -> E.float f (* TODO: preserve float *) - | Const_string {s; unicode = false} -> E.str s - | Const_string {s; unicode = true} -> E.str ~delim:DStarJ s + | Const_string {s; delim = None | Some DNoQuotes} -> E.str s + | Const_string {s; delim = Some delim} -> E.str ~delim s | Const_pointer name -> E.str name | Const_block (tag, tag_info, xs) -> Js_of_lam_block.make_block NA tag_info (E.small_int tag) diff --git a/compiler/core/lam_constant_convert.ml b/compiler/core/lam_constant_convert.ml index 3be30e048c..a576412494 100644 --- a/compiler/core/lam_constant_convert.ml +++ b/compiler/core/lam_constant_convert.ml @@ -27,12 +27,8 @@ let rec convert_constant (const : Lambda.structured_constant) : Lam_constant.t = | Const_base (Const_int i) -> Const_int {i = Int32.of_int i; comment = None} | Const_base (Const_char i) -> Const_char i | Const_base (Const_string (s, opt)) -> - let unicode = - match opt with - | Some opt -> Ast_utf8_string_interp.is_unicode_string opt - | _ -> false - in - Const_string {s; unicode} + let delim = Ast_utf8_string_interp.parse_processed_delim opt in + Const_string {s; delim} | Const_base (Const_float i) -> Const_float i | Const_base (Const_int32 i) -> Const_int {i; comment = None} | Const_base (Const_int64 _) -> assert false @@ -63,7 +59,7 @@ let rec convert_constant (const : Lambda.structured_constant) : Lam_constant.t = if Ext_string.is_valid_hash_number name then Const_int {i = Ext_string.hash_number_as_i32_exn name; comment = None} else Const_pointer name) - | Const_immstring s -> Const_string {s; unicode = false} + | Const_immstring s -> Const_string {s; delim = None} | Const_block (t, xs) -> ( let tag = Lambda.tag_of_tag_info t in match t with @@ -80,7 +76,7 @@ let rec convert_constant (const : Lambda.structured_constant) : Lam_constant.t = let tag_val : Lam_constant.t = if Ext_string.is_valid_hash_number s then Const_int {i = Ext_string.hash_number_as_i32_exn s; comment = None} - else Const_string {s; unicode = false} + else Const_string {s; delim = None} in Const_block (tag, t, [tag_val; convert_constant value]) | _ -> assert false)) diff --git a/compiler/core/lam_convert.ml b/compiler/core/lam_convert.ml index 574691ae46..2e88a3b703 100644 --- a/compiler/core/lam_convert.ml +++ b/compiler/core/lam_convert.ml @@ -184,7 +184,7 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t = let tag_val : Lam_constant.t = if Ext_string.is_valid_hash_number s then Const_int {i = Ext_string.hash_number_as_i32_exn s; comment = None} - else Const_string {s; unicode = false} + else Const_string {s; delim = None} in prim ~primitive:(Pmakeblock (tag, info, mutable_flag)) @@ -465,7 +465,7 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) : | Lprim (Pgetglobal id, args, _) -> let args = Ext_list.map args convert_aux in if Ident.is_predef_exn id then - Lam.const (Const_string {s = id.name; unicode = false}) + Lam.const (Const_string {s = id.name; delim = None}) else ( may_depend may_depends (Lam_module_ident.of_ml ~dynamic_import id); assert (args = []); diff --git a/compiler/core/lam_pass_lets_dce.ml b/compiler/core/lam_pass_lets_dce.ml index 04ab02d4bc..bf32bbc56b 100644 --- a/compiler/core/lam_pass_lets_dce.ml +++ b/compiler/core/lam_pass_lets_dce.ml @@ -63,7 +63,7 @@ let lets_helper (count_var : Ident.t -> Lam_pass_count.used_info) lam : Lam.t = -> Hash_ident.add subst v (simplif l1); simplif l2 - | _, Lconst (Const_string {s; unicode = false}) -> + | _, Lconst (Const_string {s; delim = None}) -> (* only "" added for later inlining *) Hash_ident.add string_table v s; Lam.let_ Alias v l1 (simplif l2) @@ -112,7 +112,7 @@ let lets_helper (count_var : Ident.t -> Lam_pass_count.used_info) lam : Lam.t = | _ -> ( let l1 = simplif l1 in match l1 with - | Lconst (Const_string {s; unicode = false}) -> + | Lconst (Const_string {s; delim = None}) -> Hash_ident.add string_table v s; (* we need move [simplif lbody] later, since adding Hash does have side effect *) Lam.let_ Alias v l1 (simplif lbody) @@ -127,7 +127,7 @@ let lets_helper (count_var : Ident.t -> Lam_pass_count.used_info) lam : Lam.t = let l1 = simplif l1 in match (kind, l1) with - | Strict, Lconst (Const_string {s; unicode = false}) -> + | Strict, Lconst (Const_string {s; delim = None}) -> Hash_ident.add string_table v s; Lam.let_ Alias v l1 (simplif l2) | _ -> Lam_util.refine_let ~kind v l1 (simplif l2)) @@ -157,7 +157,7 @@ let lets_helper (count_var : Ident.t -> Lam_pass_count.used_info) lam : Lam.t = let r' = simplif r in let opt_l = match l' with - | Lconst (Const_string {s = ls; unicode = false}) -> Some ls + | Lconst (Const_string {s = ls; delim = None}) -> Some ls | Lvar i -> Hash_ident.find_opt string_table i | _ -> None in @@ -166,14 +166,13 @@ let lets_helper (count_var : Ident.t -> Lam_pass_count.used_info) lam : Lam.t = | Some l_s -> ( let opt_r = match r' with - | Lconst (Const_string {s = rs; unicode = false}) -> Some rs + | Lconst (Const_string {s = rs; delim = None}) -> Some rs | Lvar i -> Hash_ident.find_opt string_table i | _ -> None in match opt_r with | None -> Lam.prim ~primitive:Pstringadd ~args:[l'; r'] loc - | Some r_s -> Lam.const (Const_string {s = l_s ^ r_s; unicode = false})) - ) + | Some r_s -> Lam.const (Const_string {s = l_s ^ r_s; delim = None}))) | Lglobal_module _ -> lam | Lprim {primitive; args; loc} -> Lam.prim ~primitive ~args:(Ext_list.map args simplif) loc diff --git a/compiler/frontend/ast_utf8_string_interp.ml b/compiler/frontend/ast_utf8_string_interp.ml index ee4ae0f7e1..90c5043256 100644 --- a/compiler/frontend/ast_utf8_string_interp.ml +++ b/compiler/frontend/ast_utf8_string_interp.ml @@ -275,35 +275,69 @@ module Delim = struct | None -> Some External_arg_spec.DNone | Some "json" -> Some DNoQuotes | Some "*j" -> Some DStarJ + | Some "bq" -> Some DBackQuotes | _ -> None type interpolation = - | Js (* string interpolation *) + | BackQuotes (* string interpolation *) + | Js (* simple double quoted string *) | Unrecognized (* no interpolation: delimiter not recognized *) - let parse_unprocessed = function - | "js" -> Js + let parse_unprocessed is_template = function + | "js" -> if is_template then BackQuotes else Js | _ -> Unrecognized let escaped_j_delimiter = "*j" (* not user level syntax allowed *) + let escaped_back_quote_delimiter = "bq" + let some_escaped_back_quote_delimiter = Some "bq" let unescaped_js_delimiter = "js" - let escaped = Some escaped_j_delimiter + let some_escaped_j_delimiter = Some escaped_j_delimiter end let transform_exp (e : Parsetree.expression) s delim : Parsetree.expression = - match Delim.parse_unprocessed delim with + let is_template = + Ext_list.exists e.pexp_attributes (fun ({txt}, _) -> + match txt with + | "res.template" | "res.taggedTemplate" -> true + | _ -> false) + in + match Delim.parse_unprocessed is_template delim with | Js -> let js_str = Ast_utf8_string.transform e.pexp_loc s in - {e with pexp_desc = Pexp_constant (Pconst_string (js_str, Delim.escaped))} + { + e with + pexp_desc = + Pexp_constant (Pconst_string (js_str, Delim.some_escaped_j_delimiter)); + } + | BackQuotes -> + { + e with + pexp_desc = + Pexp_constant + (Pconst_string (s, Delim.some_escaped_back_quote_delimiter)); + } | Unrecognized -> e let transform_pat (p : Parsetree.pattern) s delim : Parsetree.pattern = - match Delim.parse_unprocessed delim with + match Delim.parse_unprocessed false delim with | Js -> let js_str = Ast_utf8_string.transform p.ppat_loc s in - {p with ppat_desc = Ppat_constant (Pconst_string (js_str, Delim.escaped))} + { + p with + ppat_desc = + Ppat_constant (Pconst_string (js_str, Delim.some_escaped_j_delimiter)); + } + | BackQuotes -> + { + p with + ppat_desc = + Ppat_constant + (Pconst_string (s, Delim.some_escaped_back_quote_delimiter)); + } | Unrecognized -> p -let is_unicode_string opt = Ext_string.equal opt Delim.escaped_j_delimiter +let is_unicode_string opt = + Ext_string.equal opt Delim.escaped_j_delimiter + || Ext_string.equal opt Delim.escaped_back_quote_delimiter let is_unescaped s = Ext_string.equal s Delim.unescaped_js_delimiter diff --git a/compiler/frontend/external_arg_spec.ml b/compiler/frontend/external_arg_spec.ml index 287014bfe5..04c43a5157 100644 --- a/compiler/frontend/external_arg_spec.ml +++ b/compiler/frontend/external_arg_spec.ml @@ -24,7 +24,7 @@ (** type definitions for arguments to a function declared external *) -type delim = DNone | DStarJ | DNoQuotes +type delim = DNone | DStarJ | DNoQuotes | DBackQuotes type cst = Arg_int_lit of int | Arg_string_lit of string * delim diff --git a/compiler/frontend/external_arg_spec.mli b/compiler/frontend/external_arg_spec.mli index 64d3daca97..6c79a3380a 100644 --- a/compiler/frontend/external_arg_spec.mli +++ b/compiler/frontend/external_arg_spec.mli @@ -22,7 +22,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -type delim = DNone | DStarJ | DNoQuotes +type delim = DNone | DStarJ | DNoQuotes | DBackQuotes type cst = private Arg_int_lit of int | Arg_string_lit of string * delim diff --git a/compiler/frontend/external_ffi_types.ml b/compiler/frontend/external_ffi_types.ml index 55c93b89e4..ef6c1c351f 100644 --- a/compiler/frontend/external_ffi_types.ml +++ b/compiler/frontend/external_ffi_types.ml @@ -273,12 +273,8 @@ let () = | _ -> false let inline_string_primitive (s : string) (op : string option) : string list = let lam : Lam_constant.t = - let unicode = - match op with - | Some op -> Ast_utf8_string_interp.is_unicode_string op - | None -> false - in - Const_string {s; unicode} + let delim = Ast_utf8_string_interp.parse_processed_delim op in + Const_string {s; delim} in [""; to_string (Ffi_inline_const lam)] diff --git a/compiler/frontend/lam_constant.ml b/compiler/frontend/lam_constant.ml index 86ff842322..c5bab8ffa9 100644 --- a/compiler/frontend/lam_constant.ml +++ b/compiler/frontend/lam_constant.ml @@ -47,7 +47,7 @@ type t = | Const_js_false | Const_int of {i: int32; comment: pointer_info} | Const_char of int - | Const_string of {s: string; unicode: bool} + | Const_string of {s: string; delim: External_arg_spec.delim option} | Const_float of string | Const_bigint of bool * string | Const_pointer of string @@ -73,9 +73,9 @@ let rec eq_approx (x : t) (y : t) = match y with | Const_char iy -> ix = iy | _ -> false) - | Const_string {s = sx; unicode = ux} -> ( + | Const_string {s = sx; delim = ux} -> ( match y with - | Const_string {s = sy; unicode = uy} -> sx = sy && ux = uy + | Const_string {s = sy; delim = uy} -> sx = sy && ux = uy | _ -> false) | Const_float ix -> ( match y with diff --git a/compiler/frontend/lam_constant.mli b/compiler/frontend/lam_constant.mli index b529c1c3b2..846e29d743 100644 --- a/compiler/frontend/lam_constant.mli +++ b/compiler/frontend/lam_constant.mli @@ -43,7 +43,7 @@ type t = | Const_js_false | Const_int of {i: int32; comment: pointer_info} | Const_char of int - | Const_string of {s: string; unicode: bool} + | Const_string of {s: string; delim: External_arg_spec.delim option} | Const_float of string | Const_bigint of bool * string | Const_pointer of string diff --git a/packages/@rescript/runtime/lib/es6/Stdlib_Bool.js b/packages/@rescript/runtime/lib/es6/Stdlib_Bool.js index 2544dd5672..cc03a9357e 100644 --- a/packages/@rescript/runtime/lib/es6/Stdlib_Bool.js +++ b/packages/@rescript/runtime/lib/es6/Stdlib_Bool.js @@ -29,7 +29,7 @@ function fromStringOrThrow(param) { default: throw { RE_EXN_ID: "Invalid_argument", - _1: "Bool.fromStringOrThrow: value is neither \"true\" nor \"false\"", + _1: `Bool.fromStringOrThrow: value is neither "true" nor "false"`, Error: new Error() }; } diff --git a/packages/@rescript/runtime/lib/es6/Stdlib_Error.js b/packages/@rescript/runtime/lib/es6/Stdlib_Error.js index 9dcb2bfa59..682b462e12 100644 --- a/packages/@rescript/runtime/lib/es6/Stdlib_Error.js +++ b/packages/@rescript/runtime/lib/es6/Stdlib_Error.js @@ -23,7 +23,7 @@ let $$TypeError = {}; let $$URIError = {}; function panic(msg) { - throw new Error("Panic! " + msg); + throw new Error(`Panic! ` + msg); } export { diff --git a/packages/@rescript/runtime/lib/es6/Stdlib_JsError.js b/packages/@rescript/runtime/lib/es6/Stdlib_JsError.js index 04fb5fa4d2..b97281d70a 100644 --- a/packages/@rescript/runtime/lib/es6/Stdlib_JsError.js +++ b/packages/@rescript/runtime/lib/es6/Stdlib_JsError.js @@ -54,7 +54,7 @@ let $$URIError$1 = { }; function panic(msg) { - throw new Error("Panic! " + msg); + throw new Error(`Panic! ` + msg); } export { diff --git a/packages/@rescript/runtime/lib/js/Stdlib_Bool.js b/packages/@rescript/runtime/lib/js/Stdlib_Bool.js index a7ce1d1ea0..02995bc721 100644 --- a/packages/@rescript/runtime/lib/js/Stdlib_Bool.js +++ b/packages/@rescript/runtime/lib/js/Stdlib_Bool.js @@ -29,7 +29,7 @@ function fromStringOrThrow(param) { default: throw { RE_EXN_ID: "Invalid_argument", - _1: "Bool.fromStringOrThrow: value is neither \"true\" nor \"false\"", + _1: `Bool.fromStringOrThrow: value is neither "true" nor "false"`, Error: new Error() }; } diff --git a/packages/@rescript/runtime/lib/js/Stdlib_Error.js b/packages/@rescript/runtime/lib/js/Stdlib_Error.js index 3c6de75afb..58cf31a222 100644 --- a/packages/@rescript/runtime/lib/js/Stdlib_Error.js +++ b/packages/@rescript/runtime/lib/js/Stdlib_Error.js @@ -23,7 +23,7 @@ let $$TypeError = {}; let $$URIError = {}; function panic(msg) { - throw new Error("Panic! " + msg); + throw new Error(`Panic! ` + msg); } exports.fromException = fromException; diff --git a/packages/@rescript/runtime/lib/js/Stdlib_JsError.js b/packages/@rescript/runtime/lib/js/Stdlib_JsError.js index 3e6a4d822c..9aaf7a5d37 100644 --- a/packages/@rescript/runtime/lib/js/Stdlib_JsError.js +++ b/packages/@rescript/runtime/lib/js/Stdlib_JsError.js @@ -54,7 +54,7 @@ let $$URIError$1 = { }; function panic(msg) { - throw new Error("Panic! " + msg); + throw new Error(`Panic! ` + msg); } exports.$$EvalError = $$EvalError$1; diff --git a/rewatch/testrepo/packages/with-ppx/src/FileWithPpx.mjs b/rewatch/testrepo/packages/with-ppx/src/FileWithPpx.mjs index 23929387dd..659456d11f 100644 --- a/rewatch/testrepo/packages/with-ppx/src/FileWithPpx.mjs +++ b/rewatch/testrepo/packages/with-ppx/src/FileWithPpx.mjs @@ -6,7 +6,7 @@ let schema = S.schema(s => ({ foo: s.m(S.string) })); -let foo = S.parseOrThrow("{ \"foo\": \"bar\" }", schema); +let foo = S.parseOrThrow(`{ "foo": "bar" }`, schema); console.log(foo); diff --git a/tests/docstring_tests/DocTest.res.js b/tests/docstring_tests/DocTest.res.js index 12b54bf200..d71a5f1cdc 100644 --- a/tests/docstring_tests/DocTest.res.js +++ b/tests/docstring_tests/DocTest.res.js @@ -61,7 +61,7 @@ async function extractDocFromFile(file) { let e = Primitive_exceptions.internalToException(raw_e); if (e.RE_EXN_ID === "JsExn") { console.error(e._1); - return Stdlib_JsError.panic("Failed to extract code blocks from " + file); + return Stdlib_JsError.panic(`Failed to extract code blocks from ` + file); } throw e; } @@ -84,7 +84,7 @@ async function extractExamples() { return false; } }); - console.log("Extracting examples from " + docFiles.length.toString() + " runtime files..."); + console.log(`Extracting examples from ` + docFiles.length.toString() + ` runtime files...`); let examples = []; await ArrayUtils.forEachAsyncInBatches(docFiles, batchSize, async f => { let doc = await extractDocFromFile(Nodepath.join(runtimePath, f)); @@ -120,25 +120,35 @@ async function main() { } }); if (ignoreExample) { - console.warn("Ignoring " + example.id + " tests. Not supported by Node " + nodeVersion.toString()); + console.warn(`Ignoring ` + example.id + ` tests. Not supported by Node ` + nodeVersion.toString()); return; } let code = example.code; if (code.length === 0) { return; } else { - return "test(\"" + example.name + "\", () => {\n module Test = {\n " + code + "\n }\n ()\n})"; + return `test("` + example.name + `", () => { + module Test = { + ` + code + ` + } + () +})`; } }); if (codeExamples.length <= 0) { return; } - let content = "describe(\"" + key + "\", () => {\n" + codeExamples.join("\n") + "\n })"; + let content = `describe("` + key + `", () => { +` + codeExamples.join("\n") + ` + })`; output.push(content); }); let dirname = Nodepath.dirname(Nodeurl.fileURLToPath(import.meta.url)); let filepath = Nodepath.join(dirname, "generated_mocha_test.res"); - let fileContent = "open Mocha\n@@warning(\"-32-34-60-37-109-3-44\")\n\n" + output.join("\n"); + let fileContent = `open Mocha +@@warning("-32-34-60-37-109-3-44") + +` + output.join("\n"); return await Promises.writeFile(filepath, fileContent); } diff --git a/tests/syntax_tests/data/parsing/other/expected/stringLiterals.res.txt b/tests/syntax_tests/data/parsing/other/expected/stringLiterals.res.txt index 1e290bd44f..99be7cf952 100644 --- a/tests/syntax_tests/data/parsing/other/expected/stringLiterals.res.txt +++ b/tests/syntax_tests/data/parsing/other/expected/stringLiterals.res.txt @@ -1,4 +1,12 @@ let s = {js|some unicode é £ |js} +let s = + match foo with + | (({js|bar|js})[@res.template ]) -> {js|bar|js} + | {js|foo|js} -> {js|foo|js} + | _ -> {js|baz|js} +let s = (({js|你好, +世界|js})[@res.template ]) +let s = (({js|"|js})[@res.template ]) let s = (({js|foo|js})[@res.template ]) let s = (((((({js|foo |js})[@res.template ]) ++ bar)[@res.template ]) ++ diff --git a/tests/syntax_tests/data/parsing/other/stringLiterals.res b/tests/syntax_tests/data/parsing/other/stringLiterals.res index b54010b378..4ec52d4064 100644 --- a/tests/syntax_tests/data/parsing/other/stringLiterals.res +++ b/tests/syntax_tests/data/parsing/other/stringLiterals.res @@ -1,4 +1,12 @@ let s = "some unicode é £ " +let s = switch foo { + | `bar` => "bar" + | "foo" => "foo" + | _ => "baz" +} +let s = `你好, +世界` +let s = `"` let s = `foo` let s = `foo ${bar} baz` let s = `some unicode é ${bar} £ ` diff --git a/tests/tests/src/alias_default_value_test.mjs b/tests/tests/src/alias_default_value_test.mjs index f525661bb8..2d785cd801 100644 --- a/tests/tests/src/alias_default_value_test.mjs +++ b/tests/tests/src/alias_default_value_test.mjs @@ -75,7 +75,7 @@ function Alias_default_value_test$C7(props) { count !== 2 ? String(count) + " times" : "twice" ) : "once"; let name = username !== undefined && username !== "" ? username : "Anonymous"; - return "Hello " + name + ", you clicked me " + times; + return `Hello ` + name + `, you clicked me ` + times; } let C7 = { diff --git a/tests/tests/src/chn_test.mjs b/tests/tests/src/chn_test.mjs index 6742921299..d9009c7272 100644 --- a/tests/tests/src/chn_test.mjs +++ b/tests/tests/src/chn_test.mjs @@ -26,9 +26,10 @@ function eq(loc, x, y) { }; } -console.log("你好,\n世界"); +console.log(`你好, +世界`); -console.log("\x3f\u003f\b\t\n\v\f\r\0\"'"); +console.log(`\x3f\u003f\b\t\n\v\f\r\0"'`); function convert(s) { return Belt_List.fromArray(Array.from(s, x => { @@ -48,9 +49,10 @@ function convert(s) { })); } -eq("File \"chn_test.res\", line 32, characters 4-11", "你好,\n世界", "你好,\n世界"); +eq("File \"chn_test.res\", line 32, characters 4-11", `你好, +世界`, `你好,\n世界`); -eq("File \"chn_test.res\", line 38, characters 4-11", convert("汉字是世界上最美丽的character"), { +eq("File \"chn_test.res\", line 38, characters 4-11", convert(`汉字是世界上最美丽的character`), { hd: 27721, tl: { hd: 23383, @@ -109,7 +111,7 @@ eq("File \"chn_test.res\", line 38, characters 4-11", convert("汉字是世界 } }); -eq("File \"chn_test.res\", line 62, characters 5-12", convert("\x3f\x3fa"), { +eq("File \"chn_test.res\", line 62, characters 5-12", convert(`\x3f\x3fa`), { hd: 63, tl: { hd: 63, @@ -120,7 +122,7 @@ eq("File \"chn_test.res\", line 62, characters 5-12", convert("\x3f\x3fa"), { } }); -eq("File \"chn_test.res\", line 63, characters 5-12", convert("??a"), { +eq("File \"chn_test.res\", line 63, characters 5-12", convert(`??a`), { hd: 63, tl: { hd: 63, @@ -131,7 +133,7 @@ eq("File \"chn_test.res\", line 63, characters 5-12", convert("??a"), { } }); -eq("File \"chn_test.res\", line 64, characters 5-12", convert("\u003f\x3fa"), { +eq("File \"chn_test.res\", line 64, characters 5-12", convert(`\u003f\x3fa`), { hd: 63, tl: { hd: 63, @@ -142,7 +144,7 @@ eq("File \"chn_test.res\", line 64, characters 5-12", convert("\u003f\x3fa"), { } }); -eq("File \"chn_test.res\", line 65, characters 5-12", convert("🚀🚀a"), { +eq("File \"chn_test.res\", line 65, characters 5-12", convert(`🚀🚀a`), { hd: 128640, tl: { hd: 128640, @@ -153,7 +155,7 @@ eq("File \"chn_test.res\", line 65, characters 5-12", convert("🚀🚀a"), { } }); -eq("File \"chn_test.res\", line 66, characters 5-12", convert("\uD83D\uDE80a"), { +eq("File \"chn_test.res\", line 66, characters 5-12", convert(`\uD83D\uDE80a`), { hd: 128640, tl: { hd: 97, @@ -161,7 +163,7 @@ eq("File \"chn_test.res\", line 66, characters 5-12", convert("\uD83D\uDE80a"), } }); -eq("File \"chn_test.res\", line 67, characters 5-12", convert("\uD83D\uDE80\x3f"), { +eq("File \"chn_test.res\", line 67, characters 5-12", convert(`\uD83D\uDE80\x3f`), { hd: 128640, tl: { hd: 63, @@ -169,7 +171,7 @@ eq("File \"chn_test.res\", line 67, characters 5-12", convert("\uD83D\uDE80\x3f" } }); -eq("File \"chn_test.res\", line 71, characters 5-12", convert("\uD83D\uDE80\uD83D\uDE80a"), { +eq("File \"chn_test.res\", line 71, characters 5-12", convert(`\uD83D\uDE80\uD83D\uDE80a`), { hd: 128640, tl: { hd: 128640, @@ -180,18 +182,18 @@ eq("File \"chn_test.res\", line 71, characters 5-12", convert("\uD83D\uDE80\uD83 } }); -eq("No inline string length", "\uD83D\uDE80\0".length, 3); +eq("No inline string length", `\uD83D\uDE80\0`.length, 3); -eq("File \"chn_test.res\", line 78, characters 4-11", "\uD83D\uDE80\0".codePointAt(0), 128640); +eq("File \"chn_test.res\", line 78, characters 4-11", `\uD83D\uDE80\0`.codePointAt(0), 128640); -eq("File \"chn_test.res\", line 83, characters 5-12", "🚀".codePointAt(0), 128640); +eq("File \"chn_test.res\", line 83, characters 5-12", `🚀`.codePointAt(0), 128640); -eq("File \"chn_test.res\", line 88, characters 5-12", convert("\uD83D\uDE80"), { +eq("File \"chn_test.res\", line 88, characters 5-12", convert(`\uD83D\uDE80`), { hd: 128640, tl: /* [] */0 }); -eq("File \"chn_test.res\", line 89, characters 5-12", convert("\uD83D\uDE80\uD83D\uDE80"), { +eq("File \"chn_test.res\", line 89, characters 5-12", convert(`\uD83D\uDE80\uD83D\uDE80`), { hd: 128640, tl: { hd: 128640, @@ -199,7 +201,7 @@ eq("File \"chn_test.res\", line 89, characters 5-12", convert("\uD83D\uDE80\uD83 } }); -eq("File \"chn_test.res\", line 90, characters 5-12", convert(" \b\t\n\v\f\ra"), { +eq("File \"chn_test.res\", line 90, characters 5-12", convert(` \b\t\n\v\f\ra`), { hd: 32, tl: { hd: 8, @@ -225,7 +227,7 @@ eq("File \"chn_test.res\", line 90, characters 5-12", convert(" \b\t\n\v\f\ra"), } }); -eq("File \"chn_test.res\", line 96, characters 5-12", convert(" \b\t\n\v\f\r\"'\\\0a"), { +eq("File \"chn_test.res\", line 96, characters 5-12", convert(` \b\t\n\v\f\r"'\\\0a`), { hd: 32, tl: { hd: 8, diff --git a/tests/tests/src/core/Core_ObjectTests.mjs b/tests/tests/src/core/Core_ObjectTests.mjs index 5a8c271089..8c7770f929 100644 --- a/tests/tests/src/core/Core_ObjectTests.mjs +++ b/tests/tests/src/core/Core_ObjectTests.mjs @@ -428,7 +428,7 @@ function assignOverwritesTarget(title, source) { 22, 39 ], - "assign " + title + `assign ` + title ], Object.assign({ a: 1 }, sourceObj), eq, sourceObj); @@ -439,7 +439,7 @@ function assignOverwritesTarget(title, source) { 22, 39 ], - "assign " + title + `assign ` + title ], Object.assign({ a: undefined }, sourceObj), eq, sourceObj); @@ -450,7 +450,7 @@ function assignOverwritesTarget(title, source) { 22, 39 ], - "assign " + title + `assign ` + title ], Object.assign({ a: null }, sourceObj), eq, sourceObj); @@ -472,7 +472,7 @@ function runGetTest(i) { 22, 46 ], - "Object.get: " + i.title + `Object.get: ` + i.title ], i.get(i.source()), eq, i.expected); } @@ -555,7 +555,7 @@ function getSymbolTestWhenExists() { 15, 63 ], - "Object.getSymbol when exists return it as Some" + `Object.getSymbol when exists return it as Some` ], retrieved, eq, "banana"); } @@ -568,7 +568,7 @@ Test.run([ 13, 65 ], - "Object.getSymbol when not exists return it as None" + `Object.getSymbol when not exists return it as None` ], ({})[Symbol("fruit")], eq, undefined); Test.run([ @@ -578,7 +578,7 @@ Test.run([ 13, 46 ], - "Object.create clones properties" + `Object.create clones properties` ], Object.create({ a: 1 })["a"], eq, 1); @@ -590,7 +590,7 @@ Test.run([ 13, 46 ], - "Object.create clones properties" + `Object.create clones properties` ], Object.create({ a: 1 })["b"], eq, undefined); diff --git a/tests/tests/src/core/Core_TempTests.mjs b/tests/tests/src/core/Core_TempTests.mjs index 866e2e0788..519540f601 100644 --- a/tests/tests/src/core/Core_TempTests.mjs +++ b/tests/tests/src/core/Core_TempTests.mjs @@ -95,7 +95,7 @@ console.info("JSON"); console.info("---"); -let json = JSON.parse("{\"foo\": \"bar\"}"); +let json = JSON.parse(`{"foo": "bar"}`); let json$1 = Stdlib_JSON.Classify.classify(json); diff --git a/tests/tests/src/core/Core_TestTests.mjs b/tests/tests/src/core/Core_TestTests.mjs index 0c2a2b1b77..60f39dbc78 100644 --- a/tests/tests/src/core/Core_TestTests.mjs +++ b/tests/tests/src/core/Core_TestTests.mjs @@ -90,7 +90,7 @@ Test.run([ 34 ], "print string" -], Test.print("foo"), eq, "\"foo\""); +], Test.print("foo"), eq, `"foo"`); Test.run([ [ @@ -112,7 +112,7 @@ Test.run([ "print object" ], Test.print({ x: 42 -}), eq, "{ x: 42 }"); +}), eq, `{ x: 42 }`); Test.run([ [ diff --git a/tests/tests/src/core/Test.mjs b/tests/tests/src/core/Test.mjs index 9b30283508..9623c45ff3 100644 --- a/tests/tests/src/core/Test.mjs +++ b/tests/tests/src/core/Test.mjs @@ -38,7 +38,13 @@ function run(loc, left, comparator, right) { }, { highlightCode: true }); - let errorMessage = "\n \u001b[31mTest Failure!\n \u001b[36m" + file + "\u001b[0m:\u001b[2m" + String(line) + "\n" + codeFrame + "\n \u001b[39mLeft: \u001b[31m" + left$1 + "\n \u001b[39mRight: \u001b[31m" + right$1 + "\u001b[0m\n"; + let errorMessage = ` + \u001b[31mTest Failure! + \u001b[36m` + file + `\u001b[0m:\u001b[2m` + String(line) + ` +` + codeFrame + ` + \u001b[39mLeft: \u001b[31m` + left$1 + ` + \u001b[39mRight: \u001b[31m` + right$1 + `\u001b[0m +`; console.log(errorMessage); let obj = {}; Error.captureStackTrace(obj); diff --git a/tests/tests/src/core/intl/Core_IntlTests.mjs b/tests/tests/src/core/intl/Core_IntlTests.mjs index d51d8eb213..ecf0306d42 100644 --- a/tests/tests/src/core/intl/Core_IntlTests.mjs +++ b/tests/tests/src/core/intl/Core_IntlTests.mjs @@ -66,7 +66,7 @@ try { exit = 1; } if (exit === 1) { - console.warn("Unexpected error message: \"" + message + "\""); + console.warn(`Unexpected error message: "` + message + `"`); throw e$3; } diff --git a/tests/tests/src/custom_error_test.mjs b/tests/tests/src/custom_error_test.mjs index 4d53d92273..f1b1b5e016 100644 --- a/tests/tests/src/custom_error_test.mjs +++ b/tests/tests/src/custom_error_test.mjs @@ -6,7 +6,7 @@ import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_excep function test_js_error() { let e; try { - e = JSON.parse(" {\"x\" : }"); + e = JSON.parse(` {"x" : }`); } catch (raw_err) { let err = Primitive_exceptions.internalToException(raw_err); if (err.RE_EXN_ID === Stdlib_Exn.$$Error) { @@ -20,7 +20,7 @@ function test_js_error() { function test_js_error2() { try { - return JSON.parse(" {\"x\" : }"); + return JSON.parse(` {"x" : }`); } catch (raw_e) { let e = Primitive_exceptions.internalToException(raw_e); if (e.RE_EXN_ID === Stdlib_Exn.$$Error) { @@ -34,7 +34,7 @@ function test_js_error2() { function example1() { let v; try { - v = JSON.parse(" {\"x\" }"); + v = JSON.parse(` {"x" }`); } catch (raw_err) { let err = Primitive_exceptions.internalToException(raw_err); if (err.RE_EXN_ID === Stdlib_Exn.$$Error) { @@ -48,7 +48,7 @@ function example1() { function example2() { try { - return JSON.parse(" {\"x\"}"); + return JSON.parse(` {"x"}`); } catch (raw_exn) { let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID === Stdlib_Exn.$$Error) { diff --git a/tests/tests/src/exception_rebound_err_test.mjs b/tests/tests/src/exception_rebound_err_test.mjs index c9911dc3c6..12b4bf570d 100644 --- a/tests/tests/src/exception_rebound_err_test.mjs +++ b/tests/tests/src/exception_rebound_err_test.mjs @@ -34,7 +34,7 @@ let C = /* @__PURE__ */Primitive_exceptions.create("Exception_rebound_err_test.C function test_js_error4() { try { - JSON.parse(" {\"x\"}"); + JSON.parse(` {"x"}`); return 1; } catch (raw_e) { let e = Primitive_exceptions.internalToException(raw_e); diff --git a/tests/tests/src/exception_value_test.mjs b/tests/tests/src/exception_value_test.mjs index a0811e4470..dd6e8a25de 100644 --- a/tests/tests/src/exception_value_test.mjs +++ b/tests/tests/src/exception_value_test.mjs @@ -57,7 +57,7 @@ function test_not_found(f, param) { function test_js_error2() { try { - return JSON.parse(" {\"x\" : }"); + return JSON.parse(` {"x" : }`); } catch (raw_e) { let e = Primitive_exceptions.internalToException(raw_e); if (e.RE_EXN_ID === Stdlib_Exn.$$Error) { @@ -70,7 +70,7 @@ function test_js_error2() { function test_js_error3() { try { - JSON.parse(" {\"x\"}"); + JSON.parse(` {"x"}`); return 1; } catch (e) { return 0; diff --git a/tests/tests/src/gbk.mjs b/tests/tests/src/gbk.mjs index 4713069ee1..0db86aecac 100644 --- a/tests/tests/src/gbk.mjs +++ b/tests/tests/src/gbk.mjs @@ -3,7 +3,7 @@ console.log("你好"); -console.log("你好"); +console.log(`你好`); console.log("你好"); diff --git a/tests/tests/src/gpr_3142_test.mjs b/tests/tests/src/gpr_3142_test.mjs index 60628522d2..dbbd2c0eda 100644 --- a/tests/tests/src/gpr_3142_test.mjs +++ b/tests/tests/src/gpr_3142_test.mjs @@ -30,17 +30,17 @@ eq("File \"gpr_3142_test.res\", line 17, characters 3-10", tToJs("a"), "x"); eq("File \"gpr_3142_test.res\", line 18, characters 3-10", tToJs("u"), "hi"); -eq("File \"gpr_3142_test.res\", line 19, characters 3-10", tToJs("b"), "你"); +eq("File \"gpr_3142_test.res\", line 19, characters 3-10", tToJs("b"), `你`); -eq("File \"gpr_3142_test.res\", line 20, characters 3-10", tToJs("c"), "我"); +eq("File \"gpr_3142_test.res\", line 20, characters 3-10", tToJs("c"), `我`); eq("File \"gpr_3142_test.res\", line 22, characters 3-10", tFromJs("x"), "a"); eq("File \"gpr_3142_test.res\", line 23, characters 3-10", tFromJs("hi"), "u"); -eq("File \"gpr_3142_test.res\", line 24, characters 3-10", tFromJs("你"), "b"); +eq("File \"gpr_3142_test.res\", line 24, characters 3-10", tFromJs(`你`), "b"); -eq("File \"gpr_3142_test.res\", line 25, characters 3-10", tFromJs("我"), "c"); +eq("File \"gpr_3142_test.res\", line 25, characters 3-10", tFromJs(`我`), "c"); eq("File \"gpr_3142_test.res\", line 26, characters 3-10", tFromJs("xx"), undefined); diff --git a/tests/tests/src/inline_condition_with_pattern_matching.mjs b/tests/tests/src/inline_condition_with_pattern_matching.mjs index d2fd37d192..cd79b308b7 100644 --- a/tests/tests/src/inline_condition_with_pattern_matching.mjs +++ b/tests/tests/src/inline_condition_with_pattern_matching.mjs @@ -29,22 +29,22 @@ let person2 = { let message$1; if (person2.TAG === "Teacher") { - message$1 = "Hello Jane."; + message$1 = `Hello ` + "Jane" + `.`; } else { let name = "Jane"; let match = person2.reportCard; if (match.passing) { - message$1 = "Congrats " + name + ", nice GPA of " + match.gpa.toString() + " you got there!"; + message$1 = `Congrats ` + name + `, nice GPA of ` + match.gpa.toString() + ` you got there!`; } else { let exit = 0; let tmp$1 = 12345; if (typeof tmp$1 !== "object") { - message$1 = tmp$1 === "Sick" ? "How are you feeling?" : "Good luck next semester " + name + "!"; + message$1 = tmp$1 === "Sick" ? `How are you feeling?` : `Good luck next semester ` + name + `!`; } else { exit = 1; } if (exit === 1) { - message$1 = person2.reportCard.gpa !== 0.0 ? "Good luck next semester " + name + "!" : "Come back in " + (12345)._0.toString() + " days!"; + message$1 = person2.reportCard.gpa !== 0.0 ? `Good luck next semester ` + name + `!` : `Come back in ` + (12345)._0.toString() + ` days!`; } } diff --git a/tests/tests/src/inline_const_test.mjs b/tests/tests/src/inline_const_test.mjs index e5b3e28417..0f31029f9d 100644 --- a/tests/tests/src/inline_const_test.mjs +++ b/tests/tests/src/inline_const_test.mjs @@ -19,23 +19,23 @@ let H = Inline_const.N1({}); let f = "hello"; -let f1 = "a"; +let f1 = `a`; -let f2 = "中文"; +let f2 = `中文`; -let f3 = "中文"; +let f3 = `中文`; -let f4 = "中文"; +let f4 = `中文`; eq("File \"inline_const_test.res\", line 13, characters 5-12", f, "hello"); eq("File \"inline_const_test.res\", line 14, characters 5-12", f1, "a"); -eq("File \"inline_const_test.res\", line 15, characters 5-12", f2, "中文"); +eq("File \"inline_const_test.res\", line 15, characters 5-12", f2, `中文`); -eq("File \"inline_const_test.res\", line 16, characters 5-12", f3, "中文"); +eq("File \"inline_const_test.res\", line 16, characters 5-12", f3, `中文`); -eq("File \"inline_const_test.res\", line 17, characters 5-12", f4, "中文"); +eq("File \"inline_const_test.res\", line 17, characters 5-12", f4, `中文`); eq("File \"inline_const_test.res\", line 18, characters 5-12", true, true); diff --git a/tests/tests/src/js_exception_catch_test.mjs b/tests/tests/src/js_exception_catch_test.mjs index 67a13cbea7..fc5978bcb6 100644 --- a/tests/tests/src/js_exception_catch_test.mjs +++ b/tests/tests/src/js_exception_catch_test.mjs @@ -52,7 +52,7 @@ let exit = 0; let e; try { - e = JSON.parse(" {\"x\"}"); + e = JSON.parse(` {"x"}`); exit = 1; } catch (raw_x) { let x = Primitive_exceptions.internalToException(raw_x); diff --git a/tests/tests/src/js_json_test.mjs b/tests/tests/src/js_json_test.mjs index 03822b16bb..6aebf13582 100644 --- a/tests/tests/src/js_json_test.mjs +++ b/tests/tests/src/js_json_test.mjs @@ -50,7 +50,7 @@ function true_(loc) { })); } -let v = JSON.parse(" { \"x\" : [1, 2, 3 ] } "); +let v = JSON.parse(` { "x" : [1, 2, 3 ] } `); add_test("File \"js_json_test.res\", line 23, characters 11-18", () => { let ty = Js_json.classify(v); @@ -564,7 +564,7 @@ eq("File \"js_json_test.res\", line 290, characters 2-9", JSON.stringify({ baz: { baaz: 10 } -}), "{\"foo\":1,\"bar\":\"hello\",\"baz\":{\"baaz\":10}}"); +}), `{"foo":1,"bar":"hello","baz":{"baaz":10}}`); eq("File \"js_json_test.res\", line 295, characters 12-19", JSON.stringify(null), "null"); diff --git a/tests/tests/src/record_debug_test.mjs b/tests/tests/src/record_debug_test.mjs index 7c1e3bf0d8..dcfc1fa7c2 100644 --- a/tests/tests/src/record_debug_test.mjs +++ b/tests/tests/src/record_debug_test.mjs @@ -83,8 +83,8 @@ let c = [ console.log(a, c); eq("File \"record_debug_test.res\", line 56, characters 3-10", [ - "", - "a" + ``, + `a` ], [ "", "a" diff --git a/tests/tests/src/string_unicode_test.mjs b/tests/tests/src/string_unicode_test.mjs index 7df5ee7745..19220d445f 100644 --- a/tests/tests/src/string_unicode_test.mjs +++ b/tests/tests/src/string_unicode_test.mjs @@ -27,7 +27,7 @@ function eq(loc, x, y) { console.log("你好"); -console.log("你好"); +console.log(`你好`); console.log("你好"); diff --git a/tests/tests/src/switch_case_test.mjs b/tests/tests/src/switch_case_test.mjs index 652b5ec795..eecfd87c07 100644 --- a/tests/tests/src/switch_case_test.mjs +++ b/tests/tests/src/switch_case_test.mjs @@ -44,9 +44,9 @@ eq("File \"switch_case_test.res\", line 22, characters 5-12", f("xx'''"), 0); eq("File \"switch_case_test.res\", line 23, characters 5-12", f("xx\""), 1); -eq("File \"switch_case_test.res\", line 24, characters 5-12", f("xx\\\""), 2); +eq("File \"switch_case_test.res\", line 24, characters 5-12", f(`xx\\"`), 2); -eq("File \"switch_case_test.res\", line 25, characters 5-12", f("xx\\\"\""), 3); +eq("File \"switch_case_test.res\", line 25, characters 5-12", f(`xx\\""`), 3); Mt.from_pair_suites("Switch_case_test", suites.contents); diff --git a/tests/tests/src/tagged_template_test.mjs b/tests/tests/src/tagged_template_test.mjs index 8063c7c91b..8ec5ba1bda 100644 --- a/tests/tests/src/tagged_template_test.mjs +++ b/tests/tests/src/tagged_template_test.mjs @@ -18,7 +18,8 @@ let id = "5"; let queryWithModule = Tagged_template_libJs.sql`SELECT * FROM ${table} WHERE id = ${id}`; -let query = Tagged_template_libJs.sql`SELECT * FROM ${table} WHERE id = ${id}`; +let query = Tagged_template_libJs.sql` +" SELECT * FROM ${table} WHERE id = ${id}`; let length = Tagged_template_libJs.length`hello ${10} what's the total length? Is it ${3}?`; @@ -32,8 +33,8 @@ function foo(strings, values) { } let res = foo([ - "| 5 × 10 = ", - " |" + `| 5 × 10 = `, + ` |` ], [5]); Mt.from_pair_suites("tagged templates", { @@ -42,7 +43,8 @@ Mt.from_pair_suites("tagged templates", { () => ({ TAG: "Eq", _0: query, - _1: "SELECT * FROM 'users' WHERE id = '5'" + _1: ` +" SELECT * FROM 'users' WHERE id = '5'` }) ], tl: { @@ -86,7 +88,7 @@ Mt.from_pair_suites("tagged templates", { "a regular string interpolation should continue working", () => ({ TAG: "Eq", - _0: "some random string interpolation", + _0: `some random ` + "string" + ` interpolation`, _1: "some random string interpolation" }) ], diff --git a/tests/tests/src/tagged_template_test.res b/tests/tests/src/tagged_template_test.res index 92c798724a..df19ec10be 100644 --- a/tests/tests/src/tagged_template_test.res +++ b/tests/tests/src/tagged_template_test.res @@ -11,7 +11,8 @@ let id = "5" let queryWithModule = Pg.sql`SELECT * FROM ${table} WHERE id = ${id}` open Pg -let query = sql`SELECT * FROM ${table} WHERE id = ${id}` +let query = sql` +" SELECT * FROM ${table} WHERE id = ${id}` @module("./tagged_template_lib.js") @taggedTemplate external length: (array, array) => int = "length" @@ -35,7 +36,11 @@ Mt.from_pair_suites( list{ ( "with externals, it should return a string with the correct interpolations", - () => Eq(query, "SELECT * FROM 'users' WHERE id = '5'"), + () => Eq( + query, + ` +" SELECT * FROM 'users' WHERE id = '5'`, + ), ), ( "with module scoped externals, it should also return a string with the correct interpolations", diff --git a/tests/tests/src/template.mjs b/tests/tests/src/template.mjs index e205477ca3..84d606a3ee 100644 --- a/tests/tests/src/template.mjs +++ b/tests/tests/src/template.mjs @@ -1,10 +1,12 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -let bla2 = ""; +let bla2 = ``; function concat() { - return "\n display:\r flex;\n " + bla2; + return ` + display:\r flex; + ` + bla2; } export {