diff options
author | 2023-07-24 19:08:56 -0700 | |
---|---|---|
committer | 2023-07-24 19:08:56 -0700 | |
commit | e154763e4df422a33c66208717748827a1164de7 (patch) | |
tree | cdc7e5607df1b525c85e895f77666e6f39bc090a | |
parent | ac10a1b6331c1451dec3e65bb1c34b3bd65a6851 (diff) | |
download | bun-e154763e4df422a33c66208717748827a1164de7.tar.gz bun-e154763e4df422a33c66208717748827a1164de7.tar.zst bun-e154763e4df422a33c66208717748827a1164de7.zip |
fix rope string push (#3796)
* push to next next
* couple more tests
* end
-rw-r--r-- | src/js_ast.zig | 4 | ||||
-rw-r--r-- | test/transpiler/transpiler.test.js | 22 |
2 files changed, 25 insertions, 1 deletions
diff --git a/src/js_ast.zig b/src/js_ast.zig index b83f6c5c2..b5f47474a 100644 --- a/src/js_ast.zig +++ b/src/js_ast.zig @@ -2163,7 +2163,9 @@ pub const E = struct { this.next = other; this.end = other; } else { - this.end.?.next = other; + var end = this.end.?; + while (end.next != null) end = end.end.?; + end.next = other; this.end = other; } } diff --git a/test/transpiler/transpiler.test.js b/test/transpiler/transpiler.test.js index 8c77dffe6..c490abb51 100644 --- a/test/transpiler/transpiler.test.js +++ b/test/transpiler/transpiler.test.js @@ -2807,6 +2807,28 @@ console.log(foo, array); expectPrinted("'a' + 1", '"a" + 1'); expectPrinted("x * 'a' + 'b'", 'x * "a" + "b"'); + // rope string push another rope string + expectPrinted("'a' + ('b' + 'c') + 'd'", '"abcd"'); + expectPrinted("('a' + 'b') + 'c'", '"abc"'); + expectPrinted("'a' + ('b' + 'c')", '"abc"'); + expectPrinted("'a' + ('b' + ('c' + 'd')) + 'e'", '"abcde"'); + expectPrinted("'a' + ('b' + ('c' + ('d' + 'e')))", '"abcde"'); + expectPrinted("('a' + ('b' + ('c' + 'd'))) + 'e'", '"abcde"'); + expectPrinted("('a' + ('b' + 'c')) + ('d' + 'e')", '"abcde"'); + expectPrinted("('a' + 'b') + ('c' + 'd')", '"abcd"'); + expectPrinted("'a' + ('b' + 'c') + 'd'", '"abcd"'); + expectPrinted("'a' + ('b' + ('c' + 'd'))", '"abcd"'); + + function check(input, output) { + expect(transpiler.transformSync(input)).toEqual(output); + } + + var output = `var boop = "bcd";\nconst ropy = "a" + boop + "d", ropy2 = "b" + boop;\n`; + check(`var boop = ('b' + 'c') + 'd'; const ropy = "a" + boop + 'd'; const ropy2 = 'b' + boop;`, output); + + output = `var boop = "fbcd", ropy = "a" + boop + "d", ropy2 = "b" + (ropy + "d");\n`; + check(`var boop = "f" + ("b" + "c") + "d";var ropy = "a" + boop + "d";var ropy2 = "b" + (ropy + "d")`, output); + expectPrinted("'string' + `template`", `"stringtemplate"`); expectPrinted("`template` + 'string'", '"templatestring"'); |