Last active
October 31, 2016 11:41
-
-
Save fizerkhan/6fa49164cbdff17a2331351f36fbe0c6 to your computer and use it in GitHub Desktop.
Validate and get actual line number of the stacktrace using source map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Purpose: | |
// | |
// To validate the source map | |
// To get actual line number of the stack trace | |
// | |
// Usage: | |
// You need to do following | |
// | |
// 1. Copy the source map to the directory where you have this script. | |
// 2. Change source map file in the `fs.readFile` method. | |
// 3. Install source-map package | |
// npm install source-map | |
// 4. Specify the minified line number and column number and 'Save' | |
// 5. Run the script | |
// node sourcemap-checker.js | |
// | |
var sourcemap = require('source-map'), | |
fs = require('fs'); | |
fs.readFile('./myscript.min.js.map', 'utf8', function (err, rawSourceMap) { | |
if (err) { | |
return console.log(err); | |
} | |
var smc = new sourcemap.SourceMapConsumer(rawSourceMap); | |
// List all sources | |
console.log(smc.sources); | |
console.log(smc.originalPositionFor({ | |
line: 4, // Specify minified file line number | |
column: 275 // Specify minified file column number | |
})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment