packages/parse5/lib/parser/index.js
function aaInnerLoop(p, furthestBlock, formattingElement) {
    let lastElement = furthestBlock;
    let nextElement = p.openElements.getCommonAncestor(furthestBlock);

    for (let i = 0, element = nextElement; element !== formattingElement; i++, element = nextElement) {
        //NOTE: store next element for the next loop iteration (it may be deleted from the stack by step 9.5)
        nextElement = p.openElements.getCommonAncestor(element);

        const elementEntry = p.activeFormattingElements.getElementEntry(element);
        const counterOverflow = elementEntry && i >= AA_INNER_LOOP_ITER;
        const shouldRemoveFromOpenElements = !elementEntry || counterOverflow;

        if (shouldRemoveFromOpenElements) {
            if (counterOverflow) {
                p.activeFormattingElements.removeEntry(elementEntry);
            }

            p.openElements.remove(element);
        } else {
            element = aaRecreateElementFromEntry(p, elementEntry);

            if (lastElement === furthestBlock) {
                p.activeFormattingElements.bookmark = elementEntry;
            }

            p.treeAdapter.detachNode(lastElement);
            p.treeAdapter.appendChild(element, lastElement);
            lastElement = element;
        }
    }

    return lastElement;
}
function aaInnerLoop(p, furthestBlock, formattingElement) {
    let lastElement = furthestBlock;
    let nextElement = p.openElements.getCommonAncestor(furthestBlock);

    for (let i = 0, element = nextElement; element !== formattingElement; i++, element = nextElement) {
        //NOTE: store next element for the next loop iteration (it may be deleted from the stack by step 9.5)
        nextElement = p.openElements.getCommonAncestor(element);

        const elementEntry = p.activeFormattingElements.getElementEntry(element);
        const counterOverflow = elementEntry && i >= AA_INNER_LOOP_ITER;
        const shouldRemoveFromOpenElements = !elementEntry || counterOverflow;

        if (shouldRemoveFromOpenElements) {
            if (counterOverflow) {
                p.activeFormattingElements.removeEntry(elementEntry);
            }

            p.openElements.remove(element);
        } else {
            element = aaRecreateElementFromEntry(p, elementEntry);

            if (lastElement === furthestBlock) {
                p.activeFormattingElements.bookmark = elementEntry;
            }

            p.treeAdapter.detachNode(lastElement);
            p.treeAdapter.appendChild(element, lastElement);
            lastElement = element;
        }
    }

    return lastElement;
}
function aaInnerLoop ( p , furthestBlock , formattingElement ) { let lastElement = furthestBlock ; let nextElement = p . openElements . getCommonAncestor ( furthestBlock ) ; for ( let i = 0 , element = nextElement ; element !== formattingElement ; i ++ , element = nextElement ) { //NOTE: store next element for the next loop iteration (it may be deleted from the stack by step 9.5) nextElement = p . openElements . getCommonAncestor ( element ) ; const elementEntry = p . activeFormattingElements . getElementEntry ( element ) ; const counterOverflow = elementEntry && i >= AA_INNER_LOOP_ITER ; const shouldRemoveFromOpenElements = ! elementEntry || counterOverflow ; if ( shouldRemoveFromOpenElements ) { if ( counterOverflow ) { p . activeFormattingElements . removeEntry ( elementEntry ) ; } p . openElements . remove ( element ) ; } else { element = aaRecreateElementFromEntry ( p , elementEntry ) ; if ( lastElement === furthestBlock ) { p . activeFormattingElements . bookmark = elementEntry ; } p . treeAdapter . detachNode ( lastElement ) ; p . treeAdapter . appendChild ( element , lastElement ) ; lastElement = element ; } } return lastElement ; }
Step 13 of the algorithm
Step 13 of the algorithm