From d3fa519492f4e86f88f4fa7309f6c5bdc4c06f6a Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Tue, 31 Jan 2017 08:45:47 -0800 Subject: [PATCH] Break nested calls (#517) If there's a break inside of a call, we want to force it in the group, otherwise it may get the indentation wrong. See the real-world use case in #513 Fixes #513 --- src/printer.js | 3 ++- tests/break-calls/__snapshots__/jsfmt.spec.js.snap | 14 ++++++++++++++ tests/break-calls/break.js | 3 +++ tests/break-calls/jsfmt.spec.js | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/break-calls/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/break-calls/break.js create mode 100644 tests/break-calls/jsfmt.spec.js diff --git a/src/printer.js b/src/printer.js index 465b4729..934a0f72 100644 --- a/src/printer.js +++ b/src/printer.js @@ -1768,7 +1768,8 @@ function printArgumentsList(path, options, print) { ifBreak(options.trailingComma ? "," : ""), softline, ")" - ]) + ]), + { shouldBreak: printed.some(willBreak) } ); } diff --git a/tests/break-calls/__snapshots__/jsfmt.spec.js.snap b/tests/break-calls/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 00000000..f60f0bc1 --- /dev/null +++ b/tests/break-calls/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,14 @@ +exports[`test break.js 1`] = ` +"h(f(g(() => { + a +}))) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +h( + f( + g(() => { + a; + }) + ) +); +" +`; diff --git a/tests/break-calls/break.js b/tests/break-calls/break.js new file mode 100644 index 00000000..f7141fbc --- /dev/null +++ b/tests/break-calls/break.js @@ -0,0 +1,3 @@ +h(f(g(() => { + a +}))) diff --git a/tests/break-calls/jsfmt.spec.js b/tests/break-calls/jsfmt.spec.js new file mode 100644 index 00000000..989047bc --- /dev/null +++ b/tests/break-calls/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname);