@@ -211,9 +211,13 @@ function isScoped (node) {
211
211
*/
212
212
213
213
function processTemplate ( node , filePath , id , hasScopedStyle , fullSource ) {
214
- var template = checkSrc ( node , filePath ) || parse5 . serialize ( node . content )
215
- template = deindent ( template )
216
214
var lang = checkLang ( node )
215
+ var template = checkSrc ( node , filePath ) || (
216
+ lang
217
+ ? getRawTemplate ( node , fullSource ) // custom template, extract as raw string
218
+ : parse5 . serialize ( node . content ) // normal HTML, use serialization
219
+ )
220
+ template = deindent ( template )
217
221
if ( ! lang ) {
218
222
var warnings = validateTemplate ( node . content , fullSource )
219
223
if ( warnings ) {
@@ -239,6 +243,25 @@ function processTemplate (node, filePath, id, hasScopedStyle, fullSource) {
239
243
} )
240
244
}
241
245
246
+ /**
247
+ * Extract the raw content of a template node.
248
+ * This is more reliable because if the user uses a template language
249
+ * that would confuse parse5 (e.g. ejs), the serialization result
250
+ * would be different from original.
251
+ *
252
+ * @param {Node } node
253
+ * @param {String } source
254
+ */
255
+
256
+ function getRawTemplate ( node , source ) {
257
+ var content = node . content
258
+ var l = content . childNodes . length
259
+ if ( ! l ) return ''
260
+ var start = content . childNodes [ 0 ] . __location . startOffset
261
+ var end = content . childNodes [ l - 1 ] . __location . endOffset
262
+ return source . slice ( start , end )
263
+ }
264
+
242
265
/**
243
266
* Process a style node
244
267
*
@@ -355,7 +378,7 @@ function compileAsPromise (type, source, lang, filePath) {
355
378
// report babel error codeframe
356
379
if ( err . codeFrame ) {
357
380
process . nextTick ( function ( ) {
358
- console . error ( err . codeFrame )
381
+ console . error ( err . codeFrame )
359
382
} )
360
383
}
361
384
return reject ( err )
@@ -392,6 +415,10 @@ function extract (parts, type) {
392
415
. join ( '\n' )
393
416
}
394
417
418
+ /**
419
+ * Pad content into empty lines.
420
+ */
421
+
395
422
function padContent ( content , lang ) {
396
423
return content
397
424
. split ( / \r ? \n / g)
0 commit comments