Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concatenated template literals are not merged #4148

Open
qftlzxfz opened this issue Feb 2, 2024 · 0 comments
Open

Concatenated template literals are not merged #4148

qftlzxfz opened this issue Feb 2, 2024 · 0 comments
Labels
enhancement good first issue Relatively easy, but low priority bugs

Comments

@qftlzxfz
Copy link

qftlzxfz commented Feb 2, 2024

With --compilation_level ADVANCED, concatenated template literals are not merged into one.

let url = document.location.href;
console.log(
    `<h1>${url}</h1>`
    + `<p>The URL is ${url}.</p>`
);

url = '//example.com/';
console.log(
    `<h1>${url}</h1>`
    + `<p>The URL is ${url}.</p>`
);

const other_url = '//example.com/';
console.log(
    `<h1>${other_url}</h1>`
    + `<p>The URL is ${other_url}.</p>`
);

Output (with extra line breaks after ;):

let a=document.location.href;
console.log(`<h1>${a}</h1>`+`<p>The URL is ${a}.</p>`);
a="//example.com/";
console.log(`<h1>${a}</h1>`+`<p>The URL is ${a}.</p>`);
console.log("<h1>//example.com/</h1><p>The URL is //example.com/.</p>");

When the values are known, it converts the template string to a normal string and combines them.

I would expect this:

let a=document.location.href;
console.log(`<h1>${a}</h1><p>The URL is ${a}.</p>`);
a="//example.com/";
console.log(`<h1>${a}</h1><p>The URL is ${a}.</p>`);
console.log("<h1>//example.com/</h1><p>The URL is //example.com/.</p>");

Or is there a perhaps a reason not to join the template literals in the first two cases?

@lauraharker lauraharker added enhancement good first issue Relatively easy, but low priority bugs labels Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement good first issue Relatively easy, but low priority bugs
Projects
None yet
Development

No branches or pull requests

2 participants