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', () => {
'