From c9ef5cac7a0423534d58a173bdb066244b3b15cf Mon Sep 17 00:00:00 2001 From: Chris Casola Date: Thu, 28 Sep 2017 19:44:03 -0400 Subject: [PATCH] fix(compiler): warn when inline-template component has no children (fix #6703) --- src/compiler/codegen/index.js | 2 +- test/unit/modules/compiler/codegen.spec.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/compiler/codegen/index.js b/src/compiler/codegen/index.js index 46c54867bb..c4c31c2020 100644 --- a/src/compiler/codegen/index.js +++ b/src/compiler/codegen/index.js @@ -309,7 +309,7 @@ function genDirectives (el: ASTElement, state: CodegenState): string | void { function genInlineTemplate (el: ASTElement, state: CodegenState): ?string { const ast = el.children[0] if (process.env.NODE_ENV !== 'production' && ( - el.children.length > 1 || ast.type !== 1 + el.children.length !== 1 || ast.type !== 1 )) { state.warn('Inline-template components must have exactly one child element.') } diff --git a/test/unit/modules/compiler/codegen.spec.js b/test/unit/modules/compiler/codegen.spec.js index 37bcf62a76..8b415a13eb 100644 --- a/test/unit/modules/compiler/codegen.spec.js +++ b/test/unit/modules/compiler/codegen.spec.js @@ -455,7 +455,14 @@ describe('codegen', () => { '

', `with(this){return _c('my-component',{inlineTemplate:{render:function(){with(this){return _c('hr')}},staticRenderFns:[]}})}` ) + try { + assertCodegen( + '', + '' + ) + } catch (e) {} expect('Inline-template components must have exactly one child element.').toHaveBeenWarned() + expect(console.error.calls.count()).toBe(2) }) it('generate static trees inside v-for', () => {