diff --git a/lib/parser.js b/lib/parser.js index de7f533fd..a353635d1 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -97,9 +97,7 @@ module.exports = function (content, filename, needMap) { var start = node.childNodes[0].__location.startOffset var end = node.childNodes[node.childNodes.length - 1].__location.endOffset var result - var lineOffset if (type === 'script') { - lineOffset = 0 // preserve other parts as commenets so that linters // and babel can output correct line numbers in warnings result = @@ -107,8 +105,11 @@ module.exports = function (content, filename, needMap) { deindent(content.slice(start, end)) + commentScript(content.slice(end), lang) } else { - lineOffset = content.slice(0, start).split(splitRE).length - 1 + var lineOffset = content.slice(0, start).split(splitRE).length - 1 result = deindent(content.slice(start, end)) + + // pad whith whitespace so that error messages are correct + result = Array(lineOffset + 1).join('\n') + result } if (needMap) { @@ -128,7 +129,7 @@ module.exports = function (content, filename, needMap) { map.addMapping({ source: filenameWithHash, original: { - line: index + 1 + lineOffset, + line: index + 1, column: 0 }, generated: { diff --git a/test/test.js b/test/test.js index 959ab05d5..038dc6c04 100644 --- a/test/test.js +++ b/test/test.js @@ -215,7 +215,7 @@ describe('vue-loader', function () { }), function (err) { expect(err).to.be.null getFile('test.output.css', function (data) { - expect(data).to.contain('h1 {\n color: #f00;\n}\n\nh2 {\n color: green;\n}') + expect(data).to.contain('h1 {\n color: #f00;\n}\n\n\n\n\n\n\nh2 {\n color: green;\n}') done() }) })