Skip to content

Commit 6024c63

Browse files
author
Pedro Valentim
committed
Add support for custom selectors
1 parent 364e031 commit 6024c63

File tree

5 files changed

+49
-4
lines changed

5 files changed

+49
-4
lines changed

examples/example.css

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,22 @@ button
3232

3333
button
3434
border-radius: 0
35-
width: 100%
35+
width: 100%
36+
37+
@custom-selector --heading h1, h2
38+
@custom-selector :--link :hover, :active
39+
40+
@custom-selector --heading h1, h2
41+
@custom-selector :--any-link :link, :visited
42+
43+
a:hover
44+
color: red
45+
46+
a:--any-link
47+
color: blue
48+
49+
--heading
50+
color: #fff
51+
52+
article --heading
53+
color: #000

examples/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ var fs = require('fs')
99

1010
var str = read('examples/example.css', 'utf8');
1111
var css = compile(str);
12-
console.log(css);
12+
console.log(css);

lib/lexer.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ var pseudos = [
3434
'-o',
3535
'-ms',
3636
'-moz',
37-
'-webkit'
37+
'-webkit',
38+
'--'
3839
]
3940

4041
/**
@@ -196,7 +197,7 @@ module.exports = function(str) {
196197
var m = str.match(/^([^\n,]+, *\n|[^\n]+)+/);
197198
if (!m) return;
198199
str = str.slice(m[0].length);
199-
m = m[0].split(/\s*,\s*/);
200+
m = (m[0].indexOf('@custom-selector') > -1) ? [m[0]] : m[0].split(/\s*,\s*/);
200201
return ['rule', m];
201202
}
202203
}

test/cases/custom-selectors.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@custom-selector --heading h1, h2
2+
@custom-selector :--any-link :link, :visited
3+
4+
a:--any-link
5+
color: blue
6+
7+
--heading
8+
color: #fff
9+
10+
article --heading
11+
color: #000

test/cases/custom-selectors.out.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@custom-selector --heading h1, h2;
2+
3+
@custom-selector :--any-link :link, :visited;
4+
5+
a:--any-link {
6+
color: blue;
7+
}
8+
9+
--heading {
10+
color: #fff;
11+
}
12+
13+
article --heading {
14+
color: #000;
15+
}

0 commit comments

Comments
 (0)