mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
zig fmt: canonicalize stray backslashes in identifiers
This commit is contained in:
@@ -3257,6 +3257,9 @@ fn renderIdentifierContents(ais: *AutoIndentingStream, bytes: []const u8) !void
|
||||
}
|
||||
},
|
||||
.failure => {
|
||||
// Escape the stray backslash
|
||||
// This also avoids cases like "\x3\x39" becoming "\x39"
|
||||
try ais.writeByte('\\');
|
||||
try ais.writeAll(escape_sequence);
|
||||
},
|
||||
}
|
||||
|
||||
@@ -6666,6 +6666,24 @@ test "zig fmt: doc comments on fn parameters" {
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: canonicalize stray backslashes in identifiers" {
|
||||
try testTransform(
|
||||
\\const @"\x" = undefined;
|
||||
\\const @"\x3" = undefined;
|
||||
\\const @"\x3\x39" = undefined;
|
||||
\\const @"\u{" = undefined;
|
||||
\\const @"\?" = undefined;
|
||||
\\
|
||||
,
|
||||
\\const @"\\x" = undefined;
|
||||
\\const @"\\x3" = undefined;
|
||||
\\const @"\\x39" = undefined;
|
||||
\\const @"\\u{" = undefined;
|
||||
\\const @"\\?" = undefined;
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "recovery: top level" {
|
||||
try testError(
|
||||
\\test "" {inline}
|
||||
|
||||
Reference in New Issue
Block a user