Skip to content

Commit

Permalink
Added condition for '+' case. (prettier#13115)
Browse files Browse the repository at this point in the history
Co-authored-by: Sosuke Suzuki <aosukeke@gmail.com>
  • Loading branch information
t-mangoe and sosukesuzuki committed Aug 7, 2022
1 parent 67efa96 commit 00ec91b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/language-js/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -883,9 +883,26 @@ function isSimpleCallArgument(node, depth) {
);
}

const targetUnaryExpressionOperators = {
"!": true,
"-": true,
"+": true,
"~": true,
};
if (
node.type === "UnaryExpression" &&
(node.operator === "!" || node.operator === "-")
targetUnaryExpressionOperators[node.operator]
) {
return isSimpleCallArgument(node.argument, depth);
}

const targetUpdateExpressionOperators = {
"++": true,
"--": true,
};
if (
node.type === "UpdateExpression" &&
targetUpdateExpressionOperators[node.operator]
) {
return isSimpleCallArgument(node.argument, depth);
}
Expand Down
8 changes: 8 additions & 0 deletions tests/format/js/method-chain/13018.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
foo(_a).bar().leet();
foo(-a).bar().leet();
foo(+a).bar().leet();
foo(~a).bar().leet();
foo(++a).bar().leet();
foo(--a).bar().leet();
foo(a++).bar().leet();
foo(a--).bar().leet();
28 changes: 28 additions & 0 deletions tests/format/js/method-chain/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`13018.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
foo(_a).bar().leet();
foo(-a).bar().leet();
foo(+a).bar().leet();
foo(~a).bar().leet();
foo(++a).bar().leet();
foo(--a).bar().leet();
foo(a++).bar().leet();
foo(a--).bar().leet();
=====================================output=====================================
foo(_a).bar().leet();
foo(-a).bar().leet();
foo(+a).bar().leet();
foo(~a).bar().leet();
foo(++a).bar().leet();
foo(--a).bar().leet();
foo(a++).bar().leet();
foo(a--).bar().leet();
================================================================================
`;

exports[`bracket_0.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
Expand Down

0 comments on commit 00ec91b

Please sign in to comment.