diff --git a/Libraries/Core/Devtools/symbolicateStackTrace.js b/Libraries/Core/Devtools/symbolicateStackTrace.js index 2e544149d7..7be076b3de 100644 --- a/Libraries/Core/Devtools/symbolicateStackTrace.js +++ b/Libraries/Core/Devtools/symbolicateStackTrace.js @@ -18,27 +18,38 @@ const {fetch} = require('fetch'); import type {StackFrame} from 'parseErrorStack'; +function isSourcedFromDisk(sourcePath: string): boolean { + return !/^http/.test(sourcePath) && /[\\/]/.test(sourcePath); +} + async function symbolicateStackTrace(stack: Array): Promise> { const devServer = getDevServer(); if (!devServer.bundleLoadedFromServer) { throw new Error('Bundle was not loaded from the packager'); } + + let stackCopy = stack; + if (SourceCode.scriptURL) { - for (let i = 0; i < stack.length; ++i) { + let foundInternalSource: boolean = false; + stackCopy = stack.map((frame: StackFrame) => { // If the sources exist on disk rather than appearing to come from the packager, // replace the location with the packager URL until we reach an internal source // which does not have a path (no slashes), indicating a switch from within // the application to a surrounding debugging environment. - if (/^http/.test(stack[i].file) || !/[\\/]/.test(stack[i].file)) { - break; + if (!foundInternalSource && isSourcedFromDisk(frame.file)) { + // Copy frame into new object and replace 'file' property + return {...frame, file: SourceCode.scriptURL}; } - stack[i].file = SourceCode.scriptURL; - } + + foundInternalSource = true; + return frame; + }); } const response = await fetch(devServer.url + 'symbolicate', { method: 'POST', - body: JSON.stringify({stack}), + body: JSON.stringify({stack: stackCopy}), }); const json = await response.json(); return json.stack;