Skip to content

Commit 416b263

Browse files
committed
fix scoped CSS rewrite for <template> due to parse5 upgrade (fix #141)
1 parent b36eb07 commit 416b263

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

lib/template-rewriter.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ module.exports = function (html) {
2020
function walk (tree, fn) {
2121
if (tree.childNodes) {
2222
tree.childNodes.forEach(function (node) {
23-
fn(node)
24-
walk(node, fn)
23+
if (node.tagName === 'template') {
24+
walk(node.content, fn)
25+
} else {
26+
fn(node)
27+
walk(node, fn)
28+
}
2529
})
2630
}
2731
}

test/fixtures/scoped-css.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ h1 {
1313
<template>
1414
<div><h1>hi</h1></div>
1515
<p class="abc def">hi</p>
16+
<template v-if="ok"><p class="test">yo</p></template>
1617
</template>

test/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ describe('vue-loader', function () {
9797
var id = '_v-' + hash(require.resolve('./fixtures/scoped-css.vue'))
9898
expect(module.template).to.contain(
9999
'<div ' + id + '=""><h1 ' + id + '="">hi</h1></div>\n' +
100-
'<p class="abc def" ' + id + '="">hi</p>'
100+
'<p class="abc def" ' + id + '="">hi</p>\n' +
101+
'<template v-if="ok"><p class="test" ' + id + '="">yo</p></template>'
101102
)
102103
var style = window.document.querySelector('style').textContent
103104
expect(style).to.contain('.test[' + id + '] {\n color: yellow;\n}')

0 commit comments

Comments
 (0)