Skip to content

Commit

Permalink
fix: remove space after selector when inserting scoped attribute
Browse files Browse the repository at this point in the history
close vue-loader/#1370
  • Loading branch information
yyx990803 committed Aug 7, 2018
1 parent ceccb62 commit 5b299ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/stylePlugins/scoped.ts
Expand Up @@ -22,7 +22,7 @@ export default postcss.plugin('add-id', (options: any) => (root: Root) => {
}
node.selector = selectorParser((selectors: any) => {
selectors.each((selector: any) => {
let node = null
let node: any = null
selector.each((n: any) => {
// ">>>" combinator
if (n.type === 'combinator' && n.value === '>>>') {
Expand All @@ -43,12 +43,15 @@ export default postcss.plugin('add-id', (options: any) => (root: Root) => {
node = n
}
})
selector.insertAfter(
node,
selectorParser.attribute({
attribute: id
})
)
if (node) {
node.spaces.after = ''
selector.insertAfter(
node,
selectorParser.attribute({
attribute: id
})
)
}
})
}).processSync(node.selector)
})
Expand Down
12 changes: 12 additions & 0 deletions test/stylePluginScoped.spec.ts
@@ -0,0 +1,12 @@
import { compileStyle } from '../lib/compileStyle'

// vue-loader/#1370
test('spaces after selector', () => {
const { code } = compileStyle({
source: `.foo , .bar { color: red; }`,
filename: 'test.css',
id: 'test'
})

expect(code).toMatch(`.foo[test], .bar[test] { color: red;`)
})

0 comments on commit 5b299ed

Please sign in to comment.