11/* @flow */
22
33import { encodeHTML } from 'entities'
4+ import { compileToFunctions } from 'web/compiler/index'
45import { createComponentInstanceForVnode } from 'core/vdom/create-component'
56
67const normalizeAsync = ( cache , method ) => {
@@ -14,6 +15,18 @@ const normalizeAsync = (cache, method) => {
1415 }
1516}
1617
18+ const compilationCache = Object . create ( null )
19+ const normalizeRender = vm => {
20+ const { render, template } = vm . $options
21+ if ( ! render && template ) {
22+ const renderFns = (
23+ compilationCache [ template ] ||
24+ ( compilationCache [ template ] = compileToFunctions ( template ) )
25+ )
26+ Object . assign ( vm . $options , renderFns )
27+ }
28+ }
29+
1730export function createRenderFunction (
1831 modules : Array < Function > ,
1932 directives : Object ,
@@ -77,9 +90,11 @@ export function createRenderFunction (
7790 }
7891
7992 function renderComponent ( node , write , next , isRoot ) {
80- const child = createComponentInstanceForVnode ( node ) . _render ( )
81- child . parent = node
82- renderNode ( child , write , next , isRoot )
93+ const child = createComponentInstanceForVnode ( node )
94+ normalizeRender ( child )
95+ const childNode = child . _render ( )
96+ childNode . parent = node
97+ renderNode ( childNode , write , next , isRoot )
8398 }
8499
85100 function renderComponentWithCache ( node , write , next , isRoot , cache , key ) {
@@ -179,6 +194,7 @@ export function createRenderFunction (
179194 write : ( text : string , next : Function ) => void ,
180195 done : Function
181196 ) {
197+ normalizeRender ( component )
182198 renderNode ( component . _render ( ) , write , done , true )
183199 }
184200}
0 commit comments