Skip to content

Commit 182c04d

Browse files
segreyjohnjbarton
authored andcommitted
fix(reporter): format stack with 1-based column (#3325)
Columns in original stack are 1-based, but SourceMapConsumer.prototype.originalPositionFor(generatedPosition) accepts 0-based column and returns 0-based column too. This change converts columns from 1-based to 0-based forth and back. Closes #3324
1 parent f0c4677 commit 182c04d

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/reporter.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ function createErrorFormatter (config, emitter, SourceMapConsumer) {
6060
const bias = column ? SourceMapConsumer.GREATEST_LOWER_BOUND : SourceMapConsumer.LEAST_UPPER_BOUND
6161

6262
try {
63-
const original = getSourceMapConsumer(file.sourceMap).originalPositionFor({ line, column: (column || 0), bias })
63+
const zeroBasedColumn = Math.max(0, (column || 1) - 1)
64+
const original = getSourceMapConsumer(file.sourceMap).originalPositionFor({ line, column: zeroBasedColumn, bias })
6465

6566
// Source maps often only have a local file name, resolve to turn into a full path if
6667
// the path is not absolute yet.
67-
return `${PathUtils.formatPathMapping(resolve(path, original.source), original.line, original.column)} <- ${PathUtils.formatPathMapping(path, line, column)}`
68+
const oneBasedOriginalColumn = original.column == null ? original.column : original.column + 1
69+
return `${PathUtils.formatPathMapping(resolve(path, original.source), original.line, oneBasedOriginalColumn)} <- ${PathUtils.formatPathMapping(path, line, column)}`
6870
} catch (e) {
6971
log.warn(`SourceMap position not found for trace: ${input}`)
7072
}

test/unit/reporter.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ describe('reporter', () => {
195195

196196
_.defer(() => {
197197
const ERROR = 'at http://localhost:123/base/b.js:2'
198-
expect(formatError(ERROR)).to.equal('at /original/b.js:4:2 <- b.js:2\n')
198+
expect(formatError(ERROR)).to.equal('at /original/b.js:4:3 <- b.js:2\n')
199199
done()
200200
})
201201
})

0 commit comments

Comments
 (0)