Skip to content
This repository was archived by the owner on Sep 20, 2019. It is now read-only.
This repository was archived by the owner on Sep 20, 2019. It is now read-only.

TreeWalker fixes for IE #556

@treshugart

Description

@treshugart

IE 11 requires the last argument to document.createTreeWalker() even though it's being removed. If it's not provided we get an error stating "Argument not optional".

In fixing that, you must also provide the third argument. In IE 11 you can pass null, however, I believe this fails in IE9 and 10 because they require a you specify a function for acceptNode. Are we supporting these (assuming not due to the usage of classes)? If so it requires something like:

function createTreeWalker (root) {
  // Accept all currently filtered elements.
  function acceptNode () {
    return NodeFilter.FILTER_ACCEPT;
  }

  // Work around Internet Explorer wanting a function instead of an object.
  // IE also *requires* this argument where other browsers don't.
  const safeFilter = acceptNode;
  safeFilter.acceptNode = acceptNode;

  return doc.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, safeFilter, false);
}

Instead of just:

function createTreeWalker (root) {
  return doc.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, null, false);
}

Once you provide IE11 with the correct arguments, it complains with "Unexpected call to method or property access." when calling walker.nextNode(). The fix for this is to only walk trees for nodes that are Node.ELEMENT_NODE.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions