* Drops spans that are fully contained within another span, keeping only the * outermost. Nested quotes (e.g., `"$(echo 'hi')"`) yield overlapping spans * — the inner raw_string is found by recursing into the outer string node. * Processing overlapping spans corrupts indices since removing/replac
( spans: T[], )
| 157 | * outer span shifts the inner span's start/end into stale positions. |
| 158 | */ |
| 159 | function dropContainedSpans<T extends readonly [number, number, ...unknown[]]>( |
| 160 | spans: T[], |
| 161 | ): T[] { |
| 162 | return spans.filter( |
| 163 | (s, i) => |
| 164 | !spans.some( |
| 165 | (other, j) => |
| 166 | j !== i && |
| 167 | other[0] <= s[0] && |
| 168 | other[1] >= s[1] && |
| 169 | (other[0] < s[0] || other[1] > s[1]), |
| 170 | ), |
| 171 | ) |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Removes spans from a string, returning the string with those character |
no outgoing calls
no test coverage detected