From 8bab2f9953f42c4db080ed717d058b78193de449 Mon Sep 17 00:00:00 2001 From: rahulmansharamani14 Date: Fri, 29 Aug 2025 05:33:55 -0500 Subject: [PATCH] tests(peephole): add minimal failing test for template literal concatenation (#4148) --- .../jscomp/PeepholeFoldConstantsTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) 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 + " }",