fix(prettier): keep EmptyStatement in Program (#1576)

This commit is contained in:
Dunqing 2023-11-29 18:22:40 +08:00 committed by GitHub
parent 3a00382d28
commit 3a4261ff5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View file

@ -72,7 +72,12 @@ pub(super) fn print_block_body<'a>(
}
if has_body {
parts.extend(statement::print_statement_sequence(p, stmts, remove_last_statement_hardline));
parts.extend(statement::print_statement_sequence(
p,
stmts,
remove_last_statement_hardline,
!is_root,
));
}
if is_root {

View file

@ -13,16 +13,13 @@ pub(super) fn print_statement_sequence<'a>(
p: &mut Prettier<'a>,
stmts: &[Statement<'a>],
remove_last_statement_hardline: bool,
skip_empty_statement: bool,
) -> Vec<'a, Doc<'a>> {
let mut parts = p.vec();
let mut len = stmts.len();
let len = stmts.len();
for (i, stmt) in stmts.iter().enumerate() {
if i < len - 1 && matches!(stmts[i + 1], Statement::EmptyStatement(_)) {
len -= 1;
}
if matches!(stmt, Statement::EmptyStatement(_)) {
if skip_empty_statement && matches!(stmt, Statement::EmptyStatement(_)) {
continue;
}
@ -43,7 +40,7 @@ pub(super) fn print_statement_sequence<'a>(
parts.push(docs);
if i < len - 1 {
if i < len - 1 && !matches!(stmts[i + 1], Statement::EmptyStatement(_)) {
parts.extend(hardline!());
if p.is_next_line_empty(stmt.span()) {