happy-dom
Advanced tools
Comparing version 14.1.2 to 14.2.0
@@ -5,5 +5,5 @@ import SelectorItem from './SelectorItem.cjs'; | ||
arguments: string | null; | ||
selectorItem: SelectorItem | null; | ||
selectorItems: SelectorItem[] | null; | ||
nthFunction: ((n: number) => boolean) | null; | ||
} | ||
//# sourceMappingURL=ISelectorPseudo.d.ts.map |
@@ -5,5 +5,5 @@ import SelectorItem from './SelectorItem.js'; | ||
arguments: string | null; | ||
selectorItem: SelectorItem | null; | ||
selectorItems: SelectorItem[] | null; | ||
nthFunction: ((n: number) => boolean) | null; | ||
} | ||
//# sourceMappingURL=ISelectorPseudo.d.ts.map |
@@ -71,4 +71,8 @@ import DOMException from '../exception/DOMException.js'; | ||
// Pseudo match | ||
if (this.pseudos && !this.matchPsuedo(element)) { | ||
return null; | ||
if (this.pseudos) { | ||
const result = this.matchPsuedo(element); | ||
if (!result) { | ||
return null; | ||
} | ||
priorityWeight += result.priorityWeight; | ||
} | ||
@@ -89,4 +93,5 @@ return { priorityWeight }; | ||
if (!this.pseudos) { | ||
return true; | ||
return { priorityWeight: 0 }; | ||
} | ||
let priorityWeight = 0; | ||
for (const pseudo of this.pseudos) { | ||
@@ -118,10 +123,12 @@ // Validation | ||
case 'nth-last-of-type': | ||
return false; | ||
return null; | ||
} | ||
} | ||
if (!this.matchPseudoItem(element, parentChildren, pseudo)) { | ||
return false; | ||
const selectorMatch = this.matchPseudoItem(element, parentChildren, pseudo); | ||
if (!selectorMatch) { | ||
return null; | ||
} | ||
priorityWeight += selectorMatch.priorityWeight; | ||
} | ||
return true; | ||
return { priorityWeight }; | ||
} | ||
@@ -138,14 +145,18 @@ /** | ||
case 'first-child': | ||
return parentChildren[0] === element; | ||
return parentChildren[0] === element ? { priorityWeight: 10 } : null; | ||
case 'last-child': | ||
return parentChildren.length && parentChildren[parentChildren.length - 1] === element; | ||
return parentChildren.length && parentChildren[parentChildren.length - 1] === element | ||
? { priorityWeight: 10 } | ||
: null; | ||
case 'only-child': | ||
return parentChildren.length === 1 && parentChildren[0] === element; | ||
return parentChildren.length === 1 && parentChildren[0] === element | ||
? { priorityWeight: 10 } | ||
: null; | ||
case 'first-of-type': | ||
for (const child of parentChildren) { | ||
if (child[PropertySymbol.tagName] === element[PropertySymbol.tagName]) { | ||
return child === element; | ||
return child === element ? { priorityWeight: 10 } : null; | ||
} | ||
} | ||
return false; | ||
return null; | ||
case 'last-of-type': | ||
@@ -155,6 +166,6 @@ for (let i = parentChildren.length - 1; i >= 0; i--) { | ||
if (child[PropertySymbol.tagName] === element[PropertySymbol.tagName]) { | ||
return child === element; | ||
return child === element ? { priorityWeight: 10 } : null; | ||
} | ||
} | ||
return false; | ||
return null; | ||
case 'only-of-type': | ||
@@ -165,3 +176,3 @@ let isFound = false; | ||
if (isFound || child !== element) { | ||
return false; | ||
return null; | ||
} | ||
@@ -171,19 +182,23 @@ isFound = true; | ||
} | ||
return isFound; | ||
return isFound ? { priorityWeight: 10 } : null; | ||
case 'checked': | ||
return element[PropertySymbol.tagName] === 'INPUT' && element.checked; | ||
return element[PropertySymbol.tagName] === 'INPUT' && element.checked | ||
? { priorityWeight: 10 } | ||
: null; | ||
case 'empty': | ||
return !element[PropertySymbol.children].length; | ||
return !element[PropertySymbol.children].length ? { priorityWeight: 10 } : null; | ||
case 'root': | ||
return element[PropertySymbol.tagName] === 'HTML'; | ||
return element[PropertySymbol.tagName] === 'HTML' ? { priorityWeight: 10 } : null; | ||
case 'not': | ||
return !pseudo.selectorItem.match(element); | ||
return !pseudo.selectorItems[0].match(element) ? { priorityWeight: 10 } : null; | ||
case 'nth-child': | ||
const nthChildIndex = pseudo.selectorItem | ||
? parentChildren.filter((child) => pseudo.selectorItem.match(child)).indexOf(element) | ||
const nthChildIndex = pseudo.selectorItems[0] | ||
? parentChildren.filter((child) => pseudo.selectorItems[0].match(child)).indexOf(element) | ||
: parentChildren.indexOf(element); | ||
return nthChildIndex !== -1 && pseudo.nthFunction(nthChildIndex + 1); | ||
return nthChildIndex !== -1 && pseudo.nthFunction(nthChildIndex + 1) | ||
? { priorityWeight: 10 } | ||
: null; | ||
case 'nth-of-type': | ||
if (!element[PropertySymbol.parentNode]) { | ||
return false; | ||
return null; | ||
} | ||
@@ -193,11 +208,15 @@ const nthOfTypeIndex = parentChildren | ||
.indexOf(element); | ||
return nthOfTypeIndex !== -1 && pseudo.nthFunction(nthOfTypeIndex + 1); | ||
return nthOfTypeIndex !== -1 && pseudo.nthFunction(nthOfTypeIndex + 1) | ||
? { priorityWeight: 10 } | ||
: null; | ||
case 'nth-last-child': | ||
const nthLastChildIndex = pseudo.selectorItem | ||
const nthLastChildIndex = pseudo.selectorItems[0] | ||
? parentChildren | ||
.filter((child) => pseudo.selectorItem.match(child)) | ||
.filter((child) => pseudo.selectorItems[0].match(child)) | ||
.reverse() | ||
.indexOf(element) | ||
: parentChildren.reverse().indexOf(element); | ||
return nthLastChildIndex !== -1 && pseudo.nthFunction(nthLastChildIndex + 1); | ||
return nthLastChildIndex !== -1 && pseudo.nthFunction(nthLastChildIndex + 1) | ||
? { priorityWeight: 10 } | ||
: null; | ||
case 'nth-last-of-type': | ||
@@ -208,11 +227,29 @@ const nthLastOfTypeIndex = parentChildren | ||
.indexOf(element); | ||
return nthLastOfTypeIndex !== -1 && pseudo.nthFunction(nthLastOfTypeIndex + 1); | ||
return nthLastOfTypeIndex !== -1 && pseudo.nthFunction(nthLastOfTypeIndex + 1) | ||
? { priorityWeight: 10 } | ||
: null; | ||
case 'target': | ||
const hash = element[PropertySymbol.ownerDocument].location.hash; | ||
if (!hash) { | ||
return false; | ||
return null; | ||
} | ||
return element.isConnected && element.id === hash.slice(1); | ||
return element.isConnected && element.id === hash.slice(1) ? { priorityWeight: 10 } : null; | ||
case 'is': | ||
let priorityWeight = 0; | ||
for (const selectorItem of pseudo.selectorItems) { | ||
const match = selectorItem.match(element); | ||
if (match) { | ||
priorityWeight = match.priorityWeight; | ||
} | ||
} | ||
return priorityWeight ? { priorityWeight } : null; | ||
case 'where': | ||
for (const selectorItem of pseudo.selectorItems) { | ||
if (selectorItem.match(element)) { | ||
return { priorityWeight: 0 }; | ||
} | ||
} | ||
return null; | ||
default: | ||
return false; | ||
return null; | ||
} | ||
@@ -219,0 +256,0 @@ } |
@@ -235,3 +235,3 @@ import SelectorItem from './SelectorItem.js'; | ||
if (!args) { | ||
return { name: lowerName, arguments: null, selectorItem: null, nthFunction: null }; | ||
return { name: lowerName, arguments: null, selectorItems: null, nthFunction: null }; | ||
} | ||
@@ -247,3 +247,3 @@ switch (lowerName) { | ||
arguments: args, | ||
selectorItem, | ||
selectorItems: [selectorItem], | ||
nthFunction: this.getPseudoNthFunction(nthFunction) | ||
@@ -256,3 +256,3 @@ }; | ||
arguments: args, | ||
selectorItem: null, | ||
selectorItems: null, | ||
nthFunction: this.getPseudoNthFunction(args) | ||
@@ -264,7 +264,20 @@ }; | ||
arguments: args, | ||
selectorItem: this.getSelectorItem(args), | ||
selectorItems: [this.getSelectorItem(args)], | ||
nthFunction: null | ||
}; | ||
case 'is': | ||
case 'where': | ||
const selectorGroups = this.getSelectorGroups(args); | ||
const selectorItems = []; | ||
for (const group of selectorGroups) { | ||
selectorItems.push(group[0]); | ||
} | ||
return { | ||
name: lowerName, | ||
arguments: args, | ||
selectorItems, | ||
nthFunction: null | ||
}; | ||
default: | ||
return { name: lowerName, arguments: args, selectorItem: null, nthFunction: null }; | ||
return { name: lowerName, arguments: args, selectorItems: null, nthFunction: null }; | ||
} | ||
@@ -271,0 +284,0 @@ } |
{ | ||
"name": "happy-dom", | ||
"version": "14.1.2", | ||
"version": "14.2.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/capricorn86/happy-dom", |
@@ -6,4 +6,4 @@ import SelectorItem from './SelectorItem.js'; | ||
arguments: string | null; | ||
selectorItem: SelectorItem | null; | ||
selectorItems: SelectorItem[] | null; | ||
nthFunction: ((n: number) => boolean) | null; | ||
} |
@@ -100,4 +100,8 @@ import DOMException from '../exception/DOMException.js'; | ||
// Pseudo match | ||
if (this.pseudos && !this.matchPsuedo(element)) { | ||
return null; | ||
if (this.pseudos) { | ||
const result = this.matchPsuedo(element); | ||
if (!result) { | ||
return null; | ||
} | ||
priorityWeight += result.priorityWeight; | ||
} | ||
@@ -114,3 +118,3 @@ | ||
*/ | ||
private matchPsuedo(element: Element): boolean { | ||
private matchPsuedo(element: Element): ISelectorMatch | null { | ||
const parent = <Element>element[PropertySymbol.parentNode]; | ||
@@ -122,5 +126,7 @@ const parentChildren = element[PropertySymbol.parentNode] | ||
if (!this.pseudos) { | ||
return true; | ||
return { priorityWeight: 0 }; | ||
} | ||
let priorityWeight = 0; | ||
for (const pseudo of this.pseudos) { | ||
@@ -153,12 +159,16 @@ // Validation | ||
case 'nth-last-of-type': | ||
return false; | ||
return null; | ||
} | ||
} | ||
if (!this.matchPseudoItem(element, parentChildren, pseudo)) { | ||
return false; | ||
const selectorMatch = this.matchPseudoItem(element, parentChildren, pseudo); | ||
if (!selectorMatch) { | ||
return null; | ||
} | ||
priorityWeight += selectorMatch.priorityWeight; | ||
} | ||
return true; | ||
return { priorityWeight }; | ||
} | ||
@@ -177,17 +187,21 @@ | ||
pseudo: ISelectorPseudo | ||
): boolean { | ||
): ISelectorMatch | null { | ||
switch (pseudo.name) { | ||
case 'first-child': | ||
return parentChildren[0] === element; | ||
return parentChildren[0] === element ? { priorityWeight: 10 } : null; | ||
case 'last-child': | ||
return parentChildren.length && parentChildren[parentChildren.length - 1] === element; | ||
return parentChildren.length && parentChildren[parentChildren.length - 1] === element | ||
? { priorityWeight: 10 } | ||
: null; | ||
case 'only-child': | ||
return parentChildren.length === 1 && parentChildren[0] === element; | ||
return parentChildren.length === 1 && parentChildren[0] === element | ||
? { priorityWeight: 10 } | ||
: null; | ||
case 'first-of-type': | ||
for (const child of parentChildren) { | ||
if (child[PropertySymbol.tagName] === element[PropertySymbol.tagName]) { | ||
return child === element; | ||
return child === element ? { priorityWeight: 10 } : null; | ||
} | ||
} | ||
return false; | ||
return null; | ||
case 'last-of-type': | ||
@@ -197,6 +211,6 @@ for (let i = parentChildren.length - 1; i >= 0; i--) { | ||
if (child[PropertySymbol.tagName] === element[PropertySymbol.tagName]) { | ||
return child === element; | ||
return child === element ? { priorityWeight: 10 } : null; | ||
} | ||
} | ||
return false; | ||
return null; | ||
case 'only-of-type': | ||
@@ -207,3 +221,3 @@ let isFound = false; | ||
if (isFound || child !== element) { | ||
return false; | ||
return null; | ||
} | ||
@@ -213,19 +227,23 @@ isFound = true; | ||
} | ||
return isFound; | ||
return isFound ? { priorityWeight: 10 } : null; | ||
case 'checked': | ||
return element[PropertySymbol.tagName] === 'INPUT' && (<HTMLInputElement>element).checked; | ||
return element[PropertySymbol.tagName] === 'INPUT' && (<HTMLInputElement>element).checked | ||
? { priorityWeight: 10 } | ||
: null; | ||
case 'empty': | ||
return !(<Element>element)[PropertySymbol.children].length; | ||
return !(<Element>element)[PropertySymbol.children].length ? { priorityWeight: 10 } : null; | ||
case 'root': | ||
return element[PropertySymbol.tagName] === 'HTML'; | ||
return element[PropertySymbol.tagName] === 'HTML' ? { priorityWeight: 10 } : null; | ||
case 'not': | ||
return !pseudo.selectorItem.match(element); | ||
return !pseudo.selectorItems[0].match(element) ? { priorityWeight: 10 } : null; | ||
case 'nth-child': | ||
const nthChildIndex = pseudo.selectorItem | ||
? parentChildren.filter((child) => pseudo.selectorItem.match(child)).indexOf(element) | ||
const nthChildIndex = pseudo.selectorItems[0] | ||
? parentChildren.filter((child) => pseudo.selectorItems[0].match(child)).indexOf(element) | ||
: parentChildren.indexOf(element); | ||
return nthChildIndex !== -1 && pseudo.nthFunction(nthChildIndex + 1); | ||
return nthChildIndex !== -1 && pseudo.nthFunction(nthChildIndex + 1) | ||
? { priorityWeight: 10 } | ||
: null; | ||
case 'nth-of-type': | ||
if (!element[PropertySymbol.parentNode]) { | ||
return false; | ||
return null; | ||
} | ||
@@ -235,11 +253,15 @@ const nthOfTypeIndex = parentChildren | ||
.indexOf(element); | ||
return nthOfTypeIndex !== -1 && pseudo.nthFunction(nthOfTypeIndex + 1); | ||
return nthOfTypeIndex !== -1 && pseudo.nthFunction(nthOfTypeIndex + 1) | ||
? { priorityWeight: 10 } | ||
: null; | ||
case 'nth-last-child': | ||
const nthLastChildIndex = pseudo.selectorItem | ||
const nthLastChildIndex = pseudo.selectorItems[0] | ||
? parentChildren | ||
.filter((child) => pseudo.selectorItem.match(child)) | ||
.filter((child) => pseudo.selectorItems[0].match(child)) | ||
.reverse() | ||
.indexOf(element) | ||
: parentChildren.reverse().indexOf(element); | ||
return nthLastChildIndex !== -1 && pseudo.nthFunction(nthLastChildIndex + 1); | ||
return nthLastChildIndex !== -1 && pseudo.nthFunction(nthLastChildIndex + 1) | ||
? { priorityWeight: 10 } | ||
: null; | ||
case 'nth-last-of-type': | ||
@@ -250,11 +272,29 @@ const nthLastOfTypeIndex = parentChildren | ||
.indexOf(element); | ||
return nthLastOfTypeIndex !== -1 && pseudo.nthFunction(nthLastOfTypeIndex + 1); | ||
return nthLastOfTypeIndex !== -1 && pseudo.nthFunction(nthLastOfTypeIndex + 1) | ||
? { priorityWeight: 10 } | ||
: null; | ||
case 'target': | ||
const hash = element[PropertySymbol.ownerDocument].location.hash; | ||
if (!hash) { | ||
return false; | ||
return null; | ||
} | ||
return element.isConnected && element.id === hash.slice(1); | ||
return element.isConnected && element.id === hash.slice(1) ? { priorityWeight: 10 } : null; | ||
case 'is': | ||
let priorityWeight = 0; | ||
for (const selectorItem of pseudo.selectorItems) { | ||
const match = selectorItem.match(element); | ||
if (match) { | ||
priorityWeight = match.priorityWeight; | ||
} | ||
} | ||
return priorityWeight ? { priorityWeight } : null; | ||
case 'where': | ||
for (const selectorItem of pseudo.selectorItems) { | ||
if (selectorItem.match(element)) { | ||
return { priorityWeight: 0 }; | ||
} | ||
} | ||
return null; | ||
default: | ||
return false; | ||
return null; | ||
} | ||
@@ -261,0 +301,0 @@ } |
@@ -250,3 +250,3 @@ import SelectorItem from './SelectorItem.js'; | ||
if (!args) { | ||
return { name: lowerName, arguments: null, selectorItem: null, nthFunction: null }; | ||
return { name: lowerName, arguments: null, selectorItems: null, nthFunction: null }; | ||
} | ||
@@ -264,3 +264,3 @@ | ||
arguments: args, | ||
selectorItem, | ||
selectorItems: [selectorItem], | ||
nthFunction: this.getPseudoNthFunction(nthFunction) | ||
@@ -273,3 +273,3 @@ }; | ||
arguments: args, | ||
selectorItem: null, | ||
selectorItems: null, | ||
nthFunction: this.getPseudoNthFunction(args) | ||
@@ -281,7 +281,20 @@ }; | ||
arguments: args, | ||
selectorItem: this.getSelectorItem(args), | ||
selectorItems: [this.getSelectorItem(args)], | ||
nthFunction: null | ||
}; | ||
case 'is': | ||
case 'where': | ||
const selectorGroups = this.getSelectorGroups(args); | ||
const selectorItems = []; | ||
for (const group of selectorGroups) { | ||
selectorItems.push(group[0]); | ||
} | ||
return { | ||
name: lowerName, | ||
arguments: args, | ||
selectorItems, | ||
nthFunction: null | ||
}; | ||
default: | ||
return { name: lowerName, arguments: args, selectorItem: null, nthFunction: null }; | ||
return { name: lowerName, arguments: args, selectorItems: null, nthFunction: null }; | ||
} | ||
@@ -288,0 +301,0 @@ } |
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
8195369
164321