diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 5cfc020da..4070de625 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -56,23 +56,15 @@ Compiler.prototype = { // These changes will propagate to the other compiler components let knownHelpers = options.knownHelpers; - options.knownHelpers = { - 'helperMissing': true, - 'blockHelperMissing': true, - 'each': true, - 'if': true, - 'unless': true, - 'with': true, - 'log': true, - 'lookup': true - }; + + options.knownHelpers = Object.create(null); + ['helperMissing', 'blockHelperMissing', 'each', 'if', 'unless', 'with', 'log', 'lookup'].forEach(name => { + options.knownHelpers[name] = true; + }); if (knownHelpers) { - // the next line should use "Object.keys", but the code has been like this a long time and changing it, might - // cause backwards-compatibility issues... It's an old library... - // eslint-disable-next-line guard-for-in - for (let name in knownHelpers) { - this.options.knownHelpers[name] = knownHelpers[name]; - } + Object.keys(knownHelpers).forEach(name => { + this.options.knownHelpers[name] = knownHelpers[name]; + }); } return this.accept(program); @@ -267,7 +259,7 @@ Compiler.prototype = { path = sexpr.path, name = path.parts[0]; - if (this.options.knownHelpers[name] === true) { + if (this.options.knownHelpers[name]) { this.opcode('invokeKnownHelper', params.length, name); } else if (this.options.knownHelpersOnly) { throw new Exception('You specified knownHelpersOnly, but used the unknown helper ' + name, sexpr); @@ -370,7 +362,7 @@ Compiler.prototype = { let name = sexpr.path.parts[0], options = this.options; - if (options.knownHelpers.propertyIsEnumerable(name)) { + if (options.knownHelpers[name]) { isHelper = true; } else if (options.knownHelpersOnly) { isEligible = false;