(frames: string[])
| 87 | * Get the locations from a list of error stack frames. |
| 88 | */ |
| 89 | const getLocationsFromFrames = (frames: string[]): Location[] => { |
| 90 | // Prepare |
| 91 | const locations: Location[] = [] |
| 92 | |
| 93 | // Cycle through the lines |
| 94 | for (const frame of frames) { |
| 95 | // ensure each line is a string |
| 96 | const line = (frame || "").toString() |
| 97 | |
| 98 | // skip empty lines |
| 99 | if (line.length === 0) continue |
| 100 | |
| 101 | // Error |
| 102 | // at file:///Users/balupton/Projects/active/get-current-line/asd.js:1:13 |
| 103 | // at ModuleJob.run (internal/modules/esm/module_job.js:140:23) |
| 104 | // at async Loader.import (internal/modules/esm/loader.js:165:24) |
| 105 | // at async Object.loadESM (internal/process/esm_loader.js:68:5) |
| 106 | const match = line.match(lineRegex) |
| 107 | if (match && match.groups) { |
| 108 | locations.push({ |
| 109 | method: match.groups.method || "", |
| 110 | file: match.groups.file || "", |
| 111 | line: Number(match.groups.line), |
| 112 | char: Number(match.groups.char) |
| 113 | }) |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | return locations |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * If a location is not found, this is the result that is used. |
no test coverage detected