aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-16 15:21:11 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-16 15:21:11 -0800
commit34845028398b47973f123deb0f6f1863634b1445 (patch)
tree233c56a12705aef308c43f060b4e4efd722337b0
parenta345efd270bcd19672b13b363d287354113b7aba (diff)
downloadbun-34845028398b47973f123deb0f6f1863634b1445.tar.gz
bun-34845028398b47973f123deb0f6f1863634b1445.tar.zst
bun-34845028398b47973f123deb0f6f1863634b1445.zip
[JS Parser] Don't inline rope strings
Diffstat (limited to '')
-rw-r--r--src/js_ast.zig21
-rw-r--r--src/js_parser.zig4
-rw-r--r--test/bun.js/transpiler.test.js13
3 files changed, 19 insertions, 19 deletions
diff --git a/src/js_ast.zig b/src/js_ast.zig
index 82c9de809..fbeddcbb8 100644
--- a/src/js_ast.zig
+++ b/src/js_ast.zig
@@ -1672,23 +1672,15 @@ pub const E = struct {
pub fn resovleRopeIfNeeded(this: *String, allocator: std.mem.Allocator) void {
if (this.next == null or !this.isUTF8()) return;
- var bytes = allocator.alloc(u8, this.rope_len) catch unreachable;
- var ptr = bytes.ptr;
- var remain = bytes.len;
- @memcpy(ptr, this.data.ptr, this.data.len);
- ptr += this.data.len;
- remain -= this.data.len;
var str = this.next;
+ var bytes = std.ArrayList(u8).initCapacity(allocator, this.rope_len) catch unreachable;
+
+ bytes.appendSliceAssumeCapacity(this.data);
while (str) |strin| {
- @memcpy(ptr, strin.data.ptr, strin.data.len);
- ptr += strin.data.len;
- remain -= strin.data.len;
- var prev = strin;
+ bytes.appendSlice(strin.data) catch unreachable;
str = strin.next;
- prev.next = null;
- prev.end = null;
}
- this.data = bytes;
+ this.data = bytes.items;
this.next = null;
}
@@ -3607,7 +3599,8 @@ pub const Expr = struct {
pub fn canBeConstValue(this: Expr.Data) bool {
return switch (this) {
- .e_string, .e_number, .e_boolean, .e_null, .e_undefined => true,
+ .e_number, .e_boolean, .e_null, .e_undefined => true,
+ .e_string => |str| str.next == null,
.e_array => |array| array.was_originally_macro,
.e_object => |object| object.was_originally_macro,
else => false,
diff --git a/src/js_parser.zig b/src/js_parser.zig
index fbfaa3a43..c20300daa 100644
--- a/src/js_parser.zig
+++ b/src/js_parser.zig
@@ -118,7 +118,9 @@ fn foldStringAddition(lhs: Expr, rhs: Expr) ?Expr {
.e_string => |left| {
if (rhs.data == .e_string and left.isUTF8() and rhs.data.e_string.isUTF8()) {
var orig = lhs.data.e_string.*;
- orig.push(rhs.data.e_string);
+ const rhs_clone = Expr.init(E.String, rhs.data.e_string.*, rhs.loc);
+ orig.push(rhs_clone.data.e_string);
+
return Expr.init(E.String, orig, lhs.loc);
}
},
diff --git a/test/bun.js/transpiler.test.js b/test/bun.js/transpiler.test.js
index 05607091a..dcc7f397a 100644
--- a/test/bun.js/transpiler.test.js
+++ b/test/bun.js/transpiler.test.js
@@ -1774,12 +1774,17 @@ class Foo {
check(
`
-const a = "[^aeiou]";
-const b = a + "[^aeiouy]*";
-console.log(a, b);
+const a = "a";
+const c = "b" + a;
+const b = c + a;
+const d = b + a;
+console.log(a, b, c, d);
`,
`
-console.log("[^aeiou]", "[^aeiou][^aeiouy]*");
+const c = "ba";
+const b = c + "a";
+const d = b + "a";
+console.log("a", b, c, d);
`.trim(),
);