Skip to content

Commit

Permalink
fix(compiler): fix inline-template crashing (#9365)
Browse files Browse the repository at this point in the history
fix #9361
  • Loading branch information
Filipe Amaral authored and yyx990803 committed Feb 4, 2019
1 parent c27fe24 commit 55bfb94
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/compiler/codegen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions test/unit/modules/compiler/codegen.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,14 +591,21 @@ 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) {}
assertCodegen(
'<my-component inline-template></my-component>',
`with(this){return _c('my-component',{})}`
)
// have "is" attribute
assertCodegen(
'<div is="myComponent" inline-template><div></div></div>',
`with(this){return _c("myComponent",{tag:"div",inlineTemplate:{render:function(){with(this){return _c('div')}},staticRenderFns:[]}})}`
)
assertCodegen(
'<div is="myComponent" inline-template></div>',
`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', () => {
Expand Down

0 comments on commit 55bfb94

Please sign in to comment.