mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 12:51:54 +00:00
fix(transpiler): error when parsing keys with hyphen in some JSON files (#7316)
* Quote export aliases with hyphens when converting jsons to modules * Add test * Handle quotes in printer and not in bundler * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -7,6 +7,7 @@ const CodePoint = bun.CodePoint;
|
||||
const bun = @import("root").bun;
|
||||
pub const joiner = @import("./string_joiner.zig");
|
||||
const log = bun.Output.scoped(.STR, true);
|
||||
const js_lexer = @import("./js_lexer.zig");
|
||||
|
||||
pub const Encoding = enum {
|
||||
ascii,
|
||||
@@ -216,7 +217,6 @@ pub fn fmtIdentifier(name: string) FormatValidIdentifier {
|
||||
/// This will always allocate
|
||||
pub const FormatValidIdentifier = struct {
|
||||
name: string,
|
||||
const js_lexer = @import("./js_lexer.zig");
|
||||
pub fn format(self: FormatValidIdentifier, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void {
|
||||
var iterator = strings.CodepointIterator.init(self.name);
|
||||
var cursor = strings.CodepointIterator.Cursor{};
|
||||
@@ -4367,6 +4367,24 @@ pub fn containsNonBmpCodePoint(text: string) bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
pub fn containsNonBmpCodePointOrIsInvalidIdentifier(text: string) bool {
|
||||
var iter = CodepointIterator.init(text);
|
||||
var curs = CodepointIterator.Cursor{};
|
||||
|
||||
if (!iter.next(&curs)) return true;
|
||||
|
||||
if (curs.c > 0xFFFF or !js_lexer.isIdentifierStart(curs.c))
|
||||
return true;
|
||||
|
||||
while (iter.next(&curs)) {
|
||||
if (curs.c > 0xFFFF or !js_lexer.isIdentifierContinue(curs.c)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// this is std.mem.trim except it doesn't forcibly change the slice to be const
|
||||
pub fn trim(slice: anytype, comptime values_to_strip: []const u8) @TypeOf(slice) {
|
||||
var begin: usize = 0;
|
||||
|
||||
Reference in New Issue
Block a user