File tree Expand file tree Collapse file tree 3 files changed +23
-7
lines changed Expand file tree Collapse file tree 3 files changed +23
-7
lines changed Original file line number Diff line number Diff line change @@ -4,15 +4,22 @@ var hash = require('hash-sum')
4
4
5
5
var currentClass
6
6
var rootRE = / : r o o t \b / g
7
+ var liftRE = / ^ ( h t m l | h e a d | b o d y ) \b /
7
8
var processRoot = postcss . plugin ( 'process-root' , function ( ) {
8
9
return function ( root ) {
10
+ var lifted = 0
11
+ function lift ( node ) {
12
+ node . moveBefore ( root . nodes [ lifted ++ ] )
13
+ }
9
14
root . each ( function ( node ) {
10
15
node . each ( function ( node ) {
11
- if ( rootRE . test ( node . selector ) ) {
16
+ var sel = node . selector
17
+ if ( liftRE . test ( sel ) ) {
18
+ lift ( node )
19
+ } else if ( rootRE . test ( sel ) ) {
12
20
// replace :root selector
13
- node . selector = node . selector . replace ( rootRE , currentClass )
14
- // move the node to the outer scope to avoid nesting
15
- node . moveBefore ( root . nodes [ 0 ] )
21
+ node . selector = sel . replace ( rootRE , currentClass )
22
+ lift ( node )
16
23
}
17
24
} )
18
25
} )
Original file line number Diff line number Diff line change 1
1
<style local>
2
+ body {
3
+ color : yellow ;
4
+ }
2
5
:root {
3
6
color : red ;
4
7
}
Original file line number Diff line number Diff line change @@ -100,9 +100,15 @@ describe('vue-loader', function () {
100
100
'<p class="abc def ' + cls . slice ( 1 ) + '">hi</p>'
101
101
)
102
102
var style = window . document . querySelector ( 'style' ) . textContent
103
- expect ( style ) . to . contain ( 'div' + cls + '.test {\n color: blue;\n}' )
104
- expect ( style ) . to . contain ( cls + ' {\n color: red;\n}' )
105
- expect ( style ) . to . contain ( cls + ' h1 {\n color: green;\n}' )
103
+ // lift selectors that start with body
104
+ expect ( style ) . to . contain ( 'body {\n color: yellow;\n}' )
105
+ expect ( style ) . not . to . contain ( cls + ' body' )
106
+ // lift and replace :root inside compound selectors
107
+ expect ( style ) . to . contain ( '\ndiv' + cls + '.test {\n color: blue;\n}' )
108
+ // lift :root
109
+ expect ( style ) . to . contain ( '\n' + cls + ' {\n color: red;\n}' )
110
+ // nest normal selectors
111
+ expect ( style ) . to . contain ( '\n' + cls + ' h1 {\n color: green;\n}' )
106
112
done ( )
107
113
} )
108
114
} )
You can’t perform that action at this time.
0 commit comments