Skip to content

Commit 8b2c646

Browse files
haoqunjiangyyx990803
authored andcommitted
feat: implement ::v-deep as a shadow piercing combinator (#54)
1 parent cf596f8 commit 8b2c646

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/stylePlugins/scoped.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default postcss.plugin('add-id', (options: any) => (root: Root) => {
2424
selectors.each((selector: any) => {
2525
let node: any = null
2626

27+
// find the last child node to insert attribute selector
2728
selector.each((n: any) => {
2829
// ">>>" combinator
2930
// and /deep/ alias for >>>, since >>> doesn't work in SASS
@@ -35,6 +36,13 @@ export default postcss.plugin('add-id', (options: any) => (root: Root) => {
3536
n.spaces.before = n.spaces.after = ''
3637
return false
3738
}
39+
40+
// in newer versions of sass, /deep/ support is also dropped, so add a ::v-deep alias
41+
if (n.type === 'pseudo' && n.value === '::v-deep') {
42+
n.value = n.spaces.before = n.spaces.after = ''
43+
return false
44+
}
45+
3846
if (n.type !== 'pseudo' && n.type !== 'combinator') {
3947
node = n
4048
}

test/stylePluginScoped.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ h1 {
7676
.foo div /deep/ .bar {
7777
color: red;
7878
}
79+
80+
.foo span ::v-deep .bar {
81+
color: red;
82+
}
7983
`
8084
})
8185

@@ -107,6 +111,8 @@ h1 {
107111
expect(style).toContain(`.foo p[v-scope-xxx] .bar {\n color: red;\n}`)
108112
// /deep/ alias for >>>
109113
expect(style).toContain(`.foo div[v-scope-xxx] .bar {\n color: red;\n}`)
114+
// ::-v-deep alias for >>>
115+
expect(style).toContain(`.foo span[v-scope-xxx] .bar {\n color: red;\n}`)
110116
})
111117

112118
test('pseudo element', () => {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy