Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1480,11 +1480,15 @@ impl GenExpr for ObjectExpression<'_> {
let n = p.code_len();
let len = self.properties.len();
let is_multi_line = len > 1;
let wrap = p.start_of_stmt == n || p.start_of_arrow_expr == n;
let has_comment = p.has_comment(self.span.start);
let wrap = has_comment || p.start_of_stmt == n || p.start_of_arrow_expr == n;
p.wrap(wrap, |p| {
// Print comments for lingui https://lingui.dev/ref/macro#definemessage
// `const message = /*i18n*/ { };`
p.print_leading_comments(self.span.start);
if has_comment {
p.print_leading_comments(self.span.start);
p.print_indent();
}
p.add_source_mapping(self.span);
p.print_ascii_byte(b'{');
if is_multi_line {
Expand Down
8 changes: 6 additions & 2 deletions crates/oxc_codegen/tests/integration/comments.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use crate::tester::test_same;
use crate::tester::{test, test_same};

#[test]
fn unit() {
test_same("<div>{/* Hello */}</div>;\n");
// https://lingui.dev/ref/macro#definemessage
test_same("const message = /*i18n*/{};\n");
test("const message = /*i18n*/{};", "const message = (/*i18n*/ {});\n");
test(
"function foo() { return /*i18n*/ {} }",
"function foo() {\n\treturn (\t/*i18n*/ {});\n}\n",
);
}

pub mod jsdoc {
Expand Down
Loading