Propagate hard breaks within member expressions (fixes #1117) (#1193)

master
James Long 2017-04-12 12:26:27 -04:00 committed by Christopher Chedeau
parent 36bec87d17
commit 9a5b447c7f
3 changed files with 69 additions and 3 deletions

View File

@ -2827,7 +2827,13 @@ function printMemberChain(path, options, print) {
return group(expanded);
}
return conditionalGroup([oneLine, expanded]);
return concat([
// We only need to check `oneLine` because if `expanded` is chosen
// that means that the parent group has already been broken
// naturally
willBreak(oneLine) ? breakParent : "",
conditionalGroup([oneLine, expanded])
])
}
function isEmptyJSXElement(node) {

View File

@ -2,9 +2,51 @@
exports[`expand.js 1`] = `
"const veryVeryVeryVeryVeryVeryVeryLong = doc.expandedStates[doc.expandedStates.length - 1];
const small = doc.expandedStates[doc.expandedStates.length - 1];~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const small = doc.expandedStates[doc.expandedStates.length - 1];
const promises = [
promise.resolve().then(console.log).catch(err => {
console.log(err)
return null
}),
redis.fetch(),
other.fetch(),
];
const promises = [
promise.resolve().veryLongFunctionCall().veryLongFunctionCall().then(console.log).catch(err => {
console.log(err)
return null
}),
redis.fetch(),
other.fetch(),
];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const veryVeryVeryVeryVeryVeryVeryLong =
doc.expandedStates[doc.expandedStates.length - 1];
const small = doc.expandedStates[doc.expandedStates.length - 1];
const promises = [
promise.resolve().then(console.log).catch(err => {
console.log(err);
return null;
}),
redis.fetch(),
other.fetch()
];
const promises = [
promise
.resolve()
.veryLongFunctionCall()
.veryLongFunctionCall()
.then(console.log)
.catch(err => {
console.log(err);
return null;
}),
redis.fetch(),
other.fetch()
];
"
`;

View File

@ -1,2 +1,20 @@
const veryVeryVeryVeryVeryVeryVeryLong = doc.expandedStates[doc.expandedStates.length - 1];
const small = doc.expandedStates[doc.expandedStates.length - 1];
const small = doc.expandedStates[doc.expandedStates.length - 1];
const promises = [
promise.resolve().then(console.log).catch(err => {
console.log(err)
return null
}),
redis.fetch(),
other.fetch(),
];
const promises = [
promise.resolve().veryLongFunctionCall().veryLongFunctionCall().then(console.log).catch(err => {
console.log(err)
return null
}),
redis.fetch(),
other.fetch(),
];