( node: Node, cb: (el: Element) => void | false, )
| 111 | } |
| 112 | |
| 113 | export function forEachElement( |
| 114 | node: Node, |
| 115 | cb: (el: Element) => void | false, |
| 116 | ): void { |
| 117 | // fragment |
| 118 | if (isComment(node) && node.data === '[') { |
| 119 | let depth = 1 |
| 120 | let next = node.nextSibling |
| 121 | while (next) { |
| 122 | if (next.nodeType === DOMNodeTypes.ELEMENT) { |
| 123 | const result = cb(next as Element) |
| 124 | if (result === false) { |
| 125 | break |
| 126 | } |
| 127 | } else if (isComment(next)) { |
| 128 | if (next.data === ']') { |
| 129 | if (--depth === 0) break |
| 130 | } else if (next.data === '[') { |
| 131 | depth++ |
| 132 | } |
| 133 | } |
| 134 | next = next.nextSibling |
| 135 | } |
| 136 | } else { |
| 137 | cb(node as Element) |
| 138 | } |
| 139 | } |
no test coverage detected