diff --git a/changelog_unreleased/javascript/pr-7138.md b/changelog_unreleased/javascript/pr-7138.md new file mode 100644 index 000000000..7fe07e540 --- /dev/null +++ b/changelog_unreleased/javascript/pr-7138.md @@ -0,0 +1,31 @@ +#### Tweak function composition logic for decorators ([#7138](https://github.com/prettier/prettier/pull/7138) by [@brainkim](https://github.com/brainkim)) + +Because decorators modify the line following, splitting a decorator call’s +arguments onto multiple lines can obscure the relationship between the +decorator and its intended target, producing less-readable code. Therefore, the +function composition logic introduced in #6033 has been changed to exclude +decorator calls. + + +```jsx +// Input +export class Item { + @OneToOne(() => Thing, x => x.item) + thing!: Thing; +} + +// Output (Prettier stable) +export class Item { + @OneToOne( + () => Thing, + x => x.item, + ) + thing!: Thing; +} + +// Output (Prettier master) +export class Item { + @OneToOne(() => Thing, x => x.item) + thing!: Thing; +} +``` diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index b951fae1b..1bccce6bb 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -4069,7 +4069,10 @@ function printArgumentsList(path, options, print) { ); } - if (isFunctionCompositionArgs(args)) { + if ( + path.getParentNode().type !== "Decorator" && + isFunctionCompositionArgs(args) + ) { return allArgsBrokenOut(); } diff --git a/tests/decorators-ts/__snapshots__/jsfmt.spec.js.snap b/tests/decorators-ts/__snapshots__/jsfmt.spec.js.snap index 898ab7e2f..a34eb3977 100644 --- a/tests/decorators-ts/__snapshots__/jsfmt.spec.js.snap +++ b/tests/decorators-ts/__snapshots__/jsfmt.spec.js.snap @@ -321,10 +321,7 @@ export class Board { @Column() description: string; - @OneToMany( - type => Topic, - topic => topic.board - ) + @OneToMany(type => Topic, topic => topic.board) topics: Topic[]; }