happy-dom 15.3.0 → 15.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of happy-dom might be problematic. Click here for more details.

@@ -333,7 +333,7 @@ export default class QuerySelector {
333
333
  element[PropertySymbol.cache].matches.set(selector, cachedItem);
334
334
 
335
335
  for (const items of SelectorParser.getSelectorGroups(selector, options)) {
336
- const result = this.matchSelector(element, element, items.reverse(), cachedItem);
336
+ const result = this.matchSelector(element, items.reverse(), cachedItem);
337
337
 
338
338
  if (result) {
339
339
  cachedItem.result.match = result;
@@ -347,22 +347,23 @@ export default class QuerySelector {
347
347
  /**
348
348
  * Checks if a node matches a selector.
349
349
  *
350
- * @param targetElement Target element.
351
- * @param currentElement Current element.
350
+ * @param element Target element.
351
+ * @param currentElement
352
352
  * @param selectorItems Selector items.
353
353
  * @param cachedItem Cached item.
354
+ * @param [previousSelectorItem] Previous selector item.
354
355
  * @param [priorityWeight] Priority weight.
355
356
  * @returns Result.
356
357
  */
357
358
  private static matchSelector(
358
- targetElement: Element,
359
- currentElement: Element,
359
+ element: Element,
360
360
  selectorItems: SelectorItem[],
361
361
  cachedItem: ICachedMatchesItem,
362
+ previousSelectorItem: SelectorItem | null = null,
362
363
  priorityWeight = 0
363
364
  ): ISelectorMatch | null {
364
365
  const selectorItem = selectorItems[0];
365
- const result = selectorItem.match(currentElement);
366
+ const result = selectorItem.match(element);
366
367
 
367
368
  if (result) {
368
369
  if (selectorItems.length === 1) {
@@ -373,14 +374,14 @@ export default class QuerySelector {
373
374
 
374
375
  switch (selectorItem.combinator) {
375
376
  case SelectorCombinatorEnum.adjacentSibling:
376
- const previousElementSibling = currentElement.previousElementSibling;
377
+ const previousElementSibling = element.previousElementSibling;
377
378
  if (previousElementSibling) {
378
379
  previousElementSibling[PropertySymbol.affectsCache].push(cachedItem);
379
380
  const match = this.matchSelector(
380
- targetElement,
381
381
  previousElementSibling,
382
382
  selectorItems.slice(1),
383
383
  cachedItem,
384
+ selectorItem,
384
385
  priorityWeight + result.priorityWeight
385
386
  );
386
387
 
@@ -391,16 +392,18 @@ export default class QuerySelector {
391
392
  break;
392
393
  case SelectorCombinatorEnum.child:
393
394
  case SelectorCombinatorEnum.descendant:
394
- const parentElement = currentElement.parentElement;
395
+ const parentElement = element.parentElement;
395
396
  if (parentElement) {
396
397
  parentElement[PropertySymbol.affectsCache].push(cachedItem);
398
+
397
399
  const match = this.matchSelector(
398
- targetElement,
399
400
  parentElement,
400
401
  selectorItems.slice(1),
401
402
  cachedItem,
403
+ selectorItem,
402
404
  priorityWeight + result.priorityWeight
403
405
  );
406
+
404
407
  if (match) {
405
408
  return match;
406
409
  }
@@ -409,19 +412,17 @@ export default class QuerySelector {
409
412
  }
410
413
  }
411
414
 
412
- const parentElement = currentElement.parentElement;
413
- if (
414
- selectorItem.combinator === SelectorCombinatorEnum.descendant &&
415
- targetElement !== currentElement &&
416
- parentElement
417
- ) {
418
- return this.matchSelector(
419
- targetElement,
420
- parentElement,
421
- selectorItems,
422
- cachedItem,
423
- priorityWeight
424
- );
415
+ if (previousSelectorItem?.combinator === SelectorCombinatorEnum.descendant) {
416
+ const parentElement = element.parentElement;
417
+ if (parentElement) {
418
+ return this.matchSelector(
419
+ parentElement,
420
+ selectorItems,
421
+ cachedItem,
422
+ previousSelectorItem,
423
+ priorityWeight
424
+ );
425
+ }
425
426
  }
426
427
 
427
428
  return null;