mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
fix template addition folding 12904 (#12928)
This commit is contained in:
@@ -356,6 +356,7 @@ fn foldStringAddition(l: Expr, r: Expr, allocator: std.mem.Allocator, kind: Fold
|
||||
right,
|
||||
r.data == .e_inlined_enum,
|
||||
) };
|
||||
return lhs;
|
||||
}
|
||||
} else {
|
||||
if (left.head.isUTF8()) {
|
||||
@@ -364,10 +365,9 @@ fn foldStringAddition(l: Expr, r: Expr, allocator: std.mem.Allocator, kind: Fold
|
||||
right,
|
||||
r.data == .e_inlined_enum,
|
||||
) };
|
||||
return lhs;
|
||||
}
|
||||
}
|
||||
|
||||
return lhs;
|
||||
}
|
||||
},
|
||||
// `foo${bar}` + `a${hi}b` => `foo${bar}a${hi}b`
|
||||
@@ -391,6 +391,7 @@ fn foldStringAddition(l: Expr, r: Expr, allocator: std.mem.Allocator, kind: Fold
|
||||
E.TemplatePart,
|
||||
&.{ left.parts, right.parts },
|
||||
) catch bun.outOfMemory();
|
||||
return lhs;
|
||||
}
|
||||
} else {
|
||||
if (left.head.isUTF8() and right.head.isUTF8()) {
|
||||
@@ -400,9 +401,9 @@ fn foldStringAddition(l: Expr, r: Expr, allocator: std.mem.Allocator, kind: Fold
|
||||
r.data == .e_inlined_enum,
|
||||
) };
|
||||
left.parts = right.parts;
|
||||
return lhs;
|
||||
}
|
||||
}
|
||||
return lhs;
|
||||
}
|
||||
},
|
||||
else => {
|
||||
|
||||
@@ -80,6 +80,12 @@ const templateStringTests: Record<string, TemplateStringTest> = {
|
||||
FoldNested6: { expr: "`a\0${5}c\\${{$${`d`}e`", print: true },
|
||||
EscapedDollar: { expr: "`\\${'a'}`", captureRaw: "\"${'a'}\"" },
|
||||
EscapedDollar2: { expr: "`\\${'a'}\\${'b'}`", captureRaw: "\"${'a'}${'b'}\"" },
|
||||
StringAddition: { expr: "`${1}\u2796` + 'rest'", print: true },
|
||||
StringAddition2: { expr: "`\u2796${1}` + `a${Number(1)}b`", print: true },
|
||||
StringAddition3: { expr: '`0${"\u2796"}` + `a${Number(1)}b`', print: true },
|
||||
StringAddition4: { expr: "`${1}z` + `\u2796${Number(1)}rest`", print: true },
|
||||
StringAddition5: { expr: "`\u2796${1}z` + `\u2796${Number(1)}rest`", print: true },
|
||||
StringAddition6: { expr: "`${1}` + '\u2796rest'", print: true },
|
||||
};
|
||||
|
||||
describe("bundler", () => {
|
||||
|
||||
Reference in New Issue
Block a user