diff --git a/lib/Template.js b/lib/Template.js index fa83c50..573d10b 100755 --- a/lib/Template.js +++ b/lib/Template.js @@ -25,7 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -Template = function Template(config) { +var Template = exports.Template = function Template(config) { config = config || {}; for (var param in config) { this[param] = config[param]; @@ -60,7 +60,7 @@ Template.Constants = { CHOMP_NONE: 0, CHOMP_ONE: 1, CHOMP_COLLAPSE: 2, - CHOMP_GREEDY: 3, + CHOMP_GREEDY: 3 }; Template.Exception = function(code, message) { @@ -237,7 +237,7 @@ Template.Context.prototype = { catch (e) { } } if (contents === undefined) - return; + return contents; var parser = new Template.Parser(this.config); parser.parse(contents); @@ -311,12 +311,12 @@ Template.Context.prototype = { if ('assign' in args) { var last_seg = segments.pop(); if (Template.Stash.PRIVATE && Template.Stash.PRIVATE.exec(last_seg)) - return; + return undefined; for (var i in segments) { var segment = segments[i]; if (Template.Stash.PRIVATE && Template.Stash.PRIVATE.exec(segment)) - return; + return undefined; if (s[segment] === undefined) { s[segment] = {}; @@ -389,6 +389,7 @@ Template.Context.prototype = { try { return a.next(); } catch (e) { if (e !== StopIteration) throw e } + return undefined; } var idx = 0; @@ -430,7 +431,7 @@ Template.Context.prototype = { */ forEach: function(a, func, novar) { if (a === undefined || a === this.nullObj) - return; + return undefined; var stash = this.stash; var old_loop = this.stash.loop; @@ -466,7 +467,7 @@ Template.Context.prototype = { if (!novar && old_loop) this.stash.loop = old_loop; } - + return undefined; } }; @@ -605,7 +606,7 @@ Template.Parser.prototype = { this.log = function (str) { this._log.push(str); } - this.log(str); + return this.log(str); } }, @@ -657,7 +658,7 @@ Template.Parser.prototype = { '+': Template.Constants.CHOMP_NONE, '-': Template.Constants.CHOMP_ONE, '=': Template.Constants.CHOMP_COLLAPSE, - '~': Template.Constants.CHOMP_GREEDY, + '~': Template.Constants.CHOMP_GREEDY }, precedence: { @@ -683,7 +684,7 @@ Template.Parser.prototype = { '*' : 40, '/' : 40, - DIV : 40, + DIV : 40 }, /* @@ -819,7 +820,7 @@ Template.Parser.prototype = { var initPos = pos; - while (match = re.exec(text) ) { + while ( (match = re.exec(text) ) ) { pos = initPos + re.lastIndex - match[0].length; // Comment in $1 @@ -827,7 +828,7 @@ Template.Parser.prototype = { continue; // Quoted pharse in $3 (and quote char in $2) - if (token = match[3]) { + if ( (token = match[3]) ) { if (match[2] == '"') { if (token.match("[\$\\\\]") ) { type = 'QUOTED'; @@ -919,7 +920,7 @@ Template.Parser.prototype = { var match, pre, v, dir; var tokens = []; - while (match = re.exec(text)) { + while ( (match = re.exec(text)) ) { pre = match[1]; dir = match[2]; if (match[3]) @@ -1080,7 +1081,7 @@ Template.Parser.prototype = { var term = this.term(); if (term === undefined) - return; + return term; return this.expr_tail(term); }, @@ -1207,6 +1208,7 @@ Template.Parser.prototype = { if (segs.length) return {type: 'QUOTED', segments: segs }; + return undefined; }, ident: function Template$Parser$prototype$ident() { @@ -1235,18 +1237,15 @@ Template.Parser.prototype = { node: function Template$Parser$prototype$node() { var item = this.item(); - if (item === undefined) - return; - if (this.token.type == '(') { + if (item !== undefined && this.token.type == '(') { this.consumeToken(); // args var ret = {type: 'function_call', func: item }; ret.args = this.assertRule(this.args); this.assertToken(')'); return ret; - } else { - return item; } + return item; }, args: function Template$Parser$prototype$args() { @@ -1333,7 +1332,7 @@ Template.Parser.prototype = { ret = { type: 'interpret', term: ident }; return ret; default: - return; + return undefined; } }, @@ -1392,6 +1391,7 @@ Template.Parser.prototype = { return ret; } + return undefined; }, params: function Template$Parser$prototype$params() { @@ -1421,7 +1421,7 @@ Template.Parser.prototype = { } else { ret.to = this.item(); if (ret.to === undefined) - return; + return undefined; } this.assertToken('ASSIGN'); @@ -1484,7 +1484,7 @@ Template.Parser.prototype = { // Not an expression that starts with an ident (probably quoted) expr = this.expr(); if (!expr) - return; + return undefined; } } @@ -1492,7 +1492,7 @@ Template.Parser.prototype = { if (expr) { return this.postfixed_condition(expr); } - + return undefined; }, // called with an ident or a LITERAL, and the first ASSIGN already consumed @@ -1592,6 +1592,8 @@ Template.Parser.prototype = { case 'NEXT': case 'LAST': return this.consumeToken(); + default: + return undefined; } }, @@ -1611,6 +1613,7 @@ Template.Parser.prototype = { this.assertToken('END'); return ret; } + return undefined; }, loopvar: function Template$Parser$prototype$loopvar() { @@ -1647,7 +1650,7 @@ Template.Parser.prototype = { return this.consumeToken(); } else if (this.token.type == ';') { this.consumeToken(); - return; + return undefined; } else { var ret = this.assertRule(this.statement); this.assertToken(';'); @@ -1690,6 +1693,7 @@ Template.Parser.prototype = { return ret; } + return undefined; }, conditionElse: function Template$Parser$prototype$conditionElse(cond) { @@ -1735,7 +1739,7 @@ Template.Parser.prototype = { ident = this.ident(); if (ident === undefined) - return + return ident; this.assertToken('ASSIGN'); return this.setlist_tail(ident); @@ -1743,7 +1747,7 @@ Template.Parser.prototype = { block: function Template$Parser$prototype$block() { if (this.token.type != 'BLOCK') - return; + return undefined; this.consumeToken(); @@ -1772,7 +1776,7 @@ Template.Parser.prototype = { filename: function Template$Parser$prototype$filename() { var fn = this.filepart(); if (fn === undefined) - return; + return fn; while (this.token.type == 'DOT') { this.consumeToken(); @@ -1789,6 +1793,7 @@ Template.Parser.prototype = { { return this.consumeToken(); } + return undefined; }, metadata: function Template$Parser$prototype$metadata() { @@ -1817,6 +1822,7 @@ Template.Parser.prototype = { if (meta.length) return meta; + return undefined; }, lnameargs: function Template$Parser$prototype$lnameargs() { @@ -1889,6 +1895,7 @@ Template.Parser.prototype = { if (names.length) return names; + return undefined; }, name: function Template$Parser$prototype$name() { @@ -1908,7 +1915,7 @@ Template.Parser.prototype = { var valid = ['WRAPPER' ].indexOf(this.token.type) != -1; if (!valid) - return; + return undefined; var type = this.consumeToken().type; var block = this.assertRule(this.nameargs); @@ -1926,7 +1933,7 @@ Template.Parser.prototype = { filter: function Template$Parser$filter() { if (this.token.type != 'FILTER') - return; + return undefined; var ret = this.consumeToken(); @@ -1946,7 +1953,7 @@ Template.Parser.prototype = { switchBlock: function Template$Parser$switchBlock() { if (this.token.type != 'SWITCH') - return; + return undefined; var ret = this.consumeToken(); @@ -2516,8 +2523,7 @@ Template.Interpreter.prototype = { return 'parseInt'+ret; else return ret; - }, - + } }; /* @@ -2525,5 +2531,5 @@ Template.Interpreter.prototype = { */ -log = []; +var log = [];