Skip to content

Commit b0e52c3

Browse files
committed
Simplify helper wrapper
This improves performance slightly and gives the wrapper function a more descriptive name to help with debugging/profiling.
1 parent e914d60 commit b0e52c3

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

lib/handlebars/internal/wrapHelper.js

-13
This file was deleted.

lib/handlebars/runtime.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
REVISION_CHANGES
88
} from './base';
99
import { moveHelperToHooks } from './helpers';
10-
import { wrapHelper } from './internal/wrapHelper';
1110
import {
1211
createProtoAccessControl,
1312
resultIsAllowed
@@ -426,14 +425,20 @@ function addHelpers(mergedHelpers, helpers, container) {
426425
if (!helpers) return;
427426
Object.keys(helpers).forEach(helperName => {
428427
let helper = helpers[helperName];
429-
mergedHelpers[helperName] = passLookupPropertyOption(helper, container);
428+
mergedHelpers[helperName] = wrapHelper(helper, container);
430429
});
431430
}
432431

433-
function passLookupPropertyOption(helper, container) {
432+
function wrapHelper(helper, container) {
433+
if (typeof helper !== 'function') {
434+
// This should not happen, but apparently it does in https://github.com/wycats/handlebars.js/issues/1639
435+
// We try to make the wrapper least-invasive by not wrapping it, if the helper is not a function.
436+
return helper;
437+
}
434438
const lookupProperty = container.lookupProperty;
435-
return wrapHelper(helper, options => {
439+
return function invokeHelper(/* dynamic arguments */) {
440+
const options = arguments[arguments.length - 1];
436441
options.lookupProperty = lookupProperty;
437-
return options;
438-
});
442+
return helper.apply(this, arguments);
443+
};
439444
}

0 commit comments

Comments
 (0)