* Applies all committed modifications (plus an optional pending one) to the * original source text and returns the result. Modifications are applied in * reverse source order so that each offset remains valid when applied. * @param {{ start: number, end: number, replacement: string } | null} [
(pendingMod)
| 107 | * @returns {string} The modified source text |
| 108 | */ |
| 109 | function buildSource(pendingMod) { |
| 110 | const allMods = pendingMod |
| 111 | ? [...modifications, pendingMod] |
| 112 | : [...modifications]; |
| 113 | |
| 114 | allMods.sort((a, b) => b.start - a.start); |
| 115 | |
| 116 | let result = sourceText; |
| 117 | |
| 118 | for (const { start, end, replacement } of allMods) { |
| 119 | result = result.slice(0, start) + replacement + result.slice(end); |
| 120 | } |
| 121 | |
| 122 | return result; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Recursively removes descendant subtrees of the given AST node and replaces |
no outgoing calls
no test coverage detected
searching dependent graphs…