aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/js_parser.zig5
-rw-r--r--src/string_mutable.zig11
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);
}