mirror of
https://github.com/ziglang/zig.git
synced 2026-02-15 13:58:27 +00:00
fix comments getting removed after empty comments
This commit is contained in:
parent
01ff0d4d62
commit
de369de312
@ -2246,6 +2246,20 @@ test "zig fmt: if type expr" {
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: comment after empty comment" {
|
||||
try testTransform(
|
||||
\\const x = true; //
|
||||
\\//
|
||||
\\//
|
||||
\\//a
|
||||
\\
|
||||
,
|
||||
\\const x = true;
|
||||
\\//a
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
const std = @import("std");
|
||||
const mem = std.mem;
|
||||
const warn = std.debug.warn;
|
||||
|
||||
@ -1941,15 +1941,24 @@ fn renderTokenOffset(
|
||||
}
|
||||
}
|
||||
|
||||
const comment_is_empty = mem.trimRight(u8, tree.tokenSlicePtr(next_token), " ").len == 2;
|
||||
if (comment_is_empty) {
|
||||
switch (space) {
|
||||
Space.Newline => {
|
||||
try stream.writeByte('\n');
|
||||
start_col.* = 0;
|
||||
return;
|
||||
},
|
||||
else => {},
|
||||
while (true) {
|
||||
const comment_is_empty = mem.trimRight(u8, tree.tokenSlicePtr(next_token), " ").len == 2;
|
||||
if (comment_is_empty) {
|
||||
switch (space) {
|
||||
Space.Newline => {
|
||||
offset += 1;
|
||||
token = next_token;
|
||||
next_token = tree.tokens.at(token_index + offset);
|
||||
if (next_token.id != .LineComment) {
|
||||
try stream.writeByte('\n');
|
||||
start_col.* = 0;
|
||||
return;
|
||||
}
|
||||
},
|
||||
else => break,
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user