diff --git a/test/com/google/javascript/jscomp/PeepholeFoldConstantsTest.java b/test/com/google/javascript/jscomp/PeepholeFoldConstantsTest.java index ecd86e966b4..1a851ee1853 100644 --- a/test/com/google/javascript/jscomp/PeepholeFoldConstantsTest.java +++ b/test/com/google/javascript/jscomp/PeepholeFoldConstantsTest.java @@ -2217,6 +2217,35 @@ public void testAssociativeFoldConstantsWithVariables() { test("alert(12 & x & 20);", "alert(x & 4);"); } + + @Test + public void testTemplateLiteralConcat() { + // --- Issue #4148 core case: template + template should merge + +// string + template literal (with any order) +// string + string (already working) +// template literal + template literal (template literal can include referenced variable +// or valid HTML) + + test( + "const x = 'X'; console.log('pre' + `${x}`);", + "const x = 'X'; console.log(`pre${x}`);"); + + test( + """ + var a = document.location.href; + console.log(`

${a}

` + `

The URL is ${a}.

`); + """, + """ + var a = document.location.href; + console.log(`

${a}

The URL is ${a}.

`); + """ + ); + + } + + + private void foldBigIntTypes(String js, String expected) { test( "function f(/** @type {bigint} */ x) { " + js + " }",