Use breakParent inside of last arrow expansion (#559)

Fixes #549
Fixes #553
master
Christopher Chedeau 2017-02-03 13:15:21 -08:00 committed by James Long
parent b2a8f2de56
commit 4bd194e2ce
3 changed files with 106 additions and 22 deletions

View File

@ -17,6 +17,7 @@ var group = docBuilders.group;
var indent = docBuilders.indent;
var conditionalGroup = docBuilders.conditionalGroup;
var ifBreak = docBuilders.ifBreak;
var breakParent = docBuilders.breakParent;
var docUtils = require("./doc-utils");
var willBreak = docUtils.willBreak;
@ -1745,32 +1746,35 @@ function printArgumentsList(path, options, print) {
if (groupLastArg) {
const shouldBreak = printed.slice(0, -1).some(willBreak);
return conditionalGroup(
[
concat(["(", join(concat([", "]), printed), ")"]),
concat([
"(",
join(concat([",", line]), printed.slice(0, -1)),
printed.length > 1 ? ", " : "",
group(util.getLast(printed), { shouldBreak: true }),
")"
]),
group(
return concat([
printed.some(willBreak) ? breakParent : "",
conditionalGroup(
[
concat(["(", join(concat([", "]), printed), ")"]),
concat([
"(",
indent(
options.tabWidth,
concat([line, join(concat([",", line]), printed)])
),
options.trailingComma ? "," : "",
line,
join(concat([",", line]), printed.slice(0, -1)),
printed.length > 1 ? ", " : "",
group(util.getLast(printed), { shouldBreak: true }),
")"
]),
{ shouldBreak: true }
)
],
{ shouldBreak }
);
group(
concat([
"(",
indent(
options.tabWidth,
concat([line, join(concat([",", line]), printed)])
),
options.trailingComma ? "," : "",
line,
")"
]),
{ shouldBreak: true }
)
],
{ shouldBreak }
)
]);
}
return group(

View File

@ -35,6 +35,61 @@ export default function searchUsers(action$) {
"
`;
exports[`test break-parent.js 1`] = `
"({
processors: [
require(\"autoprefixer\", {
browsers: [\"> 1%\", \"last 2 versions\", \"ie >= 11\", \"Firefox ESR\"]
}),
require(\"postcss-url\")({
url: url =>
url.startsWith(\"/\") || /^[a-z]+:/.test(url) ? url : \`/static/\${url}\`
})
]
});
true
? test({
a: 1
})
: <div
a={123412342314}
b={123412341234}
c={123412341234}
d={123412341234}
e={123412341234}
f={123412341234}
g={123412341234}
/>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
({
processors: [
require(\"autoprefixer\", {
browsers: [\"> 1%\", \"last 2 versions\", \"ie >= 11\", \"Firefox ESR\"]
}),
require(\"postcss-url\")({
url: url =>
url.startsWith(\"/\") || /^[a-z]+:/.test(url) ? url : \`/static/\${url}\`
})
]
});
true
? test({
a: 1
})
: <div
a={123412342314}
b={123412341234}
c={123412341234}
d={123412341234}
e={123412341234}
f={123412341234}
g={123412341234}
/>;
"
`;
exports[`test jsx.js 1`] = `
"const els = items.map(item => (
<div className=\"whatever\">

View File

@ -0,0 +1,25 @@
({
processors: [
require("autoprefixer", {
browsers: ["> 1%", "last 2 versions", "ie >= 11", "Firefox ESR"]
}),
require("postcss-url")({
url: url =>
url.startsWith("/") || /^[a-z]+:/.test(url) ? url : `/static/${url}`
})
]
});
true
? test({
a: 1
})
: <div
a={123412342314}
b={123412341234}
c={123412341234}
d={123412341234}
e={123412341234}
f={123412341234}
g={123412341234}
/>;