Skip to content

Commit

Permalink
use null-constructor for "knownHelper" instead of checking for true
Browse files Browse the repository at this point in the history
- the performance-tests use a non-true but truthy value for "knownHelpers"
  and some other people might do that too.
  • Loading branch information
nknapp committed Nov 9, 2019
1 parent 8bb3f06 commit ab74b7f
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions lib/handlebars/compiler/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ab74b7f

Please sign in to comment.