Format SCSS maps like CSS rules (#3070)

* Format SCSS maps like CSS rules

* Ensure parent value starts with $ before formatting map with hardlines
master
Andy Mockler 2017-10-21 21:35:22 -04:00 committed by Lucas Azzola
parent b53a426e15
commit c6d97abf95
3 changed files with 16 additions and 1 deletions

View File

@ -339,13 +339,22 @@ function genericPrint(path, options, print) {
return group(indent(fill(res))); return group(indent(fill(res)));
} }
const declaration = path.getParentNode(2);
const isMap =
declaration &&
declaration.type === "css-decl" &&
declaration.prop.startsWith("$");
return group( return group(
concat([ concat([
n.open ? path.call(print, "open") : "", n.open ? path.call(print, "open") : "",
indent( indent(
concat([ concat([
softline, softline,
join(concat([",", line]), path.map(print, "groups")) join(
concat([",", isMap ? hardline : line]),
path.map(print, "groups")
)
]) ])
), ),
softline, softline,

View File

@ -18,6 +18,7 @@ div {
} }
} }
a { margin: 0 { left: 10px; } } a { margin: 0 { left: 10px; } }
$map: (color: #111111, text-shadow: 1px 1px 0 salmon);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@media #{$g-breakpoint-tiny} { @media #{$g-breakpoint-tiny} {
} }
@ -38,5 +39,9 @@ a {
left: 10px; left: 10px;
} }
} }
$map: (
color: #111111,
text-shadow: 1px 1px 0 salmon
);
`; `;

View File

@ -8,3 +8,4 @@ div {
} }
} }
a { margin: 0 { left: 10px; } } a { margin: 0 { left: 10px; } }
$map: (color: #111111, text-shadow: 1px 1px 0 salmon);