Skip to content

Instantly share code, notes, and snippets.

@fizerkhan
Last active October 31, 2016 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fizerkhan/6fa49164cbdff17a2331351f36fbe0c6 to your computer and use it in GitHub Desktop.
Save fizerkhan/6fa49164cbdff17a2331351f36fbe0c6 to your computer and use it in GitHub Desktop.
Validate and get actual line number of the stacktrace using source map
//
// 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