Fix spacing issue in postcss simple vars (#4408)

This commit is contained in:
Aakansha Doshi authored and Simon Lydell committed 2018-05-06 13:51:28 +02:00
1 parent 7e81a613b5
commit 299cc97ceb
4 files changed
+47 -1

No files matched your search

+4
View File
@@ -44,6 +44,7 @@ const hasComposesValueNode = utils.hasComposesValueNode;
const hasLessExtendValueNode = utils.hasLessExtendValueNode;
const hasParensAroundValueNode = utils.hasParensAroundValueNode;
const maybeToLowerCase = utils.maybeToLowerCase;
const isPostcssSimpleVar = utils.isPostcssSimpleVar;
function genericPrint(path, options, print) {
const node = path.getValue();
@@ -409,6 +410,9 @@ function genericPrint(path, options, print) {
const iNextNode = node.groups[i + 1];
const iNextNextNode = node.groups[i + 2];
if (isPostcssSimpleVar(iNode, iNextNode)) {
continue;
}
// Ignore after latest node (i.e. before semicolon)
if (!iNextNode) {
continue;
+11 -1
View File
@@ -211,6 +211,15 @@ function hasParensAroundValueNode(node) {
);
}
function isPostcssSimpleVar(currentNode, nextNode) {
return (
currentNode.value === "$$" &&
currentNode.type === "value-func" &&
nextNode &&
nextNode.type === "value-word" &&
!nextNode.raws.before
);
}
module.exports = {
getAncestorCounter,
getAncestorNode,
@@ -237,5 +246,6 @@ module.exports = {
maybeToLowerCase,
hasLessExtendValueNode,
hasComposesValueNode,
hasParensAroundValueNode
hasParensAroundValueNode,
isPostcssSimpleVar
};
@@ -552,3 +552,26 @@ a {
}
`;
exports[`postcss-simple-vars.css 1`] = `
background-color: $$(style)Color;
background-color: $$(style)Color Color122;
color: @@color;
font: 100% $font-stack;
background-color: darken(@link-color, 10%);
border: 1px solid var(--border-color);
color: $(style)color;
color: @@(style) color123;
color: @@(style)color123;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
background-color: $$(style)Color;
background-color: $$(style)Color Color122;
color: @@color;
font: 100% $font-stack;
background-color: darken(@link-color, 10%);
border: 1px solid var(--border-color);
color: $(style) color;
color: @@(style) color123;
color: @@(style) color123;
`;
@@ -0,0 +1,9 @@
background-color: $$(style)Color;
background-color: $$(style)Color Color122;
color: @@color;
font: 100% $font-stack;
background-color: darken(@link-color, 10%);
border: 1px solid var(--border-color);
color: $(style)color;
color: @@(style) color123;
color: @@(style)color123;