@@ -10,7 +10,7 @@ import {identifier, stringLiteral, program} from 'babel-types';
1010import generate from 'babel-generator' ;
1111
1212import * as postcss from 'postcss' ;
13- import createSelectorParser from 'postcss-selector-parser' ;
13+ import createSelectorParser , { className } from 'postcss-selector-parser' ;
1414
1515import HTMLTagList from './HTMLTagList' ;
1616import * as ComponentRef from './ComponentRef' ;
@@ -34,11 +34,9 @@ const LOADER = require.resolve('../webpack');
3434
3535const COMPONENT_RE = / ^ [ a - z A - Z _ 0 - 9 ] + $ / ;
3636
37- const selectorParser = createSelectorParser ( ) ;
38-
3937function findComponentNames ( node : CSSNode ) : Array < string > {
4038 let componentNames = [ ] ;
41- selectorParser . process ( node . selector ) . res . eachTag ( selector => {
39+ createSelectorParser ( ) . process ( node . selector ) . res . eachTag ( selector => {
4240 if ( COMPONENT_RE . exec ( selector . value ) ) {
4341 componentNames . push ( selector . value ) ;
4442 }
@@ -66,12 +64,17 @@ function removeBaseDeclaration(node) {
6664function localizeComponentRule ( node ) {
6765 let componentNames = findComponentNames ( node ) ;
6866 if ( componentNames . length > 0 ) {
69- let selector = selectorParser . process ( node . selector ) . res ;
67+ let toProcess = [ ] ;
68+ let selector = createSelectorParser ( ) . process ( node . selector ) . res ;
7069 selector . eachTag ( selector => {
7170 if ( componentNames . indexOf ( selector . value ) > - 1 ) {
72- selector . replaceWith ( createSelectorParser . className ( { value : selector . value } ) ) ;
71+ toProcess . push ( selector ) ;
7372 }
7473 } ) ;
74+ toProcess . forEach ( selector => {
75+ let nextSelector = className ( { value : selector . value } ) ;
76+ selector . replaceWith ( nextSelector ) ;
77+ } ) ;
7578 let nextNode = node . clone ( ) ;
7679 nextNode . selector = selector . toString ( ) ;
7780 node . replaceWith ( nextNode ) ;
0 commit comments