* @param {!Node} root
(root)
| 1778 | * @param {!Node} root |
| 1779 | */ |
| 1780 | constructor(root) { |
| 1781 | const doc = devAssert( |
| 1782 | root.nodeType == Node.DOCUMENT_NODE ? root : root.ownerDocument, |
| 1783 | 'ownerDocument is null.' |
| 1784 | ); |
| 1785 | |
| 1786 | const useQuerySelector = |
| 1787 | doc.documentElement.hasAttribute('i-amphtml-binding'); |
| 1788 | /** @private @const {boolean} */ |
| 1789 | this.useQuerySelector_ = useQuerySelector; |
| 1790 | |
| 1791 | /** @type {!Node} */ |
| 1792 | this.currentNode = root; |
| 1793 | |
| 1794 | /** @private {number} */ |
| 1795 | this.index_ = 0; |
| 1796 | |
| 1797 | /** @private @const {!Array<!Element>} */ |
| 1798 | this.nodeList_ = useQuerySelector |
| 1799 | ? toArray(root.querySelectorAll('[i-amphtml-binding]')) |
| 1800 | : []; |
| 1801 | |
| 1802 | // Confusingly, the old TreeWalker hit the root node. We need to match that behavior. |
| 1803 | if ( |
| 1804 | useQuerySelector && |
| 1805 | root.nodeType === Node.ELEMENT_NODE && |
| 1806 | root.hasAttribute('i-amphtml-binding') |
| 1807 | ) { |
| 1808 | this.nodeList_.unshift(root); |
| 1809 | } |
| 1810 | |
| 1811 | /** |
| 1812 | * Third and fourth params of `createTreeWalker` are not optional on IE11. |
| 1813 | * @private @const {?TreeWalker} |
| 1814 | */ |
| 1815 | this.treeWalker_ = useQuerySelector |
| 1816 | ? null |
| 1817 | : doc.createTreeWalker( |
| 1818 | root, |
| 1819 | NodeFilter.SHOW_ELEMENT, |
| 1820 | null, |
| 1821 | /* entityReferenceExpansion */ false |
| 1822 | ); |
| 1823 | } |
| 1824 | |
| 1825 | /** |
| 1826 | * Finds the next node in document order, if it exists. Returns that node, or null if it doesn't exist. |