diff --git a/src/compiler/codegen/index.js b/src/compiler/codegen/index.js
index b186cb92f6..c0038a1f79 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 20d065b3e7..083a736f5b 100644
--- a/test/unit/modules/compiler/codegen.spec.js
+++ b/test/unit/modules/compiler/codegen.spec.js
@@ -591,14 +591,21 @@ describe('codegen', () => {
'