Skip to content

Commit 3230c00

Browse files
committed
Add support for CSS4 descendant selector >>
1 parent 9f257f9 commit 3230c00

File tree

8 files changed

+59
-9
lines changed

8 files changed

+59
-9
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ node_modules/
22
npm-debug.log
33

44
playground/node_modules/
5-
playground/jspm_packages/github/
6-
playground/jspm_packages/npm/
5+
playground/jspm_packages/
76
todo.md

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,16 @@ We strive for the most complete transformation but we/no plugin can achieve true
1515

1616
`npm install postcss-css-variables --save-dev`
1717

18+
# [Code Playground](https://madlittlemods.github.io/postcss-css-variables/playground/)
19+
20+
[Try it](https://madlittlemods.github.io/postcss-css-variables/playground/) before you install it!
21+
22+
Add some PostCSS and it will show you the transformed/compiled CSS.
1823

1924
# Usage
2025

26+
You can try any of these examples on the [code playground](https://madlittlemods.github.io/postcss-css-variables/playground/).
27+
2128
```
2229
var postcss = require('postcss');
2330
var cssvariables = require('postcss-css-variables');

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ function generateScopeList(node, /*optional*/includeSelf) {
6666
return false;
6767
})
6868
.map(function(piece) {
69-
return piece.trim();
69+
// Trim whitespace which would be a normal descendant selector
70+
// and trim off the CSS4 descendant `>>` into a normal descendant selector
71+
return piece.trim().replace(/\s*?>>\s*?/, function(match) {
72+
return '';
73+
});
7074
});
7175

7276
// Add to the front of the array

playground/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ The code playground for `postcss-css-variables` is [available live here](https:/
1212

1313
## Instructions:
1414

15-
When developing run the following to build:
15+
Run once to set everything up:
1616

17-
`npm run build-dev`
17+
`npm run setup`
1818

19-
To bundle for production, run:
19+
When developing run the following to build:
2020

21-
`npm run build`
21+
- `npm run build-dev`: Build
22+
- `npm run build`: Build and bundle for production

playground/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
if(window.location.host === 'madlittlemods.github.io') {
1616
System.baseURL = '/postcss-css-variables/playground/';
1717
}
18-
</script>
19-
<script>
18+
2019
System.import('build/js/main');
2120
</script>
2221
</body>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.some-foo-group, .some-bar-group {
2+
--foo-width: 150px;
3+
--bar-width: 300px;
4+
}
5+
6+
.some-foo-group >> .box-foo {
7+
--foo-width: 180px;
8+
width: var(--foo-width);
9+
}
10+
11+
.some-bar-group >> .box-bar {
12+
width: var(--bar-width);
13+
}
14+
15+
.some-foo-group {
16+
width: var(--foo-width);
17+
18+
.box-foo {
19+
width: var(--foo-width);
20+
}
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.some-foo-group >> .box-foo {
2+
width: 180px;
3+
}
4+
5+
.some-bar-group >> .box-bar {
6+
width: 300px;
7+
}
8+
9+
.some-foo-group {
10+
width: 150px;
11+
12+
.box-foo {
13+
width: 180px;
14+
}
15+
}

test/test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ describe('postcss-css-variables', function() {
5353
return testPlugin('./test/fixtures/descendant-selector.css', './test/fixtures/descendant-selector.expected.css');
5454
});
5555

56+
it('should work with css4 descendant selector type "nesting"', function() {
57+
return testPlugin('./test/fixtures/css4-descendant-selector.css', './test/fixtures/css4-descendant-selector.expected.css');
58+
});
59+
5660
describe('with @rules', function() {
5761
it('should add rule declaration of property in @media', function() {
5862
return testPlugin('./test/fixtures/media-query.css', './test/fixtures/media-query.expected.css');

0 commit comments

Comments
 (0)