瀏覽代碼

catch exceptions when parsing selectors

Gildas 7 年之前
父節點
當前提交
4239d333cd
共有 1 個文件被更改,包括 7 次插入3 次删除
  1. 7 3
      lib/single-file/css-rules-matcher.js

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

@@ -70,9 +70,13 @@ this.RulesMatcher = this.RulesMatcher || (() => {
 				getMatchedElementsRules(doc, cssRule.cssRules, ruleMediaInfo, sheetIndex, matchedElementsCache, unmatchedSelectorsCache);
 			} else if (cssRule.type == CSSRule.STYLE_RULE) {
 				if (cssRule.selectorText) {
-					let selectors = cssWhat.parse(cssRule.selectorText);
-					const selectorsText = selectors.map(selector => cssWhat.stringify([selector]));
-					selectors.forEach((selector, selectorIndex) => getMatchedElementsSelector(doc, cssRule, selector, selectorsText[selectorIndex], selectorsText, mediaInfo, ruleIndex, sheetIndex, matchedElementsCache, unmatchedSelectorsCache));
+					try {
+						let selectors = cssWhat.parse(cssRule.selectorText);
+						const selectorsText = selectors.map(selector => cssWhat.stringify([selector]));
+						selectors.forEach((selector, selectorIndex) => getMatchedElementsSelector(doc, cssRule, selector, selectorsText[selectorIndex], selectorsText, mediaInfo, ruleIndex, sheetIndex, matchedElementsCache, unmatchedSelectorsCache));
+					} catch (error) {
+						/* ignored */
+					}
 				}
 			}
 		});