Skip to content

Commit

Permalink
Simplify helper wrapper
Browse files Browse the repository at this point in the history
This improves performance slightly and gives the wrapper function a more
descriptive name to help with debugging/profiling.
  • Loading branch information
mohd-akram committed Sep 4, 2024
1 parent e914d60 commit b0e52c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
13 changes: 0 additions & 13 deletions lib/handlebars/internal/wrapHelper.js

This file was deleted.

17 changes: 11 additions & 6 deletions lib/handlebars/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
REVISION_CHANGES
} from './base';
import { moveHelperToHooks } from './helpers';
import { wrapHelper } from './internal/wrapHelper';
import {
createProtoAccessControl,
resultIsAllowed
Expand Down Expand Up @@ -426,14 +425,20 @@ function addHelpers(mergedHelpers, helpers, container) {
if (!helpers) return;
Object.keys(helpers).forEach(helperName => {
let helper = helpers[helperName];
mergedHelpers[helperName] = passLookupPropertyOption(helper, container);
mergedHelpers[helperName] = wrapHelper(helper, container);
});
}

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

0 comments on commit b0e52c3

Please sign in to comment.