Skip to content

Instantly share code, notes, and snippets.

@vongohren
Created April 27, 2017 11:41
Show Gist options
  • Save vongohren/5619e7ab9a2f6b352f66c996fc908a86 to your computer and use it in GitHub Desktop.
Save vongohren/5619e7ab9a2f6b352f66c996fc908a86 to your computer and use it in GitHub Desktop.
var fs = require('fs'),
path = require('path'),
sourceMap = require('source-map');
var line = process.argv[2];
var column = process.argv[3];
var file = process.argv[4];
// file output by Webpack, Uglify, etc.
var GENERATED_FILE = path.join('.', file);
// line and column located in your generated file (e.g. source of your error
// from your minified file)
var GENERATED_LINE_AND_COLUMN = {line: line, column: column};
var rawSourceMap = fs.readFileSync(GENERATED_FILE).toString();
var smc = new sourceMap.SourceMapConsumer(rawSourceMap);
var pos = smc.originalPositionFor(GENERATED_LINE_AND_COLUMN);
// should see something like:
// { source: 'original.js', line: 57, column: 9, name: 'myfunc' }
console.log(pos);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment