Skip to content
This repository was archived by the owner on Aug 16, 2022. It is now read-only.

Commit f8fee48

Browse files
authored
chore: Scoped CSS transform bug fixes (#49)
* fix: avoid removing space after /deep/ when used directly vuejs/vue-loader@c303312 * fix: scoping of multiple animations vuejs/vue-loader@47c3317 * fix: animation value replacement vuejs/vue-loader@6d3c5b2 * fix: assignment to constant issue
1 parent 93b6847 commit f8fee48

File tree

2 files changed

+67
-8
lines changed

2 files changed

+67
-8
lines changed

src/style-compiler/plugins/scope-id.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = postcss.plugin('add-id', function (opts) {
2020
}
2121
node.selector = selectorParser(function (selectors) {
2222
selectors.each(function (selector) {
23-
var node = null
23+
let node = null
2424
selector.each(function (n) {
2525
// ">>>" combinator
2626
if (n.type === 'combinator' && n.value === '>>>') {
@@ -30,9 +30,9 @@ module.exports = postcss.plugin('add-id', function (opts) {
3030
}
3131
// /deep/ alias for >>>, since >>> doesn't work in SASS
3232
if (n.type === 'tag' && n.value === '/deep/') {
33-
var next = n.next()
34-
if (next.type === 'combinator' && next.value === ' ') {
35-
next.remove()
33+
const prev = n.prev()
34+
if (prev.type === 'combinator' && prev.value === ' ') {
35+
prev.remove()
3636
}
3737
n.remove()
3838
return false
@@ -64,10 +64,12 @@ module.exports = postcss.plugin('add-id', function (opts) {
6464
if (/-?animation$/.test(decl.prop)) {
6565
decl.value = decl.value.split(',')
6666
.map(v => {
67-
var vals = v.split(/\s+/)
68-
var name = vals[0]
69-
if (keyframes[name]) {
70-
return [keyframes[name]].concat(vals.slice(1)).join(' ')
67+
const vals = v.trim().split(/\s+/)
68+
const i = vals.findIndex(val => keyframes[val])
69+
if (i !== -1) {
70+
vals.splice(i, 1, keyframes[vals[i]])
71+
72+
return vals.join(' ')
7173
} else {
7274
return v
7375
}

test/fixtures/scoped-css.vue

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<style scoped>
2+
.test {
3+
color: red;
4+
}
5+
.test:after {
6+
content: 'bye!';
7+
}
8+
h1 {
9+
color: green;
10+
}
11+
.anim {
12+
animation: color 5s infinite, other 5s;
13+
}
14+
.anim-2 {
15+
animation-name: color;
16+
animation-duration: 5s;
17+
}
18+
.anim-3 {
19+
animation: 5s color infinite, 5s other;
20+
}
21+
.anim-multiple {
22+
animation: color 5s infinite, opacity 2s;
23+
}
24+
.anim-multiple-2 {
25+
animation-name: color, opacity;
26+
animation-duration: 5s, 2s;
27+
}
28+
29+
@keyframes color {
30+
from { color: red; }
31+
to { color: green; }
32+
}
33+
@-webkit-keyframes color {
34+
from { color: red; }
35+
to { color: green; }
36+
}
37+
@keyframes opacity {
38+
from { opacity: 0; }
39+
to { opacity: 1; }
40+
}
41+
@-webkit-keyframes opacity {
42+
from { opacity: 0; }
43+
to { opacity: 1; }
44+
}
45+
.foo p >>> .bar {
46+
color: red;
47+
}
48+
</style>
49+
50+
<template>
51+
<div>
52+
<div><h1>hi</h1></div>
53+
<p class="abc def">hi</p>
54+
<template v-if="!ok"><p class="test" id="test">Hello</p></template>
55+
<svg><template><p></p></template></svg>
56+
</div>
57+
</template>

0 commit comments

Comments
 (0)