summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/javascript-compiler.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/handlebars/compiler/javascript-compiler.js')
-rw-r--r--lib/handlebars/compiler/javascript-compiler.js88
1 files changed, 46 insertions, 42 deletions
diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js
index a027edb..e278162 100644
--- a/lib/handlebars/compiler/javascript-compiler.js
+++ b/lib/handlebars/compiler/javascript-compiler.js
@@ -1,7 +1,7 @@
-import { COMPILER_REVISION, REVISION_CHANGES } from "../base";
-import Exception from "../exception";
-import {isArray} from "../utils";
-import CodeGen from "./code-gen";
+import { COMPILER_REVISION, REVISION_CHANGES } from '../base';
+import Exception from '../exception';
+import {isArray} from '../utils';
+import CodeGen from './code-gen';
function Literal(value) {
this.value = value;
@@ -14,7 +14,7 @@ JavaScriptCompiler.prototype = {
// alternative compiled forms for name lookup and buffering semantics
nameLookup: function(parent, name /* , type*/) {
if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
- return [parent, ".", name];
+ return [parent, '.', name];
} else {
return [parent, "['", name, "']"];
}
@@ -50,7 +50,7 @@ JavaScriptCompiler.prototype = {
},
initializeBuffer: function() {
- return this.quotedString("");
+ return this.quotedString('');
},
// END PUBLIC API
@@ -169,8 +169,8 @@ JavaScriptCompiler.prototype = {
var varDeclarations = '';
var locals = this.stackVars.concat(this.registers.list);
- if(locals.length > 0) {
- varDeclarations += ", " + locals.join(", ");
+ if (locals.length > 0) {
+ varDeclarations += ', ' + locals.join(', ');
}
// Generate minimizer alias mappings
@@ -180,7 +180,7 @@ JavaScriptCompiler.prototype = {
// aliases will not be used, but this case is already being run on the client and
// we aren't concern about minimizing the template size.
var aliasCount = 0;
- for (var alias in this.aliases) {
+ for (var alias in this.aliases) { // eslint-disable-line guard-for-in
var node = this.aliases[alias];
if (this.aliases.hasOwnProperty(alias) && node.children && node.referenceCount > 1) {
@@ -189,7 +189,7 @@ JavaScriptCompiler.prototype = {
}
}
- var params = ["depth0", "helpers", "partials", "data"];
+ var params = ['depth0', 'helpers', 'partials', 'data'];
if (this.useBlockParams || this.useDepths) {
params.push('blockParams');
@@ -252,7 +252,7 @@ JavaScriptCompiler.prototype = {
this.source.push('return "";');
}
} else {
- varDeclarations += ", buffer = " + (appendFirst ? '' : this.initializeBuffer());
+ varDeclarations += ', buffer = ' + (appendFirst ? '' : this.initializeBuffer());
if (bufferStart) {
bufferStart.prepend('return buffer + ');
@@ -446,6 +446,7 @@ JavaScriptCompiler.prototype = {
var len = parts.length;
for (; i < len; i++) {
+ /*eslint-disable no-loop-func */
this.replaceStack(function(current) {
var lookup = this.nameLookup(current, parts[i], type);
// We want to ensure that zero and false are handled properly if the context (falsy flag)
@@ -457,6 +458,7 @@ JavaScriptCompiler.prototype = {
return [' && ', lookup];
}
});
+ /*eslint-enable no-loop-func */
}
},
@@ -633,7 +635,7 @@ JavaScriptCompiler.prototype = {
'(', lookup,
(helper.paramsInit ? ['),(', helper.paramsInit] : []), '),',
'(typeof helper === ', this.aliasable('"function"'), ' ? ',
- this.source.functionCall('helper','call', helper.callParams), ' : helper))'
+ this.source.functionCall('helper', 'call', helper.callParams), ' : helper))'
]);
},
@@ -728,9 +730,9 @@ JavaScriptCompiler.prototype = {
compileChildren: function(environment, options) {
var children = environment.children, child, compiler;
- for(var i=0, l=children.length; i<l; i++) {
+ for (var i = 0, l = children.length; i < l; i++) {
child = children[i];
- compiler = new this.compiler();
+ compiler = new this.compiler(); // eslint-disable-line new-cap
var index = this.matchExistingProgram(child);
@@ -777,7 +779,7 @@ JavaScriptCompiler.prototype = {
},
useRegister: function(name) {
- if(!this.registers[name]) {
+ if (!this.registers[name]) {
this.registers[name] = true;
this.registers.list.push(name);
}
@@ -849,11 +851,11 @@ JavaScriptCompiler.prototype = {
incrStack: function() {
this.stackSlot++;
- if(this.stackSlot > this.stackVars.length) { this.stackVars.push("stack" + this.stackSlot); }
+ if (this.stackSlot > this.stackVars.length) { this.stackVars.push('stack' + this.stackSlot); }
return this.topStackName();
},
topStackName: function() {
- return "stack" + this.stackSlot;
+ return 'stack' + this.stackSlot;
},
flushInline: function() {
var inlineStack = this.inlineStack;
@@ -1019,33 +1021,35 @@ JavaScriptCompiler.prototype = {
};
-var reservedWords = (
- "break else new var" +
- " case finally return void" +
- " catch for switch while" +
- " continue function this with" +
- " default if throw" +
- " delete in try" +
- " do instanceof typeof" +
- " abstract enum int short" +
- " boolean export interface static" +
- " byte extends long super" +
- " char final native synchronized" +
- " class float package throws" +
- " const goto private transient" +
- " debugger implements protected volatile" +
- " double import public let yield await" +
- " null true false"
-).split(" ");
-
-var compilerWords = JavaScriptCompiler.RESERVED_WORDS = {};
-
-for(var i=0, l=reservedWords.length; i<l; i++) {
- compilerWords[reservedWords[i]] = true;
-}
+(function() {
+ var reservedWords = (
+ 'break else new var' +
+ ' case finally return void' +
+ ' catch for switch while' +
+ ' continue function this with' +
+ ' default if throw' +
+ ' delete in try' +
+ ' do instanceof typeof' +
+ ' abstract enum int short' +
+ ' boolean export interface static' +
+ ' byte extends long super' +
+ ' char final native synchronized' +
+ ' class float package throws' +
+ ' const goto private transient' +
+ ' debugger implements protected volatile' +
+ ' double import public let yield await' +
+ ' null true false'
+ ).split(' ');
+
+ var compilerWords = JavaScriptCompiler.RESERVED_WORDS = {};
+
+ for (var i = 0, l = reservedWords.length; i < l; i++) {
+ compilerWords[reservedWords[i]] = true;
+ }
+}());
JavaScriptCompiler.isValidJavaScriptVariableName = function(name) {
- return !JavaScriptCompiler.RESERVED_WORDS[name] && /^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(name);
+ return !JavaScriptCompiler.RESERVED_WORDS[name] && (/^[a-zA-Z_$][0-9a-zA-Z_$]*$/).test(name);
};
function strictLookup(requireTerminal, compiler, parts, type) {