mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
There is no need to concat empty string literals when building template literals. Now strings will only be concatenated if they need to be. To handle the edge case where the first segment is not a string literal, a new `ToString` op code has been added to ensure the value is a string concatenating more strings. In addition, basic const folding is now supported for template literal constants (templates with no interpolated values), which is commonly used for multi-line string constants.
34 lines
654 B
JavaScript
34 lines
654 B
JavaScript
function prefix(x) {
|
|
return `prefix-${x}`;
|
|
}
|
|
function suffix(x) {
|
|
return `${x}-suffix`;
|
|
}
|
|
function tostring(x) {
|
|
return `${x}`;
|
|
}
|
|
function multi(a, b, c) {
|
|
return `${a}${b}${c}`;
|
|
}
|
|
function literal() {
|
|
return `hello world`;
|
|
}
|
|
function empty() {
|
|
return ``;
|
|
}
|
|
|
|
const a = `abc` + "xyz";
|
|
const b = `abc` + `xyz`;
|
|
const c = "abc" + `xyz`;
|
|
const d = "abc" + "xyz";
|
|
const e = `abc` + `` + `xyz`;
|
|
const f = `abc` + "" + `xyz`;
|
|
const g = `${"abc"}${"xyz"}`;
|
|
|
|
const _prefix = prefix("abc");
|
|
const _suffix = suffix("abc");
|
|
const _tostring = tostring("abc");
|
|
const _multi = multi(1, 2, 3);
|
|
const _literal = literal();
|
|
const _empty = empty();
|