From 55bfb94a33ecc9b33131ec0fb78bba2946e8fc75 Mon Sep 17 00:00:00 2001 From: Filipe Amaral Date: Mon, 4 Feb 2019 19:49:27 -0200 Subject: [PATCH] fix(compiler): fix inline-template crashing (#9365) fix #9361 --- src/compiler/codegen/index.js | 2 +- test/unit/modules/compiler/codegen.spec.js | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) 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', () => {