handle template edge cases

This commit is contained in:
Evan You 2016-04-12 23:06:42 -04:00
parent 448f3a6a78
commit d04dbab15e
2 changed files with 11 additions and 4 deletions

View File

@ -13,7 +13,7 @@ const onRE = /^@|^v-on:/
const mustUsePropsRE = /^(value|selected|checked|muted)$/
export function generate (ast) {
const code = genElement(ast)
const code = ast ? genElement(ast) : '__h__("div")'
return new Function(`with (this) { return ${code}}`)
}

View File

@ -23,9 +23,9 @@ export function parse (html, preserveWhiteSpace) {
}
if (!root) {
root = element
} else if (!stack.length) {
} else if (process.env.NODE_ENV !== 'production' && !stack.length) {
console.error(
'Component template should contain ony one root element:\n\n' + html
'Component template should contain exactly one root element:\n\n' + html
)
}
if (currentParent) {
@ -41,7 +41,14 @@ export function parse (html, preserveWhiteSpace) {
currentParent = stack[stack.length - 1]
},
chars (text) {
if (!currentParent) return
if (!currentParent) {
if (process.env.NODE_ENV !== 'production' && !root) {
console.error(
'Component template should contain exactly one root element:\n\n' + html
)
}
return
}
text = currentParent.tag === 'pre'
? decodeHTML(text)
: text.trim()