diff --git a/src/compiler/codegen/index.js b/src/compiler/codegen/index.js index d91dee824..afdf60a76 100644 --- a/src/compiler/codegen/index.js +++ b/src/compiler/codegen/index.js @@ -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}}`) } diff --git a/src/compiler/html-parser.js b/src/compiler/html-parser.js index 419e0ff93..9e39e6c6f 100644 --- a/src/compiler/html-parser.js +++ b/src/compiler/html-parser.js @@ -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()