From 7d35a6f5820752d24f69e749ed4b350695384da7 Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Mon, 2 Feb 2026 02:40:06 +0000 Subject: [PATCH] test(formatter): add regression test for member chain with rest params (#18835) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #16177 ## Summary - Adds a regression test for issue #16177 ## Details The issue was that member chains would incorrectly break when a function expression had rest parameters: **Before (incorrect):** ```ts jest .spyOn(Element.prototype, "getBoundingClientRect") .mockImplementation(function (this: Element, ...args) { ``` **After (correct - matches Prettier):** ```ts jest.spyOn(Element.prototype, "getBoundingClientRect").mockImplementation(function ( this: Element, ...args ) { ``` This was fixed by #17354, which ensures the `rest` parameter is not considered "simple", allowing the member chain to stay hugged while function parameters break vertically. 🤖 Generated with [Claude Code](https://claude.ai/code) --- .../fixtures/ts/member-chains/issue-16177.ts | 16 +++++ .../ts/member-chains/issue-16177.ts.snap | 62 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 crates/oxc_formatter/tests/fixtures/ts/member-chains/issue-16177.ts create mode 100644 crates/oxc_formatter/tests/fixtures/ts/member-chains/issue-16177.ts.snap diff --git a/crates/oxc_formatter/tests/fixtures/ts/member-chains/issue-16177.ts b/crates/oxc_formatter/tests/fixtures/ts/member-chains/issue-16177.ts new file mode 100644 index 0000000000000..bdd6295136b5d --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/ts/member-chains/issue-16177.ts @@ -0,0 +1,16 @@ +{ + { + jest.spyOn(Element.prototype, 'getBoundingClientRect').mockImplementation(function ( + this: Element, + ...args + ) { + return { + ...originalGetBoundingClientRect.bind(this)(...args), + top: canvasTop, + left: canvasLeft, + width: canvasWidth, + height: canvasHeight, + }; + }); + } +} diff --git a/crates/oxc_formatter/tests/fixtures/ts/member-chains/issue-16177.ts.snap b/crates/oxc_formatter/tests/fixtures/ts/member-chains/issue-16177.ts.snap new file mode 100644 index 0000000000000..d3893534e14d1 --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/ts/member-chains/issue-16177.ts.snap @@ -0,0 +1,62 @@ +--- +source: crates/oxc_formatter/tests/fixtures/mod.rs +--- +==================== Input ==================== +{ + { + jest.spyOn(Element.prototype, 'getBoundingClientRect').mockImplementation(function ( + this: Element, + ...args + ) { + return { + ...originalGetBoundingClientRect.bind(this)(...args), + top: canvasTop, + left: canvasLeft, + width: canvasWidth, + height: canvasHeight, + }; + }); + } +} + +==================== Output ==================== +------------------ +{ printWidth: 80 } +------------------ +{ + { + jest + .spyOn(Element.prototype, "getBoundingClientRect") + .mockImplementation(function (this: Element, ...args) { + return { + ...originalGetBoundingClientRect.bind(this)(...args), + top: canvasTop, + left: canvasLeft, + width: canvasWidth, + height: canvasHeight, + }; + }); + } +} + +------------------- +{ printWidth: 100 } +------------------- +{ + { + jest.spyOn(Element.prototype, "getBoundingClientRect").mockImplementation(function ( + this: Element, + ...args + ) { + return { + ...originalGetBoundingClientRect.bind(this)(...args), + top: canvasTop, + left: canvasLeft, + width: canvasWidth, + height: canvasHeight, + }; + }); + } +} + +===================== End =====================