feat(prettier): implement should_break in CallExpression and Object (#1448)

This commit is contained in:
Dunqing 2023-11-20 17:07:32 +08:00 committed by GitHub
parent aabed6bee8
commit 719ed744e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 10 deletions

View file

@ -1,11 +1,14 @@
use oxc_allocator::{Box, Vec};
use oxc_ast::ast::*;
use oxc_span::GetSpan;
use crate::{
doc::{Doc, Group},
if_break, ss, Format, Prettier,
};
use super::misc;
pub(super) fn print_call_expression<'a>(
p: &mut Prettier<'a>,
callee: &Expression<'a>,
@ -49,5 +52,8 @@ fn print_call_expression_arguments<'a>(
parts.push(if_break!(p, ","));
parts.push(Doc::Softline);
parts.push(ss!(")"));
Doc::Group(Group::new(parts, false))
let should_break = arguments
.iter()
.any(|arg| misc::has_new_line_in_range(p.source_text, arg.span().start, arg.span().end));
Doc::Group(Group::new(parts, should_break))
}

View file

@ -70,7 +70,9 @@ pub(super) fn print_object_properties<'a, F: Format<'a> + GetSpan>(
}
parts.push(ss!("}"));
Doc::Group(Group::new(parts, false))
let should_break =
misc::has_new_line_in_range(p.source_text, object.span().start, object.span().end);
Doc::Group(Group::new(parts, should_break))
};
content

View file

@ -1,4 +1,4 @@
Compatibility: 113/601 (18.80%)
Compatibility: 118/601 (19.63%)
# Failed
@ -89,7 +89,6 @@ Compatibility: 113/601 (18.80%)
### async
* async/async-iteration.js
* async/async-shorthand-method.js
* async/await-parse.js
* async/conditional-expression.js
* async/exponentiation.js
@ -132,7 +131,6 @@ Compatibility: 113/601 (18.80%)
### call/first-argument-expansion
* call/first-argument-expansion/expression-2nd-arg.js
* call/first-argument-expansion/issue-12892.js
* call/first-argument-expansion/issue-13237.js
* call/first-argument-expansion/issue-2456.js
* call/first-argument-expansion/issue-4401.js
@ -423,7 +421,6 @@ Compatibility: 113/601 (18.80%)
* last-argument-expansion/empty-lines.js
* last-argument-expansion/empty-object.js
* last-argument-expansion/function-body-in-mode-break.js
* last-argument-expansion/function-expression.js
* last-argument-expansion/issue-10708.js
* last-argument-expansion/issue-7518.js
* last-argument-expansion/jsx.js
@ -499,12 +496,8 @@ Compatibility: 113/601 (18.80%)
### nullish-coalescing
* nullish-coalescing/nullish_coalesing_operator.js
### object-colon-bug
* object-colon-bug/bug.js
### object-prop-break-in
* object-prop-break-in/comment.js
* object-prop-break-in/long-value.js
* object-prop-break-in/short-keys.js
* object-prop-break-in/test.js