diff --git a/src/compiler/codegen/index.js b/src/compiler/codegen/index.js index bdd76be0033..0dc6d357fca 100644 --- a/src/compiler/codegen/index.js +++ b/src/compiler/codegen/index.js @@ -340,7 +340,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 7f5fbeae333..b1c2cdfe06e 100644 --- a/test/unit/modules/compiler/codegen.spec.js +++ b/test/unit/modules/compiler/codegen.spec.js @@ -584,14 +584,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', () => {