Skip to content

Commit baabd6d

Browse files
chriscasolayyx990803
authored andcommitted
fix(compiler): warn when inline-template component has no children (fix #6703) (#6715)
1 parent c5d0fa0 commit baabd6d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/compiler/codegen/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ function genDirectives (el: ASTElement, state: CodegenState): string | void {
309309
function genInlineTemplate (el: ASTElement, state: CodegenState): ?string {
310310
const ast = el.children[0]
311311
if (process.env.NODE_ENV !== 'production' && (
312-
el.children.length > 1 || ast.type !== 1
312+
el.children.length !== 1 || ast.type !== 1
313313
)) {
314314
state.warn('Inline-template components must have exactly one child element.')
315315
}

test/unit/modules/compiler/codegen.spec.js

+7
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,14 @@ describe('codegen', () => {
455455
'<my-component inline-template><hr><hr></my-component>',
456456
`with(this){return _c('my-component',{inlineTemplate:{render:function(){with(this){return _c('hr')}},staticRenderFns:[]}})}`
457457
)
458+
try {
459+
assertCodegen(
460+
'<my-component inline-template></my-component>',
461+
''
462+
)
463+
} catch (e) {}
458464
expect('Inline-template components must have exactly one child element.').toHaveBeenWarned()
465+
expect(console.error.calls.count()).toBe(2)
459466
})
460467

461468
it('generate static trees inside v-for', () => {

0 commit comments

Comments
 (0)