feat(prettier): add HardLine and Semicolon in ExpressionStatement (#1285)

This commit is contained in:
Dunqing 2023-11-14 12:14:45 +08:00 committed by GitHub
parent b528af1b93
commit c15b76b92d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 17 deletions

View file

@ -69,7 +69,13 @@ impl<'a> Format<'a> for Statement<'a> {
impl<'a> Format<'a> for ExpressionStatement<'a> {
fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> {
self.expression.format(p)
let mut parts = p.vec();
parts.push(self.expression.format(p));
if p.options.semi {
parts.push(p.str(";"));
}
parts.push(Doc::Hardline);
Doc::Array(parts)
}
}
@ -151,19 +157,7 @@ impl<'a> Format<'a> for DoWhileStatement<'a> {
impl<'a> Format<'a> for ContinueStatement {
fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> {
let mut parts = p.vec();
parts.push(string!(p, "continue"));
if let Some(label) = &self.label {
parts.push(string!(p, " "));
parts.push(format!(p, label));
}
if p.options.semi {
parts.push(Doc::Str(";"));
}
Doc::Array(parts)
Doc::Line
}
}

View file

@ -1,4 +1,4 @@
Compatibility: 0/173 (0.00%)
Compatibility: 2/173 (0.01%)
# Failed
@ -11,7 +11,6 @@ Compatibility: 0/173 (0.00%)
* arrows-bind
* assignment
* assignment-comments
* assignment-expression
* async
* async-do-expressions
* babel-plugins
@ -96,7 +95,6 @@ Compatibility: 0/173 (0.00%)
* line
* line-suffix-boundary
* literal
* literal-numeric-separator
* logical-assignment
* logical_expressions
* member