diff --git a/lib/handlebars/internal/wrapHelper.js b/lib/handlebars/internal/wrapHelper.js index 0010eb8c2..29d65b033 100644 --- a/lib/handlebars/internal/wrapHelper.js +++ b/lib/handlebars/internal/wrapHelper.js @@ -1,4 +1,9 @@ export function wrapHelper(helper, transformOptionsFn) { + 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; + } let wrapper = function(/* dynamic arguments */) { const options = arguments[arguments.length - 1]; arguments[arguments.length - 1] = transformOptionsFn(options); diff --git a/spec/regressions.js b/spec/regressions.js index 3a84dd7da..f6147ad6e 100644 --- a/spec/regressions.js +++ b/spec/regressions.js @@ -518,4 +518,13 @@ describe('Regressions', function() { sinon.restore(); }); }); + + describe("GH-1639: TypeError: Cannot read property 'apply' of undefined\" when handlebars version > 4.6.0 (undocumented, deprecated usage)", function() { + it('should treat undefined helpers like non-existing helpers', function() { + expectTemplate('{{foo}}') + .withHelper('foo', undefined) + .withInput({ foo: 'bar' }) + .toCompileTo('bar'); + }); + }); });