@@ -2,8 +2,6 @@ require('es6-promise').polyfill()
2
2
var fs = require ( 'fs' )
3
3
var path = require ( 'path' )
4
4
var parse5 = require ( 'parse5' )
5
- var parser = new parse5 . Parser ( )
6
- var serializer = new parse5 . TreeSerializer ( )
7
5
var hash = require ( 'hash-sum' )
8
6
var compilers = require ( './compilers' )
9
7
var options = require ( './compilers/options' )
@@ -79,7 +77,7 @@ compiler.compile = function (content, filePath, cb) {
79
77
var id = '_v-' + hash ( filePath || content )
80
78
81
79
// parse the file into an HTML tree
82
- var fragment = parser . parseFragment ( content )
80
+ var fragment = parse5 . parseFragment ( content , { locationInfo : true } )
83
81
84
82
// check node numbers
85
83
if ( ! validateNodeCount ( fragment ) ) {
@@ -206,7 +204,7 @@ function isScoped (node) {
206
204
*/
207
205
208
206
function processTemplate ( node , filePath , id , hasScopedStyle ) {
209
- var template = checkSrc ( node , filePath ) || serializeTemplate ( node )
207
+ var template = checkSrc ( node , filePath ) || parse5 . serialize ( node . content )
210
208
var lang = checkLang ( node )
211
209
return compileAsPromise ( 'template' , template , lang , filePath )
212
210
. then ( function ( res ) {
@@ -234,7 +232,7 @@ function processTemplate (node, filePath, id, hasScopedStyle) {
234
232
*/
235
233
236
234
function processStyle ( node , filePath , id ) {
237
- var style = checkSrc ( node , filePath ) || serializer . serialize ( node )
235
+ var style = checkSrc ( node , filePath ) || parse5 . serialize ( node )
238
236
var lang = checkLang ( node )
239
237
return compileAsPromise ( 'style' , style , lang , filePath )
240
238
. then ( function ( res ) {
@@ -255,7 +253,7 @@ function processScript (node, filePath, content) {
255
253
var lang = checkLang ( node ) || 'babel'
256
254
var script = checkSrc ( node , filePath )
257
255
if ( ! script ) {
258
- script = serializer . serialize ( node )
256
+ script = parse5 . serialize ( node )
259
257
// pad the script to ensure correct line number for syntax errors
260
258
var location = content . indexOf ( script )
261
259
var before = padContent ( content . slice ( 0 , location ) )
@@ -318,15 +316,6 @@ function checkSrc (node, filePath) {
318
316
}
319
317
}
320
318
321
- // Work around changes in parse5 >= 1.2.0
322
- function serializeTemplate ( node ) {
323
- var childNode = node . childNodes [ 0 ]
324
- if ( childNode && childNode . nodeName === '#document-fragment' ) {
325
- return serializer . serialize ( childNode )
326
- }
327
- return serializer . serialize ( node )
328
- }
329
-
330
319
/**
331
320
* Compile a piece of source code with an async compiler and
332
321
* return a Promise.
@@ -386,7 +375,7 @@ function extract (parts, type) {
386
375
387
376
function padContent ( content , lang ) {
388
377
return content
389
- . split ( / \n \r | \n | \r / g)
378
+ . split ( / \r ? \n / g)
390
379
. map ( function ( ) { return '' } )
391
380
. join ( '\n' )
392
381
}
0 commit comments