Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit abd0453

Browse files
indirectlylityyx990803
authored andcommitted
pad results with whitespace - re #190 (#230)
* pad results with whitespace - re #190 * address linter issues * fix failing test * remove debug log * move var definition inside else block
1 parent 99be619 commit abd0453

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

‎lib/parser.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,19 @@ module.exports = function (content, filename, needMap) {
9797
var start = node.childNodes[0].__location.startOffset
9898
var end = node.childNodes[node.childNodes.length - 1].__location.endOffset
9999
var result
100-
var lineOffset
101100
if (type === 'script') {
102-
lineOffset = 0
103101
// preserve other parts as commenets so that linters
104102
// and babel can output correct line numbers in warnings
105103
result =
106104
commentScript(content.slice(0, start), lang) +
107105
deindent(content.slice(start, end)) +
108106
commentScript(content.slice(end), lang)
109107
} else {
110-
lineOffset = content.slice(0, start).split(splitRE).length - 1
108+
var lineOffset = content.slice(0, start).split(splitRE).length - 1
111109
result = deindent(content.slice(start, end))
110+
111+
// pad whith whitespace so that error messages are correct
112+
result = Array(lineOffset + 1).join('\n') + result
112113
}
113114

114115
if (needMap) {
@@ -128,7 +129,7 @@ module.exports = function (content, filename, needMap) {
128129
map.addMapping({
129130
source: filenameWithHash,
130131
original: {
131-
line: index + 1 + lineOffset,
132+
line: index + 1,
132133
column: 0
133134
},
134135
generated: {

‎test/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ describe('vue-loader', function () {
215215
}), function (err) {
216216
expect(err).to.be.null
217217
getFile('test.output.css', function (data) {
218-
expect(data).to.contain('h1 {\n color: #f00;\n}\n\nh2 {\n color: green;\n}')
218+
expect(data).to.contain('h1 {\n color: #f00;\n}\n\n\n\n\n\n\nh2 {\n color: green;\n}')
219219
done()
220220
})
221221
})

0 commit comments

Comments
 (0)