fix column numbers
This commit is contained in:
parent
e7b02406fd
commit
4afea4855d
@ -76,7 +76,7 @@ compiled.js.map:
|
|||||||
"file": "compiled.js",
|
"file": "compiled.js",
|
||||||
"sources": ["original.js"],
|
"sources": ["original.js"],
|
||||||
"names": [],
|
"names": [],
|
||||||
"mappings": ";;;AAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"
|
"mappings": ";;;AAAA,MAAM,IAAI"
|
||||||
}
|
}
|
||||||
|
|
||||||
Run compiled.js using node (notice how the stack trace uses original.js instead of compiled.js):
|
Run compiled.js using node (notice how the stack trace uses original.js instead of compiled.js):
|
||||||
|
@ -154,13 +154,13 @@ function wrapCallSite(frame) {
|
|||||||
var position = mapSourcePosition({
|
var position = mapSourcePosition({
|
||||||
source: source,
|
source: source,
|
||||||
line: frame.getLineNumber(),
|
line: frame.getLineNumber(),
|
||||||
column: frame.getColumnNumber()
|
column: frame.getColumnNumber() - 1
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
__proto__: frame,
|
__proto__: frame,
|
||||||
getFileName: function() { return position.source; },
|
getFileName: function() { return position.source; },
|
||||||
getLineNumber: function() { return position.line; },
|
getLineNumber: function() { return position.line; },
|
||||||
getColumnNumber: function() { return position.column; },
|
getColumnNumber: function() { return position.column + 1; },
|
||||||
getScriptNameOrSourceURL: function() { return position.source; }
|
getScriptNameOrSourceURL: function() { return position.source; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -192,25 +192,23 @@ function prepareStackTrace(error, stack) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mimic node's stack trace printing when an exception escapes the process
|
// Mimic node's stack trace printing when an exception escapes the process
|
||||||
function handleUncaughtExceptions(error) {
|
function handleUncaughtException(error) {
|
||||||
if (!error || !error.stack) {
|
if (!error || !error.stack) {
|
||||||
console.log('Uncaught exception:', error);
|
console.log('Uncaught exception:', error);
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
var match = /\n at [^(]+ \((.*):(\d+):(\d+)\)/.exec(error.stack);
|
var match = /\n at [^(]+ \((.*):(\d+):(\d+)\)/.exec(error.stack);
|
||||||
if (match) {
|
if (match) {
|
||||||
var position = mapSourcePosition({
|
var source = match[1];
|
||||||
source: match[1],
|
var line = +match[2];
|
||||||
line: match[2],
|
var column = +match[3];
|
||||||
column: match[3]
|
if (fs.existsSync(source)) {
|
||||||
});
|
var contents = fs.readFileSync(source, 'utf8');
|
||||||
if (fs.existsSync(position.source)) {
|
var code = contents.split(/(?:\r\n|\r|\n)/)[line - 1];
|
||||||
var contents = fs.readFileSync(position.source, 'utf8');
|
if (code) {
|
||||||
var line = contents.split(/(?:\r\n|\r|\n)/)[position.line - 1];
|
console.log('\n' + source + ':' + line);
|
||||||
if (line) {
|
console.log(code);
|
||||||
console.log('\n' + position.source + ':' + position.line);
|
console.log(new Array(column).join(' ') + '^');
|
||||||
console.log(line);
|
|
||||||
console.log(new Array(+position.column).join(' ') + '^');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -225,8 +223,8 @@ exports.install = function(options) {
|
|||||||
|
|
||||||
// Configure options
|
// Configure options
|
||||||
options = options || {};
|
options = options || {};
|
||||||
var installHandler = 'handleUncaughtExceptions' in options ?
|
var installHandler = 'handleUncaughtException' in options ?
|
||||||
options.handleUncaughtExceptions : true;
|
options.handleUncaughtException : true;
|
||||||
emptyCacheBetweenOperations = 'emptyCacheBetweenOperations' in options ?
|
emptyCacheBetweenOperations = 'emptyCacheBetweenOperations' in options ?
|
||||||
options.emptyCacheBetweenOperations : false;
|
options.emptyCacheBetweenOperations : false;
|
||||||
|
|
||||||
@ -243,7 +241,7 @@ exports.install = function(options) {
|
|||||||
// generated JavaScript code will be shown above the stack trace instead of
|
// generated JavaScript code will be shown above the stack trace instead of
|
||||||
// the original source code.
|
// the original source code.
|
||||||
if (installHandler && !isInBrowser()) {
|
if (installHandler && !isInBrowser()) {
|
||||||
process.on('uncaughtException', handleUncaughtExceptions);
|
process.on('uncaughtException', handleUncaughtException);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user