mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
zig fmt: canonicalize stray backslashes in identifiers
This commit is contained in:
parent
4b73d5e029
commit
6bcd6b35ce
2 changed files with 21 additions and 0 deletions
|
|
@ -3449,6 +3449,9 @@ fn renderIdentifierContents(ais: *AutoIndentingStream, bytes: []const u8) !void
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.failure => {
|
.failure => {
|
||||||
|
// Escape the stray backslash
|
||||||
|
// This also avoids cases like "\x3\x39" becoming "\x39"
|
||||||
|
try ais.writeByte('\\');
|
||||||
try ais.writeAll(escape_sequence);
|
try ais.writeAll(escape_sequence);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6732,6 +6732,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" {
|
test "recovery: top level" {
|
||||||
try testError(
|
try testError(
|
||||||
\\test "" {inline}
|
\\test "" {inline}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue