Parcourir la source

minor refactoring

Gildas il y a 7 ans
Parent
commit
28e4d348d4
1 fichiers modifiés avec 7 ajouts et 7 suppressions
  1. 7 7
      lib/single-file/css-rules-matcher.js

+ 7 - 7
lib/single-file/css-rules-matcher.js

@@ -23,7 +23,6 @@
 this.RulesMatcher = this.RulesMatcher || (() => {
 
 	const MEDIA_ALL = "all";
-	const PRIORITY_IMPORTANT = "important";
 	const IGNORED_PSEUDO_CLASSES = [":focus", ":focus-within", ":hover", ":link", ":visited", ":active"];
 
 	class RulesMatcher {
@@ -67,10 +66,11 @@ this.RulesMatcher = this.RulesMatcher || (() => {
 				mediaInfo.medias.set(cssRule.media, ruleMediaInfo);
 				getMatchedElementsRules(doc, cssRule.cssRules, ruleMediaInfo, sheetIndex);
 			} else if (cssRule.type == CSSRule.STYLE_RULE) {
-				if (cssRule.selectorText) {
+				const selectorText = cssRule.selectorText;
+				if (selectorText) {
 					let selectors;
 					try {
-						selectors = cssWhat.parse(cssRule.selectorText);
+						selectors = cssWhat.parse(selectorText);
 					} catch (error) {
 						/* ignored */
 					}
@@ -172,16 +172,16 @@ this.RulesMatcher = this.RulesMatcher || (() => {
 				const cssStyle = ruleInfo.cssStyle;
 				const stylesInfo = parseCss.parseAListOfDeclarations(cssStyle.cssText);
 				stylesInfo.forEach(styleInfo => {
-					const important = cssStyle.getPropertyPriority(styleInfo.name) == PRIORITY_IMPORTANT;
-					const styleValue = cssStyle.getPropertyValue(styleInfo.name) + (important ? "!" + PRIORITY_IMPORTANT : "");
+					const important = cssStyle.getPropertyPriority(styleInfo.name);
+					const styleValue = cssStyle.getPropertyValue(styleInfo.name) + (important && "!" + important);
 					elementStylesInfo.set(styleInfo.name, { styleValue, cssStyle: ruleInfo.cssStyle, important });
 				});
 			} else {
 				const cssStyle = ruleInfo.cssRule.style;
 				const stylesInfo = parseCss.parseAListOfDeclarations(cssStyle.cssText);
 				stylesInfo.forEach(styleInfo => {
-					const important = cssStyle.getPropertyPriority(styleInfo.name) == PRIORITY_IMPORTANT;
-					const styleValue = cssStyle.getPropertyValue(styleInfo.name) + (important ? "!" + PRIORITY_IMPORTANT : "");
+					const important = cssStyle.getPropertyPriority(styleInfo.name);
+					const styleValue = cssStyle.getPropertyValue(styleInfo.name) + (important && "!" + important);
 					let elementStyleInfo = elementStylesInfo.get(styleInfo.name);
 					if (!elementStyleInfo || (important && !elementStyleInfo.important)) {
 						elementStylesInfo.set(styleInfo.name, { styleValue, cssRule: ruleInfo.cssRule, selectorText: ruleInfo.selectorText, selectorsText: ruleInfo.selectorsText, important });