Browse Source

prevent removing declarations if a pseudo is found in the selector

Gildas 7 năm trước cách đây
mục cha
commit
4af08ce90e
1 tập tin đã thay đổi với 11 bổ sung5 xóa
  1. 11 5
      lib/single-file/modules/css-rules-minifier.js

+ 11 - 5
lib/single-file/modules/css-rules-minifier.js

@@ -101,17 +101,23 @@ this.cssRulesMinifier = this.cssRulesMinifier || (() => {
 	function processRuleInfo(ruleData, ruleInfo, pseudoSelectors) {
 		const removedDeclarations = [];
 		const removedSelectors = [];
-		for (let declaration = ruleData.block.children.tail; declaration; declaration = declaration.prev) {
-			if (!ruleInfo.declarations.has(declaration.data)) {
-				removedDeclarations.push(declaration);
-			}
-		}
+		let pseudoSelectorFound;
 		for (let selector = ruleData.prelude.children.head; selector; selector = selector.next) {
 			const selectorText = cssTree.generate(selector.data);
+			if (pseudoSelectors && pseudoSelectors.has(selectorText)) {
+				pseudoSelectorFound = true;
+			}
 			if (!ruleInfo.matchedSelectors.has(selectorText) && (!pseudoSelectors || !pseudoSelectors.has(selectorText))) {
 				removedSelectors.push(selector);
 			}
 		}
+		if (!pseudoSelectorFound) {
+			for (let declaration = ruleData.block.children.tail; declaration; declaration = declaration.prev) {
+				if (!ruleInfo.declarations.has(declaration.data)) {
+					removedDeclarations.push(declaration);
+				}
+			}
+		}
 		removedDeclarations.forEach(declaration => ruleData.block.children.remove(declaration));
 		removedSelectors.forEach(selector => ruleData.prelude.children.remove(selector));
 	}