diff --git a/src/compiler/codegen/index.js b/src/compiler/codegen/index.js index b186cb92f63..c0038a1f79f 100644 --- a/src/compiler/codegen/index.js +++ b/src/compiler/codegen/index.js @@ -346,7 +346,7 @@ function genInlineTemplate (el: ASTElement, state: CodegenState): ?string { { start: el.start } ) } - if (ast.type === 1) { + if (ast && ast.type === 1) { const inlineRenderFns = generate(ast, state.options) return `inlineTemplate:{render:function(){${ inlineRenderFns.render diff --git a/test/unit/modules/compiler/codegen.spec.js b/test/unit/modules/compiler/codegen.spec.js index 20d065b3e72..083a736f5b0 100644 --- a/test/unit/modules/compiler/codegen.spec.js +++ b/test/unit/modules/compiler/codegen.spec.js @@ -591,14 +591,21 @@ describe('codegen', () => { '

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