(locations: Array<Location>, offset: Offset)
| 132 | * If none are found, return the failure location |
| 133 | */ |
| 134 | const getLocationWithOffset = (locations: Array<Location>, offset: Offset) => { |
| 135 | // Continue |
| 136 | let found: boolean = !offset.file && !offset.method |
| 137 | |
| 138 | // use while loop so we can skip ahead |
| 139 | let i = 0 |
| 140 | while (i < locations.length) { |
| 141 | const location = locations[i] |
| 142 | |
| 143 | // the current location matches the offset |
| 144 | if ( |
| 145 | (offset.file && |
| 146 | (typeof offset.file === "string" ? |
| 147 | location.file.includes(offset.file) |
| 148 | : offset.file.test(location.file))) || |
| 149 | (offset.method && |
| 150 | (typeof offset.method === "string" ? |
| 151 | location.method.includes(offset.method) |
| 152 | : offset.method.test(location.method))) |
| 153 | ) { |
| 154 | // we are found, and we should exit immediatelyg, so return with the frame offset applied |
| 155 | if (offset.immediate) { |
| 156 | // apply frame offset |
| 157 | i += offset.frames || 0 |
| 158 | // and return the result |
| 159 | return locations[i] |
| 160 | } |
| 161 | // otherwise, continue until the found condition has exited |
| 162 | else { |
| 163 | found = true |
| 164 | ++i |
| 165 | continue |
| 166 | } |
| 167 | } |
| 168 | // has been found, and the found condition has exited, so return with the frame offset applied |
| 169 | else if (found) { |
| 170 | // apply frame offset |
| 171 | i += offset.frames || 0 |
| 172 | // and return the result |
| 173 | return locations[i] |
| 174 | } |
| 175 | // nothing has been found yet, so continue until we find the offset |
| 176 | else { |
| 177 | ++i |
| 178 | continue |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | // return failure |
| 183 | return failureLocation |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Get each error stack frame's location information. |
no test coverage detected