summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/compiler.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r--lib/handlebars/compiler/compiler.js54
1 files changed, 30 insertions, 24 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js
index a39082d..a9bfc85 100644
--- a/lib/handlebars/compiler/compiler.js
+++ b/lib/handlebars/compiler/compiler.js
@@ -1,6 +1,6 @@
-import Exception from "../exception";
-import {isArray, indexOf} from "../utils";
-import AST from "./ast";
+import Exception from '../exception';
+import {isArray, indexOf} from '../utils';
+import AST from './ast';
var slice = [].slice;
@@ -67,7 +67,9 @@ Compiler.prototype = {
};
if (knownHelpers) {
for (var name in knownHelpers) {
- options.knownHelpers[name] = knownHelpers[name];
+ if (name in knownHelpers) {
+ options.knownHelpers[name] = knownHelpers[name];
+ }
}
}
@@ -75,7 +77,7 @@ Compiler.prototype = {
},
compileProgram: function(program) {
- var result = new this.compiler().compile(program, this.options);
+ var result = new this.compiler().compile(program, this.options); // eslint-disable-line new-cap
var guid = this.guid++;
this.usePartial = this.usePartial || result.usePartial;
@@ -97,7 +99,7 @@ Compiler.prototype = {
this.options.blockParams.unshift(program.blockParams);
var body = program.body;
- for(var i=0, l=body.length; i<l; i++) {
+ for (var i = 0, l = body.length; i < l; i++) {
this.accept(body[i]);
}
@@ -174,9 +176,9 @@ Compiler.prototype = {
},
MustacheStatement: function(mustache) {
- this.SubExpression(mustache);
+ this.SubExpression(mustache); // eslint-disable-line new-cap
- if(mustache.escaped && !this.options.noEscape) {
+ if (mustache.escaped && !this.options.noEscape) {
this.opcode('appendEscaped');
} else {
this.opcode('append');
@@ -231,7 +233,7 @@ Compiler.prototype = {
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);
+ throw new Exception('You specified knownHelpersOnly, but used the unknown helper ' + name, sexpr);
} else {
path.falsy = true;
@@ -250,7 +252,7 @@ Compiler.prototype = {
if (blockParamId) {
this.opcode('lookupBlockParam', blockParamId, path.parts);
- } else if (!name) {
+ } else if (!name) {
// Context reference, i.e. `{{foo .}}` or `{{foo ..}}`
this.opcode('pushContext');
} else if (path.data) {
@@ -286,7 +288,7 @@ Compiler.prototype = {
this.opcode('pushHash');
- for (i=0, l=pairs.length; i<l; i++) {
+ for (i = 0, l = pairs.length; i < l; i++) {
this.pushParam(pairs[i].value);
}
while (i--) {
@@ -336,13 +338,17 @@ Compiler.prototype = {
}
}
- if (isHelper) { return 'helper'; }
- else if (isEligible) { return 'ambiguous'; }
- else { return 'simple'; }
+ if (isHelper) {
+ return 'helper';
+ } else if (isEligible) {
+ return 'ambiguous';
+ } else {
+ return 'simple';
+ }
},
pushParams: function(params) {
- for(var i=0, l=params.length; i<l; i++) {
+ for (var i = 0, l = params.length; i < l; i++) {
this.pushParam(params[i]);
}
},
@@ -357,7 +363,7 @@ Compiler.prototype = {
.replace(/\//g, '.');
}
- if(val.depth) {
+ if (val.depth) {
this.addDepth(val.depth);
}
this.opcode('getContext', val.depth || 0);
@@ -421,7 +427,7 @@ Compiler.prototype = {
export function precompile(input, options, env) {
if (input == null || (typeof input !== 'string' && input.type !== 'Program')) {
- throw new Exception("You must pass a string or Handlebars AST to Handlebars.precompile. You passed " + input);
+ throw new Exception('You must pass a string or Handlebars AST to Handlebars.precompile. You passed ' + input);
}
options = options || {};
@@ -439,7 +445,7 @@ export function precompile(input, options, env) {
export function compile(input, options, env) {
if (input == null || (typeof input !== 'string' && input.type !== 'Program')) {
- throw new Exception("You must pass a string or Handlebars AST to Handlebars.compile. You passed " + input);
+ throw new Exception('You must pass a string or Handlebars AST to Handlebars.compile. You passed ' + input);
}
options = options || {};
@@ -461,17 +467,17 @@ export function compile(input, options, env) {
}
// Template is only compiled on first use and cached after that point.
- var ret = function(context, options) {
+ function ret(context, execOptions) {
if (!compiled) {
compiled = compileInput();
}
- return compiled.call(this, context, options);
- };
- ret._setup = function(options) {
+ return compiled.call(this, context, execOptions);
+ }
+ ret._setup = function(setupOptions) {
if (!compiled) {
compiled = compileInput();
}
- return compiled._setup(options);
+ return compiled._setup(setupOptions);
};
ret._child = function(i, data, blockParams, depths) {
if (!compiled) {
@@ -502,6 +508,6 @@ function transformLiteralToPath(sexpr) {
var literal = sexpr.path;
// Casting to string here to make false and 0 literal values play nicely with the rest
// of the system.
- sexpr.path = new AST.PathExpression(false, 0, [literal.original+''], literal.original+'', literal.loc);
+ sexpr.path = new AST.PathExpression(false, 0, [literal.original + ''], literal.original + '', literal.loc);
}
}