Break object destructuring with nested destructuring (#4267)

This commit is contained in:
Lucas Duailibe authored and GitHub committed 2018-04-06 11:57:37 -03:00
1 parent 7029346887
commit 18aaee594f
3 files changed
+77 -1

No files matched your search

+12 -1
View File
@@ -1039,15 +1039,26 @@ function printPathNoParens(path, options, print, args) {
case "TSInterfaceBody":
case "TSTypeLiteral": {
const isTypeAnnotation = n.type === "ObjectTypeAnnotation";
const parent = path.getParentNode(0);
const shouldBreak =
n.type === "TSInterfaceBody" ||
(n.type === "ObjectPattern" &&
parent.type !== "FunctionDeclaration" &&
parent.type !== "FunctionExpression" &&
parent.type !== "ArrowFunctionExpression" &&
parent.type !== "AssignmentPattern" &&
n.properties.some(
property =>
property.value &&
(property.value.type === "ObjectPattern" ||
property.value.type === "ArrayPattern")
)) ||
(n.type !== "ObjectPattern" &&
privateUtil.hasNewlineInRange(
options.originalText,
options.locStart(n),
options.locEnd(n)
));
const parent = path.getParentNode(0);
const isFlowInterfaceLikeBody =
isTypeAnnotation &&
parent &&
@@ -4,9 +4,56 @@ exports[`destructuring.js 1`] = `
const [one, two = null, three = null] = arr;
a = ([s=1,]) => 1
const { children, ...props } = this.props
const { user: { firstName, lastName } } = this.props;
const {
name: { first, last },
organisation: { address: { street: orgStreetAddress, postcode: orgPostcode } }
} = user;
function f({ data: { name } }) {}
const UserComponent = function({
name: { first, last },
organisation: { address: { street: orgStreetAddress, postcode: orgPostcode } },
}) {
return
};
const { a, b, c, d: { e } } = someObject;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const [one, two = null, three = null] = arr;
a = ([s = 1]) => 1;
const { children, ...props } = this.props;
const {
user: { firstName, lastName }
} = this.props;
const {
name: { first, last },
organisation: {
address: { street: orgStreetAddress, postcode: orgPostcode }
}
} = user;
function f({ data: { name } }) {}
const UserComponent = function({
name: { first, last },
organisation: {
address: { street: orgStreetAddress, postcode: orgPostcode }
}
}) {
return;
};
const {
a,
b,
c,
d: { e }
} = someObject;
`;
+18
View File
@@ -1,3 +1,21 @@
const [one, two = null, three = null] = arr;
a = ([s=1,]) => 1
const { children, ...props } = this.props
const { user: { firstName, lastName } } = this.props;
const {
name: { first, last },
organisation: { address: { street: orgStreetAddress, postcode: orgPostcode } }
} = user;
function f({ data: { name } }) {}
const UserComponent = function({
name: { first, last },
organisation: { address: { street: orgStreetAddress, postcode: orgPostcode } },
}) {
return
};
const { a, b, c, d: { e } } = someObject;