* Fixes #2946

* Update string_mutable.zig

* Fixes #2948

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
Jarred Sumner
2023-05-18 13:27:05 -07:00
committed by GitHub
parent 755c0d62c4
commit f3a1a3bb2b
3 changed files with 57 additions and 2 deletions

View File

@@ -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);
}