Comparing version 0.4.4-926 to 0.4.5-977
@@ -28,7 +28,9 @@ /*jshint strict:false, laxcomma:true, laxbreak:true, boss:true, curly:true, node:true, browser:true, devel:true */ | ||
exports["version"] = "0.4.4-926"; | ||
exports["version"] = "0.4.4-977"; | ||
exports["helpers"] = {}; | ||
exports["config"] = { | ||
"useWith": false | ||
,"modelName": "model" | ||
,"helpersName": "html" | ||
,"htmlEscape": true | ||
,"debug": false | ||
@@ -58,3 +60,2 @@ ,"debugParser": false | ||
,HARD_PAREN_OPEN = 'HARD_PAREN_OPEN' | ||
,HTML_RAW = 'HTML_RAW' | ||
,HTML_TAG_CLOSE = 'HTML_TAG_CLOSE' | ||
@@ -100,3 +101,3 @@ ,HTML_TAG_OPEN = 'HTML_TAG_OPEN' | ||
EMAIL, (/^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})\b/) | ||
EMAIL, (/^([a-zA-Z0-9._%\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,4})\b/) | ||
@@ -131,11 +132,7 @@ | ||
,HTML_TAG_SELFCLOSE, function(){ | ||
return this.scan(/^(<[^@>]+?\/>)/, HTML_TAG_SELFCLOSE); | ||
} | ||
,HTML_TAG_SELFCLOSE, (/^(<[^@>]+?\/>)/) | ||
,HTML_TAG_OPEN, function(){ | ||
return this.spewIf(this.scan(/^(<[^\/ >]+?[^>]*?>)/, HTML_TAG_OPEN), '@'); | ||
} | ||
,HTML_TAG_CLOSE, function(){ | ||
return this.scan(/^(<\/[^>@\b]+?>)/, HTML_TAG_CLOSE); | ||
} | ||
,HTML_TAG_CLOSE, (/^(<\/[^>@\b]+?>)/) | ||
@@ -155,3 +152,2 @@ | ||
,KEYWORD, (/^(case|catch|do|else|finally|for|function|goto|if|instanceof|return|switch|try|typeof|var|while|with)(?![\d\w])/) | ||
,HTML_RAW, (/^(vash\.raw)(?![\d\w])/) | ||
,IDENTIFIER, (/^([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)/) | ||
@@ -187,17 +183,3 @@ | ||
tok: function(type, val){ | ||
return { | ||
type: type | ||
,line: this.lineno | ||
,chr: this.charno | ||
,val: val | ||
,toString: function(){ | ||
return '[' + this.type | ||
+ ' (' + this.line + ',' + this.chr + '): ' | ||
+ this.val + ']'; | ||
} | ||
}; | ||
} | ||
,scan: function(regexp, type){ | ||
scan: function(regexp, type){ | ||
var captures, token; | ||
@@ -207,3 +189,14 @@ if (captures = regexp.exec(this.input)) { | ||
token = this.tok(type, captures[1]); | ||
token = { | ||
type: type | ||
,line: this.lineno | ||
,chr: this.charno | ||
,val: captures[1] | ||
,toString: function(){ | ||
return '[' + this.type | ||
+ ' (' + this.line + ',' + this.chr + '): ' | ||
+ this.val + ']'; | ||
} | ||
}; | ||
this.charno += captures[0].length; | ||
@@ -408,12 +401,14 @@ return token; | ||
vQuery.copyObj = function(obj){ | ||
var nObj = {}; | ||
vQuery.extend = function(obj){ | ||
var next, i, p; | ||
for(var i in obj){ | ||
if(Object.prototype.hasOwnProperty.call(obj, i)){ | ||
nObj[i] = obj[i]; | ||
for(i = 1; i < arguments.length; i++){ | ||
next = arguments[i]; | ||
for(p in next){ | ||
obj[p] = next[p]; | ||
} | ||
} | ||
return nObj; | ||
return obj; | ||
} | ||
@@ -436,5 +431,4 @@ | ||
(function(methodName){ | ||
var slice = Array.prototype.slice; | ||
vQuery.fn[methodName] = function(){ | ||
return arr[methodName].apply(this, slice.call(arguments, 0)); | ||
return arr[methodName].apply(this, Array.prototype.slice.call(arguments, 0)); | ||
} | ||
@@ -591,3 +585,3 @@ })(m); | ||
,miniParse | ||
,parseOpts = vQuery.copyObj(this.options); | ||
,parseOpts = vQuery.extend({}, this.options); | ||
@@ -633,4 +627,3 @@ parseOpts.initialMode = modeToOpen; | ||
case IDENTIFIER: | ||
case HTML_RAW: | ||
if(this.ast.length === 0) { | ||
@@ -717,3 +710,3 @@ this.ast = this.ast.parent; | ||
this.ast.parent && this.ast.parent.mode === BLK | ||
&& (next.type === WHITESPACE || next.type === NEWLINE) | ||
&& (next && (next.type === WHITESPACE || next.type === NEWLINE)) | ||
){ | ||
@@ -730,3 +723,3 @@ this.ast = this.ast.parent; | ||
this.ast.parent && this.ast.parent.mode === BLK | ||
&& (next.type === WHITESPACE || next.type === NEWLINE) | ||
&& (next && (next.type === WHITESPACE || next.type === NEWLINE)) | ||
){ | ||
@@ -853,3 +846,2 @@ this.ast = this.ast.parent; | ||
case IDENTIFIER: | ||
case HTML_RAW: | ||
this.ast.push(curr); | ||
@@ -942,5 +934,7 @@ break; | ||
VCP.assemble = function(options){ | ||
VCP.assemble = function(options, helpers){ | ||
options = options || {}; | ||
helpers = helpers || {}; | ||
@@ -954,3 +948,6 @@ var buffer = [] | ||
,joined | ||
,func; | ||
,compiledFunc | ||
,linkedFunc | ||
,markupBuffer = []; | ||
@@ -968,6 +965,6 @@ function insertDebugVars(tok){ | ||
buffer.push( | ||
"__vo.push('" + tok.val | ||
"MKP('" + tok.val | ||
.replace(reQuote, '\"') | ||
.replace(reLineBreak, '\\n') | ||
+ "'); \n" ); | ||
+ "')MKP" ); | ||
} | ||
@@ -988,28 +985,12 @@ | ||
if(tok.type === HTML_RAW){ | ||
escapeStack.push(true); | ||
} | ||
if( parentParentIsNotEXP && index === 0 && isHomogenous ){ | ||
if(escapeStack.length === 0){ | ||
start += '( typeof (__vt = '; | ||
} | ||
start += options.helpersName + '.escape('; | ||
} | ||
if( parentParentIsNotEXP && index === parentNode.length - 1 && isHomogenous){ | ||
if(escapeStack.length > 0){ | ||
escapeStack.pop(); | ||
} else { | ||
end += ") !== 'undefined' ? __vt : '' ).toString()\n" | ||
+ ".replace(/&(?!\\w+;)/g, '&')\n" | ||
+ ".replace(/</g, '<')\n" | ||
+ ".replace(/>/g, '>')\n" | ||
+ ".replace(/\"/g, '"') \n"; | ||
} | ||
end += ").toHtmlString() \n"; | ||
} | ||
} | ||
if(parentParentIsNotEXP && (index === 0 || (index === 1 && parentNode[0].type === HTML_RAW) ) ){ | ||
if(parentParentIsNotEXP && (index === 0 ) ){ | ||
insertDebugVars(tok); | ||
@@ -1019,14 +1000,7 @@ start = "__vo.push(" + start; | ||
if( | ||
parentParentIsNotEXP | ||
&& (index === parentNode.length - 1 | ||
|| (index === parentNode.length - 2 | ||
&& parentNode[ parentNode.length - 1 ].type === HTML_RAW) ) | ||
){ | ||
if( parentParentIsNotEXP && index === parentNode.length - 1 ){ | ||
end += "); \n"; | ||
} | ||
if(tok.type !== HTML_RAW){ | ||
buffer.push( start + tok.val.replace(reQuote, '"').replace(reEscapedQuote, '"') + end ); | ||
} | ||
buffer.push( start + tok.val.replace(reQuote, '"').replace(reEscapedQuote, '"') + end ); | ||
@@ -1090,3 +1064,3 @@ if(parentParentIsNotEXP && index === parentNode.length - 1){ | ||
} | ||
visitNode(this.ast); | ||
@@ -1114,2 +1088,8 @@ | ||
// coalesce markup | ||
joined = joined | ||
.split("')MKPMKP('").join('') | ||
.split("MKP(").join("__vo.push(") | ||
.split(")MKP").join("); \n"); | ||
if(options.debugCompiler){ | ||
@@ -1120,9 +1100,14 @@ console.log(joined); | ||
try { | ||
func = new Function(options.modelName, joined); | ||
compiledFunc = new Function(options.modelName, options.helpersName, joined); | ||
} catch(e){ | ||
e.message += ' -> ' + joined; | ||
throw e; | ||
} | ||
} | ||
return func; | ||
// Link compiled function to helpers collection, but report original function | ||
// body for code generation purposes. | ||
linkedFunc = function(model) { return compiledFunc(model, helpers); }; | ||
linkedFunc.toString = function() { return compiledFunc.toString(); }; | ||
return linkedFunc; | ||
} | ||
@@ -1156,4 +1141,45 @@ | ||
} | ||
/************** End injected code from build script */ | ||
/************** End injected code from build script */ | ||
exports["helpers"].raw = function( val ) { | ||
var func = function() { return val; } | ||
val = val != null ? val : ""; | ||
return { | ||
toHtmlString: func | ||
,toString: func | ||
}; | ||
} | ||
// Cached to compile once and reuse. | ||
var HTML_REGEX = /[&<>"'`]/g | ||
,HTML_REPLACER = function(match) { return HTML_CHARS[match]; } | ||
,HTML_CHARS = { | ||
"&": "&" | ||
,"<": "<" | ||
,">": ">" | ||
,'"': """ | ||
,"'": "'" | ||
,"`": "`" | ||
}; | ||
exports["helpers"].escape = function( val ) { | ||
var func = function() { return val; } | ||
val = val != null ? val : ""; | ||
if ( typeof val.toHtmlString !== "function" ) { | ||
val = val.toString().replace( HTML_REGEX, HTML_REPLACER ); | ||
return { | ||
toHtmlString: func | ||
,toString: func | ||
}; | ||
} | ||
return val; | ||
} | ||
exports["VLexer"] = VLexer; | ||
@@ -1173,10 +1199,6 @@ exports["VParser"] = VParser; | ||
,c | ||
,cmp; | ||
,cmp | ||
,i; | ||
options = options || {}; | ||
options.useWith = options.useWith || exports.config.useWith; | ||
options.modelName = options.modelName || exports.config.modelName; | ||
options.debug = options.debug || exports.config.debug; | ||
options.debugParser = options.debugParser || exports.config.debugParser; | ||
options.debugCompiler = options.debugCompiler || exports.config.debugCompiler; | ||
options = vQuery.extend( {}, exports.config, options || {} ); | ||
@@ -1192,3 +1214,3 @@ l = new VLexer(markup); | ||
cmp = c.assemble(options); | ||
cmp = c.assemble(options, exports.helpers); | ||
cmp.displayName = 'render'; | ||
@@ -1195,0 +1217,0 @@ return cmp; |
@@ -1,1 +0,1 @@ | ||
(function(a){typeof define=="function"&&define.amd?define(a):typeof module=="object"&&module.exports?module.exports=a:window.vash=a})(function(a){function R(a,b){this.ast=a,this.originalMarkup=b||""}function M(a,b){this.options=b||{},this.tokens=a,this.ast=L(N),this.prevTokens=[]}function K(a){this.input=this.originalInput=a.replace(/\r\n|\r/g,"\n"),this.lineno=1,this.charno=0}var b=a;a.version="0.4.4-926",a.config={useWith:!1,modelName:"model",debug:!1,debugParser:!1,debugCompiler:!1};var c="AT",d="ASSIGN_OPERATOR",e="AT_COLON",f="AT_STAR_CLOSE",g="AT_STAR_OPEN",h="BACKSLASH",i="BRACE_CLOSE",j="BRACE_OPEN",k="CONTENT",l="DOUBLE_QUOTE",m="EMAIL",n="FAT_ARROW",o="FUNCTION",p="HARD_PAREN_CLOSE",q="HARD_PAREN_OPEN",r="HTML_RAW",s="HTML_TAG_CLOSE",t="HTML_TAG_OPEN",u="HTML_TAG_SELFCLOSE",v="IDENTIFIER",w="KEYWORD",x="LOGICAL",y="NEWLINE",z="NUMERIC_CONTENT",A="OPERATOR",B="PAREN_CLOSE",C="PAREN_OPEN",D="PERIOD",E="SINGLE_QUOTE",F="TEXT_TAG_CLOSE",G="TEXT_TAG_OPEN",H="WHITESPACE",I={};I[g]=f,I[j]=i,I[l]=l,I[q]=p,I[C]=B,I[E]=E;var J=[m,/^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})\b/,g,/^(@\*)/,f,/^(\*@)/,e,/^@\:/,c,/^(@)/,n,/^(\(.*?\)?\s*?=>)/,C,/^(\()/,B,/^(\))/,q,/^(\[)/,p,/^(\])/,j,/^(\{)/,i,/^(\})/,G,/^(<text>)/,F,/^(<\/text>)/,u,function(){return this.scan(/^(<[^@>]+?\/>)/,u)},t,function(){return this.spewIf(this.scan(/^(<[^\/ >]+?[^>]*?>)/,t),"@")},s,function(){return this.scan(/^(<\/[^>@\b]+?>)/,s)},D,/^(\.)/,y,function(){var a=this.scan(/^(\n)/,y);a&&(this.lineno++,this.charno=0);return a},H,/^(\s)/,o,/^(function)(?![\d\w])/,w,/^(case|catch|do|else|finally|for|function|goto|if|instanceof|return|switch|try|typeof|var|while|with)(?![\d\w])/,r,/^(vash\.raw)(?![\d\w])/,v,/^([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)/,A,/^(===|!==|==|!==|>>>|<<|>>|>=|<=|>|<|\+|-|\/|\*|\^|%|\:|\?)/,d,/^(\|=|\^=|&=|>>>=|>>=|<<=|-=|\+=|%=|\/=|\*=|=)/,x,/^(&&|\|\||&|\||\^)/,h,/^(\\)/,l,/^(\")/,E,/^(\')/,z,/^([0-9]+)/,k,/^([^\s})@.]+?)/];K.prototype={tok:function(a,b){return{type:a,line:this.lineno,chr:this.charno,val:b,toString:function(){return"["+this.type+" ("+this.line+","+this.chr+"): "+this.val+"]"}}},scan:function(a,b){var c,d;if(c=a.exec(this.input)){this.input=this.input.substr(c[0].length),d=this.tok(b,c[1]),this.charno+=c[0].length;return d}},spewIf:function(a,b){var c,d;a&&(c=a.val.split(b),c.length>1&&(a.val=c.shift(),d=b+c.join(b),this.input=d+this.input,this.charno-=d.length));return a},advance:function(){var a,b,c,d;for(a=0;a<J.length;a+=2){c=J[a+1],c.displayName=J[a],typeof c=="function"&&(d=c.call(this)),typeof c.exec=="function"&&(d=this.scan(c,J[a]));if(d)return d}}};var L=function(a){return new L.fn.init(a)};L.prototype.init=function(a){typeof a=="string"&&(this.mode=a),this.maxCheck()},L.fn=L.prototype.init.prototype=L.prototype,L.fn.vquery="yep",L.fn.constructor=L,L.fn.length=0,L.fn.parent=null,L.fn.mode=null,L.fn.tagName=null,L.fn.beget=function(a,b){var c=L(a);c.parent=this,this.push(c),b&&(c.tagName=b),this.maxCheck();return c},L.fn.closest=function(a,b){var c=this;while(c)if(c.tagName!==b&&c.parent)c=c.parent;else break;return c},L.fn.pushFlatten=function(a){var b=a,c,d;while(b.length===1&&b[0].vquery)b=b[0];if(b.mode!==N)this.push(b);else for(c=0;c<b.length;c++)this.push(b[c]);this.maxCheck();return this},L.fn.push=function(a){L.isArray(a)?(a.vquery&&a.forEach(function(a){a.parent=this},this),Array.prototype.push.apply(this,a)):(a.vquery&&(a.parent=this),Array.prototype.push.call(this,a)),this.maxCheck();return this.length},L.fn.root=function(){var a=this;while(a&&a.parent&&(a=a.parent));return a},L.fn.toTreeString=function(){function c(d){var e,f;a.push(Array(b).join(" |")+" +"+d.mode+" "+(d.tagName||"")),b+=1,e=d.slice();while(f=e.shift())f.vquery===L.fn.vquery?c(f):a.push(Array(b).join(" |")+" "+(f?f.toString():"[empty]"));b-=1}var a=[],b=1;c(this);return a.join("\n")},L.fn.maxCheck=function(){if(this.length>=L.maxSize){var a=new Error;a.message="Maximum number of elements exceeded",a.name="vQueryDepthException";throw a}},L.maxSize=1e3,L.isArray=function(a){return Object.prototype.toString.call(a)=="[object Array]"},L.copyObj=function(a){var b={};for(var c in a)Object.prototype.hasOwnProperty.call(a,c)&&(b[c]=a[c]);return b},L.takeMethodsFromArray=function(){var a=["pop","push","reverse","shift","sort","splice","unshift","concat","join","slice","indexOf","lastIndexOf","filter","forEach","every","map","some","reduce","reduceRight"],b=[],c;for(var d=0;d<a.length;d++){c=a[d];if(typeof b[c]=="function")L.fn[c]||function(a){var c=Array.prototype.slice;L.fn[a]=function(){return b[a].apply(this,c.call(arguments,0))}}(c);else throw new Error("Vash requires ES5 array iteration methods, missing: "+c)}},L.takeMethodsFromArray();var N="PROGRAM",O="MARKUP",P="BLOCK",Q="EXPRESSION";M.prototype={parse:function(){var a,b,c,d;while(this.prevTokens.push(a),a=this.tokens.pop()){this.options.debugParser&&console.log(this.ast&&this.ast.mode,a.type,a,a.val);if(this.ast.mode===N||this.ast.mode===null)this.ast=this.ast.beget(this.options.initialMode||O),this.options.initialMode===Q&&(this.ast=this.ast.beget(Q));if(this.ast.mode===O){this.handleMKP(a);continue}if(this.ast.mode===P){this.handleBLK(a);continue}if(this.ast.mode===Q){this.handleEXP(a);continue}}this.ast=this.ast.root(),this.options.debugParser&&!this.options.initialMode&&(console.log(this.ast),console.log(this.ast.toTreeString()));return this.ast},exceptionFactory:function(a,b,c){b=="UNMATCHED"&&(a.name="UnmatchedCharacterError",this.ast=this.ast.root(),c&&(a.message="Unmatched "+c.type+" at line "+c.line+", character "+c.chr+". Value: "+c.val+"\n "+this.ast.toTreeString(),a.lineNumber=c.line));return a},advanceUntilNot:function(a){var b,c,d=[];while(c=this.tokens[this.tokens.length-1])if(c.type===a)b=this.tokens.pop(),d.push(b);else break;return d},advanceUntilMatched:function(a,b,c,d,e){var f=a,g=null,h=0,i=0,j=[];while(f){f.type===b?g&&g.type!==escape&&b!==c||!g?h++:b===c&&i++:f.type===c&&(i++,g&&g.type===e&&i--),j.push(f);if(h===i)break;g=f,f=this.tokens.pop();if(!f)throw this.exceptionFactory(new Error,"UNMATCHED",a)}return j.reverse()},subParse:function(a,b){var d,e,f,g=L.copyObj(this.options);g.initialMode=b,d=this.advanceUntilMatched(a,a.type,I[a.type],null,c),d.pop(),e=d.shift(),this.ast.push(a),f=new M(d,g),f.parse(),this.ast.pushFlatten(f.ast),this.ast.push(e)},handleMKP:function(a){var b=this.tokens[this.tokens.length-1],d=this.tokens[this.tokens.length-2],e=null,h;switch(a.type){case g:this.advanceUntilMatched(a,g,f,c,c);break;case c:if(b)switch(b.type){case C:case v:case r:this.ast.length===0&&(this.ast=this.ast.parent,this.ast.pop()),this.ast=this.ast.beget(Q);break;case w:case o:case j:this.ast.length===0&&(this.ast=this.ast.parent,this.ast.pop()),this.ast=this.ast.beget(P);break;default:this.ast.push(this.tokens.pop())}break;case j:this.ast=this.ast.beget(P),this.tokens.push(a);break;case i:this.ast=this.ast.parent,this.tokens.push(a);break;case G:case t:e=a.val.match(/^<([^\/ >]+)/i),e===null&&b&&b.type===c&&d&&(e=d.val.match(/(.*)/)),this.ast.tagName?this.ast=this.ast.beget(O,e[1]):this.ast.tagName=e[1],t===a.type&&this.ast.push(a);break;case F:case s:e=a.val.match(/^<\/([^>]+)/i),e===null&&b&&b.type===c&&d&&(e=d.val.match(/(.*)/)),h=this.ast.closest(O,e[1]),h!==null&&h.tagName===e[1]&&(this.ast=h),s===a.type&&this.ast.push(a),this.ast.parent&&this.ast.parent.mode===P&&(b.type===H||b.type===y)&&(this.ast=this.ast.parent);break;case u:this.ast.push(a),this.ast.parent&&this.ast.parent.mode===P&&(b.type===H||b.type===y)&&(this.ast=this.ast.parent);break;default:this.ast.push(a)}},handleBLK:function(a){var b=this.tokens[this.tokens.length-1],d,f,g,h,i,k;switch(a.type){case c:b.type!==c&&(this.tokens.push(a),this.ast=this.ast.beget(O));break;case e:this.ast=this.ast.beget(O);break;case G:case F:case u:case t:case s:this.ast=this.ast.beget(O),this.tokens.push(a);break;case n:this.ast=this.ast.beget(P);break;case j:case C:this.subParse(a,P),g=this.advanceUntilNot(H),b=this.tokens[this.tokens.length-1],b&&b.type!==w&&b.type!==o&&b.type!==j&&a.type!==C?(this.tokens.push.apply(this.tokens,g.reverse()),this.ast=this.ast.parent):this.ast.push(g);break;case H:this.ast.push(a),this.advanceUntilNot(H);break;default:this.ast.push(a)}},handleEXP:function(a){var b=null,e,f,g,i,k,m,p;switch(a.type){case w:case o:this.ast=this.ast.beget(P),this.tokens.push(a);break;case H:case x:case d:case A:case z:this.ast.parent&&this.ast.parent.mode===Q?this.ast.push(a):(this.ast=this.ast.parent,this.tokens.push(a));break;case v:case r:this.ast.push(a);break;case E:case l:this.ast.parent&&this.ast.parent.mode===Q?(k=this.advanceUntilMatched(a,a.type,I[a.type],h,h),this.ast.pushFlatten(k.reverse())):(this.ast=this.ast.parent,this.tokens.push(a));break;case q:case C:m=this.prevTokens[this.prevTokens.length-1],this.subParse(a,Q),b=this.tokens[this.tokens.length-1];if(m&&m.type===c||b&&b.type===v)this.ast=this.ast.parent;break;case j:this.tokens.push(a),this.ast=this.ast.beget(P);break;case n:this.tokens.push(a),this.ast=this.ast.beget(P);break;case D:b=this.tokens[this.tokens.length-1],!b||b.type!==v&&b.type!==w&&b.type!==o&&b.type!==D?(this.ast=this.ast.parent,this.tokens.push(a)):this.ast.push(a);break;default:this.ast.parent&&this.ast.parent.mode!==Q?(this.ast=this.ast.parent,this.tokens.push(a)):this.ast.push(a)}}};var S=R.prototype;S.assemble=function(a){function n(a){return a.vquery&&a.mode===Q?a.filter(n).length>0:a.vquery&&a.mode!==Q?!0:!1}function m(a){var b,c=a.slice(0),d,e,f;a.mode===Q&&a.parent&&a.parent.mode!==Q&&(d=a.filter(n).length);for(e=0;e<c.length;e++)f=c[e],f.vquery?m(f):a.mode===O?j(f,a,e):a.mode===P?k(f,a,e):a.mode===Q&&l(f,a,e,d>0?!1:!0)}function l(f,g,h,j){var k="",l="",m=g.parent&&g.parent.mode!==Q;a.htmlEscape!==!1&&(f.type===r&&c.push(!0),m&&h===0&&j&&c.length===0&&(k+="( typeof (__vt = "),m&&h===g.length-1&&j&&(c.length>0?c.pop():l+=") !== 'undefined' ? __vt : '' ).toString()\n.replace(/&(?!\\w+;)/g, '&')\n.replace(/</g, '<')\n.replace(/>/g, '>')\n.replace(/\"/g, '"') \n")),m&&(h===0||h===1&&g[0].type===r)&&(i(f),k="__vo.push("+k),m&&(h===g.length-1||h===g.length-2&&g[g.length-1].type===r)&&(l+="); \n"),f.type!==r&&b.push(k+f.val.replace(d,'"').replace(e,'"')+l),m&&h===g.length-1&&i(f)}function k(a,c,e){b.push(a.val.replace(d,'"'))}function j(a,c,e){i(a),b.push("__vo.push('"+a.val.replace(d,'"').replace(f,"\\n")+"'); \n")}function i(c){a.debug&&(b.push("__vl = "+c.line+", "),b.push("__vc = "+c.chr+"; \n"))}a=a||{};var b=[],c=[],d=/["']/gi,e=/(\\?)(["'])/gi,f=/[\n\r]/gi,g,h;b.push("var __vo = [], __vt; \n"),a.debug&&b.push("var __vl = 0, __vc = 0; \n"),m(this.ast),a.useWith===!0&&(b.unshift("with("+a.modelName+" || {}){ \n"),b.push("}")),a.debug&&(b.unshift("try { \n"),b.push("} catch(e){ (",S.reportError.toString(),")(e, __vl, __vc, ",'"'+this.originalMarkup.replace(f,"!LB!").replace(e,"\\$2")+'"',") } \n")),b.push("return __vo.join('');"),g=b.join(""),a.debugCompiler&&console.log(g);try{h=new Function(a.modelName,g)}catch(o){o.message+=" -> "+g;throw o}return h},S.reportError=function(a,b,c,d){var e=d.split("!LB!"),f=3,g=Math.max(0,b-f),h=Math.min(e.length,b+f),i=e.slice(g,h).map(function(a,c,d){var e=c+g+1;return(e===b?" > ":" ")+e+" | "+a}).join("\n");a.message="Problem while rendering template at line "+b+", character "+c+".\nOriginal message: "+a.message+"."+"\nContext: \n\n"+i+"\n\n";throw a},a.VLexer=K,a.VParser=M,a.VCompiler=R,a.compile=function(b,c){if(b===""||typeof b!="string")throw new Error("Empty or non-string cannot be compiled");var d,e,f=[],g,h,i;c=c||{},c.useWith=c.useWith||a.config.useWith,c.modelName=c.modelName||a.config.modelName,c.debug=c.debug||a.config.debug,c.debugParser=c.debugParser||a.config.debugParser,c.debugCompiler=c.debugCompiler||a.config.debugCompiler,d=new K(b);while(e=d.advance())f.push(e);f.reverse(),g=new M(f,c),g.parse(),h=new R(g.ast,b),i=h.assemble(c),i.displayName="render";return i};return a}({})) | ||
(function(a){typeof define=="function"&&define.amd?define(a):typeof module=="object"&&module.exports?module.exports=a:window.vash=a})(function(a){function Q(a,b){this.ast=a,this.originalMarkup=b||""}function L(a,b){this.options=b||{},this.tokens=a,this.ast=K(M),this.prevTokens=[]}function J(a){this.input=this.originalInput=a.replace(/\r\n|\r/g,"\n"),this.lineno=1,this.charno=0}var b=a;a.version="0.4.4-977",a.helpers={},a.config={useWith:!1,modelName:"model",helpersName:"html",htmlEscape:!0,debug:!1,debugParser:!1,debugCompiler:!1};var c="AT",d="ASSIGN_OPERATOR",e="AT_COLON",f="AT_STAR_CLOSE",g="AT_STAR_OPEN",h="BACKSLASH",i="BRACE_CLOSE",j="BRACE_OPEN",k="CONTENT",l="DOUBLE_QUOTE",m="EMAIL",n="FAT_ARROW",o="FUNCTION",p="HARD_PAREN_CLOSE",q="HARD_PAREN_OPEN",r="HTML_TAG_CLOSE",s="HTML_TAG_OPEN",t="HTML_TAG_SELFCLOSE",u="IDENTIFIER",v="KEYWORD",w="LOGICAL",x="NEWLINE",y="NUMERIC_CONTENT",z="OPERATOR",A="PAREN_CLOSE",B="PAREN_OPEN",C="PERIOD",D="SINGLE_QUOTE",E="TEXT_TAG_CLOSE",F="TEXT_TAG_OPEN",G="WHITESPACE",H={};H[g]=f,H[j]=i,H[l]=l,H[q]=p,H[B]=A,H[D]=D;var I=[m,/^([a-zA-Z0-9._%\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,4})\b/,g,/^(@\*)/,f,/^(\*@)/,e,/^@\:/,c,/^(@)/,n,/^(\(.*?\)?\s*?=>)/,B,/^(\()/,A,/^(\))/,q,/^(\[)/,p,/^(\])/,j,/^(\{)/,i,/^(\})/,F,/^(<text>)/,E,/^(<\/text>)/,t,/^(<[^@>]+?\/>)/,s,function(){return this.spewIf(this.scan(/^(<[^\/ >]+?[^>]*?>)/,s),"@")},r,/^(<\/[^>@\b]+?>)/,C,/^(\.)/,x,function(){var a=this.scan(/^(\n)/,x);a&&(this.lineno++,this.charno=0);return a},G,/^(\s)/,o,/^(function)(?![\d\w])/,v,/^(case|catch|do|else|finally|for|function|goto|if|instanceof|return|switch|try|typeof|var|while|with)(?![\d\w])/,u,/^([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)/,z,/^(===|!==|==|!==|>>>|<<|>>|>=|<=|>|<|\+|-|\/|\*|\^|%|\:|\?)/,d,/^(\|=|\^=|&=|>>>=|>>=|<<=|-=|\+=|%=|\/=|\*=|=)/,w,/^(&&|\|\||&|\||\^)/,h,/^(\\)/,l,/^(\")/,D,/^(\')/,y,/^([0-9]+)/,k,/^([^\s})@.]+?)/];J.prototype={scan:function(a,b){var c,d;if(c=a.exec(this.input)){this.input=this.input.substr(c[0].length),d={type:b,line:this.lineno,chr:this.charno,val:c[1],toString:function(){return"["+this.type+" ("+this.line+","+this.chr+"): "+this.val+"]"}},this.charno+=c[0].length;return d}},spewIf:function(a,b){var c,d;a&&(c=a.val.split(b),c.length>1&&(a.val=c.shift(),d=b+c.join(b),this.input=d+this.input,this.charno-=d.length));return a},advance:function(){var a,b,c,d;for(a=0;a<I.length;a+=2){c=I[a+1],c.displayName=I[a],typeof c=="function"&&(d=c.call(this)),typeof c.exec=="function"&&(d=this.scan(c,I[a]));if(d)return d}}};var K=function(a){return new K.fn.init(a)};K.prototype.init=function(a){typeof a=="string"&&(this.mode=a),this.maxCheck()},K.fn=K.prototype.init.prototype=K.prototype,K.fn.vquery="yep",K.fn.constructor=K,K.fn.length=0,K.fn.parent=null,K.fn.mode=null,K.fn.tagName=null,K.fn.beget=function(a,b){var c=K(a);c.parent=this,this.push(c),b&&(c.tagName=b),this.maxCheck();return c},K.fn.closest=function(a,b){var c=this;while(c)if(c.tagName!==b&&c.parent)c=c.parent;else break;return c},K.fn.pushFlatten=function(a){var b=a,c,d;while(b.length===1&&b[0].vquery)b=b[0];if(b.mode!==M)this.push(b);else for(c=0;c<b.length;c++)this.push(b[c]);this.maxCheck();return this},K.fn.push=function(a){K.isArray(a)?(a.vquery&&a.forEach(function(a){a.parent=this},this),Array.prototype.push.apply(this,a)):(a.vquery&&(a.parent=this),Array.prototype.push.call(this,a)),this.maxCheck();return this.length},K.fn.root=function(){var a=this;while(a&&a.parent&&(a=a.parent));return a},K.fn.toTreeString=function(){function c(d){var e,f;a.push(Array(b).join(" |")+" +"+d.mode+" "+(d.tagName||"")),b+=1,e=d.slice();while(f=e.shift())f.vquery===K.fn.vquery?c(f):a.push(Array(b).join(" |")+" "+(f?f.toString():"[empty]"));b-=1}var a=[],b=1;c(this);return a.join("\n")},K.fn.maxCheck=function(){if(this.length>=K.maxSize){var a=new Error;a.message="Maximum number of elements exceeded",a.name="vQueryDepthException";throw a}},K.maxSize=1e3,K.isArray=function(a){return Object.prototype.toString.call(a)=="[object Array]"},K.extend=function(a){var b,c,d;for(c=1;c<arguments.length;c++){b=arguments[c];for(d in b)a[d]=b[d]}return a},K.takeMethodsFromArray=function(){var a=["pop","push","reverse","shift","sort","splice","unshift","concat","join","slice","indexOf","lastIndexOf","filter","forEach","every","map","some","reduce","reduceRight"],b=[],c;for(var d=0;d<a.length;d++){c=a[d];if(typeof b[c]=="function")K.fn[c]||function(a){K.fn[a]=function(){return b[a].apply(this,Array.prototype.slice.call(arguments,0))}}(c);else throw new Error("Vash requires ES5 array iteration methods, missing: "+c)}},K.takeMethodsFromArray();var M="PROGRAM",N="MARKUP",O="BLOCK",P="EXPRESSION";L.prototype={parse:function(){var a,b,c,d;while(this.prevTokens.push(a),a=this.tokens.pop()){this.options.debugParser&&console.log(this.ast&&this.ast.mode,a.type,a,a.val);if(this.ast.mode===M||this.ast.mode===null)this.ast=this.ast.beget(this.options.initialMode||N),this.options.initialMode===P&&(this.ast=this.ast.beget(P));if(this.ast.mode===N){this.handleMKP(a);continue}if(this.ast.mode===O){this.handleBLK(a);continue}if(this.ast.mode===P){this.handleEXP(a);continue}}this.ast=this.ast.root(),this.options.debugParser&&!this.options.initialMode&&(console.log(this.ast),console.log(this.ast.toTreeString()));return this.ast},exceptionFactory:function(a,b,c){b=="UNMATCHED"&&(a.name="UnmatchedCharacterError",this.ast=this.ast.root(),c&&(a.message="Unmatched "+c.type+" at line "+c.line+", character "+c.chr+". Value: "+c.val+"\n "+this.ast.toTreeString(),a.lineNumber=c.line));return a},advanceUntilNot:function(a){var b,c,d=[];while(c=this.tokens[this.tokens.length-1])if(c.type===a)b=this.tokens.pop(),d.push(b);else break;return d},advanceUntilMatched:function(a,b,c,d,e){var f=a,g=null,h=0,i=0,j=[];while(f){f.type===b?g&&g.type!==escape&&b!==c||!g?h++:b===c&&i++:f.type===c&&(i++,g&&g.type===e&&i--),j.push(f);if(h===i)break;g=f,f=this.tokens.pop();if(!f)throw this.exceptionFactory(new Error,"UNMATCHED",a)}return j.reverse()},subParse:function(a,b){var d,e,f,g=K.extend({},this.options);g.initialMode=b,d=this.advanceUntilMatched(a,a.type,H[a.type],null,c),d.pop(),e=d.shift(),this.ast.push(a),f=new L(d,g),f.parse(),this.ast.pushFlatten(f.ast),this.ast.push(e)},handleMKP:function(a){var b=this.tokens[this.tokens.length-1],d=this.tokens[this.tokens.length-2],e=null,h;switch(a.type){case g:this.advanceUntilMatched(a,g,f,c,c);break;case c:if(b)switch(b.type){case B:case u:this.ast.length===0&&(this.ast=this.ast.parent,this.ast.pop()),this.ast=this.ast.beget(P);break;case v:case o:case j:this.ast.length===0&&(this.ast=this.ast.parent,this.ast.pop()),this.ast=this.ast.beget(O);break;default:this.ast.push(this.tokens.pop())}break;case j:this.ast=this.ast.beget(O),this.tokens.push(a);break;case i:this.ast=this.ast.parent,this.tokens.push(a);break;case F:case s:e=a.val.match(/^<([^\/ >]+)/i),e===null&&b&&b.type===c&&d&&(e=d.val.match(/(.*)/)),this.ast.tagName?this.ast=this.ast.beget(N,e[1]):this.ast.tagName=e[1],s===a.type&&this.ast.push(a);break;case E:case r:e=a.val.match(/^<\/([^>]+)/i),e===null&&b&&b.type===c&&d&&(e=d.val.match(/(.*)/)),h=this.ast.closest(N,e[1]),h!==null&&h.tagName===e[1]&&(this.ast=h),r===a.type&&this.ast.push(a),this.ast.parent&&this.ast.parent.mode===O&&b&&(b.type===G||b.type===x)&&(this.ast=this.ast.parent);break;case t:this.ast.push(a),this.ast.parent&&this.ast.parent.mode===O&&b&&(b.type===G||b.type===x)&&(this.ast=this.ast.parent);break;default:this.ast.push(a)}},handleBLK:function(a){var b=this.tokens[this.tokens.length-1],d,f,g,h,i,k;switch(a.type){case c:b.type!==c&&(this.tokens.push(a),this.ast=this.ast.beget(N));break;case e:this.ast=this.ast.beget(N);break;case F:case E:case t:case s:case r:this.ast=this.ast.beget(N),this.tokens.push(a);break;case n:this.ast=this.ast.beget(O);break;case j:case B:this.subParse(a,O),g=this.advanceUntilNot(G),b=this.tokens[this.tokens.length-1],b&&b.type!==v&&b.type!==o&&b.type!==j&&a.type!==B?(this.tokens.push.apply(this.tokens,g.reverse()),this.ast=this.ast.parent):this.ast.push(g);break;case G:this.ast.push(a),this.advanceUntilNot(G);break;default:this.ast.push(a)}},handleEXP:function(a){var b=null,e,f,g,i,k,m,p;switch(a.type){case v:case o:this.ast=this.ast.beget(O),this.tokens.push(a);break;case G:case w:case d:case z:case y:this.ast.parent&&this.ast.parent.mode===P?this.ast.push(a):(this.ast=this.ast.parent,this.tokens.push(a));break;case u:this.ast.push(a);break;case D:case l:this.ast.parent&&this.ast.parent.mode===P?(k=this.advanceUntilMatched(a,a.type,H[a.type],h,h),this.ast.pushFlatten(k.reverse())):(this.ast=this.ast.parent,this.tokens.push(a));break;case q:case B:m=this.prevTokens[this.prevTokens.length-1],this.subParse(a,P),b=this.tokens[this.tokens.length-1];if(m&&m.type===c||b&&b.type===u)this.ast=this.ast.parent;break;case j:this.tokens.push(a),this.ast=this.ast.beget(O);break;case n:this.tokens.push(a),this.ast=this.ast.beget(O);break;case C:b=this.tokens[this.tokens.length-1],!b||b.type!==u&&b.type!==v&&b.type!==o&&b.type!==C?(this.ast=this.ast.parent,this.tokens.push(a)):this.ast.push(a);break;default:this.ast.parent&&this.ast.parent.mode!==P?(this.ast=this.ast.parent,this.tokens.push(a)):this.ast.push(a)}}};var R=Q.prototype;R.assemble=function(a,b){function q(a){return a.vquery&&a.mode===P?a.filter(q).length>0:a.vquery&&a.mode!==P?!0:!1}function p(a){var b,c=a.slice(0),d,e,f;a.mode===P&&a.parent&&a.parent.mode!==P&&(d=a.filter(q).length);for(e=0;e<c.length;e++)f=c[e],f.vquery?p(f):a.mode===N?m(f,a,e):a.mode===O?n(f,a,e):a.mode===P&&o(f,a,e,d>0?!1:!0)}function o(b,d,g,h){var i="",j="",k=d.parent&&d.parent.mode!==P;a.htmlEscape!==!1&&(k&&g===0&&h&&(i+=a.helpersName+".escape("),k&&g===d.length-1&&h&&(j+=").toHtmlString() \n")),k&&g===0&&(l(b),i="__vo.push("+i),k&&g===d.length-1&&(j+="); \n"),c.push(i+b.val.replace(e,'"').replace(f,'"')+j),k&&g===d.length-1&&l(b)}function n(a,b,d){c.push(a.val.replace(e,'"'))}function m(a,b,d){l(a),c.push("MKP('"+a.val.replace(e,'"').replace(g,"\\n")+"')MKP")}function l(b){a.debug&&(c.push("__vl = "+b.line+", "),c.push("__vc = "+b.chr+"; \n"))}a=a||{},b=b||{};var c=[],d=[],e=/["']/gi,f=/(\\?)(["'])/gi,g=/[\n\r]/gi,h,i,j,k=[];c.push("var __vo = [], __vt; \n"),a.debug&&c.push("var __vl = 0, __vc = 0; \n"),p(this.ast),a.useWith===!0&&(c.unshift("with("+a.modelName+" || {}){ \n"),c.push("}")),a.debug&&(c.unshift("try { \n"),c.push("} catch(e){ (",R.reportError.toString(),")(e, __vl, __vc, ",'"'+this.originalMarkup.replace(g,"!LB!").replace(f,"\\$2")+'"',") } \n")),c.push("return __vo.join('');"),h=c.join(""),h=h.split("')MKPMKP('").join("").split("MKP(").join("__vo.push(").split(")MKP").join("); \n"),a.debugCompiler&&console.log(h);try{i=new Function(a.modelName,a.helpersName,h)}catch(r){r.message+=" -> "+h;throw r}j=function(a){return i(a,b)},j.toString=function(){return i.toString()};return j},R.reportError=function(a,b,c,d){var e=d.split("!LB!"),f=3,g=Math.max(0,b-f),h=Math.min(e.length,b+f),i=e.slice(g,h).map(function(a,c,d){var e=c+g+1;return(e===b?" > ":" ")+e+" | "+a}).join("\n");a.message="Problem while rendering template at line "+b+", character "+c+".\nOriginal message: "+a.message+"."+"\nContext: \n\n"+i+"\n\n";throw a},a.helpers.raw=function(a){var b=function(){return a};a=a!=null?a:"";return{toHtmlString:b,toString:b}};var S=/[&<>"'`]/g,T=function(a){return U[a]},U={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"};a.helpers.escape=function(a){var b=function(){return a};a=a!=null?a:"";if(typeof a.toHtmlString!="function"){a=a.toString().replace(S,T);return{toHtmlString:b,toString:b}}return a},a.VLexer=J,a.VParser=L,a.VCompiler=Q,a.compile=function(b,c){if(b===""||typeof b!="string")throw new Error("Empty or non-string cannot be compiled");var d,e,f=[],g,h,i,j;c=K.extend({},a.config,c||{}),d=new J(b);while(e=d.advance())f.push(e);f.reverse(),g=new L(f,c),g.parse(),h=new Q(g.ast,b),i=h.assemble(c,a.helpers),i.displayName="render";return i};return a}({})) |
{ | ||
"name": "vash", | ||
"description": "Razor syntax template parser/generator, for JS", | ||
"version": "0.4.4-926", | ||
"version": "0.4.5-977", | ||
"author": "Andrew Petersen <senofpeter@gmail.com>", | ||
@@ -6,0 +6,0 @@ "keywords": ["razor", "parser", "template", "express"], |
@@ -200,2 +200,14 @@ var vows = require('vows') | ||
} | ||
,'no whitespace': { | ||
topic: function(){ | ||
var str = '<ul class="friends">@friends.forEach(function(friend){<li></li>})</ul>'; | ||
return str; | ||
} | ||
,'output markup': function(topic){ | ||
var topic = vash.compile(topic, {useWith: true}) | ||
,model = { friends: [ 'a' ] }; | ||
assert.equal( topic(model), '<ul class="friends"><li></li></ul>' ); | ||
} | ||
} | ||
} | ||
@@ -1009,5 +1021,5 @@ ,'empty try/catch block': { | ||
,'force no escaping per call (vash.raw)': { | ||
,'force no escaping per call (html.raw)': { | ||
topic: function(){ | ||
return vash.compile( '<span>@vash.raw(it)</span>' ); | ||
return vash.compile( '<span>@html.raw(it)</span>' ); | ||
} | ||
@@ -1019,16 +1031,18 @@ ,'is escaped': function(topic){ | ||
,'vash.raw call is ignored when forced no escaping': { | ||
,'multiple function calls': { | ||
topic: function(){ | ||
return vash.compile( '<span>@vash.raw(it)</span>', { htmlEscape: false } ); | ||
return vash.compile( '@function f(i){ <b>@i</b> }<span>@f(it)</span>@f(it)' ); | ||
} | ||
,'is escaped': function(topic){ | ||
assert.equal( topic({ it: '<b>texted</b>' }), '<span><b>texted</b></span>' ); | ||
} | ||
,'are escaped': function(topic){ | ||
assert.equal( topic({ it: '<b>texted</b>' }), | ||
'<span><b><b>texted</b></b></span><b><b>texted</b></b>' ); | ||
} | ||
} | ||
,'multiple function calls': { | ||
,'multiple function calls are not double escaped': { | ||
topic: function(){ | ||
return vash.compile( '@function f(i){ <b>@i</b> }<span>@f(it)</span>@f(it)' ); | ||
return vash.compile( '@function f(i){ <b>@i</b> }<span>@f(model.it)</span>@f(model.it)', { useWith: false } ); | ||
} | ||
,'are escaped': function(topic){ | ||
//console.log( topic.toString() ); | ||
assert.equal( topic({ it: '<b>texted</b>' }), | ||
@@ -1035,0 +1049,0 @@ '<span><b><b>texted</b></b></span><b><b>texted</b></b>' ); |
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
70799
1947
4
1