(node, source, snippetLen, full)
| 170 | } |
| 171 | |
| 172 | function renderSnippet(node, source, snippetLen, full) { |
| 173 | if (typeof node.__startOffset !== 'number') { |
| 174 | try { |
| 175 | return new XMLSerializer().serializeToString(node) |
| 176 | } catch { |
| 177 | return `<${node.nodeName || '?'}>` |
| 178 | } |
| 179 | } |
| 180 | const start = node.__startOffset |
| 181 | const end = node.__endOffset ?? start |
| 182 | if (full) return source.slice(start, end) |
| 183 | |
| 184 | const tagEnd = node.__startTagEndOffset ?? end |
| 185 | const openingTag = source.slice(start, tagEnd) |
| 186 | if (end <= tagEnd) return openingTag |
| 187 | |
| 188 | const totalLen = end - start |
| 189 | if (totalLen <= snippetLen) return source.slice(start, end) |
| 190 | |
| 191 | const remaining = Math.max(0, snippetLen - openingTag.length) |
| 192 | if (remaining < 20) return openingTag + ' …' |
| 193 | return openingTag + source.slice(tagEnd, tagEnd + remaining) + ' …' |
| 194 | } |
| 195 | |
| 196 | function readStdin() { |
| 197 | return new Promise((resolve, reject) => { |
no outgoing calls
no test coverage detected
searching dependent graphs…