* Turns a set of mapped StackFrame s back into their generated code position and enhances them with code. * @param {string} fileUri The URI of the bundle.js file. * @param {StackFrame[]} frames A set of StackFrame s which are already mapped and missing their ge
(
_fileUri: string | { uri: string, contents: string },
frames: StackFrame[],
contextLines: number = 3
)
| 32 | * @param {number} [fileContents=3] The number of lines to provide before and after the line specified in the <code>StackFrame</code>. |
| 33 | */ |
| 34 | async function unmap( |
| 35 | _fileUri: string | { uri: string, contents: string }, |
| 36 | frames: StackFrame[], |
| 37 | contextLines: number = 3 |
| 38 | ): Promise<StackFrame[]> { |
| 39 | let fileContents = typeof _fileUri === 'object' ? _fileUri.contents : null; |
| 40 | let fileUri = typeof _fileUri === 'object' ? _fileUri.uri : _fileUri; |
| 41 | if (fileContents == null) { |
| 42 | fileContents = await fetch(fileUri).then(res => res.text()); |
| 43 | } |
| 44 | const map = await getSourceMap(fileUri, fileContents); |
| 45 | return frames.map(frame => { |
| 46 | const { |
| 47 | functionName, |
| 48 | lineNumber, |
| 49 | columnNumber, |
| 50 | _originalLineNumber, |
| 51 | } = frame; |
| 52 | if (_originalLineNumber != null) { |
| 53 | return frame; |
| 54 | } |
| 55 | let { fileName } = frame; |
| 56 | if (fileName) { |
| 57 | // The web version of this module only provides POSIX support, so Windows |
| 58 | // paths like C:\foo\\baz\..\\bar\ cannot be normalized. |
| 59 | // A simple solution to this is to replace all `\` with `/`, then |
| 60 | // normalize afterwards. |
| 61 | fileName = path.normalize(fileName.replace(/[\\]+/g, '/')); |
| 62 | } |
| 63 | if (fileName == null) { |
| 64 | return frame; |
| 65 | } |
| 66 | const fN: string = fileName; |
| 67 | const source = map |
| 68 | .getSources() |
| 69 | // Prepare path for normalization; see comment above for reasoning. |
| 70 | .map(s => s.replace(/[\\]+/g, '/')) |
| 71 | .filter(p => { |
| 72 | p = path.normalize(p); |
| 73 | const i = p.lastIndexOf(fN); |
| 74 | return i !== -1 && i === p.length - fN.length; |
| 75 | }) |
| 76 | .map(p => ({ |
| 77 | token: p, |
| 78 | seps: count(path.sep, path.normalize(p)), |
| 79 | penalties: count('node_modules', p) + count('~', p), |
| 80 | })) |
| 81 | .sort((a, b) => { |
| 82 | const s = Math.sign(a.seps - b.seps); |
| 83 | if (s !== 0) { |
| 84 | return s; |
| 85 | } |
| 86 | return Math.sign(a.penalties - b.penalties); |
| 87 | }); |
| 88 | if (source.length < 1 || lineNumber == null) { |
| 89 | return new StackFrame( |
| 90 | null, |
| 91 | null, |
no test coverage detected