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
master
Christopher Chedeau 2017-03-14 18:36:35 -07:00 committed by James Long
parent 0fc8584827
commit 36a1d12f47
3 changed files with 32 additions and 5 deletions

View File

@ -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(

View File

@ -1,5 +1,22 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`expand.js 1`] = `
"const Component1 = ({ props }) => (
<Text>Test</Text>
);
const Component2 = ({
props
}) => (
<Text>Test</Text>
);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const Component1 = ({ props }) => <Text>Test</Text>;
const Component2 = ({ props }) => <Text>Test</Text>;
"
`;
exports[`expression.js 1`] = `
"() => ({}\`\`);
({})\`\`;

9
tests/objects/expand.js Normal file
View File

@ -0,0 +1,9 @@
const Component1 = ({ props }) => (
<Text>Test</Text>
);
const Component2 = ({
props
}) => (
<Text>Test</Text>
);