feat(prettier): print inner comment in PropertyKey (#1479)

This commit is contained in:
Dunqing 2023-11-21 17:26:36 +08:00 committed by GitHub
parent 4dbe17c33a
commit c762a85fcc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 6 deletions

View file

@ -58,6 +58,7 @@ impl<'a> Prettier<'a> {
break;
}
}
parts
}

View file

@ -80,7 +80,7 @@ fn print_call_expression_arguments<'a>(
let arguments = expression.arguments();
let should_break = !is_commons_js_or_amd_call(expression.callee(), arguments);
if arguments.len() == 0 {
if arguments.is_empty() {
parts.extend(p.print_inner_comment(Span::new(callee.span().end, expression.span().end)));
}

View file

@ -25,7 +25,7 @@ use std::borrow::Cow;
use oxc_allocator::{Box, Vec};
use oxc_ast::{ast::*, AstKind};
use oxc_span::GetSpan;
use oxc_span::{GetSpan, Span};
use crate::{
array,
@ -1422,6 +1422,12 @@ impl<'a> Format<'a> for ObjectProperty<'a> {
}
} else {
parts.push(format!(p, self.key));
let comments =
p.print_inner_comment(Span::new(self.key.span().end, self.value.span().start));
if !comments.is_empty() {
parts.push(ss!(" "));
parts.extend(comments);
}
parts.push(ss!(": "));
parts.push(format!(p, self.value));
}

View file

@ -1,4 +1,4 @@
Compatibility: 133/601 (22.13%)
Compatibility: 134/601 (22.30%)
# Failed
@ -484,9 +484,6 @@ Compatibility: 133/601 (22.13%)
* object-prop-break-in/short-keys.js
* object-prop-break-in/test.js
### object-property-comment
* object-property-comment/after-key.js
### object-property-ignore
* object-property-ignore/ignore.js
* object-property-ignore/issue-5678.js