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

Commit 91d4175

Browse files
committed
upgrade to parse5 2.1
1 parent 3dd3e2b commit 91d4175

File tree

3 files changed

+8
-21
lines changed

3 files changed

+8
-21
lines changed

lib/compiler.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ require('es6-promise').polyfill()
22
var fs = require('fs')
33
var path = require('path')
44
var parse5 = require('parse5')
5-
var parser = new parse5.Parser()
6-
var serializer = new parse5.TreeSerializer()
75
var hash = require('hash-sum')
86
var compilers = require('./compilers')
97
var options = require('./compilers/options')
@@ -79,7 +77,7 @@ compiler.compile = function (content, filePath, cb) {
7977
var id = '_v-' + hash(filePath || content)
8078

8179
// parse the file into an HTML tree
82-
var fragment = parser.parseFragment(content)
80+
var fragment = parse5.parseFragment(content, { locationInfo: true })
8381

8482
// check node numbers
8583
if (!validateNodeCount(fragment)) {
@@ -206,7 +204,7 @@ function isScoped (node) {
206204
*/
207205

208206
function processTemplate (node, filePath, id, hasScopedStyle) {
209-
var template = checkSrc(node, filePath) || serializeTemplate(node)
207+
var template = checkSrc(node, filePath) || parse5.serialize(node.content)
210208
var lang = checkLang(node)
211209
return compileAsPromise('template', template, lang, filePath)
212210
.then(function (res) {
@@ -234,7 +232,7 @@ function processTemplate (node, filePath, id, hasScopedStyle) {
234232
*/
235233

236234
function processStyle (node, filePath, id) {
237-
var style = checkSrc(node, filePath) || serializer.serialize(node)
235+
var style = checkSrc(node, filePath) || parse5.serialize(node)
238236
var lang = checkLang(node)
239237
return compileAsPromise('style', style, lang, filePath)
240238
.then(function (res) {
@@ -255,7 +253,7 @@ function processScript (node, filePath, content) {
255253
var lang = checkLang(node) || 'babel'
256254
var script = checkSrc(node, filePath)
257255
if (!script) {
258-
script = serializer.serialize(node)
256+
script = parse5.serialize(node)
259257
// pad the script to ensure correct line number for syntax errors
260258
var location = content.indexOf(script)
261259
var before = padContent(content.slice(0, location))
@@ -318,15 +316,6 @@ function checkSrc (node, filePath) {
318316
}
319317
}
320318

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-
330319
/**
331320
* Compile a piece of source code with an async compiler and
332321
* return a Promise.
@@ -386,7 +375,7 @@ function extract (parts, type) {
386375

387376
function padContent (content, lang) {
388377
return content
389-
.split(/\n\r|\n|\r/g)
378+
.split(/\r?\n/g)
390379
.map(function () { return '' })
391380
.join('\n')
392381
}

lib/template-rewriter.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
var parse5 = require('parse5')
2-
var parser = new parse5.Parser()
3-
var serializer = new parse5.Serializer()
42
var cache = require('lru-cache')(100)
53

64
/**
@@ -17,7 +15,7 @@ module.exports = function (id, html) {
1715
if (val) {
1816
return Promise.resolve(val)
1917
}
20-
var tree = parser.parseFragment(html)
18+
var tree = parse5.parseFragment(html)
2119
walk(tree, function (node) {
2220
if (node.attrs) {
2321
node.attrs.push({
@@ -27,7 +25,7 @@ module.exports = function (id, html) {
2725
}
2826
})
2927
val = {
30-
source: serializer.serialize(tree),
28+
source: parse5.serialize(tree),
3129
type: 'template'
3230
}
3331
cache.set(key, val)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"html-minifier": "^1.0.0",
2929
"lru-cache": "^2.7.0",
3030
"object-assign": "^4.0.1",
31-
"parse5": "^1.5.0",
31+
"parse5": "^2.1.0",
3232
"postcss": "^5.0.10",
3333
"postcss-selector-parser": "^1.3.0",
3434
"through": "^2.3.6"

0 commit comments

Comments
 (0)