Merge pull request #12 from patrikpihlstrom/master

support ',' in query selectors
This commit is contained in:
taoqf 2020-01-08 00:05:01 -05:00 committed by GitHub
commit 4b588b69e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View file

@ -325,6 +325,14 @@ export class HTMLElement extends Node {
matcher = selector;
matcher.reset();
} else {
if (selector.includes(',')) {
const selectors = selector.split(',') as string[];
let result = [] as HTMLElement[];
selectors.forEach((s) => {
result = result.concat(this.querySelectorAll(s.trim()));
})
return result;
}
matcher = new Matcher(selector);
}
const res = [] as HTMLElement[];

View file

@ -310,6 +310,7 @@ describe('HTML Parser', function () {
root.querySelectorAll('span.a.b').should.eql([root.firstChild.firstChild.firstChild]);
root.querySelectorAll('#id .b').should.eql([root.firstChild.firstChild.firstChild]);
root.querySelectorAll('#id span').should.eql(root.firstChild.firstChild.childNodes);
root.querySelectorAll('#id, #id .b').should.eql([root.firstChild, root.firstChild.firstChild.firstChild]);
});
});