Use correct JS context to enable use of instanceof

This commit is contained in:
Niklas von Hertzen 2017-08-04 19:27:35 +08:00
parent 3977ebeadd
commit e380e2c873

View File

@ -44,23 +44,21 @@ const parseNodeTree = (
): void => { ): void => {
for (let childNode = node.firstChild, nextNode; childNode; childNode = nextNode) { for (let childNode = node.firstChild, nextNode; childNode; childNode = nextNode) {
nextNode = childNode.nextSibling; nextNode = childNode.nextSibling;
if (childNode.nodeType === Node.TEXT_NODE) { const defaultView = childNode.ownerDocument.defaultView;
//$FlowFixMe if (childNode instanceof defaultView.Text) {
if (childNode.data.trim().length > 0) { if (childNode.data.trim().length > 0) {
//$FlowFixMe
parent.textNodes.push(new TextContainer(childNode, parent)); 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) { if (IGNORED_NODE_NAMES.indexOf(childNode.nodeName) === -1) {
const childElement = flowRefineToHTMLElement(childNode); inlinePseudoElement(childNode, PSEUDO_BEFORE);
inlinePseudoElement(childElement, PSEUDO_BEFORE); inlinePseudoElement(childNode, PSEUDO_AFTER);
inlinePseudoElement(childElement, PSEUDO_AFTER); const container = new NodeContainer(childNode, parent, imageLoader);
const container = new NodeContainer(childElement, parent, imageLoader);
if (container.isVisible()) { if (container.isVisible()) {
const treatAsRealStackingContext = createsRealStackingContext( const treatAsRealStackingContext = createsRealStackingContext(
container, container,
childElement childNode
); );
if (treatAsRealStackingContext || createsStackingContext(container)) { if (treatAsRealStackingContext || createsStackingContext(container)) {
// for treatAsRealStackingContext:false, any positioned descendants and descendants // for treatAsRealStackingContext:false, any positioned descendants and descendants
@ -75,10 +73,10 @@ const parseNodeTree = (
treatAsRealStackingContext treatAsRealStackingContext
); );
parentStack.contexts.push(childStack); parentStack.contexts.push(childStack);
parseNodeTree(childElement, container, childStack, imageLoader); parseNodeTree(childNode, container, childStack, imageLoader);
} else { } else {
stack.children.push(container); 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 stripQuotes = (content: string): string => {
const first = content.substr(0, 1); const first = content.substr(0, 1);
return first === content.substr(content.length - 1) && first.match(/['"]/) return first === content.substr(content.length - 1) && first.match(/['"]/)