Explorar o código

fixed inline style issue

Gildas %!s(int64=7) %!d(string=hai) anos
pai
achega
ca8897b00f
Modificáronse 1 ficheiros con 16 adicións e 14 borrados
  1. 16 14
      lib/single-file/rules-matcher.js

+ 16 - 14
lib/single-file/rules-matcher.js

@@ -42,7 +42,7 @@ this.RulesMatcher = this.RulesMatcher || (() => {
 				}
 			});
 			sortRules(this.mediaAllInfo);
-			computeCascade(this.mediaAllInfo);
+			computeCascade(this.mediaAllInfo, [], this.mediaAllInfo);
 		}
 
 		getAllMatchedRules() {
@@ -117,30 +117,32 @@ this.RulesMatcher = this.RulesMatcher || (() => {
 		}
 	}
 
-	function computeCascade(mediaInfo, parentMediaInfos = []) {
-		mediaInfo.elements.forEach(elementInfo => {
+	function computeCascade(mediaInfo, parentMediaInfos, allMediaInfo) {
+		mediaInfo.elements.forEach((elementInfo, element) => {
 			getStylesInfo(elementInfo).forEach((elementStyleInfo, styleName) => {
-				let ruleInfo, ascendantMedia, allMedia;
+				let ruleInfo, ascendantMedia;
 				if (elementStyleInfo.cssRule) {
 					ascendantMedia = [mediaInfo, ...parentMediaInfos].find(media => media.rules.get(elementStyleInfo.cssRule)) || mediaInfo;
 					ruleInfo = ascendantMedia.rules.get(elementStyleInfo.cssRule);
-				}
-				if (elementStyleInfo.cssStyle) {
-					allMedia = parentMediaInfos[parentMediaInfos.length - 1] || mediaInfo;
-					ruleInfo = allMedia.styles.get(elementStyleInfo.cssStyle);
+				} else if (mediaInfo == allMediaInfo) {
+					ruleInfo = allMediaInfo.styles.get(elementStyleInfo.cssStyle);
 				}
 				if (!ruleInfo) {
 					ruleInfo = { style: new Map(), matchedSelectors: new Set(), selectorsText: elementStyleInfo.selectorsText };
 					if (elementStyleInfo.cssRule) {
 						ascendantMedia.rules.set(elementStyleInfo.cssRule, ruleInfo);
-					} else {
-						allMedia.styles.set(elementStyleInfo.cssStyle, ruleInfo);
+					} else if (mediaInfo == allMediaInfo) {
+						allMediaInfo.styles.set(elementStyleInfo.cssStyle, ruleInfo);
 					}
 				}
-				ruleInfo.matchedSelectors.add(elementStyleInfo.selectorText);
-				const styleValue = ruleInfo.style.get(styleName);
-				if (!styleValue) {
-					ruleInfo.style.set(styleName, elementStyleInfo.styleValue);
+				if (ruleInfo) {
+					if (elementStyleInfo.selectorText) {
+						ruleInfo.matchedSelectors.add(elementStyleInfo.selectorText); // FIXME
+					}
+					const styleValue = ruleInfo.style.get(styleName);
+					if (!styleValue) {
+						ruleInfo.style.set(styleName, elementStyleInfo.styleValue);
+					}
 				}
 			});
 		});