sourcemapped-stacktrace icon indicating copy to clipboard operation
sourcemapped-stacktrace copied to clipboard

Allow preserving original source context

Open lared opened this issue 6 years ago • 0 comments

Consider the following code:

setTimeout(() => dupa(), 0);

function dupa() {
  jaś();
}

function jaś() {
  throw new TypeError("whatever");
}

When minified and executed in chrome without any source maps, this generates stacktrace with the following content (more or less):

TypeError: whatever
    at jaś(bundle.js:8:12)
    at dupa(bundle.js:4:4)
    at setTimeout(bundle.js:1:17)

Note that the names refer to the actual context in which code is executed, but the locations themselves refer to the places where execution of another function occurred, or where the exception was defined (as expected of course). When translating the stacktraces, in some cases (I haven't extensively tested it, likely depends on the source map) names will be replaced with the names of functions being called:

    at TypeError(index.ts:8:12)
    at jaś(index.ts:4:4)
    at dupa(index.ts:1:17)

Which can be a tad bit annoying since it doesn't contain the root context of the issue (where was dupa called from? You have to look at index.ts to find out).

It would be nice if there was some sort of an option like preserveOriginalContext, by default set to false (after all tooling can rename functions), which would allow preserving original context as reported by the browser.

I'll try to provide a reproducible sample later this week, and if you approve of the idea - a PR

lared avatar Feb 04 '19 09:02 lared