11import * as Utils from './utils' ;
22import Exception from './exception' ;
3- import { COMPILER_REVISION , REVISION_CHANGES , createFrame } from './base' ;
3+ import { COMPILER_REVISION , createFrame , REVISION_CHANGES } from './base' ;
4+ import { moveHelperToHooks } from './helpers' ;
45
56export function checkRevision ( compilerInfo ) {
67 const compilerRevision = compilerInfo && compilerInfo [ 0 ] || 1 ,
@@ -21,6 +22,7 @@ export function checkRevision(compilerInfo) {
2122}
2223
2324export function template ( templateSpec , env ) {
25+
2426 /* istanbul ignore next */
2527 if ( ! env ) {
2628 throw new Exception ( 'No environment passed to template' ) ;
@@ -42,13 +44,15 @@ export function template(templateSpec, env) {
4244 options . ids [ 0 ] = true ;
4345 }
4446 }
45-
4647 partial = env . VM . resolvePartial . call ( this , partial , context , options ) ;
47- let result = env . VM . invokePartial . call ( this , partial , context , options ) ;
48+
49+ let optionsWithHooks = Utils . extend ( { } , options , { hooks : this . hooks } ) ;
50+
51+ let result = env . VM . invokePartial . call ( this , partial , context , optionsWithHooks ) ;
4852
4953 if ( result == null && env . compile ) {
5054 options . partials [ options . name ] = env . compile ( partial , templateSpec . compilerOptions , env ) ;
51- result = options . partials [ options . name ] ( context , options ) ;
55+ result = options . partials [ options . name ] ( context , optionsWithHooks ) ;
5256 }
5357 if ( result != null ) {
5458 if ( options . indent ) {
@@ -115,15 +119,6 @@ export function template(templateSpec, env) {
115119 }
116120 return value ;
117121 } ,
118- merge : function ( param , common ) {
119- let obj = param || common ;
120-
121- if ( param && common && ( param !== common ) ) {
122- obj = Utils . extend ( { } , common , param ) ;
123- }
124-
125- return obj ;
126- } ,
127122 // An empty object to use as replacement for null-contexts
128123 nullContext : Object . seal ( { } ) ,
129124
@@ -158,19 +153,27 @@ export function template(templateSpec, env) {
158153
159154 ret . _setup = function ( options ) {
160155 if ( ! options . partial ) {
161- container . helpers = container . merge ( options . helpers , env . helpers ) ;
156+ container . helpers = Utils . extend ( { } , env . helpers , options . helpers ) ;
162157
163158 if ( templateSpec . usePartial ) {
164- container . partials = container . merge ( options . partials , env . partials ) ;
159+ container . partials = Utils . extend ( { } , env . partials , options . partials ) ;
165160 }
166161 if ( templateSpec . usePartial || templateSpec . useDecorators ) {
167- container . decorators = container . merge ( options . decorators , env . decorators ) ;
162+ container . decorators = Utils . extend ( { } , env . decorators , options . decorators ) ;
168163 }
164+
165+ container . hooks = { } ;
166+ let keepHelper = options . allowCallsToHelperMissing ;
167+ moveHelperToHooks ( container , 'helperMissing' , keepHelper ) ;
168+ moveHelperToHooks ( container , 'blockHelperMissing' , keepHelper ) ;
169+
169170 } else {
170171 container . helpers = options . helpers ;
171172 container . partials = options . partials ;
172173 container . decorators = options . decorators ;
174+ container . hooks = options . hooks ;
173175 }
176+
174177 } ;
175178
176179 ret . _child = function ( i , data , blockParams , depths ) {
0 commit comments