Skip to content

Commit

Permalink
fix(compiler): warn when inline-template component has no children (fix
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscasola authored and hefeng committed Jan 25, 2019
1 parent c48457b commit b32590e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/codegen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
}
Expand Down
7 changes: 7 additions & 0 deletions test/unit/modules/compiler/codegen.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,14 @@ describe('codegen', () => {
'<my-component inline-template><hr><hr></my-component>',
`with(this){return _c('my-component',{inlineTemplate:{render:function(){with(this){return _c('hr')}},staticRenderFns:[]}})}`
)
try {
assertCodegen(
'<my-component inline-template></my-component>',
''
)
} 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', () => {
Expand Down

0 comments on commit b32590e

Please sign in to comment.