Skip to content

Commit 1a3b5bb

Browse files
committed
feat(scoped-css): support leading >>> or /deep/ in selectors
1 parent 80edaf4 commit 1a3b5bb

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/stylePlugins/scoped.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ export default postcss.plugin('add-id', (options: any) => (root: Root) => {
2323
node.selector = selectorParser((selectors: any) => {
2424
selectors.each((selector: any) => {
2525
let node: any = null
26+
let hasDeep: boolean = false
2627
selector.each((n: any) => {
2728
// ">>>" combinator
2829
if (n.type === 'combinator' && n.value === '>>>') {
2930
n.value = ' '
3031
n.spaces.before = n.spaces.after = ''
32+
hasDeep = true
3133
return false
3234
}
3335
// /deep/ alias for >>>, since >>> doesn't work in SASS
@@ -37,6 +39,7 @@ export default postcss.plugin('add-id', (options: any) => (root: Root) => {
3739
prev.remove()
3840
}
3941
n.remove()
42+
hasDeep = true
4043
return false
4144
}
4245
if (n.type !== 'pseudo' && n.type !== 'combinator') {
@@ -51,6 +54,12 @@ export default postcss.plugin('add-id', (options: any) => (root: Root) => {
5154
attribute: id
5255
})
5356
)
57+
} else if (hasDeep) {
58+
selector.prepend(
59+
selectorParser.attribute({
60+
attribute: id
61+
})
62+
)
5463
}
5564
})
5665
}).processSync(node.selector)

test/stylePluginScoped.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,13 @@ test('spaces after selector', () => {
1010

1111
expect(code).toMatch(`.foo[test], .bar[test] { color: red;`)
1212
})
13+
14+
test('leading deep selector', () => {
15+
const { code } = compileStyle({
16+
source: `>>> .foo { color: red; }`,
17+
filename: 'test.css',
18+
id: 'test'
19+
})
20+
21+
expect(code).toMatch(`[test] .foo { color: red;`)
22+
})

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