* Get the source location of an error. If source map is enabled, resolve the source location * based on the source map. * * The `error.stack` must not have been accessed. The resolution is based on the structured * error stack data. * @param {Error|object} error An error object, or an object be
(error)
| 24 | * @returns {{sourceLine: string, startColumn: number}|undefined} |
| 25 | */ |
| 26 | function getErrorSourceLocation(error) { |
| 27 | const pos = getErrorSourcePositions(error); |
| 28 | const { |
| 29 | sourceLine, |
| 30 | scriptResourceName, |
| 31 | lineNumber, |
| 32 | startColumn, |
| 33 | } = pos; |
| 34 | |
| 35 | // Source map is not enabled. Return the source line directly. |
| 36 | if (!getSourceMapsSupport().enabled) { |
| 37 | return { sourceLine, startColumn }; |
| 38 | } |
| 39 | |
| 40 | const sm = findSourceMap(scriptResourceName); |
| 41 | if (sm === undefined) { |
| 42 | return; |
| 43 | } |
| 44 | const { |
| 45 | originalLine, |
| 46 | originalColumn, |
| 47 | originalSource, |
| 48 | } = sm.findEntry(lineNumber - 1, startColumn); |
| 49 | const originalSourceLine = getSourceLine(sm, originalSource, originalLine, originalColumn); |
| 50 | |
| 51 | if (!originalSourceLine) { |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | return { |
| 56 | sourceLine: originalSourceLine, |
| 57 | startColumn: originalColumn, |
| 58 | }; |
| 59 | } |
| 60 | |
| 61 | const memberAccessTokens = [ '.', '?.', '[', ']' ]; |
| 62 | const memberNameTokens = [ 'name', 'string', 'num' ]; |
no test coverage detected
searching dependent graphs…