diff options
author | kpdecker <kpdecker@gmail.com> | 2014-12-27 13:30:20 -0600 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2014-12-27 13:30:20 -0600 |
commit | ec798a7c4493cd0c4d78b42c78c667600fc1bed3 (patch) | |
tree | c2b504f11c32d900886418ceb8967642cc1207ca /lib | |
parent | be0ba759250489858cb6844c5de47cfa003b87ba (diff) | |
parent | b764fb1ded3c2bb3c56796e6d7264981e63ba0d7 (diff) | |
download | handlebars.js-ec798a7c4493cd0c4d78b42c78c667600fc1bed3.zip handlebars.js-ec798a7c4493cd0c4d78b42c78c667600fc1bed3.tar.gz handlebars.js-ec798a7c4493cd0c4d78b42c78c667600fc1bed3.tar.bz2 |
Merge branch 'master' into visitor-update
Diffstat (limited to 'lib')
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 4 | ||||
-rw-r--r-- | lib/handlebars/compiler/javascript-compiler.js | 4 | ||||
-rw-r--r-- | lib/handlebars/utils.js | 10 |
3 files changed, 14 insertions, 4 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 13143cc..95fe101 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -1,5 +1,5 @@ import Exception from "../exception"; -import {isArray} from "../utils"; +import {isArray, indexOf} from "../utils"; import AST from "./ast"; var slice = [].slice; @@ -400,7 +400,7 @@ Compiler.prototype = { blockParamIndex: function(name) { for (var depth = 0, len = this.options.blockParams.length; depth < len; depth++) { var blockParams = this.options.blockParams[depth], - param = blockParams && blockParams.indexOf(name); + param = blockParams && indexOf(blockParams, name); if (blockParams && param >= 0) { return [depth, param]; } diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js index 9f40792..247f5e0 100644 --- a/lib/handlebars/compiler/javascript-compiler.js +++ b/lib/handlebars/compiler/javascript-compiler.js @@ -248,7 +248,7 @@ JavaScriptCompiler.prototype = { if (bufferStart) { bufferStart.prepend('return '); bufferEnd.add(';'); - } else { + } else if (!sourceSeen) { this.source.push('return "";'); } } else { @@ -263,7 +263,7 @@ JavaScriptCompiler.prototype = { } if (varDeclarations) { - this.source.prepend('var ' + varDeclarations.substring(2) + (appendFirst ? '' : ';\n ')); + this.source.prepend('var ' + varDeclarations.substring(2) + (appendFirst ? '' : ';\n')); } return this.source.merge(); diff --git a/lib/handlebars/utils.js b/lib/handlebars/utils.js index 8cea50d..fc2b846 100644 --- a/lib/handlebars/utils.js +++ b/lib/handlebars/utils.js @@ -48,6 +48,16 @@ export var isArray = Array.isArray || function(value) { return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false; }; +// Older IE versions do not directly support indexOf so we must implement our own, sadly. +export function indexOf(array, value) { + for (var i = 0, len = array.length; i < len; i++) { + if (array[i] === value) { + return i; + } + } + return -1; +} + export function escapeExpression(string) { // don't escape SafeStrings, since they're already safe |