happy-dom
Advanced tools
Comparing version 14.3.3 to 14.3.4
@@ -67,5 +67,9 @@ import Element from '../nodes/element/Element.cjs'; | ||
* @param selector Selector to match with. | ||
* @param [options] Options. | ||
* @param [options.ignoreErrors] Ignores errors. | ||
* @returns Result. | ||
*/ | ||
static match(element: Element, selector: string): ISelectorMatch | null; | ||
static matches(element: Element, selector: string, options?: { | ||
ignoreErrors?: boolean; | ||
}): ISelectorMatch | null; | ||
/** | ||
@@ -72,0 +76,0 @@ * Checks if a node matches a selector. |
@@ -17,2 +17,3 @@ import Element from '../nodes/element/Element.cjs'; | ||
combinator: SelectorCombinatorEnum; | ||
ignoreErrors: boolean; | ||
/** | ||
@@ -29,2 +30,3 @@ * Constructor. | ||
* @param [options.isPseudoElement] Is pseudo element. | ||
* @param [options.ignoreErrors] Ignore errors. | ||
*/ | ||
@@ -39,2 +41,3 @@ constructor(options?: { | ||
combinator?: SelectorCombinatorEnum; | ||
ignoreErrors?: boolean; | ||
}); | ||
@@ -54,3 +57,3 @@ /** | ||
*/ | ||
private matchPsuedo; | ||
private matchPseudo; | ||
/** | ||
@@ -57,0 +60,0 @@ * Matches a pseudo selector. |
@@ -10,5 +10,9 @@ import SelectorItem from './SelectorItem.cjs'; | ||
* @param selector Selector. | ||
* @param [options] Options. | ||
* @param [options.ignoreErrors] Ignores errors. | ||
* @returns Selector item. | ||
*/ | ||
static getSelectorItem(selector: string): SelectorItem; | ||
static getSelectorItem(selector: string, options?: { | ||
ignoreErrors?: boolean; | ||
}): SelectorItem; | ||
/** | ||
@@ -18,5 +22,9 @@ * Parses a selector string and returns groups with SelectorItem instances. | ||
* @param selector Selector. | ||
* @param [options] Options. | ||
* @param [options.ignoreErrors] Ignores errors. | ||
* @returns Selector groups. | ||
*/ | ||
static getSelectorGroups(selector: string): Array<Array<SelectorItem>>; | ||
static getSelectorGroups(selector: string, options?: { | ||
ignoreErrors?: boolean; | ||
}): Array<Array<SelectorItem>>; | ||
/** | ||
@@ -37,2 +45,4 @@ * Returns attribute RegExp. | ||
* @param args Pseudo arguments. | ||
* @param [options] Options. | ||
* @param [options.ignoreErrors] Ignores errors. | ||
* @returns Pseudo. | ||
@@ -39,0 +49,0 @@ */ |
@@ -248,7 +248,9 @@ import * as PropertySymbol from '../../../PropertySymbol.js'; | ||
for (const element of options.elements) { | ||
const matchResult = QuerySelector.match(element.element, selectorText); | ||
if (matchResult) { | ||
const match = QuerySelector.matches(element.element, selectorText, { | ||
ignoreErrors: true | ||
}); | ||
if (match) { | ||
element.cssTexts.push({ | ||
cssText: rule[PropertySymbol.cssText], | ||
priorityWeight: matchResult.priorityWeight | ||
priorityWeight: match.priorityWeight | ||
}); | ||
@@ -255,0 +257,0 @@ } |
@@ -733,3 +733,3 @@ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; | ||
matches(selector) { | ||
return !!QuerySelector.match(this, selector); | ||
return !!QuerySelector.matches(this, selector); | ||
} | ||
@@ -746,3 +746,3 @@ /** | ||
while (parent) { | ||
if (QuerySelector.match(parent, selector)) { | ||
if (QuerySelector.matches(parent, selector)) { | ||
return parent; | ||
@@ -749,0 +749,0 @@ } |
@@ -67,5 +67,9 @@ import Element from '../nodes/element/Element.js'; | ||
* @param selector Selector to match with. | ||
* @param [options] Options. | ||
* @param [options.ignoreErrors] Ignores errors. | ||
* @returns Result. | ||
*/ | ||
static match(element: Element, selector: string): ISelectorMatch | null; | ||
static matches(element: Element, selector: string, options?: { | ||
ignoreErrors?: boolean; | ||
}): ISelectorMatch | null; | ||
/** | ||
@@ -72,0 +76,0 @@ * Checks if a node matches a selector. |
@@ -83,5 +83,7 @@ import * as PropertySymbol from '../PropertySymbol.js'; | ||
* @param selector Selector to match with. | ||
* @param [options] Options. | ||
* @param [options.ignoreErrors] Ignores errors. | ||
* @returns Result. | ||
*/ | ||
static match(element, selector) { | ||
static matches(element, selector, options) { | ||
if (!selector) { | ||
@@ -95,7 +97,11 @@ return null; | ||
} | ||
const ignoreErrors = options?.ignoreErrors; | ||
if (INVALID_SELECTOR_REGEXP.test(selector)) { | ||
throw new Error(`Failed to execute 'match' on '${element.constructor.name}': '${selector}' is not a valid selector.`); | ||
if (ignoreErrors) { | ||
return null; | ||
} | ||
throw new Error(`Failed to execute 'matches' on '${element.constructor.name}': '${selector}' is not a valid selector.`); | ||
} | ||
for (const items of SelectorParser.getSelectorGroups(selector)) { | ||
const result = this.matchSelector(element, element, items.reverse()); | ||
for (const items of SelectorParser.getSelectorGroups(selector, options)) { | ||
const result = this.matchSelector(element, element, items.reverse(), 0); | ||
if (result) { | ||
@@ -102,0 +108,0 @@ return result; |
@@ -17,2 +17,3 @@ import Element from '../nodes/element/Element.js'; | ||
combinator: SelectorCombinatorEnum; | ||
ignoreErrors: boolean; | ||
/** | ||
@@ -29,2 +30,3 @@ * Constructor. | ||
* @param [options.isPseudoElement] Is pseudo element. | ||
* @param [options.ignoreErrors] Ignore errors. | ||
*/ | ||
@@ -39,2 +41,3 @@ constructor(options?: { | ||
combinator?: SelectorCombinatorEnum; | ||
ignoreErrors?: boolean; | ||
}); | ||
@@ -54,3 +57,3 @@ /** | ||
*/ | ||
private matchPsuedo; | ||
private matchPseudo; | ||
/** | ||
@@ -57,0 +60,0 @@ * Matches a pseudo selector. |
@@ -19,2 +19,3 @@ import DOMException from '../exception/DOMException.js'; | ||
* @param [options.isPseudoElement] Is pseudo element. | ||
* @param [options.ignoreErrors] Ignore errors. | ||
*/ | ||
@@ -29,2 +30,3 @@ constructor(options) { | ||
this.combinator = options?.combinator || SelectorCombinatorEnum.descendant; | ||
this.ignoreErrors = options?.ignoreErrors || false; | ||
} | ||
@@ -74,3 +76,3 @@ /** | ||
if (this.pseudos) { | ||
const result = this.matchPsuedo(element); | ||
const result = this.matchPseudo(element); | ||
if (!result) { | ||
@@ -89,3 +91,3 @@ return null; | ||
*/ | ||
matchPsuedo(element) { | ||
matchPseudo(element) { | ||
const parent = element[PropertySymbol.parentNode]; | ||
@@ -108,3 +110,6 @@ const parentChildren = element[PropertySymbol.parentNode] | ||
if (!pseudo.arguments) { | ||
throw new DOMException(`The selector "${this.getSelectorString()}" is not valid.`); | ||
if (this.ignoreErrors) { | ||
return null; | ||
} | ||
throw new DOMException(`Failed to execute 'matches' on '${element.constructor.name}': '${this.getSelectorString()}' is not a valid selector.`); | ||
} | ||
@@ -305,3 +310,3 @@ break; | ||
getSelectorString() { | ||
return `${this.tagName || ''}${this.id ? `#${this.id}` : ''}${this.classNames ? `.${this.classNames.join('.')}` : ''}${this.attributes | ||
return `${this.tagName ? this.tagName.toLowerCase() : ''}${this.id ? `#${this.id}` : ''}${this.classNames ? `.${this.classNames.join('.')}` : ''}${this.attributes | ||
? this.attributes | ||
@@ -308,0 +313,0 @@ .map((attribute) => `[${attribute.name}${attribute.value ? `${attribute.operator || ''}="${attribute.value}"` : ''}]`) |
@@ -10,5 +10,9 @@ import SelectorItem from './SelectorItem.js'; | ||
* @param selector Selector. | ||
* @param [options] Options. | ||
* @param [options.ignoreErrors] Ignores errors. | ||
* @returns Selector item. | ||
*/ | ||
static getSelectorItem(selector: string): SelectorItem; | ||
static getSelectorItem(selector: string, options?: { | ||
ignoreErrors?: boolean; | ||
}): SelectorItem; | ||
/** | ||
@@ -18,5 +22,9 @@ * Parses a selector string and returns groups with SelectorItem instances. | ||
* @param selector Selector. | ||
* @param [options] Options. | ||
* @param [options.ignoreErrors] Ignores errors. | ||
* @returns Selector groups. | ||
*/ | ||
static getSelectorGroups(selector: string): Array<Array<SelectorItem>>; | ||
static getSelectorGroups(selector: string, options?: { | ||
ignoreErrors?: boolean; | ||
}): Array<Array<SelectorItem>>; | ||
/** | ||
@@ -37,2 +45,4 @@ * Returns attribute RegExp. | ||
* @param args Pseudo arguments. | ||
* @param [options] Options. | ||
* @param [options.ignoreErrors] Ignores errors. | ||
* @returns Pseudo. | ||
@@ -39,0 +49,0 @@ */ |
@@ -58,6 +58,8 @@ import SelectorItem from './SelectorItem.js'; | ||
* @param selector Selector. | ||
* @param [options] Options. | ||
* @param [options.ignoreErrors] Ignores errors. | ||
* @returns Selector item. | ||
*/ | ||
static getSelectorItem(selector) { | ||
return this.getSelectorGroups(selector)[0][0]; | ||
static getSelectorItem(selector, options) { | ||
return this.getSelectorGroups(selector, options)[0][0]; | ||
} | ||
@@ -68,7 +70,10 @@ /** | ||
* @param selector Selector. | ||
* @param [options] Options. | ||
* @param [options.ignoreErrors] Ignores errors. | ||
* @returns Selector groups. | ||
*/ | ||
static getSelectorGroups(selector) { | ||
static getSelectorGroups(selector, options) { | ||
const ignoreErrors = options?.ignoreErrors; | ||
if (selector === '*') { | ||
return [[new SelectorItem({ tagName: '*' })]]; | ||
return [[new SelectorItem({ tagName: '*', ignoreErrors })]]; | ||
} | ||
@@ -78,9 +83,11 @@ const simpleMatch = selector.match(SIMPLE_SELECTOR_REGEXP); | ||
if (simpleMatch[1]) { | ||
return [[new SelectorItem({ tagName: selector.toUpperCase() })]]; | ||
return [[new SelectorItem({ tagName: selector.toUpperCase(), ignoreErrors })]]; | ||
} | ||
else if (simpleMatch[2]) { | ||
return [[new SelectorItem({ classNames: selector.replace('.', '').split('.') })]]; | ||
return [ | ||
[new SelectorItem({ classNames: selector.replace('.', '').split('.'), ignoreErrors })] | ||
]; | ||
} | ||
else if (simpleMatch[3]) { | ||
return [[new SelectorItem({ id: selector.replace('#', '') })]]; | ||
return [[new SelectorItem({ id: selector.replace('#', ''), ignoreErrors })]]; | ||
} | ||
@@ -90,3 +97,4 @@ } | ||
let currentSelectorItem = new SelectorItem({ | ||
combinator: SelectorCombinatorEnum.descendant | ||
combinator: SelectorCombinatorEnum.descendant, | ||
ignoreErrors | ||
}); | ||
@@ -149,7 +157,7 @@ let currentGroup = [currentSelectorItem]; | ||
currentSelectorItem.pseudos = currentSelectorItem.pseudos || []; | ||
currentSelectorItem.pseudos.push(this.getPseudo(match[13], match[14])); | ||
currentSelectorItem.pseudos.push(this.getPseudo(match[13], match[14], options)); | ||
} | ||
else if (match[15]) { | ||
currentSelectorItem.pseudos = currentSelectorItem.pseudos || []; | ||
currentSelectorItem.pseudos.push(this.getPseudo(match[15])); | ||
currentSelectorItem.pseudos.push(this.getPseudo(match[15], null, options)); | ||
} | ||
@@ -163,3 +171,4 @@ else if (match[16]) { | ||
currentSelectorItem = new SelectorItem({ | ||
combinator: SelectorCombinatorEnum.descendant | ||
combinator: SelectorCombinatorEnum.descendant, | ||
ignoreErrors | ||
}); | ||
@@ -170,3 +179,6 @@ currentGroup = [currentSelectorItem]; | ||
case '>': | ||
currentSelectorItem = new SelectorItem({ combinator: SelectorCombinatorEnum.child }); | ||
currentSelectorItem = new SelectorItem({ | ||
combinator: SelectorCombinatorEnum.child, | ||
ignoreErrors | ||
}); | ||
currentGroup.push(currentSelectorItem); | ||
@@ -176,3 +188,4 @@ break; | ||
currentSelectorItem = new SelectorItem({ | ||
combinator: SelectorCombinatorEnum.adjacentSibling | ||
combinator: SelectorCombinatorEnum.adjacentSibling, | ||
ignoreErrors | ||
}); | ||
@@ -183,3 +196,4 @@ currentGroup.push(currentSelectorItem); | ||
currentSelectorItem = new SelectorItem({ | ||
combinator: SelectorCombinatorEnum.descendant | ||
combinator: SelectorCombinatorEnum.descendant, | ||
ignoreErrors | ||
}); | ||
@@ -196,2 +210,5 @@ currentGroup.push(currentSelectorItem); | ||
if (!isValid) { | ||
if (options?.ignoreErrors) { | ||
return []; | ||
} | ||
throw new DOMException(`Invalid selector: "${selector}"`); | ||
@@ -240,5 +257,7 @@ } | ||
* @param args Pseudo arguments. | ||
* @param [options] Options. | ||
* @param [options.ignoreErrors] Ignores errors. | ||
* @returns Pseudo. | ||
*/ | ||
static getPseudo(name, args) { | ||
static getPseudo(name, args, options) { | ||
const lowerName = name.toLowerCase(); | ||
@@ -253,3 +272,5 @@ if (!args) { | ||
const nthFunction = nthOfIndex !== -1 ? args.substring(0, nthOfIndex) : args; | ||
const selectorItem = nthOfIndex !== -1 ? this.getSelectorItem(args.substring(nthOfIndex + 4).trim()) : null; | ||
const selectorItem = nthOfIndex !== -1 | ||
? this.getSelectorItem(args.substring(nthOfIndex + 4).trim(), options) | ||
: null; | ||
return { | ||
@@ -273,3 +294,3 @@ name: lowerName, | ||
arguments: args, | ||
selectorItems: [this.getSelectorItem(args)], | ||
selectorItems: [this.getSelectorItem(args, options)], | ||
nthFunction: null | ||
@@ -279,3 +300,3 @@ }; | ||
case 'where': | ||
const selectorGroups = this.getSelectorGroups(args); | ||
const selectorGroups = this.getSelectorGroups(args, options); | ||
const selectorItems = []; | ||
@@ -282,0 +303,0 @@ for (const group of selectorGroups) { |
{ | ||
"name": "happy-dom", | ||
"version": "14.3.3", | ||
"version": "14.3.4", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/capricorn86/happy-dom", |
@@ -331,7 +331,9 @@ import ShadowRoot from '../../../nodes/shadow-root/ShadowRoot.js'; | ||
for (const element of options.elements) { | ||
const matchResult = QuerySelector.match(<Element>element.element, selectorText); | ||
if (matchResult) { | ||
const match = QuerySelector.matches(<Element>element.element, selectorText, { | ||
ignoreErrors: true | ||
}); | ||
if (match) { | ||
element.cssTexts.push({ | ||
cssText: (<CSSStyleRule>rule)[PropertySymbol.cssText], | ||
priorityWeight: matchResult.priorityWeight | ||
priorityWeight: match.priorityWeight | ||
}); | ||
@@ -338,0 +340,0 @@ } |
@@ -854,3 +854,3 @@ import Node from '../node/Node.js'; | ||
public matches(selector: string): boolean { | ||
return !!QuerySelector.match(this, selector); | ||
return !!QuerySelector.matches(this, selector); | ||
} | ||
@@ -869,3 +869,3 @@ | ||
while (parent) { | ||
if (QuerySelector.match(parent, selector)) { | ||
if (QuerySelector.matches(parent, selector)) { | ||
return parent; | ||
@@ -872,0 +872,0 @@ } |
@@ -201,5 +201,11 @@ import Element from '../nodes/element/Element.js'; | ||
* @param selector Selector to match with. | ||
* @param [options] Options. | ||
* @param [options.ignoreErrors] Ignores errors. | ||
* @returns Result. | ||
*/ | ||
public static match(element: Element, selector: string): ISelectorMatch | null { | ||
public static matches( | ||
element: Element, | ||
selector: string, | ||
options?: { ignoreErrors?: boolean } | ||
): ISelectorMatch | null { | ||
if (!selector) { | ||
@@ -215,10 +221,15 @@ return null; | ||
const ignoreErrors = options?.ignoreErrors; | ||
if (INVALID_SELECTOR_REGEXP.test(selector)) { | ||
if (ignoreErrors) { | ||
return null; | ||
} | ||
throw new Error( | ||
`Failed to execute 'match' on '${element.constructor.name}': '${selector}' is not a valid selector.` | ||
`Failed to execute 'matches' on '${element.constructor.name}': '${selector}' is not a valid selector.` | ||
); | ||
} | ||
for (const items of SelectorParser.getSelectorGroups(selector)) { | ||
const result = this.matchSelector(element, element, items.reverse()); | ||
for (const items of SelectorParser.getSelectorGroups(selector, options)) { | ||
const result = this.matchSelector(element, element, items.reverse(), 0); | ||
@@ -225,0 +236,0 @@ if (result) { |
@@ -21,2 +21,3 @@ import DOMException from '../exception/DOMException.js'; | ||
public combinator: SelectorCombinatorEnum; | ||
public ignoreErrors: boolean; | ||
@@ -34,2 +35,3 @@ /** | ||
* @param [options.isPseudoElement] Is pseudo element. | ||
* @param [options.ignoreErrors] Ignore errors. | ||
*/ | ||
@@ -44,2 +46,3 @@ constructor(options?: { | ||
combinator?: SelectorCombinatorEnum; | ||
ignoreErrors?: boolean; | ||
}) { | ||
@@ -53,2 +56,3 @@ this.tagName = options?.tagName || null; | ||
this.combinator = options?.combinator || SelectorCombinatorEnum.descendant; | ||
this.ignoreErrors = options?.ignoreErrors || false; | ||
} | ||
@@ -105,3 +109,3 @@ | ||
if (this.pseudos) { | ||
const result = this.matchPsuedo(element); | ||
const result = this.matchPseudo(element); | ||
if (!result) { | ||
@@ -122,3 +126,3 @@ return null; | ||
*/ | ||
private matchPsuedo(element: Element): ISelectorMatch | null { | ||
private matchPseudo(element: Element): ISelectorMatch | null { | ||
const parent = <Element>element[PropertySymbol.parentNode]; | ||
@@ -144,3 +148,10 @@ const parentChildren = element[PropertySymbol.parentNode] | ||
if (!pseudo.arguments) { | ||
throw new DOMException(`The selector "${this.getSelectorString()}" is not valid.`); | ||
if (this.ignoreErrors) { | ||
return null; | ||
} | ||
throw new DOMException( | ||
`Failed to execute 'matches' on '${ | ||
element.constructor.name | ||
}': '${this.getSelectorString()}' is not a valid selector.` | ||
); | ||
} | ||
@@ -367,3 +378,3 @@ break; | ||
private getSelectorString(): string { | ||
return `${this.tagName || ''}${this.id ? `#${this.id}` : ''}${ | ||
return `${this.tagName ? this.tagName.toLowerCase() : ''}${this.id ? `#${this.id}` : ''}${ | ||
this.classNames ? `.${this.classNames.join('.')}` : '' | ||
@@ -370,0 +381,0 @@ }${ |
@@ -66,6 +66,11 @@ import SelectorItem from './SelectorItem.js'; | ||
* @param selector Selector. | ||
* @param [options] Options. | ||
* @param [options.ignoreErrors] Ignores errors. | ||
* @returns Selector item. | ||
*/ | ||
public static getSelectorItem(selector: string): SelectorItem { | ||
return this.getSelectorGroups(selector)[0][0]; | ||
public static getSelectorItem( | ||
selector: string, | ||
options?: { ignoreErrors?: boolean } | ||
): SelectorItem { | ||
return this.getSelectorGroups(selector, options)[0][0]; | ||
} | ||
@@ -77,7 +82,13 @@ | ||
* @param selector Selector. | ||
* @param [options] Options. | ||
* @param [options.ignoreErrors] Ignores errors. | ||
* @returns Selector groups. | ||
*/ | ||
public static getSelectorGroups(selector: string): Array<Array<SelectorItem>> { | ||
public static getSelectorGroups( | ||
selector: string, | ||
options?: { ignoreErrors?: boolean } | ||
): Array<Array<SelectorItem>> { | ||
const ignoreErrors = options?.ignoreErrors; | ||
if (selector === '*') { | ||
return [[new SelectorItem({ tagName: '*' })]]; | ||
return [[new SelectorItem({ tagName: '*', ignoreErrors })]]; | ||
} | ||
@@ -89,7 +100,9 @@ | ||
if (simpleMatch[1]) { | ||
return [[new SelectorItem({ tagName: selector.toUpperCase() })]]; | ||
return [[new SelectorItem({ tagName: selector.toUpperCase(), ignoreErrors })]]; | ||
} else if (simpleMatch[2]) { | ||
return [[new SelectorItem({ classNames: selector.replace('.', '').split('.') })]]; | ||
return [ | ||
[new SelectorItem({ classNames: selector.replace('.', '').split('.'), ignoreErrors })] | ||
]; | ||
} else if (simpleMatch[3]) { | ||
return [[new SelectorItem({ id: selector.replace('#', '') })]]; | ||
return [[new SelectorItem({ id: selector.replace('#', ''), ignoreErrors })]]; | ||
} | ||
@@ -100,3 +113,4 @@ } | ||
let currentSelectorItem: SelectorItem = new SelectorItem({ | ||
combinator: SelectorCombinatorEnum.descendant | ||
combinator: SelectorCombinatorEnum.descendant, | ||
ignoreErrors | ||
}); | ||
@@ -154,6 +168,6 @@ let currentGroup: SelectorItem[] = [currentSelectorItem]; | ||
currentSelectorItem.pseudos = currentSelectorItem.pseudos || []; | ||
currentSelectorItem.pseudos.push(this.getPseudo(match[13], match[14])); | ||
currentSelectorItem.pseudos.push(this.getPseudo(match[13], match[14], options)); | ||
} else if (match[15]) { | ||
currentSelectorItem.pseudos = currentSelectorItem.pseudos || []; | ||
currentSelectorItem.pseudos.push(this.getPseudo(match[15])); | ||
currentSelectorItem.pseudos.push(this.getPseudo(match[15], null, options)); | ||
} else if (match[16]) { | ||
@@ -165,3 +179,4 @@ currentSelectorItem.isPseudoElement = true; | ||
currentSelectorItem = new SelectorItem({ | ||
combinator: SelectorCombinatorEnum.descendant | ||
combinator: SelectorCombinatorEnum.descendant, | ||
ignoreErrors | ||
}); | ||
@@ -172,3 +187,6 @@ currentGroup = [currentSelectorItem]; | ||
case '>': | ||
currentSelectorItem = new SelectorItem({ combinator: SelectorCombinatorEnum.child }); | ||
currentSelectorItem = new SelectorItem({ | ||
combinator: SelectorCombinatorEnum.child, | ||
ignoreErrors | ||
}); | ||
currentGroup.push(currentSelectorItem); | ||
@@ -178,3 +196,4 @@ break; | ||
currentSelectorItem = new SelectorItem({ | ||
combinator: SelectorCombinatorEnum.adjacentSibling | ||
combinator: SelectorCombinatorEnum.adjacentSibling, | ||
ignoreErrors | ||
}); | ||
@@ -185,3 +204,4 @@ currentGroup.push(currentSelectorItem); | ||
currentSelectorItem = new SelectorItem({ | ||
combinator: SelectorCombinatorEnum.descendant | ||
combinator: SelectorCombinatorEnum.descendant, | ||
ignoreErrors | ||
}); | ||
@@ -198,2 +218,5 @@ currentGroup.push(currentSelectorItem); | ||
if (!isValid) { | ||
if (options?.ignoreErrors) { | ||
return []; | ||
} | ||
throw new DOMException(`Invalid selector: "${selector}"`); | ||
@@ -254,5 +277,11 @@ } | ||
* @param args Pseudo arguments. | ||
* @param [options] Options. | ||
* @param [options.ignoreErrors] Ignores errors. | ||
* @returns Pseudo. | ||
*/ | ||
private static getPseudo(name: string, args?: string): ISelectorPseudo { | ||
private static getPseudo( | ||
name: string, | ||
args?: string, | ||
options?: { ignoreErrors?: boolean } | ||
): ISelectorPseudo { | ||
const lowerName = name.toLowerCase(); | ||
@@ -270,3 +299,5 @@ | ||
const selectorItem = | ||
nthOfIndex !== -1 ? this.getSelectorItem(args.substring(nthOfIndex + 4).trim()) : null; | ||
nthOfIndex !== -1 | ||
? this.getSelectorItem(args.substring(nthOfIndex + 4).trim(), options) | ||
: null; | ||
return { | ||
@@ -290,3 +321,3 @@ name: lowerName, | ||
arguments: args, | ||
selectorItems: [this.getSelectorItem(args)], | ||
selectorItems: [this.getSelectorItem(args, options)], | ||
nthFunction: null | ||
@@ -296,3 +327,3 @@ }; | ||
case 'where': | ||
const selectorGroups = this.getSelectorGroups(args); | ||
const selectorGroups = this.getSelectorGroups(args, options); | ||
const selectorItems = []; | ||
@@ -299,0 +330,0 @@ for (const group of selectorGroups) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8221219
164816