diff --git a/src/compiler/parser/index.js b/src/compiler/parser/index.js index 9b246236c1c..1a54c2308d9 100644 --- a/src/compiler/parser/index.js +++ b/src/compiler/parser/index.js @@ -153,8 +153,9 @@ export function parse ( checkRootConstraints(root) } else if (process.env.NODE_ENV !== 'production' && !stack.length && !warned) { // allow 2 root elements with v-if and v-else - if ((root.attrsMap.hasOwnProperty('v-if') && element.attrsMap.hasOwnProperty('v-else'))) { + if (root.if && element.else) { checkRootConstraints(element) + root.elseBlock = element } else { warned = true warn( @@ -201,10 +202,10 @@ export function parse ( chars (text: string) { if (!currentParent) { - if (process.env.NODE_ENV !== 'production' && !warned) { + if (process.env.NODE_ENV !== 'production' && !warned && text === template) { warned = true warn( - 'Component template should contain exactly one root element:\n\n' + template + 'Component template requires a root element, rather than just text:\n\n' + template ) } return diff --git a/test/unit/modules/compiler/compiler-options.spec.js b/test/unit/modules/compiler/compiler-options.spec.js index a3037ae56e0..405458cc3df 100644 --- a/test/unit/modules/compiler/compiler-options.spec.js +++ b/test/unit/modules/compiler/compiler-options.spec.js @@ -118,7 +118,7 @@ describe('compile options', () => { it('should collect errors', () => { let compiled = compile('hello') expect(compiled.errors.length).toBe(1) - expect(compiled.errors[0]).toContain('should contain exactly one root element') + expect(compiled.errors[0]).toContain('root element') compiled = compile('