···478478 }
479479480480 // Match elements by isEqualNode
481481- for (const i of unmatchedElements) {
482482- const element = toChildNodes[i] as Element
481481+ for (const unmatchedIndex of unmatchedElements) {
482482+ const element = toChildNodes[unmatchedIndex] as Element
483483484484 for (const candidateIndex of candidateElements) {
485485 const candidate = fromChildNodes[candidateIndex]!
486486 if (candidate.isEqualNode(element)) {
487487- matches[i] = candidate
487487+ matches[unmatchedIndex] = candidate
488488 candidateElements.delete(candidateIndex)
489489- unmatchedElements.delete(i)
489489+ unmatchedElements.delete(unmatchedIndex)
490490 break
491491 }
492492 }
493493 }
494494495495 // Match by exact id
496496- for (const i of unmatchedElements) {
497497- const element = toChildNodes[i] as Element
496496+ for (const unmatchedIndex of unmatchedElements) {
497497+ const element = toChildNodes[unmatchedIndex] as Element
498498499499 const id = element.id
500500 if (id === "") continue
···502502 for (const candidateIndex of candidateElements) {
503503 const candidate = fromChildNodes[candidateIndex] as Element
504504 if (element.localName === candidate.localName && id === candidate.id) {
505505- matches[i] = candidate
505505+ matches[unmatchedIndex] = candidate
506506 candidateElements.delete(candidateIndex)
507507- unmatchedElements.delete(i)
507507+ unmatchedElements.delete(unmatchedIndex)
508508 break
509509 }
510510 }
511511 }
512512513513 // Match by idSet
514514- for (const i of unmatchedElements) {
515515- const element = toChildNodes[i] as Element
514514+ for (const unmatchedIndex of unmatchedElements) {
515515+ const element = toChildNodes[unmatchedIndex] as Element
516516517517 const idSet = this.#idMap.get(element)
518518 if (!idSet) continue
···523523 if (candidateIdSet) {
524524 for (const id of idSet) {
525525 if (candidateIdSet.has(id)) {
526526- matches[i] = candidate
526526+ matches[unmatchedIndex] = candidate
527527 candidateElements.delete(candidateIndex)
528528- unmatchedElements.delete(i)
528528+ unmatchedElements.delete(unmatchedIndex)
529529 break candidateLoop
530530 }
531531 }
···534534 }
535535536536 // Match by heuristics
537537- for (const i of unmatchedElements) {
538538- const element = toChildNodes[i] as Element
537537+ for (const unmatchedIndex of unmatchedElements) {
538538+ const element = toChildNodes[unmatchedIndex] as Element
539539540540 const name = element.getAttribute("name")
541541 const href = element.getAttribute("href")
···549549 (href && href === candidate.getAttribute("href")) ||
550550 (src && src === candidate.getAttribute("src")))
551551 ) {
552552- matches[i] = candidate
552552+ matches[unmatchedIndex] = candidate
553553 candidateElements.delete(candidateIndex)
554554- unmatchedElements.delete(i)
554554+ unmatchedElements.delete(unmatchedIndex)
555555 break
556556 }
557557 }
558558 }
559559560560 // Match by tagName
561561- for (const i of unmatchedElements) {
562562- const element = toChildNodes[i] as Element
561561+ for (const unmatchedIndex of unmatchedElements) {
562562+ const element = toChildNodes[unmatchedIndex] as Element
563563564564 const localName = element.localName
565565···570570 // Treat inputs with different type as though they are different tags.
571571 continue
572572 }
573573- matches[i] = candidate
573573+ matches[unmatchedIndex] = candidate
574574 candidateElements.delete(candidateIndex)
575575- unmatchedElements.delete(i)
575575+ unmatchedElements.delete(unmatchedIndex)
576576 break
577577 }
578578 }
579579 }
580580581581 // Match nodes by isEqualNode (skip whitespace-only text nodes)
582582- for (const i of unmatchedNodes) {
583583- const node = toChildNodes[i]!
582582+ for (const unmatchedIndex of unmatchedNodes) {
583583+ const node = toChildNodes[unmatchedIndex]!
584584 if (isWhitespace(node)) continue
585585586586 for (const candidateIndex of candidateNodes) {
587587 const candidate = fromChildNodes[candidateIndex]!
588588 if (candidate.isEqualNode(node)) {
589589- matches[i] = candidate
589589+ matches[unmatchedIndex] = candidate
590590 candidateNodes.delete(candidateIndex)
591591- unmatchedNodes.delete(i)
591591+ unmatchedNodes.delete(unmatchedIndex)
592592 break
593593 }
594594 }
595595 }
596596597597 // Match by nodeType (skip whitespace-only text nodes)
598598- for (const i of unmatchedNodes) {
599599- const node = toChildNodes[i]!
598598+ for (const unmatchedIndex of unmatchedNodes) {
599599+ const node = toChildNodes[unmatchedIndex]!
600600 if (isWhitespace(node)) continue
601601602602 const nodeType = node.nodeType
···604604 for (const candidateIndex of candidateNodes) {
605605 const candidate = fromChildNodes[candidateIndex]!
606606 if (nodeType === candidate.nodeType) {
607607- matches[i] = candidate
607607+ matches[unmatchedIndex] = candidate
608608 candidateNodes.delete(candidateIndex)
609609- unmatchedNodes.delete(i)
609609+ unmatchedNodes.delete(unmatchedIndex)
610610 break
611611 }
612612 }