Skip to content

Commit e3237fd

Browse files
committed
fix: workaround bug with selector localization
1 parent 4ff8693 commit e3237fd

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/index.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {identifier, stringLiteral, program} from 'babel-types';
1010
import generate from 'babel-generator';
1111

1212
import * as postcss from 'postcss';
13-
import createSelectorParser from 'postcss-selector-parser';
13+
import createSelectorParser, {className} from 'postcss-selector-parser';
1414

1515
import HTMLTagList from './HTMLTagList';
1616
import * as ComponentRef from './ComponentRef';
@@ -34,11 +34,9 @@ const LOADER = require.resolve('../webpack');
3434

3535
const COMPONENT_RE = /^[a-zA-Z_0-9]+$/;
3636

37-
const selectorParser = createSelectorParser();
38-
3937
function 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) {
6664
function 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

Comments
 (0)