Browse Source

added logs

Gildas 7 năm trước cách đây
mục cha
commit
2128210901
1 tập tin đã thay đổi với 25 bổ sung0 xóa
  1. 25 0
      lib/single-file/css-rules-matcher.js

+ 25 - 0
lib/single-file/css-rules-matcher.js

@@ -34,14 +34,20 @@ this.RulesMatcher = this.RulesMatcher || (() => {
 	const SELECTOR_TOKEN_ACTION_EQUALS = "equals";
 	const SELECTOR_TOKEN_ACTION_ELEMENT = "element";
 	const SELECTOR_TOKEN_VALUE_STAR = "*";
+	const DEBUG = false;
 
 	class RulesMatcher {
 		constructor(doc) {
 			this.doc = doc;
 			this.mediaAllInfo = createMediaInfo(MEDIA_ALL);
 			const matchedElementsCache = new Map();
+			let startTime;
 			doc.querySelectorAll("style").forEach((styleElement, styleIndex) => {
 				if (styleElement.sheet) {
+					if (DEBUG) {
+						startTime = Date.now();
+						log("  // STARTED getMatchedElementsRules style", styleIndex);
+					}
 					if (styleElement.media && styleElement.media != MEDIA_ALL) {
 						const mediaInfo = createMediaInfo(styleElement.media);
 						this.mediaAllInfo.medias.set(styleIndex + "-" + styleElement.media, mediaInfo);
@@ -49,10 +55,25 @@ this.RulesMatcher = this.RulesMatcher || (() => {
 					} else {
 						getMatchedElementsRules(doc, styleElement.sheet.cssRules, this.mediaAllInfo, styleIndex, matchedElementsCache);
 					}
+					if (DEBUG) {
+						log("  // ENDED   getMatchedElementsRules style", Date.now() - startTime);
+					}
 				}
 			});
+			if (DEBUG) {
+				startTime = Date.now();
+				log("  // STARTED sortRules");
+			}
 			sortRules(this.mediaAllInfo);
+			if (DEBUG) {
+				log("  // ENDED sortRules", Date.now() - startTime);
+				startTime = Date.now();
+				log("  // STARTED computeCascade");
+			}
 			computeCascade(this.mediaAllInfo, [], this.mediaAllInfo);
+			if (DEBUG) {
+				log("  // ENDED computeCascade", Date.now() - startTime);
+			}
 		}
 
 		getAllMatchedRules() {
@@ -272,4 +293,8 @@ this.RulesMatcher = this.RulesMatcher || (() => {
 		}
 	}
 
+	function log(...args) {
+		console.log("S-File <css-ma>", ...args); // eslint-disable-line no-console
+	}
+
 })();