Skip to content
This repository was archived by the owner on Dec 26, 2018. It is now read-only.

Commit bd6c094

Browse files
committed
map all render errors to the template
1 parent b527242 commit bd6c094

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lib/compiler.js

+26
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,16 @@ compiler.compile = function (content, filePath, cb) {
137137
'should be defined in plain js files using render functions.' +
138138
'")}\n'
139139
}
140+
var beforeLines
141+
if (map) {
142+
beforeLines = output.split(splitRE).length
143+
}
140144
output +=
141145
'__vue__options__.render = ' + template.render + '\n' +
142146
'__vue__options__.staticRenderFns = ' + template.staticRenderFns + '\n'
147+
if (map) {
148+
addTemplateMapping(content, parts, output, map, beforeLines)
149+
}
143150
}
144151
// scoped CSS id
145152
if (hasScopedStyle) {
@@ -205,10 +212,29 @@ compiler.compile = function (content, filePath, cb) {
205212
})
206213
}
207214
})
215+
map._hashedFilename = hashedFilename
208216
return map
209217
}
210218
}
211219

220+
function addTemplateMapping (content, parts, output, map, beforeLines) {
221+
var afterLines = output.split(splitRE).length
222+
var templateLine = content.slice(0, parts.template.start).split(splitRE).length
223+
for (; beforeLines < afterLines; beforeLines++) {
224+
map.addMapping({
225+
source: map._hashedFilename,
226+
generated: {
227+
line: beforeLines,
228+
column: 0
229+
},
230+
original: {
231+
line: templateLine,
232+
column: 0
233+
}
234+
})
235+
}
236+
}
237+
212238
function processTemplate (part, filePath, parts) {
213239
if (!part) return Promise.resolve()
214240
var template = getContent(part, filePath)

0 commit comments

Comments
 (0)