support ',' in query selectors

This commit is contained in:
patrik 2020-01-07 13:43:14 +01:00
parent 8a481f5d19
commit 7651417f1e
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]);
});
});