From e380e2c873209f19f50176e440e2672705d89182 Mon Sep 17 00:00:00 2001 From: Niklas von Hertzen Date: Fri, 4 Aug 2017 19:27:35 +0800 Subject: [PATCH] Use correct JS context to enable use of instanceof --- src/NodeParser.js | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/NodeParser.js b/src/NodeParser.js index ccf1ba6..45efb70 100644 --- a/src/NodeParser.js +++ b/src/NodeParser.js @@ -44,23 +44,21 @@ const parseNodeTree = ( ): void => { for (let childNode = node.firstChild, nextNode; childNode; childNode = nextNode) { nextNode = childNode.nextSibling; - if (childNode.nodeType === Node.TEXT_NODE) { - //$FlowFixMe + const defaultView = childNode.ownerDocument.defaultView; + if (childNode instanceof defaultView.Text) { if (childNode.data.trim().length > 0) { - //$FlowFixMe parent.textNodes.push(new TextContainer(childNode, parent)); } - } else if (childNode.nodeType === Node.ELEMENT_NODE) { + } else if (childNode instanceof defaultView.HTMLElement) { if (IGNORED_NODE_NAMES.indexOf(childNode.nodeName) === -1) { - const childElement = flowRefineToHTMLElement(childNode); - inlinePseudoElement(childElement, PSEUDO_BEFORE); - inlinePseudoElement(childElement, PSEUDO_AFTER); - const container = new NodeContainer(childElement, parent, imageLoader); + inlinePseudoElement(childNode, PSEUDO_BEFORE); + inlinePseudoElement(childNode, PSEUDO_AFTER); + const container = new NodeContainer(childNode, parent, imageLoader); if (container.isVisible()) { const treatAsRealStackingContext = createsRealStackingContext( container, - childElement + childNode ); if (treatAsRealStackingContext || createsStackingContext(container)) { // for treatAsRealStackingContext:false, any positioned descendants and descendants @@ -75,10 +73,10 @@ const parseNodeTree = ( treatAsRealStackingContext ); parentStack.contexts.push(childStack); - parseNodeTree(childElement, container, childStack, imageLoader); + parseNodeTree(childNode, container, childStack, imageLoader); } else { stack.children.push(container); - parseNodeTree(childElement, container, stack, imageLoader); + parseNodeTree(childNode, container, stack, imageLoader); } } } @@ -145,9 +143,6 @@ const isBodyWithTransparentRoot = (container: NodeContainer, node: HTMLElement): ); }; -//$FlowFixMe -const flowRefineToHTMLElement = (node: Node): HTMLElement => node; - const stripQuotes = (content: string): string => { const first = content.substr(0, 1); return first === content.substr(content.length - 1) && first.match(/['"]/)