Просмотр исходного кода

ensure computedStyle is not null

Gildas 6 лет назад
Родитель
Сommit
811288c3f4
1 измененных файлов с 13 добавлено и 11 удалено
  1. 13 11
      lib/single-file/single-file-helper.js

+ 13 - 11
lib/single-file/single-file-helper.js

@@ -124,9 +124,9 @@ this.singlefile.lib.helper = this.singlefile.lib.helper || (() => {
 					elementHidden = ascendantHidden || testHiddenElement(element, computedStyle);
 				}
 				if (!elementHidden) {
-					if (options.compressHTML) {
+					if (options.compressHTML && computedStyle) {
 						const whiteSpace = computedStyle.getPropertyValue("white-space");
-						if (whiteSpace.startsWith("pre")) {
+						if (whiteSpace && whiteSpace.startsWith("pre")) {
 							element.setAttribute(PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME, "");
 						}
 					}
@@ -215,15 +215,17 @@ this.singlefile.lib.helper = this.singlefile.lib.helper || (() => {
 	}
 
 	function getUsedFont(computedStyle, options, usedFonts) {
-		const fontStyle = computedStyle.getPropertyValue("font-style") || "normal";
-		computedStyle.getPropertyValue("font-family").split(",").forEach(fontFamilyName => {
-			fontFamilyName = normalizeFontFamily(fontFamilyName);
-			if (!options.loadedFonts || options.loadedFonts.find(font => normalizeFontFamily(font.family) == fontFamilyName && font.style == fontStyle)) {
-				const fontWeight = getFontWeight(computedStyle.getPropertyValue("font-weight"));
-				const fontVariant = computedStyle.getPropertyValue("font-variant") || "normal";
-				usedFonts.add([fontFamilyName, fontWeight, fontStyle, fontVariant]);
-			}
-		});
+		if (computedStyle) {
+			const fontStyle = computedStyle.getPropertyValue("font-style") || "normal";
+			computedStyle.getPropertyValue("font-family").split(",").forEach(fontFamilyName => {
+				fontFamilyName = normalizeFontFamily(fontFamilyName);
+				if (!options.loadedFonts || options.loadedFonts.find(font => normalizeFontFamily(font.family) == fontFamilyName && font.style == fontStyle)) {
+					const fontWeight = getFontWeight(computedStyle.getPropertyValue("font-weight"));
+					const fontVariant = computedStyle.getPropertyValue("font-variant") || "normal";
+					usedFonts.add([fontFamilyName, fontWeight, fontStyle, fontVariant]);
+				}
+			});
+		}
 	}
 
 	function normalizeFontFamily(fontFamilyName) {