From 9d5aa363cf3031b586e9945cf990e178f5b370db Mon Sep 17 00:00:00 2001
From: Nils Knappmeier <github@knappi.org>
Date: Mon, 13 Jan 2020 21:39:01 +0100
Subject: [PATCH 1/4] fix: don't wrap helpers that are not functions

- helpers should always be a function, but in #1639 one seems to
  be undefined. This was not a problem before 4.6 because helpers
  weren't wrapped then.
  Now, we must take care only to wrap helpers (when adding
  the "lookupProperty" function to the options), if they
  are really functions.
---
 lib/handlebars/internal/wrapHelper.js | 5 +++++
 spec/regressions.js                   | 9 +++++++++
 2 files changed, 14 insertions(+)

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');
+    });
+  });
 });

From a4fd391ba1c9faa1004e879f314beb80c3afe0b6 Mon Sep 17 00:00:00 2001
From: Nils Knappmeier <github@knappi.org>
Date: Mon, 13 Jan 2020 21:47:51 +0100
Subject: [PATCH 2/4] chore: execute saucelabs-task only if access-key exists

- up to now, the existance of the SAUCE_USERNAME was checked
  but this variable is even present in pull-requests from other
  repos. This means that builds fail, because the access key
  is not there.
  This change looks for SAUCE_ACCESS_KEY instead, which is
  a secure variable, only present in build originating from
  the handlebars.js repo.
---
 Gruntfile.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Gruntfile.js b/Gruntfile.js
index 65e0b8f33..528c0af82 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -267,7 +267,7 @@ module.exports = function(grunt) {
 
   grunt.registerTask('bench', ['metrics']);
 
-  if (process.env.SAUCE_USERNAME) {
+  if (process.env.SAUCE_ACCESS_KEY) {
     grunt.registerTask('sauce', ['concat:tests', 'connect', 'saucelabs-mocha']);
   } else {
     grunt.registerTask('sauce', []);

From f0c6c4cc1f9a91371535ad6affe09dfc1880dd9e Mon Sep 17 00:00:00 2001
From: Nils Knappmeier <github@knappi.org>
Date: Mon, 13 Jan 2020 21:52:50 +0100
Subject: [PATCH 3/4] Update release notes

---
 release-notes.md | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/release-notes.md b/release-notes.md
index 8e391a775..09ecc2a03 100644
--- a/release-notes.md
+++ b/release-notes.md
@@ -2,7 +2,23 @@
 
 ## Development
 
-[Commits](https://github.com/wycats/handlebars.js/compare/v4.7.1...master)
+[Commits](https://github.com/wycats/handlebars.js/compare/v4.7.2...master)
+
+## v4.7.2 - January 13th, 2020
+
+Bugfixes:
+
+- fix: don't wrap helpers that are not functions - 9d5aa36, #1639
+
+Chore/Build:
+
+- chore: execute saucelabs-task only if access-key exists - a4fd391
+
+Compatibility notes:
+
+- No breaking changes are to be expected
+
+[Commits](https://github.com/wycats/handlebars.js/compare/v4.7.1...v4.7.2)
 
 ## v4.7.1 - January 12th, 2020
 

From 586e672c8bba7db787bc9bfe9a9fde4ec98d5b4f Mon Sep 17 00:00:00 2001
From: Nils Knappmeier <github@knappi.org>
Date: Mon, 13 Jan 2020 21:53:14 +0100
Subject: [PATCH 4/4] v4.7.2

---
 components/bower.json           | 2 +-
 components/handlebars.js.nuspec | 2 +-
 components/package.json         | 2 +-
 lib/handlebars/base.js          | 2 +-
 package.json                    | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/components/bower.json b/components/bower.json
index ccebdef1b..f62ac8caf 100644
--- a/components/bower.json
+++ b/components/bower.json
@@ -1,6 +1,6 @@
 {
   "name": "handlebars",
-  "version": "4.7.1",
+  "version": "4.7.2",
   "main": "handlebars.js",
   "license": "MIT",
   "dependencies": {}
diff --git a/components/handlebars.js.nuspec b/components/handlebars.js.nuspec
index 44747f7f4..078ea8693 100644
--- a/components/handlebars.js.nuspec
+++ b/components/handlebars.js.nuspec
@@ -2,7 +2,7 @@
 <package>
 	<metadata>
 		<id>handlebars.js</id>
-		<version>4.7.1</version>
+		<version>4.7.2</version>
 		<authors>handlebars.js Authors</authors>
 		<licenseUrl>https://github.com/wycats/handlebars.js/blob/master/LICENSE</licenseUrl>
 		<projectUrl>https://github.com/wycats/handlebars.js/</projectUrl>
diff --git a/components/package.json b/components/package.json
index c296a32c2..0963613b1 100644
--- a/components/package.json
+++ b/components/package.json
@@ -1,6 +1,6 @@
 {
   "name": "handlebars",
-  "version": "4.7.1",
+  "version": "4.7.2",
   "license": "MIT",
   "jspm": {
     "main": "handlebars",
diff --git a/lib/handlebars/base.js b/lib/handlebars/base.js
index 2aa3a62f5..40f2fc561 100644
--- a/lib/handlebars/base.js
+++ b/lib/handlebars/base.js
@@ -5,7 +5,7 @@ import { registerDefaultDecorators } from './decorators';
 import logger from './logger';
 import { resetLoggedProperties } from './internal/proto-access';
 
-export const VERSION = '4.7.1';
+export const VERSION = '4.7.2';
 export const COMPILER_REVISION = 8;
 export const LAST_COMPATIBLE_COMPILER_REVISION = 7;
 
diff --git a/package.json b/package.json
index 5c289a2c2..8b6658e83 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
   "name": "handlebars",
   "barename": "handlebars",
-  "version": "4.7.1",
+  "version": "4.7.2",
   "description": "Handlebars provides the power necessary to let you build semantic templates effectively with no frustration",
   "homepage": "http://www.handlebarsjs.com/",
   "keywords": [
