Skip to content

Commit

Permalink
revert function composition logic for decorators (prettier#7138)
Browse files Browse the repository at this point in the history
  • Loading branch information
brainkim authored and thorn0 committed Dec 14, 2019
1 parent 025fcde commit 64d4b2f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
31 changes: 31 additions & 0 deletions changelog_unreleased/javascript/pr-7138.md
Original file line number Diff line number Diff line change
@@ -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.

<!-- prettier-ignore -->
```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;
}
```
5 changes: 4 additions & 1 deletion src/language-js/printer-estree.js
Original file line number Diff line number Diff line change
Expand Up @@ -4069,7 +4069,10 @@ function printArgumentsList(path, options, print) {
);
}

if (isFunctionCompositionArgs(args)) {
if (
path.getParentNode().type !== "Decorator" &&
isFunctionCompositionArgs(args)
) {
return allArgsBrokenOut();
}

Expand Down
5 changes: 1 addition & 4 deletions tests/decorators-ts/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,7 @@ export class Board {
@Column()
description: string;
@OneToMany(
type => Topic,
topic => topic.board
)
@OneToMany(type => Topic, topic => topic.board)
topics: Topic[];
}
Expand Down

0 comments on commit 64d4b2f

Please sign in to comment.