Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DocumentFragment only matches childNodes #79

Closed
Joris-van-der-Wel opened this issue Mar 24, 2014 · 0 comments
Closed

DocumentFragment only matches childNodes #79

Joris-van-der-Wel opened this issue Mar 24, 2014 · 0 comments

Comments

@Joris-van-der-Wel
Copy link
Contributor

I was trying to get querySelector in jsdom to work on DocumentFragments, but I think I have come across an issue in this library.
To rule out anything in jsdom I have tried using this library in chrome and firefox 27

NW.Dom.configure( { USE_QSAPI: false, VERBOSITY: true, CACHING: false } );
var frag = document.createDocumentFragment();
var div = document.createElement('div');
frag.appendChild(div);
var p = document.createElement('p');
div.appendChild(p);
console.log(frag.querySelector('div')); // Firebug / chrome dev tools shows <div>
console.log(NW.Dom.first('div', frag)); // <div>
console.log(frag.querySelector('p')); // <p>
console.log(NW.Dom.first('p', frag)); // null

I think the issue is in nwmatches-noqsa.js:725

If I replace that line with this:

        elements = [];
        var node = from.firstChild;
        while(node) {
          if (node.nodeType === 1) {
            elements.push(node);
          }
          if (node.firstChild) {
            node = node.firstChild;
          } else {
            while (!node.nextSibling) {
              node = node.parentNode;
              if (node === from) {
                break;
              }
            }            
            node = node.nextSibling;
          }
        }

it seems to work properly. That code should give identical results as getElementsByTagName('*')

I'll send a pull request in a moment. I will try to match the code style used (2 spaces per indent is hurting my eyes haha).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant