Fix less &:extends when parsed with scss (#2034)

This is the only breakage that people ever reported with CSS so I'm happy adding one edge case like this.

Fixes #1967
This commit is contained in:
Christopher Chedeau authored and GitHub committed 2017-06-07 12:40:36 -07:00
1 parent cabae6d877
commit e16478ef80
4 files changed
+52 -1

No files matched your search

+12 -1
View File
@@ -60,10 +60,21 @@ function genericPrint(path, options, print) {
]);
}
case "css-decl": {
// When the following less construct &:extend(.foo); is parsed with scss,
// it will put a space after `:` and break it. Ideally we should parse
// less files with less, but we can hardcode this to work with scss as
// well.
const isValueExtend =
n.value.type === "value-root" &&
n.value.group.type === "value-value" &&
n.value.group.group.type === "value-func" &&
n.value.group.group.value === "extend";
return concat([
n.raws.before.replace(/[\s;]/g, ""),
n.prop,
": ",
":",
isValueExtend ? "" : " ",
path.call(print, "value"),
n.important ? " !important" : "",
n.nodes
@@ -0,0 +1,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`extend.css 1`] = `
.foobar {
&:extend(.foo);
}
.thing {
&:hover {
background-color: blue;
.thing-child {
}
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.foobar {
&:extend(.foo);
}
.thing {
&:hover {
background-color: blue;
.thing-child {
}
}
}
`;
+11
View File
@@ -0,0 +1,11 @@
.foobar {
&:extend(.foo);
}
.thing {
&:hover {
background-color: blue;
.thing-child {
}
}
}
+1
View File
@@ -0,0 +1 @@
run_spec(__dirname, { parser: "postcss" });