Skip to content

Commit 3ad3b05

Browse files
committed
Support custom properties as $variable #27
1 parent a0c82ed commit 3ad3b05

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function getAtruleSortName(node, order) {
100100
function getSortName(node, order) {
101101
switch (node.type) {
102102
case 'decl':
103-
return (/^\$[\w-]+/).test(node.prop) ? '$variable' : node.prop;
103+
return (/^(\$|--)[\w-]+/).test(node.prop) ? '$variable' : node.prop;
104104

105105
case 'atrule':
106106
return getAtruleSortName(node, order);

test/fixtures/variable.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
div { color: $tomato; $red: tomato; }
2+
3+
.block {
4+
background: #3d3d3d;
5+
--width: 100px;
6+
background-position: 50% 0;
7+
background-size: 2000px 100%;
8+
--offset: 539px;
9+
}

test/fixtures/variable.expected.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
div { $red: tomato; color: $tomato; }
2+
3+
.block {
4+
--width: 100px;
5+
--offset: 539px;
6+
background: #3d3d3d;
7+
background-position: 50% 0;
8+
background-size: 2000px 100%;
9+
}

test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ test('Should sort properties divided by nested rules', t => {
137137

138138
test('Should sort variables', t => {
139139
return run(t, 'variable', { 'sort-order': [
140-
['$variable', 'color']
140+
['$variable', '...']
141141
] });
142142
});
143143

0 commit comments

Comments
 (0)