()
| 129 | |
| 130 | // Main worker method. checks all permutations of a given edit length for acceptance. |
| 131 | const execEditLength = () => { |
| 132 | for ( |
| 133 | let diagonalPath = Math.max(minDiagonalToConsider, -editLength); |
| 134 | diagonalPath <= Math.min(maxDiagonalToConsider, editLength); |
| 135 | diagonalPath += 2 |
| 136 | ) { |
| 137 | let basePath; |
| 138 | const removePath = bestPath[diagonalPath - 1], |
| 139 | addPath = bestPath[diagonalPath + 1]; |
| 140 | if (removePath) { |
| 141 | // No one else is going to attempt to use this value, clear it |
| 142 | // @ts-expect-error - perf optimisation. This type-violating value will never be read. |
| 143 | bestPath[diagonalPath - 1] = undefined; |
| 144 | } |
| 145 | |
| 146 | let canAdd = false; |
| 147 | if (addPath) { |
| 148 | // what newPos will be after we do an insertion: |
| 149 | const addPathNewPos = addPath.oldPos - diagonalPath; |
| 150 | canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen; |
| 151 | } |
| 152 | |
| 153 | const canRemove = removePath && removePath.oldPos + 1 < oldLen; |
| 154 | if (!canAdd && !canRemove) { |
| 155 | // If this path is a terminal then prune |
| 156 | // @ts-expect-error - perf optimisation. This type-violating value will never be read. |
| 157 | bestPath[diagonalPath] = undefined; |
| 158 | continue; |
| 159 | } |
| 160 | |
| 161 | // Select the diagonal that we want to branch from. We select the prior |
| 162 | // path whose position in the old string is the farthest from the origin |
| 163 | // and does not pass the bounds of the diff graph |
| 164 | if (!canRemove || (canAdd && removePath.oldPos < addPath.oldPos)) { |
| 165 | basePath = this.addToPath(addPath, true, false, 0, options); |
| 166 | } else { |
| 167 | basePath = this.addToPath(removePath, false, true, 1, options); |
| 168 | } |
| 169 | |
| 170 | newPos = this.extractCommon(basePath, newTokens, oldTokens, diagonalPath, options); |
| 171 | |
| 172 | if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) { |
| 173 | // If we have hit the end of both strings, then we are done |
| 174 | return done(this.buildValues(basePath.lastComponent, newTokens, oldTokens)) || true; |
| 175 | } else { |
| 176 | bestPath[diagonalPath] = basePath; |
| 177 | if (basePath.oldPos + 1 >= oldLen) { |
| 178 | maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1); |
| 179 | } |
| 180 | if (newPos + 1 >= newLen) { |
| 181 | minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1); |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | editLength++; |
| 187 | }; |
| 188 |
nothing calls this directly
no test coverage detected