ソースを参照

avoid overriding entries into elementsInfo

Gildas 6 年 前
コミット
76c5297c81
1 ファイル変更5 行追加4 行削除
  1. 5 4
      lib/single-file/util/doc-helper.js

+ 5 - 4
lib/single-file/util/doc-helper.js

@@ -91,7 +91,7 @@ this.docHelper = this.docHelper || (() => {
 							}
 						}
 					});
-					elementsInfo = new Map(Array.from(elementsInfo).filter(([element]) => element.getAttribute(REMOVED_CONTENT_ATTRIBUTE_NAME) != ""));
+					elementsInfo = new Map(Array.from(elementsInfo).filter(([element]) => !element.attributes || element.getAttribute(REMOVED_CONTENT_ATTRIBUTE_NAME) != ""));
 				}
 				if (options.removeUnusedFonts) {
 					let loadedFonts;
@@ -102,14 +102,14 @@ this.docHelper = this.docHelper || (() => {
 				}
 				if (options.compressHTML) {
 					elementsInfo.forEach((elementInfo, element) => {
-						if (elementInfo.whiteSpace.startsWith("pre")) {
+						if (element.attributes && elementInfo.whiteSpace.startsWith("pre")) {
 							element.setAttribute(PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME, "");
 						}
 					});
 				}
 				elementsInfo.forEach((elementInfo, element) => {
 					let elementIndex = 0;
-					if (elementInfo.shadowRoot) {
+					if (element.attributes && elementInfo.shadowRoot) {
 						element.setAttribute(SHADOW_ROOT_ATTRIBUTE_NAME, elementIndex);
 						elementIndex++;
 						if (!shadowRootContents) {
@@ -166,7 +166,8 @@ this.docHelper = this.docHelper || (() => {
 
 	function setInfo(win, element, elementsInfo, pseudoElement) {
 		const computedStyle = win.getComputedStyle(element, pseudoElement);
-		elementsInfo.set(element, {
+		const key = pseudoElement ? { element, pseudoElement } : element;
+		elementsInfo.set(key, {
 			display: computedStyle.getPropertyValue("display"),
 			opacity: computedStyle.getPropertyValue("opacity"),
 			visibility: computedStyle.getPropertyValue("visibility"),