diff options
author | 2023-01-12 10:14:35 -0800 | |
---|---|---|
committer | 2023-01-12 10:14:35 -0800 | |
commit | edf9757650f8b498841d1a95269289b74d0b4023 (patch) | |
tree | 114922ab91cc2e25908daec51d5686ba31457510 | |
parent | e65def0f82482a08521ec608efa6d8c14a700270 (diff) | |
download | bun-edf9757650f8b498841d1a95269289b74d0b4023.tar.gz bun-edf9757650f8b498841d1a95269289b74d0b4023.tar.zst bun-edf9757650f8b498841d1a95269289b74d0b4023.zip |
Fixes #1772
-rw-r--r-- | src/js_parser.zig | 5 | ||||
-rw-r--r-- | test/bun.js/transpiler.test.js | 24 |
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( ` |