Skip to content

Commit

Permalink
fix scoped css for rules with pseudo classes
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Oct 30, 2015
1 parent e8611e5 commit b14b1e7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/style-rewriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ var addId = postcss.plugin('add-id', function () {
root.each(function (node) {
node.selector = selectorParser(function (selectors) {
selectors.each(function (selector) {
selector.append(selectorParser.attribute({
var node = null
selector.each(function (n) {
if (n.type !== 'pseudo') node = n
})
selector.insertAfter(node, selectorParser.attribute({
attribute: currentId
}))
})
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/scoped-css.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
.test {
color: yellow;
}
.test:after {
content: 'bye!';
}
h1 {
color: green;
}
Expand Down
1 change: 1 addition & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ describe('vue-loader', function () {
)
var style = window.document.querySelector('style').textContent
expect(style).to.contain('.test[' + id + '] {\n color: yellow;\n}')
expect(style).to.contain('.test[' + id + ']:after {\n content: \'bye!\';\n}')
expect(style).to.contain('h1[' + id + '] {\n color: green;\n}')
done()
})
Expand Down

0 comments on commit b14b1e7

Please sign in to comment.