Procházet zdrojové kódy

better parsing of the selector

Gildas před 7 roky
rodič
revize
f3d70fc79f
1 změnil soubory, kde provedl 15 přidání a 12 odebrání
  1. 15 12
      lib/single-file/single-file-core.js

+ 15 - 12
lib/single-file/single-file-core.js

@@ -374,18 +374,21 @@ const SingleFileCore = (() => {
 						} else if (rule.selectorText) {
 							let selector = rule.selectorText;
 							if (selector.match(REGEXP)) {
-								let simpleSelectors = selector.split(",");
-								simpleSelectors = simpleSelectors.map(selector => {
-									while (selector.match(REGEXP)) {
-										selector = selector.replace(REGEXP, "").trim();
-									}
-									selector = selector.replace(/:[^(]+\(\)/gi, "");
-									if (selector == "") {
-										selector = "*";
-									}
-									return selector;
-								});
-								selector = simpleSelectors.join(",");
+								let selectors = selector.split(/\s*,\s*/g);
+								selector = selectors.map(selector => {
+									const simpleSelectors = selector.split(/\s*[ >~+]\s*/g);
+									const separators = selector.match(/\s*[ >~+]\s*/g);
+									return simpleSelectors.map((selector, selectorIndex) => {
+										while (selector.match(REGEXP)) {
+											selector = selector.replace(REGEXP, "").trim();
+										}
+										selector = selector.replace(/:?:[^(]+\(\)/g, "");
+										if (selector == "") {
+											selector = "*";
+										}
+										return selector + (separators && separators[selectorIndex] ? separators[selectorIndex] : "");
+									}).join("");
+								}).join(",");
 							}
 							if (selector) {
 								try {