From b1592154e589d7a09171148858763bc6b4b01d18 Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Sun, 12 Oct 2025 16:13:21 +0000 Subject: [PATCH] fix(formatter): ignore the leading line break for the first argument of the call expression (#14483) --- .../oxc_formatter/src/write/call_arguments.rs | 6 ++++-- .../tests/fixtures/js/calls/blank-line.js | 9 +++++++++ .../fixtures/js/calls/blank-line.js.snap | 19 +++++++++++++++++++ tasks/coverage/snapshots/formatter_babel.snap | 4 +--- 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 crates/oxc_formatter/tests/fixtures/js/calls/blank-line.js create mode 100644 crates/oxc_formatter/tests/fixtures/js/calls/blank-line.js.snap diff --git a/crates/oxc_formatter/src/write/call_arguments.rs b/crates/oxc_formatter/src/write/call_arguments.rs index a7ff6a03a7a98..46ffb0b97e2ba 100644 --- a/crates/oxc_formatter/src/write/call_arguments.rs +++ b/crates/oxc_formatter/src/write/call_arguments.rs @@ -96,8 +96,10 @@ impl<'a> Format<'a> for AstNode<'a, ArenaVec<'a, Argument<'a>>> { ); } - let has_empty_line = - self.iter().any(|arg| f.source_text().get_lines_before(arg.span(), f.comments()) > 1); + let has_empty_line = self + .iter() + .skip(1) + .any(|arg| f.source_text().get_lines_before(arg.span(), f.comments()) > 1); if has_empty_line || (!matches!(self.parent.parent(), AstNodes::Decorator(_)) && is_function_composition_args(self)) diff --git a/crates/oxc_formatter/tests/fixtures/js/calls/blank-line.js b/crates/oxc_formatter/tests/fixtures/js/calls/blank-line.js new file mode 100644 index 0000000000000..628b0aff2bbba --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/js/calls/blank-line.js @@ -0,0 +1,9 @@ +gen + + ("a"); + +gen + + ( + + "b"); \ No newline at end of file diff --git a/crates/oxc_formatter/tests/fixtures/js/calls/blank-line.js.snap b/crates/oxc_formatter/tests/fixtures/js/calls/blank-line.js.snap new file mode 100644 index 0000000000000..8c2e4b58036fc --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/js/calls/blank-line.js.snap @@ -0,0 +1,19 @@ +--- +source: crates/oxc_formatter/tests/fixtures/mod.rs +--- +==================== Input ==================== +gen + + ("a"); + +gen + + ( + + "b"); +==================== Output ==================== +gen("a"); + +gen("b"); + +===================== End ===================== diff --git a/tasks/coverage/snapshots/formatter_babel.snap b/tasks/coverage/snapshots/formatter_babel.snap index 817cd6f11b51e..d848b5c7f66a6 100644 --- a/tasks/coverage/snapshots/formatter_babel.snap +++ b/tasks/coverage/snapshots/formatter_babel.snap @@ -2,10 +2,8 @@ commit: 41d96516 formatter_babel Summary: AST Parsed : 2423/2423 (100.00%) -Positive Passed: 2420/2423 (99.88%) +Positive Passed: 2421/2423 (99.92%) Mismatch: tasks/coverage/babel/packages/babel-parser/test/fixtures/comments/basic/try-statement/input.js -Mismatch: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2015/class/division/input.js - Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/top-level-await-unambiguous/module/input.js `await` is only allowed within async functions and at the top levels of modules