Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix inline-template crashing (fix #9361) #9365

Merged
merged 1 commit into from
Feb 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/codegen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 @@ -584,14 +584,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