Skip to content

Commit c0e851c

Browse files
committed
fix: :root Selector should not be scoped (vuejs#85)
1 parent 8b0da74 commit c0e851c

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/stylePlugins/scoped.ts

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ export default postcss.plugin('add-id', (options: any) => (root: Root) => {
4646
if (n.type !== 'pseudo' && n.type !== 'combinator') {
4747
node = n
4848
}
49+
50+
if (n.type === 'pseudo' && n.value === ':root') {
51+
n.value = n.spaces.before = n.spaces.after = ''
52+
}
4953
})
5054

5155
if (node) {

test/stylePluginScoped.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,19 @@ test('spaces before pseudo element', () => {
135135
expect(code).toContain('.abc[test],')
136136
expect(code).toContain('[test]::selection {')
137137
})
138+
139+
test('scoped :root selector', () => {
140+
const { code } = compileStyle({
141+
source: `
142+
:root { color: red; }
143+
:root p { color: red; }
144+
div:root { color: red; }
145+
`,
146+
filename: 'test.css',
147+
id: 'test'
148+
})
149+
150+
expect(code).toMatch(/^\[test\] { color: red;/m)
151+
expect(code).toMatch(/^ ?p\[test\] { color: red;/m)
152+
expect(code).toMatch(/^div\[test\] { color: red;/m)
153+
})

0 commit comments

Comments
 (0)