Skip to content

Commit 5b299ed

Browse files
committed
fix: remove space after selector when inserting scoped attribute
close vue-loader/#1370
1 parent ceccb62 commit 5b299ed

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

lib/stylePlugins/scoped.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default postcss.plugin('add-id', (options: any) => (root: Root) => {
2222
}
2323
node.selector = selectorParser((selectors: any) => {
2424
selectors.each((selector: any) => {
25-
let node = null
25+
let node: any = null
2626
selector.each((n: any) => {
2727
// ">>>" combinator
2828
if (n.type === 'combinator' && n.value === '>>>') {
@@ -43,12 +43,15 @@ export default postcss.plugin('add-id', (options: any) => (root: Root) => {
4343
node = n
4444
}
4545
})
46-
selector.insertAfter(
47-
node,
48-
selectorParser.attribute({
49-
attribute: id
50-
})
51-
)
46+
if (node) {
47+
node.spaces.after = ''
48+
selector.insertAfter(
49+
node,
50+
selectorParser.attribute({
51+
attribute: id
52+
})
53+
)
54+
}
5255
})
5356
}).processSync(node.selector)
5457
})

test/stylePluginScoped.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { compileStyle } from '../lib/compileStyle'
2+
3+
// vue-loader/#1370
4+
test('spaces after selector', () => {
5+
const { code } = compileStyle({
6+
source: `.foo , .bar { color: red; }`,
7+
filename: 'test.css',
8+
id: 'test'
9+
})
10+
11+
expect(code).toMatch(`.foo[test], .bar[test] { color: red;`)
12+
})

0 commit comments

Comments
 (0)