From 36a1d12f47f87e91979db54110109c3d5141d255 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Tue, 14 Mar 2017 18:36:35 -0700 Subject: [PATCH] Do not respect newlines for object destructuring pattern (#981) This was intended for object expressions. I tried to remove it for ObjectTypeAnnotation but it changes a ton of stuff as it's used all over the place in many different contexts. We should clean it up but in a later PR :) Fixes part of #975 --- src/printer.js | 11 ++++++----- tests/objects/__snapshots__/jsfmt.spec.js.snap | 17 +++++++++++++++++ tests/objects/expand.js | 9 +++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 tests/objects/expand.js diff --git a/src/printer.js b/src/printer.js index de01deb9..5f112409 100644 --- a/src/printer.js +++ b/src/printer.js @@ -700,11 +700,12 @@ function genericPrintNoParens(path, options, print) { const canHaveTrailingComma = !(lastElem && lastElem.type === "RestProperty"); - const shouldBreak = util.hasNewlineInRange( - options.originalText, - util.locStart(n), - util.locEnd(n) - ); + const shouldBreak = n.type !== "ObjectPattern" && + util.hasNewlineInRange( + options.originalText, + util.locStart(n), + util.locEnd(n) + ); if (props.length === 0) { return group( diff --git a/tests/objects/__snapshots__/jsfmt.spec.js.snap b/tests/objects/__snapshots__/jsfmt.spec.js.snap index 062c0608..e96e512a 100644 --- a/tests/objects/__snapshots__/jsfmt.spec.js.snap +++ b/tests/objects/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,22 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`expand.js 1`] = ` +"const Component1 = ({ props }) => ( + Test +); + +const Component2 = ({ + props +}) => ( + Test +); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const Component1 = ({ props }) => Test; + +const Component2 = ({ props }) => Test; +" +`; + exports[`expression.js 1`] = ` "() => ({}\`\`); ({})\`\`; diff --git a/tests/objects/expand.js b/tests/objects/expand.js new file mode 100644 index 00000000..ce2c37f9 --- /dev/null +++ b/tests/objects/expand.js @@ -0,0 +1,9 @@ +const Component1 = ({ props }) => ( + Test +); + +const Component2 = ({ + props +}) => ( + Test +);