Skip to content

Commit abd0453

Browse files
indirectlylityyx990803
authored andcommitted
pad results with whitespace - re vuejs#190 (vuejs#230)
* pad results with whitespace - re vuejs#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

Lines changed: 5 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy