Inline url('string') (#1751)

We don't want them to break even if they go beyond 80 columns
master
Christopher Chedeau 2017-05-26 13:42:32 -07:00 committed by GitHub
parent 48d9267dd5
commit 2f6d12aaa8
5 changed files with 62 additions and 2 deletions

View File

@ -220,6 +220,34 @@ function parseValueNodes(nodes) {
return rootParenGroup;
}
function flattenGroups(node) {
if (
node.type === "paren_group" &&
!node.open &&
!node.close &&
node.groups.length === 1
) {
return flattenGroups(node.groups[0]);
}
if (
node.type === "comma_group" &&
node.groups.length === 1
) {
return flattenGroups(node.groups[0]);
}
if (node.type === "paren_group" || node.type === "comma_group") {
return Object.assign(
{},
node,
{groups: node.groups.map(flattenGroups)}
);
}
return node;
}
function addTypePrefix(node, prefix) {
if (node && typeof node === "object") {
delete node.parent;
@ -254,7 +282,7 @@ function parseNestedValue(node) {
for (const key in node) {
parseNestedValue(node[key]);
if (key === "nodes") {
node.group = parseValueNodes(node[key]);
node.group = flattenGroups(parseValueNodes(node[key]));;
delete node[key];
}
}

View File

@ -2635,7 +2635,23 @@ function genericPrintNoParens(path, options, print, args) {
}
case "value-paren_group": {
if (!n.open) {
return join(concat([",", line]), path.map(print, "groups"));
return group(join(concat([",", line]), path.map(print, "groups")));
}
const parent = path.getParentNode();
if (
parent &&
parent.type === "value-func" &&
parent.value === "url" &&
n.groups.length === 1 &&
n.groups[0].type === "value-string"
) {
return concat([
n.open ? path.call(print, "open") : "",
join(", ", path.map(print, "groups")),
n.close ? path.call(print, "close") : ""
])
}
return group(

View File

@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`inline_url.js 1`] = `
.breadItem {
background-image: url('/images/product/simple_product_manager/breadcrumb/chevron_right.png');
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.breadItem {
background-image: url('/images/product/simple_product_manager/breadcrumb/chevron_right.png');
}
`;

View File

@ -0,0 +1,3 @@
.breadItem {
background-image: url('/images/product/simple_product_manager/breadcrumb/chevron_right.png');
}

View File

@ -0,0 +1 @@
run_spec(__dirname, { parser: "postcss" });