Blogger 2015
Blogger 2015

Reputation: 149

How to programatically find position in original js file based on position in minified file and sourcemap file?

So if I have script.js (original file), script.minified.js (minified file) and script.minified.js.map (source map file) - how do I find position in original file based on random position in minified file with the help of source map file?

Example:

I have some position in minified file like script.minified.js:100:30 (meaning it's 100th line and 30th column in the minified file)

What I need to retreive:

Corresponding position in original file like script.js:200:30 (meaning it's 200th line and 30th column in the original file)

A pseudo function would look like:

getOriginalPositionFromMinifiedPosition(minifiedJs, originalJs, sourceMapFile, row, column)
returns [originalRow, originalColumn]

There is a similar qestion but it was left unanswered Google Chrome: how to find original line from minified line using a source map?

Upvotes: 1

Views: 823

Answers (1)

Blogger 2015
Blogger 2015

Reputation: 149

Ok, it seems like https://github.com/sokra/source-map-visualization does exactly what I need with mathcing between positions in minified and original files. I knew about this tool but haven't noticed so far it has this functionality as well.

And another tool I've found right now similar to the first one but contains less code. It also performs better with larger source maps compared to the previous project. https://github.com/evanw/source-map-visualization

Upvotes: 1

Related Questions