diff options
author | 2023-05-18 13:27:05 -0700 | |
---|---|---|
committer | 2023-05-18 13:27:05 -0700 | |
commit | f3a1a3bb2bee56940426a6541c46775a2f8ab28a (patch) | |
tree | 2e7afa31e566b16feed02d4d3bcef666377768fd /src | |
parent | 755c0d62c47b0e8301a3d975697d476fe5c7436f (diff) | |
download | bun-f3a1a3bb2bee56940426a6541c46775a2f8ab28a.tar.gz bun-f3a1a3bb2bee56940426a6541c46775a2f8ab28a.tar.zst bun-f3a1a3bb2bee56940426a6541c46775a2f8ab28a.zip |
Fixes #2946 (#2949)
* Fixes #2946
* Update string_mutable.zig
* Fixes #2948
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/js_parser.zig | 5 | ||||
-rw-r--r-- | src/string_mutable.zig | 11 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/js_parser.zig b/src/js_parser.zig index 90d7a5d24..ee6a5e6b8 100644 --- a/src/js_parser.zig +++ b/src/js_parser.zig @@ -20389,7 +20389,10 @@ fn NewParser_( var decl = &prev_local.decls.slice()[0]; if (decl.binding.data == .b_identifier and decl.binding.data.b_identifier.ref.eql(bin_assign.left.data.e_identifier.ref) and - (decl.value == null or decl.value.?.isPrimitiveLiteral())) + // If the value was assigned, we shouldn't merge it incase it was used in the current statement + // https://github.com/oven-sh/bun/issues/2948 + // We don't have a more granular way to check symbol usage so this is the best we can do + decl.value == null) { decl.value = bin_assign.right; p.ignoreUsage(bin_assign.left.data.e_identifier.ref); diff --git a/src/string_mutable.zig b/src/string_mutable.zig index 2b8d80429..e6738ae7f 100644 --- a/src/string_mutable.zig +++ b/src/string_mutable.zig @@ -109,7 +109,12 @@ pub const MutableString = struct { } if (needs_gap) { - var mutable = try MutableString.initCopy(allocator, str[0..start_i]); + var mutable = try MutableString.initCopy(allocator, if (start_i == 0) + // the first letter can be a non-identifier start + // https://github.com/oven-sh/bun/issues/2946 + "_" + else + str[0..start_i]); needs_gap = false; var slice = str[start_i..]; @@ -137,6 +142,10 @@ pub const MutableString = struct { has_needed_gap = true; } + if (comptime bun.Environment.allow_assert) { + std.debug.assert(js_lexer.isIdentifier(mutable.list.items)); + } + return try mutable.list.toOwnedSlice(allocator); } |