@@ -10,7 +10,7 @@ import {identifier, stringLiteral, program} from 'babel-types';
10
10
import generate from 'babel-generator' ;
11
11
12
12
import * as postcss from 'postcss' ;
13
- import createSelectorParser from 'postcss-selector-parser' ;
13
+ import createSelectorParser , { className } from 'postcss-selector-parser' ;
14
14
15
15
import HTMLTagList from './HTMLTagList' ;
16
16
import * as ComponentRef from './ComponentRef' ;
@@ -34,11 +34,9 @@ const LOADER = require.resolve('../webpack');
34
34
35
35
const COMPONENT_RE = / ^ [ a - z A - Z _ 0 - 9 ] + $ / ;
36
36
37
- const selectorParser = createSelectorParser ( ) ;
38
-
39
37
function findComponentNames ( node : CSSNode ) : Array < string > {
40
38
let componentNames = [ ] ;
41
- selectorParser . process ( node . selector ) . res . eachTag ( selector => {
39
+ createSelectorParser ( ) . process ( node . selector ) . res . eachTag ( selector => {
42
40
if ( COMPONENT_RE . exec ( selector . value ) ) {
43
41
componentNames . push ( selector . value ) ;
44
42
}
@@ -66,12 +64,17 @@ function removeBaseDeclaration(node) {
66
64
function localizeComponentRule ( node ) {
67
65
let componentNames = findComponentNames ( node ) ;
68
66
if ( componentNames . length > 0 ) {
69
- let selector = selectorParser . process ( node . selector ) . res ;
67
+ let toProcess = [ ] ;
68
+ let selector = createSelectorParser ( ) . process ( node . selector ) . res ;
70
69
selector . eachTag ( selector => {
71
70
if ( componentNames . indexOf ( selector . value ) > - 1 ) {
72
- selector . replaceWith ( createSelectorParser . className ( { value : selector . value } ) ) ;
71
+ toProcess . push ( selector ) ;
73
72
}
74
73
} ) ;
74
+ toProcess . forEach ( selector => {
75
+ let nextSelector = className ( { value : selector . value } ) ;
76
+ selector . replaceWith ( nextSelector ) ;
77
+ } ) ;
75
78
let nextNode = node . clone ( ) ;
76
79
nextNode . selector = selector . toString ( ) ;
77
80
node . replaceWith ( nextNode ) ;
0 commit comments