aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/js_parser.zig5
-rw-r--r--test/bun.js/transpiler.test.js24
2 files changed, 27 insertions, 2 deletions
diff --git a/src/js_parser.zig b/src/js_parser.zig
index 1fa86041f..1dbf1ebf9 100644
--- a/src/js_parser.zig
+++ b/src/js_parser.zig
@@ -117,8 +117,9 @@ fn foldStringAddition(lhs: Expr, rhs: Expr) ?Expr {
switch (lhs.data) {
.e_string => |left| {
if (rhs.data == .e_string and left.isUTF8() and rhs.data.e_string.isUTF8()) {
- lhs.data.e_string.push(rhs.data.e_string);
- return lhs;
+ var orig = lhs.data.e_string.*;
+ orig.push(rhs.data.e_string);
+ return Expr.init(E.String, orig, lhs.loc);
}
},
.e_binary => |bin| {
diff --git a/test/bun.js/transpiler.test.js b/test/bun.js/transpiler.test.js
index bc7102b95..94c3d52d2 100644
--- a/test/bun.js/transpiler.test.js
+++ b/test/bun.js/transpiler.test.js
@@ -915,6 +915,19 @@ export var ComponentThatHasSpreadCausesDeopt = $jsx(Hello, {
it("fold string addition", () => {
expectPrinted_(
+ `
+const a = "[^aeiou]";
+const b = a + "[^aeiouy]*";
+console.log(a);
+ `,
+ `
+const a = "[^aeiou]";
+const b = a + "[^aeiouy]*";
+console.log(a)
+ `.trim(),
+ );
+
+ expectPrinted_(
`export const foo = "a" + "b";`,
`export const foo = "ab"`,
);
@@ -1734,6 +1747,17 @@ class Foo {
`return "foobar";`,
);
+ check(
+ `
+const a = "[^aeiou]";
+const b = a + "[^aeiouy]*";
+console.log(a, b);
+ `,
+ `
+console.log("[^aeiou]", "[^aeiou][^aeiouy]*");
+ `.trim(),
+ );
+
// check that it doesn't inline after "var"
check(
`