Skip to content

Commit

Permalink
Error locations should be 1-based instead of 0-based (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrantly committed May 28, 2015
1 parent 56fc843 commit 39f52bd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function handleErrors(diagnostics: typescript.Diagnostic[], compiler: typeof typ
var messageText = compiler.flattenDiagnosticMessageText(diagnostic.messageText, os.EOL);
if (diagnostic.file) {
var lineChar = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
outputFn(` ${diagnostic.file.fileName.blue} (${lineChar.line.toString().cyan},${lineChar.character.toString().cyan}): ${messageText.red}`)
outputFn(` ${diagnostic.file.fileName.blue} (${(lineChar.line+1).toString().cyan},${(lineChar.character+1).toString().cyan}): ${messageText.red}`)
}
else {
outputFn(` ${"unknown file".blue}: ${messageText.red}`)
Expand Down
1 change: 1 addition & 0 deletions test/errorlocation/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var a == 0;
16 changes: 16 additions & 0 deletions test/errorlocation/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
context: __dirname,
entry: './app.ts',
output: {
path: __dirname,
filename: 'bundle.js'
},
resolve: {
extensions: ['', '.js', '.ts']
},
module: {
loaders: [
{ test: /\.ts$/, loader: '../../index.js?instance=errorlocation' }
]
}
}
18 changes: 17 additions & 1 deletion test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var path = require('path');
var newLine = require('os').EOL;
var tsLoader = require('../index');
var webpack = require('webpack');
var colors = require('colors');

function handleErrors(err, stats, done) {
if (err) {
Expand Down Expand Up @@ -89,6 +90,21 @@ describe('externals', function() {
})
})

describe('errorlocation', function() {
it('should report correct error location', function(done) {
webpack(require('./errorlocation/webpack.config')).run(function(err, stats) {
if (err) return done(err)

var errors = stats.toJson().errors;

assert.equal(errors.length, 2, 'Exactly two errors should be reported');
assert.ok(colors.strip(errors[0]).indexOf(" (1,7): ") != -1, 'The error reported was in the wrong location');

done();
})
})
})

describe('instance', function() {
it('should error when incorrectly configured', function(done) {
webpack(require('./instance/bad.config')).run(function(err, stats) {
Expand Down Expand Up @@ -260,4 +276,4 @@ describe('tsconfigSearch', function() {
}
})
})
})
})

0 comments on commit 39f52bd

Please sign in to comment.