handlebars
Advanced tools
Comparing version 1.0.6 to 1.0.7
@@ -47,9 +47,6 @@ // BEGIN(BROWSER) | ||
if(context.length > 0) { | ||
for(var i=0, j=context.length; i<j; i++) { | ||
ret = ret + fn(context[i]); | ||
} | ||
return Handlebars.helpers.each(context, options); | ||
} else { | ||
ret = inverse(this); | ||
return inverse(this); | ||
} | ||
return ret; | ||
} else { | ||
@@ -56,0 +53,0 @@ return fn(context); |
@@ -243,4 +243,10 @@ var Handlebars = require("./base"); | ||
this.opcode('getContext', id.depth); | ||
this.opcode('lookupOnContext', id.parts[0]); | ||
var name = id.parts[0]; | ||
if (!name) { | ||
this.opcode('pushContext'); | ||
} else { | ||
this.opcode('lookupOnContext', id.parts[0]); | ||
} | ||
for(var i=1, l=id.parts.length; i<l; i++) { | ||
@@ -247,0 +253,0 @@ this.opcode('lookup', id.parts[i]); |
@@ -106,86 +106,65 @@ /* Jison generated parser */ | ||
parse: function parse(input) { | ||
var self = this, | ||
stack = [0], | ||
vstack = [null], // semantic value stack | ||
lstack = [], // location stack | ||
table = this.table, | ||
yytext = '', | ||
yylineno = 0, | ||
yyleng = 0, | ||
recovering = 0, | ||
TERROR = 2, | ||
EOF = 1; | ||
//this.reductionCount = this.shiftCount = 0; | ||
var self = this, stack = [0], vstack = [null], lstack = [], table = this.table, yytext = "", yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1; | ||
this.lexer.setInput(input); | ||
this.lexer.yy = this.yy; | ||
this.yy.lexer = this.lexer; | ||
if (typeof this.lexer.yylloc == 'undefined') | ||
this.yy.parser = this; | ||
if (typeof this.lexer.yylloc == "undefined") | ||
this.lexer.yylloc = {}; | ||
var yyloc = this.lexer.yylloc; | ||
lstack.push(yyloc); | ||
if (typeof this.yy.parseError === 'function') | ||
var ranges = this.lexer.options && this.lexer.options.ranges; | ||
if (typeof this.yy.parseError === "function") | ||
this.parseError = this.yy.parseError; | ||
function popStack (n) { | ||
stack.length = stack.length - 2*n; | ||
function popStack(n) { | ||
stack.length = stack.length - 2 * n; | ||
vstack.length = vstack.length - n; | ||
lstack.length = lstack.length - n; | ||
} | ||
function lex() { | ||
var token; | ||
token = self.lexer.lex() || 1; // $end = 1 | ||
// if token isn't its numeric value, convert | ||
if (typeof token !== 'number') { | ||
token = self.lexer.lex() || 1; | ||
if (typeof token !== "number") { | ||
token = self.symbols_[token] || token; | ||
} | ||
return token; | ||
}; | ||
var symbol, preErrorSymbol, state, action, a, r, yyval={},p,len,newState, expected; | ||
} | ||
var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected; | ||
while (true) { | ||
// retreive state number from top of stack | ||
state = stack[stack.length-1]; | ||
// use default actions if available | ||
state = stack[stack.length - 1]; | ||
if (this.defaultActions[state]) { | ||
action = this.defaultActions[state]; | ||
} else { | ||
if (symbol == null) | ||
if (symbol === null || typeof symbol == "undefined") { | ||
symbol = lex(); | ||
// read action for current state and first input | ||
} | ||
action = table[state] && table[state][symbol]; | ||
} | ||
// handle parse error | ||
if (typeof action === 'undefined' || !action.length || !action[0]) { | ||
if (typeof action === "undefined" || !action.length || !action[0]) { | ||
var errStr = ""; | ||
if (!recovering) { | ||
// Report error | ||
expected = []; | ||
for (p in table[state]) if (this.terminals_[p] && p > 2) { | ||
expected.push("'"+this.terminals_[p]+"'"); | ||
} | ||
var errStr = ''; | ||
for (p in table[state]) | ||
if (this.terminals_[p] && p > 2) { | ||
expected.push("'" + this.terminals_[p] + "'"); | ||
} | ||
if (this.lexer.showPosition) { | ||
errStr = 'Parse error on line '+(yylineno+1)+":\n"+this.lexer.showPosition()+'\nExpecting '+expected.join(', '); | ||
errStr = "Parse error on line " + (yylineno + 1) + ":\n" + this.lexer.showPosition() + "\nExpecting " + expected.join(", ") + ", got '" + (this.terminals_[symbol] || symbol) + "'"; | ||
} else { | ||
errStr = 'Parse error on line '+(yylineno+1)+": Unexpected " + | ||
(symbol == 1 /*EOF*/ ? "end of input" : | ||
("'"+(this.terminals_[symbol] || symbol)+"'")); | ||
errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == 1?"end of input":"'" + (this.terminals_[symbol] || symbol) + "'"); | ||
} | ||
this.parseError(errStr, | ||
{text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected}); | ||
this.parseError(errStr, {text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected}); | ||
} | ||
// just recovered from another error | ||
if (recovering == 3) { | ||
if (symbol == EOF) { | ||
throw new Error(errStr || 'Parsing halted.'); | ||
} | ||
// discard current lookahead and grab another | ||
} | ||
if (action[0] instanceof Array && action.length > 1) { | ||
throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol); | ||
} | ||
switch (action[0]) { | ||
case 1: | ||
stack.push(symbol); | ||
vstack.push(this.lexer.yytext); | ||
lstack.push(this.lexer.yylloc); | ||
stack.push(action[1]); | ||
symbol = null; | ||
if (!preErrorSymbol) { | ||
yyleng = this.lexer.yyleng; | ||
@@ -195,100 +174,44 @@ yytext = this.lexer.yytext; | ||
yyloc = this.lexer.yylloc; | ||
symbol = lex(); | ||
if (recovering > 0) | ||
recovering--; | ||
} else { | ||
symbol = preErrorSymbol; | ||
preErrorSymbol = null; | ||
} | ||
// try to recover from error | ||
while (1) { | ||
// check for error recovery rule in this state | ||
if ((TERROR.toString()) in table[state]) { | ||
break; | ||
} | ||
if (state == 0) { | ||
throw new Error(errStr || 'Parsing halted.'); | ||
} | ||
popStack(1); | ||
state = stack[stack.length-1]; | ||
break; | ||
case 2: | ||
len = this.productions_[action[1]][1]; | ||
yyval.$ = vstack[vstack.length - len]; | ||
yyval._$ = {first_line: lstack[lstack.length - (len || 1)].first_line, last_line: lstack[lstack.length - 1].last_line, first_column: lstack[lstack.length - (len || 1)].first_column, last_column: lstack[lstack.length - 1].last_column}; | ||
if (ranges) { | ||
yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]]; | ||
} | ||
preErrorSymbol = symbol; // save the lookahead token | ||
symbol = TERROR; // insert generic error symbol as new lookahead | ||
state = stack[stack.length-1]; | ||
action = table[state] && table[state][TERROR]; | ||
recovering = 3; // allow 3 real symbols to be shifted before reporting a new error | ||
r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack); | ||
if (typeof r !== "undefined") { | ||
return r; | ||
} | ||
if (len) { | ||
stack = stack.slice(0, -1 * len * 2); | ||
vstack = vstack.slice(0, -1 * len); | ||
lstack = lstack.slice(0, -1 * len); | ||
} | ||
stack.push(this.productions_[action[1]][0]); | ||
vstack.push(yyval.$); | ||
lstack.push(yyval._$); | ||
newState = table[stack[stack.length - 2]][stack[stack.length - 1]]; | ||
stack.push(newState); | ||
break; | ||
case 3: | ||
return true; | ||
} | ||
// this shouldn't happen, unless resolve defaults are off | ||
if (action[0] instanceof Array && action.length > 1) { | ||
throw new Error('Parse Error: multiple actions possible at state: '+state+', token: '+symbol); | ||
} | ||
switch (action[0]) { | ||
case 1: // shift | ||
//this.shiftCount++; | ||
stack.push(symbol); | ||
vstack.push(this.lexer.yytext); | ||
lstack.push(this.lexer.yylloc); | ||
stack.push(action[1]); // push state | ||
symbol = null; | ||
if (!preErrorSymbol) { // normal execution/no error | ||
yyleng = this.lexer.yyleng; | ||
yytext = this.lexer.yytext; | ||
yylineno = this.lexer.yylineno; | ||
yyloc = this.lexer.yylloc; | ||
if (recovering > 0) | ||
recovering--; | ||
} else { // error just occurred, resume old lookahead f/ before error | ||
symbol = preErrorSymbol; | ||
preErrorSymbol = null; | ||
} | ||
break; | ||
case 2: // reduce | ||
//this.reductionCount++; | ||
len = this.productions_[action[1]][1]; | ||
// perform semantic action | ||
yyval.$ = vstack[vstack.length-len]; // default to $$ = $1 | ||
// default location, uses first token for firsts, last for lasts | ||
yyval._$ = { | ||
first_line: lstack[lstack.length-(len||1)].first_line, | ||
last_line: lstack[lstack.length-1].last_line, | ||
first_column: lstack[lstack.length-(len||1)].first_column, | ||
last_column: lstack[lstack.length-1].last_column | ||
}; | ||
r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack); | ||
if (typeof r !== 'undefined') { | ||
return r; | ||
} | ||
// pop off stack | ||
if (len) { | ||
stack = stack.slice(0,-1*len*2); | ||
vstack = vstack.slice(0, -1*len); | ||
lstack = lstack.slice(0, -1*len); | ||
} | ||
stack.push(this.productions_[action[1]][0]); // push nonterminal (reduce) | ||
vstack.push(yyval.$); | ||
lstack.push(yyval._$); | ||
// goto new state = table[STATE][NONTERMINAL] | ||
newState = table[stack[stack.length-2]][stack[stack.length-1]]; | ||
stack.push(newState); | ||
break; | ||
case 3: // accept | ||
return true; | ||
} | ||
} | ||
return true; | ||
}};/* Jison generated lexer */ | ||
var lexer = (function(){var lexer = ({EOF:1, | ||
} | ||
}; | ||
/* Jison generated lexer */ | ||
var lexer = (function(){ | ||
var lexer = ({EOF:1, | ||
parseError:function parseError(str, hash) { | ||
if (this.yy.parseError) { | ||
this.yy.parseError(str, hash); | ||
if (this.yy.parser) { | ||
this.yy.parser.parseError(str, hash); | ||
} else { | ||
@@ -305,2 +228,4 @@ throw new Error(str); | ||
this.yylloc = {first_line:1,first_column:0,last_line:1,last_column:0}; | ||
if (this.options.ranges) this.yylloc.range = [0,0]; | ||
this.offset = 0; | ||
return this; | ||
@@ -310,8 +235,16 @@ }, | ||
var ch = this._input[0]; | ||
this.yytext+=ch; | ||
this.yytext += ch; | ||
this.yyleng++; | ||
this.match+=ch; | ||
this.matched+=ch; | ||
var lines = ch.match(/\n/); | ||
if (lines) this.yylineno++; | ||
this.offset++; | ||
this.match += ch; | ||
this.matched += ch; | ||
var lines = ch.match(/(?:\r\n?|\n).*/g); | ||
if (lines) { | ||
this.yylineno++; | ||
this.yylloc.last_line++; | ||
} else { | ||
this.yylloc.last_column++; | ||
} | ||
if (this.options.ranges) this.yylloc.range[1]++; | ||
this._input = this._input.slice(1); | ||
@@ -321,3 +254,27 @@ return ch; | ||
unput:function (ch) { | ||
var len = ch.length; | ||
var lines = ch.split(/(?:\r\n?|\n)/g); | ||
this._input = ch + this._input; | ||
this.yytext = this.yytext.substr(0, this.yytext.length-len-1); | ||
//this.yyleng -= len; | ||
this.offset -= len; | ||
var oldLines = this.match.split(/(?:\r\n?|\n)/g); | ||
this.match = this.match.substr(0, this.match.length-1); | ||
this.matched = this.matched.substr(0, this.matched.length-1); | ||
if (lines.length-1) this.yylineno -= lines.length-1; | ||
var r = this.yylloc.range; | ||
this.yylloc = {first_line: this.yylloc.first_line, | ||
last_line: this.yylineno+1, | ||
first_column: this.yylloc.first_column, | ||
last_column: lines ? | ||
(lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length: | ||
this.yylloc.first_column - len | ||
}; | ||
if (this.options.ranges) { | ||
this.yylloc.range = [r[0], r[0] + this.yyleng - len]; | ||
} | ||
return this; | ||
@@ -329,2 +286,5 @@ }, | ||
}, | ||
less:function (n) { | ||
this.unput(this.match.slice(n)); | ||
}, | ||
pastInput:function () { | ||
@@ -354,2 +314,4 @@ var past = this.matched.substr(0, this.matched.length - this.match.length); | ||
match, | ||
tempMatch, | ||
index, | ||
col, | ||
@@ -363,26 +325,35 @@ lines; | ||
for (var i=0;i < rules.length; i++) { | ||
match = this._input.match(this.rules[rules[i]]); | ||
if (match) { | ||
lines = match[0].match(/\n.*/g); | ||
if (lines) this.yylineno += lines.length; | ||
this.yylloc = {first_line: this.yylloc.last_line, | ||
last_line: this.yylineno+1, | ||
first_column: this.yylloc.last_column, | ||
last_column: lines ? lines[lines.length-1].length-1 : this.yylloc.last_column + match[0].length} | ||
this.yytext += match[0]; | ||
this.match += match[0]; | ||
this.matches = match; | ||
this.yyleng = this.yytext.length; | ||
this._more = false; | ||
this._input = this._input.slice(match[0].length); | ||
this.matched += match[0]; | ||
token = this.performAction.call(this, this.yy, this, rules[i],this.conditionStack[this.conditionStack.length-1]); | ||
if (token) return token; | ||
else return; | ||
tempMatch = this._input.match(this.rules[rules[i]]); | ||
if (tempMatch && (!match || tempMatch[0].length > match[0].length)) { | ||
match = tempMatch; | ||
index = i; | ||
if (!this.options.flex) break; | ||
} | ||
} | ||
if (match) { | ||
lines = match[0].match(/(?:\r\n?|\n).*/g); | ||
if (lines) this.yylineno += lines.length; | ||
this.yylloc = {first_line: this.yylloc.last_line, | ||
last_line: this.yylineno+1, | ||
first_column: this.yylloc.last_column, | ||
last_column: lines ? lines[lines.length-1].length-lines[lines.length-1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length}; | ||
this.yytext += match[0]; | ||
this.match += match[0]; | ||
this.matches = match; | ||
this.yyleng = this.yytext.length; | ||
if (this.options.ranges) { | ||
this.yylloc.range = [this.offset, this.offset += this.yyleng]; | ||
} | ||
this._more = false; | ||
this._input = this._input.slice(match[0].length); | ||
this.matched += match[0]; | ||
token = this.performAction.call(this, this.yy, this, rules[index],this.conditionStack[this.conditionStack.length-1]); | ||
if (this.done && this._input) this.done = false; | ||
if (token) return token; | ||
else return; | ||
} | ||
if (this._input === "") { | ||
return this.EOF; | ||
} else { | ||
this.parseError('Lexical error on line '+(this.yylineno+1)+'. Unrecognized text.\n'+this.showPosition(), | ||
return this.parseError('Lexical error on line '+(this.yylineno+1)+'. Unrecognized text.\n'+this.showPosition(), | ||
{text: "", token: null, line: this.yylineno}); | ||
@@ -407,3 +378,10 @@ } | ||
return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules; | ||
}, | ||
topState:function () { | ||
return this.conditionStack[this.conditionStack.length-2]; | ||
}, | ||
pushState:function begin(condition) { | ||
this.begin(condition); | ||
}}); | ||
lexer.options = {}; | ||
lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) { | ||
@@ -421,3 +399,7 @@ | ||
break; | ||
case 2: this.popState(); return 14; | ||
case 2: | ||
if(yy_.yytext.slice(-1) !== "\\") this.popState(); | ||
if(yy_.yytext.slice(-1) === "\\") yy_.yytext = yy_.yytext.substr(0,yy_.yyleng-1); | ||
return 14; | ||
break; | ||
@@ -458,27 +440,32 @@ case 3: return 24; | ||
break; | ||
case 20: yy_.yytext = yy_.yytext.substr(1); return 27; | ||
case 20: yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\"/g,'"'); return 29; | ||
break; | ||
case 21: return 31; | ||
case 21: yy_.yytext = yy_.yytext.substr(1); return 27; | ||
break; | ||
case 22: return 31; | ||
break; | ||
case 23: return 30; | ||
case 23: return 31; | ||
break; | ||
case 24: return 34; | ||
case 24: return 30; | ||
break; | ||
case 25: yy_.yytext = yy_.yytext.substr(1, yy_.yyleng-2); return 34; | ||
case 25: return 34; | ||
break; | ||
case 26: return 'INVALID'; | ||
case 26: yy_.yytext = yy_.yytext.substr(1, yy_.yyleng-2); return 34; | ||
break; | ||
case 27: return 5; | ||
case 27: return 'INVALID'; | ||
break; | ||
case 28: return 5; | ||
break; | ||
} | ||
}; | ||
lexer.rules = [/^[^\x00]*?(?=(\{\{))/,/^[^\x00]+/,/^[^\x00]{2,}?(?=(\{\{))/,/^\{\{>/,/^\{\{#/,/^\{\{\//,/^\{\{\^/,/^\{\{\s*else\b/,/^\{\{\{/,/^\{\{&/,/^\{\{![\s\S]*?\}\}/,/^\{\{/,/^=/,/^\.(?=[} ])/,/^\.\./,/^[\/.]/,/^\s+/,/^\}\}\}/,/^\}\}/,/^"(\\["]|[^"])*"/,/^@[a-zA-Z]+/,/^true(?=[}\s])/,/^false(?=[}\s])/,/^[0-9]+(?=[}\s])/,/^[a-zA-Z0-9_$-]+(?=[=}\s\/.])/,/^\[[^\]]*\]/,/^./,/^$/]; | ||
lexer.conditions = {"mu":{"rules":[3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27],"inclusive":false},"emu":{"rules":[2],"inclusive":false},"INITIAL":{"rules":[0,1,27],"inclusive":true}};return lexer;})() | ||
lexer.rules = [/^(?:[^\x00]*?(?=(\{\{)))/,/^(?:[^\x00]+)/,/^(?:[^\x00]{2,}?(?=(\{\{|$)))/,/^(?:\{\{>)/,/^(?:\{\{#)/,/^(?:\{\{\/)/,/^(?:\{\{\^)/,/^(?:\{\{\s*else\b)/,/^(?:\{\{\{)/,/^(?:\{\{&)/,/^(?:\{\{![\s\S]*?\}\})/,/^(?:\{\{)/,/^(?:=)/,/^(?:\.(?=[} ]))/,/^(?:\.\.)/,/^(?:[\/.])/,/^(?:\s+)/,/^(?:\}\}\})/,/^(?:\}\})/,/^(?:"(\\["]|[^"])*")/,/^(?:'(\\[']|[^'])*')/,/^(?:@[a-zA-Z]+)/,/^(?:true(?=[}\s]))/,/^(?:false(?=[}\s]))/,/^(?:[0-9]+(?=[}\s]))/,/^(?:[a-zA-Z0-9_$-]+(?=[=}\s\/.]))/,/^(?:\[[^\]]*\])/,/^(?:.)/,/^(?:$)/]; | ||
lexer.conditions = {"mu":{"rules":[3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28],"inclusive":false},"emu":{"rules":[2],"inclusive":false},"INITIAL":{"rules":[0,1,28],"inclusive":true}}; | ||
return lexer;})() | ||
parser.lexer = lexer; | ||
return parser; | ||
function Parser () { this.yy = {}; }Parser.prototype = parser;parser.Parser = Parser; | ||
return new Parser; | ||
})(); | ||
if (typeof require !== 'undefined' && typeof exports !== 'undefined') { | ||
exports.parser = handlebars; | ||
exports.Parser = handlebars.Parser; | ||
exports.parse = function () { return handlebars.parse.apply(handlebars, arguments); } | ||
@@ -488,7 +475,7 @@ exports.main = function commonjsMain(args) { | ||
throw new Error('Usage: '+args[0]+' FILE'); | ||
var source, cwd; | ||
if (typeof process !== 'undefined') { | ||
var source = require('fs').readFileSync(require('path').join(process.cwd(), args[1]), "utf8"); | ||
source = require('fs').readFileSync(require('path').resolve(args[1]), "utf8"); | ||
} else { | ||
var cwd = require("file").path(require("file").cwd()); | ||
var source = cwd.join(args[1]).read({charset: "utf-8"}); | ||
source = require("file").path(require("file").cwd()).join(args[1]).read({charset: "utf-8"}); | ||
} | ||
@@ -495,0 +482,0 @@ return exports.parser.parse(source); |
@@ -59,3 +59,3 @@ var Handlebars = require("./base"); | ||
} else { | ||
partials[name] = Handlebars.compile(partial); | ||
partials[name] = Handlebars.compile(partial, {data: data !== undefined}); | ||
return partials[name](context, options); | ||
@@ -62,0 +62,0 @@ } |
@@ -25,2 +25,3 @@ var Handlebars = require("./base"); | ||
var escape = { | ||
"&": "&", | ||
"<": "<", | ||
@@ -33,3 +34,3 @@ ">": ">", | ||
var badChars = /&(?!\w+;)|[<>"'`]/g; | ||
var badChars = /[&<>"'`]/g; | ||
var possible = /[&<>"'`]/; | ||
@@ -36,0 +37,0 @@ |
{ | ||
"name": "handlebars", | ||
"description": "Extension of the Mustache logicless template language", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"homepage": "http://www.handlebarsjs.com/", | ||
@@ -11,3 +11,3 @@ "keywords": [ | ||
"type": "git", | ||
"url": "git://github.com/kpdecker/handlebars.js.git" | ||
"url": "git://github.com/wycats/handlebars.js.git" | ||
}, | ||
@@ -14,0 +14,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1791
84953
18