Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

vash

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vash - npm Package Compare versions

Comparing version 0.2.2 to 0.3.0-291

47

build/vash.js

@@ -6,3 +6,3 @@ /**

*
* Copyright (c) 2011 Andrew Petersen
* Copyright (c) 2012 Andrew Petersen
* MIT License (LICENSE)

@@ -12,3 +12,3 @@ */

exports["version"] = "0.2.2-256";
exports["version"] = "0.3.0-291";

@@ -184,3 +184,3 @@ exports["config"] = {

,KEYWORD: function(){
return this.scan(/^(case|catch|do|else|finally|for|function|goto|if|instanceof|return|switch|try|typeof|var|while|with)/, VLexer.tks.KEYWORD);
return this.scan(/^(case|catch|do|else|finally|for|function|goto|if|instanceof|return|switch|try|typeof|var|while|with)(?![\d\w])/, VLexer.tks.KEYWORD);
}

@@ -322,3 +322,3 @@ ,IDENTIFIER: function(){

while( (curr = this.lex.advance()) ){
this.debug && console.debug(curr.val, curr.type, curr);
this.debug && console.debug(this.mode, curr.type, curr, curr.val);

@@ -397,10 +397,12 @@ if(this.mode === VParser.modes.MKP){

: 'out +=')
+ ' ('
//+ ' ('
+ current.value
.replace(reQuote, '\"')
.replace(reLineBreak, '\\n')
+ ')\n';
+ '\n';//+ ')\n';
}
}
this.debug && console.debug(generated);
return new Function(options.modelName,

@@ -443,2 +445,7 @@ (options.useWith === true

// allows a mode switch without closing the current buffer
,_retconMode: function(correctMode){
this.mode = correctMode;
}
,_endMode: function(nextMode){

@@ -485,2 +492,7 @@ if(this.buffer !== ''){

case this.tks.BRACE_OPEN:
this._endMode(VParser.modes.BLK);
this.lex.defer(curr);
break;
case this.tks.BRACE_CLOSE:

@@ -577,2 +589,3 @@ this._endMode(VParser.modes.BLK);

case this.tks.BRACE_OPEN:
case this.tks.PAREN_OPEN:
this.blockStack.push({ type: VParser.modes.BLK, tok: curr });

@@ -583,2 +596,3 @@ this._useToken(curr);

case this.tks.BRACE_CLOSE:
case this.tks.PAREN_CLOSE:
block = this.blockStack.pop();

@@ -603,4 +617,5 @@

this._endMode(VParser.modes.MKP);
break;
default:

@@ -630,6 +645,20 @@ this._useToken(curr);

this._useTokens(this._advanceUntilMatched(curr, this.tks.HARD_PAREN_OPEN, this.tks.HARD_PAREN_CLOSE));
ahead = this.lex.lookahead(1);
if(ahead && ahead.type === this.tks.IDENTIFIER){
this._endMode(VParser.modes.MKP);
}
break;
case this.tks.PAREN_OPEN:
this._useTokens(this._advanceUntilMatched(curr, this.tks.PAREN_OPEN, this.tks.PAREN_CLOSE));
ahead = this.lex.lookahead(1);
if(ahead && ahead.type === this.tks.KEYWORD){
this.lex.defer(curr);
this._retconMode(VParser.modes.BLK);
} else {
this._useTokens(this._advanceUntilMatched(curr, this.tks.PAREN_OPEN, this.tks.PAREN_CLOSE));
ahead = this.lex.lookahead(1);
if(ahead && ahead.type === this.tks.IDENTIFIER){
this._endMode(VParser.modes.MKP);
}
}
break;

@@ -639,3 +668,3 @@

ahead = this.lex.lookahead(1);
if(ahead && ahead.type === this.tks.IDENTIFIER)
if(ahead && (ahead.type === this.tks.IDENTIFIER || ahead.type === this.tks.KEYWORD))
this._useToken(curr);

@@ -642,0 +671,0 @@ else {

2

build/vash.min.js

@@ -1,1 +0,1 @@

(function(a){function d(a){if(typeof a!="string")throw new d.exceptions.INVALIDINPUT(a);this.lex=new b(a),this.tks=b.tks,this.blockStack=new c,this.mode=d.modes.MKP,this.buffer="",this.buffers=[],this.debug=!1}function c(){this._stack=[]}function b(a){this.tokens=[],this.input=a.replace(/\r\n|\r/g,"\n"),this.deferredTokens=[],this.stash=[],this.lineno=1,this.charno=0}a.version="0.2.2-256",a.config={useWith:!1,modelName:"model"},b.prototype={tok:function(a,b){return{type:a,line:this.lineno,chr:this.charno,val:b}},scan:function(a,b){var c,d;if(c=a.exec(this.input)){this.consume(c[0].length),d=this.tok(b,c[1]),this.charno+=c[0].length;return d}},spew:function(a){this.input=a+this.input,this.charno-=a.length},consume:function(a){this.input=this.input.substr(a)},spewIf:function(a,b){var c;a&&(c=a.val.split(b),c.length>1&&(a.val=c.shift(),this.spew(b+c.join(b))));return a},advance:function(){return this.deferred()||this.stashed()||this.next()},defer:function(a){this.deferredTokens.push(a)},lookahead:function(a){var b=a-this.stash.length;while(b-->0)this.stash.push(this.next());return this.stash[--a]},next:function(){return this.EMAIL()||this.AT_STAR_OPEN()||this.AT_STAR_CLOSE()||this.AT_COLON()||this.AT()||this.PAREN_OPEN()||this.PAREN_CLOSE()||this.HARD_PAREN_OPEN()||this.HARD_PAREN_CLOSE()||this.BRACE_OPEN()||this.BRACE_CLOSE()||this.TEXT_TAG_OPEN()||this.TEXT_TAG_CLOSE()||this.HTML_TAG_SELFCLOSE()||this.HTML_TAG_OPEN()||this.HTML_TAG_CLOSE()||this.PERIOD()||this.NEWLINE()||this.WHITESPACE()||this.KEYWORD()||this.IDENTIFIER()||this.CONTENT()},deferred:function(){return this.deferredTokens.length&&this.deferredTokens.shift()},stashed:function(){return this.stash.length&&this.stash.shift()},AT:function(){return this.scan(/^(@)/,b.tks.AT)},AT_COLON:function(){return this.scan(/^@\:/,b.tks.AT_COLON)},AT_STAR_OPEN:function(){return this.scan(/^(@\*)/,b.tks.AT_STAR_OPEN)},AT_STAR_CLOSE:function(){return this.scan(/^(\*@)/,b.tks.AT_STAR_CLOSE)},PAREN_OPEN:function(){return this.scan(/^(\()/,b.tks.PAREN_OPEN)},PAREN_CLOSE:function(){return this.scan(/^(\))/,b.tks.PAREN_CLOSE)},BRACE_OPEN:function(){return this.scan(/^(\{)/,b.tks.BRACE_OPEN)},BRACE_CLOSE:function(){return this.scan(/^(\})/,b.tks.BRACE_CLOSE)},HARD_PAREN_OPEN:function(){return this.scan(/^(\[)/,b.tks.HARD_PAREN_OPEN)},HARD_PAREN_CLOSE:function(){return this.scan(/^(\])/,b.tks.HARD_PAREN_CLOSE)},TEXT_TAG_OPEN:function(){return this.scan(/^(<text>)/,b.tks.TEXT_TAG_OPEN)},TEXT_TAG_CLOSE:function(){return this.scan(/^(<\/text>)/,b.tks.TEXT_TAG_CLOSE)},HTML_TAG_SELFCLOSE:function(){return this.spewIf(this.scan(/^(<[^>]+?\/>)/,b.tks.HTML_TAG_SELFCLOSE),"@")},HTML_TAG_OPEN:function(){return this.spewIf(this.scan(/^(<[^\/ >]+?[^>]*?>)/,b.tks.HTML_TAG_OPEN),"@")},HTML_TAG_CLOSE:function(){return this.spewIf(this.scan(/^(<\/[^>\b]+?>)/,b.tks.HTML_TAG_CLOSE),"@")},KEYWORD:function(){return this.scan(/^(case|catch|do|else|finally|for|function|goto|if|instanceof|return|switch|try|typeof|var|while|with)/,b.tks.KEYWORD)},IDENTIFIER:function(){return this.scan(/^([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)/,b.tks.IDENTIFIER)},PERIOD:function(){return this.scan(/^(\.)/,b.tks.PERIOD)},EMAIL:function(){return this.scan(/^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})\b/,b.tks.EMAIL)},CONTENT:function(){return this.scan(/^([^\s})@.]+?)/,b.tks.CONTENT)},WHITESPACE:function(){return this.scan(/^(\s+)/,b.tks.WHITESPACE)},NEWLINE:function(){var a=this.scan(/^(\n)/,b.tks.NEWLINE);a&&(this.lineno++,this.charno=0);return a}},b.tks={AT:"AT",AT_STAR_OPEN:"AT_STAR_OPEN",AT_STAR_CLOSE:"AT_STAR_CLOSE",AT_COLON:"AT_COLON",EMAIL:"EMAIL",PAREN_OPEN:"PAREN_OPEN",PAREN_CLOSE:"PAREN_CLOSE",BRACE_OPEN:"BRACE_OPEN",BRACE_CLOSE:"BRACE_CLOSE",HARD_PAREN_OPEN:"HARD_PAREN_OPEN",HARD_PAREN_CLOSE:"HARD_PAREN_CLOSE",TEXT_TAG_OPEN:"TEXT_TAG_OPEN",TEXT_TAG_CLOSE:"TEXT_TAG_CLOSE",HTML_TAG_SELFCLOSE:"HTML_TAG_SELFCLOSE",HTML_TAG_OPEN:"HTML_TAG_OPEN",HTML_TAG_CLOSE:"HTML_TAG_CLOSE",KEYWORD:"KEYWORD",IDENTIFIER:"IDENTIFIER",PERIOD:"PERIOD",CONTENT:"CONTENT",WHITESPACE:"WHITESPACE",NEWLINE:"NEWLINE"},c.prototype={push:function(a){this._stack.push(a);return this},pop:function(){if(this._stack.length>0)return this._stack.pop();throw new Error("Stack Underflow")},peek:function(){return this._stack.length>0?this._stack[this._stack.length-1]:null},count:function(){return this._stack.length},raw:function(){return this._stack}},d.modes={MKP:"MARKUP",BLK:"BLOCK",EXP:"EXPRESSION"},d.exceptions=function(){var a={UNMATCHED:function(a){this.name="UnmatchedCharacterError",this.message="Unmatched "+a.type+" at line "+a.line+", character "+a.chr+". Value: "+a.val,this.lineNumber=a.line,this.stack=""},INVALIDINPUT:function(a){this.name="InvalidParserInputError",this.message="Asked to parse invalid or non-string input: "+a,this.lineNumber=0,this.stack=""}};for(var b in a)a.hasOwnProperty(b)&&(a[b].prototype=new Error,a[b].constructor=a[b]);return a}(),d.prototype={parse:function(){var a,b,c,e;while(a=this.lex.advance()){this.debug&&console.debug(a.val,a.type,a);if(this.mode===d.modes.MKP){this._handleMKP(a);continue}if(this.mode===d.modes.BLK){this._handleBLK(a);continue}if(this.mode===d.modes.EXP){this._handleEXP(a);continue}}this._endMode(d.modes.MKP);for(b=0,c=this.blockStack.count();b<c;b++){e=this.blockStack.pop();if(e.type===d.modes.BLK)throw new d.exceptions.UNMATCHED(e.tok)}return this.buffers},compile:function(a){a=a||{},a.useWith=a.useWith===!0?!0:!1,a.modelName=a.modelName||"model";var b,c,e=null,f=null,g='var out = "";\n',h=d.modes,i=/[\"']/gi,j=/[\n\r]/gi;for(b=0,c=this.buffers.length;b<c;b++)e=f,f=this.buffers[b],f.type===h.MKP&&(g+=(e!==null&&(e.type===h.MKP||e.type===h.EXP)?"+":"out += ")+"'"+f.value.replace(i,'"').replace(j,"\\n")+"'\n"),f.type===h.BLK&&(g+=f.value.replace(i,'"').replace(j,"")+"\n"),f.type===h.EXP&&(g+=(e!==null&&(e.type===h.MKP||e.type===h.EXP)?"+":"out +=")+" ("+f.value.replace(i,'"').replace(j,"\\n")+")\n");return new Function(a.modelName,(a.useWith===!0?"with("+a.modelName+" || {}){"+g+"}":g)+"\nreturn out;")},_useToken:function(a){this.buffer+=a.val},_useTokens:function(a){for(var b=0,c=a.length;b<c;b++)this.buffer+=a[b].val},_advanceUntilMatched:function(a,b,c){var e=a,f=0,g=0,h=[];while(e){e.type===b&&f++,e.type===c&&g++,h.push(e);if(f===g)break;e=this.lex.advance();if(!e)throw new d.exceptions.UNMATCHED(a)}return h},_endMode:function(a){this.buffer!==""&&(this.buffers.push({type:this.mode,value:this.buffer}),this.buffer=""),this.mode=a||d.modes.MKP},_handleMKP:function(a){var b=this.lex.lookahead(1),c=this.lex.lookahead(2),e=null,f=null,g=[];switch(a.type){case this.tks.AT_STAR_OPEN:this._advanceUntilMatched(a,this.tks.AT_STAR_OPEN,this.tks.AT_STAR_CLOSE);break;case this.tks.AT:if(b)switch(b.type){case this.tks.PAREN_OPEN:case this.tks.IDENTIFIER:this._endMode(d.modes.EXP);break;case this.tks.KEYWORD:case this.tks.BRACE_OPEN:this._endMode(d.modes.BLK);break;default:this._useToken(this.lex.advance())}break;case this.tks.BRACE_CLOSE:this._endMode(d.modes.BLK),this.lex.defer(a);break;case this.tks.TEXT_TAG_OPEN:case this.tks.HTML_TAG_OPEN:f=a.val.match(/^<([^\/ >]+)/i),f===null&&b&&b.type===this.tks.AT&&c&&(f=c.val.match(/(.*)/)),this.blockStack.push({type:d.modes.MKP,tag:f[1],tok:a}),this.tks.HTML_TAG_OPEN===a.type&&this._useToken(a);break;case this.tks.TEXT_TAG_CLOSE:case this.tks.HTML_TAG_CLOSE:f=a.val.match(/^<\/([^>]+)/i),f===null&&b&&b.type===this.tks.AT&&c&&(f=c.val.match(/(.*)/)),e=this.blockStack.pop();while(e!==null){if(e.type===d.modes.MKP&&f[1]===e.tag)break;g.push(e),e=this.blockStack.pop()}if(e===null)throw new d.exceptions.UNMATCHED(e.tok);this.blockStack.raw().push.apply(this.blockStack.raw(),g),this.tks.HTML_TAG_CLOSE===a.type&&this._useToken(a),e=this.blockStack.peek(),e!==null&&e.type===d.modes.BLK&&this._endMode(d.modes.BLK);break;default:this._useToken(a)}},_handleBLK:function(a){var b=this.lex.lookahead(1),c=null,e=[];switch(a.type){case this.tks.AT:switch(b.type){case this.tks.AT:break;default:this.lex.defer(a),this._endMode(d.modes.MKP)}break;case this.tks.AT_COLON:this._endMode(d.modes.MKP);break;case this.tks.TEXT_TAG_OPEN:case this.tks.TEXT_TAG_CLOSE:case this.tks.HTML_TAG_SELFCLOSE:case this.tks.HTML_TAG_OPEN:case this.tks.HTML_TAG_CLOSE:this._endMode(d.modes.MKP),this.lex.defer(a);break;case this.tks.BRACE_OPEN:this.blockStack.push({type:d.modes.BLK,tok:a}),this._useToken(a);break;case this.tks.BRACE_CLOSE:c=this.blockStack.pop();while(c!==null&&c.type!==d.modes.BLK)e.push(c),c=this.blockStack.pop();this.blockStack.raw().push.apply(this.blockStack.raw(),e);if(c===null||c!==null&&c.type!==d.modes.BLK)throw new d.exceptions.UNMATCHED(a);this._useToken(a),c=this.blockStack.peek(),c!==null&&c.type===d.modes.MKP&&this._endMode(d.modes.MKP);break;default:this._useToken(a)}},_handleEXP:function(a){var b=null;switch(a.type){case this.tks.KEYWORD:this._endMode(d.modes.BLK),this.lex.defer(a);break;case this.tks.IDENTIFIER:this._useToken(a);break;case this.tks.HARD_PAREN_OPEN:this._useTokens(this._advanceUntilMatched(a,this.tks.HARD_PAREN_OPEN,this.tks.HARD_PAREN_CLOSE));break;case this.tks.PAREN_OPEN:this._useTokens(this._advanceUntilMatched(a,this.tks.PAREN_OPEN,this.tks.PAREN_CLOSE));break;case this.tks.PERIOD:b=this.lex.lookahead(1),b&&b.type===this.tks.IDENTIFIER?this._useToken(a):(this._endMode(d.modes.MKP),this.lex.defer(a));break;default:this._endMode(d.modes.MKP),this.lex.defer(a)}}},a.VLexer=b,a.VParser=d,a.compile=function e(b,c){var e=new d(b),f;c=c||{},c.useWith=typeof c.useWith=="undefined"?a.config.useWith:c.useWith,c.modelName=c.modelName||a.config.modelName,e.parse(),f=e.compile(c);return function(a){return f(a)}}})(typeof exports=="undefined"?this.vash={}:exports)
(function(a){function d(a){if(typeof a!="string")throw new d.exceptions.INVALIDINPUT(a);this.lex=new b(a),this.tks=b.tks,this.blockStack=new c,this.mode=d.modes.MKP,this.buffer="",this.buffers=[],this.debug=!1}function c(){this._stack=[]}function b(a){this.tokens=[],this.input=a.replace(/\r\n|\r/g,"\n"),this.deferredTokens=[],this.stash=[],this.lineno=1,this.charno=0}a.version="0.3.0-291",a.config={useWith:!1,modelName:"model"},b.prototype={tok:function(a,b){return{type:a,line:this.lineno,chr:this.charno,val:b}},scan:function(a,b){var c,d;if(c=a.exec(this.input)){this.consume(c[0].length),d=this.tok(b,c[1]),this.charno+=c[0].length;return d}},spew:function(a){this.input=a+this.input,this.charno-=a.length},consume:function(a){this.input=this.input.substr(a)},spewIf:function(a,b){var c;a&&(c=a.val.split(b),c.length>1&&(a.val=c.shift(),this.spew(b+c.join(b))));return a},advance:function(){return this.deferred()||this.stashed()||this.next()},defer:function(a){this.deferredTokens.push(a)},lookahead:function(a){var b=a-this.stash.length;while(b-->0)this.stash.push(this.next());return this.stash[--a]},next:function(){return this.EMAIL()||this.AT_STAR_OPEN()||this.AT_STAR_CLOSE()||this.AT_COLON()||this.AT()||this.PAREN_OPEN()||this.PAREN_CLOSE()||this.HARD_PAREN_OPEN()||this.HARD_PAREN_CLOSE()||this.BRACE_OPEN()||this.BRACE_CLOSE()||this.TEXT_TAG_OPEN()||this.TEXT_TAG_CLOSE()||this.HTML_TAG_SELFCLOSE()||this.HTML_TAG_OPEN()||this.HTML_TAG_CLOSE()||this.PERIOD()||this.NEWLINE()||this.WHITESPACE()||this.KEYWORD()||this.IDENTIFIER()||this.CONTENT()},deferred:function(){return this.deferredTokens.length&&this.deferredTokens.shift()},stashed:function(){return this.stash.length&&this.stash.shift()},AT:function(){return this.scan(/^(@)/,b.tks.AT)},AT_COLON:function(){return this.scan(/^@\:/,b.tks.AT_COLON)},AT_STAR_OPEN:function(){return this.scan(/^(@\*)/,b.tks.AT_STAR_OPEN)},AT_STAR_CLOSE:function(){return this.scan(/^(\*@)/,b.tks.AT_STAR_CLOSE)},PAREN_OPEN:function(){return this.scan(/^(\()/,b.tks.PAREN_OPEN)},PAREN_CLOSE:function(){return this.scan(/^(\))/,b.tks.PAREN_CLOSE)},BRACE_OPEN:function(){return this.scan(/^(\{)/,b.tks.BRACE_OPEN)},BRACE_CLOSE:function(){return this.scan(/^(\})/,b.tks.BRACE_CLOSE)},HARD_PAREN_OPEN:function(){return this.scan(/^(\[)/,b.tks.HARD_PAREN_OPEN)},HARD_PAREN_CLOSE:function(){return this.scan(/^(\])/,b.tks.HARD_PAREN_CLOSE)},TEXT_TAG_OPEN:function(){return this.scan(/^(<text>)/,b.tks.TEXT_TAG_OPEN)},TEXT_TAG_CLOSE:function(){return this.scan(/^(<\/text>)/,b.tks.TEXT_TAG_CLOSE)},HTML_TAG_SELFCLOSE:function(){return this.spewIf(this.scan(/^(<[^>]+?\/>)/,b.tks.HTML_TAG_SELFCLOSE),"@")},HTML_TAG_OPEN:function(){return this.spewIf(this.scan(/^(<[^\/ >]+?[^>]*?>)/,b.tks.HTML_TAG_OPEN),"@")},HTML_TAG_CLOSE:function(){return this.spewIf(this.scan(/^(<\/[^>\b]+?>)/,b.tks.HTML_TAG_CLOSE),"@")},KEYWORD:function(){return this.scan(/^(case|catch|do|else|finally|for|function|goto|if|instanceof|return|switch|try|typeof|var|while|with)(?![\d\w])/,b.tks.KEYWORD)},IDENTIFIER:function(){return this.scan(/^([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)/,b.tks.IDENTIFIER)},PERIOD:function(){return this.scan(/^(\.)/,b.tks.PERIOD)},EMAIL:function(){return this.scan(/^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})\b/,b.tks.EMAIL)},CONTENT:function(){return this.scan(/^([^\s})@.]+?)/,b.tks.CONTENT)},WHITESPACE:function(){return this.scan(/^(\s+)/,b.tks.WHITESPACE)},NEWLINE:function(){var a=this.scan(/^(\n)/,b.tks.NEWLINE);a&&(this.lineno++,this.charno=0);return a}},b.tks={AT:"AT",AT_STAR_OPEN:"AT_STAR_OPEN",AT_STAR_CLOSE:"AT_STAR_CLOSE",AT_COLON:"AT_COLON",EMAIL:"EMAIL",PAREN_OPEN:"PAREN_OPEN",PAREN_CLOSE:"PAREN_CLOSE",BRACE_OPEN:"BRACE_OPEN",BRACE_CLOSE:"BRACE_CLOSE",HARD_PAREN_OPEN:"HARD_PAREN_OPEN",HARD_PAREN_CLOSE:"HARD_PAREN_CLOSE",TEXT_TAG_OPEN:"TEXT_TAG_OPEN",TEXT_TAG_CLOSE:"TEXT_TAG_CLOSE",HTML_TAG_SELFCLOSE:"HTML_TAG_SELFCLOSE",HTML_TAG_OPEN:"HTML_TAG_OPEN",HTML_TAG_CLOSE:"HTML_TAG_CLOSE",KEYWORD:"KEYWORD",IDENTIFIER:"IDENTIFIER",PERIOD:"PERIOD",CONTENT:"CONTENT",WHITESPACE:"WHITESPACE",NEWLINE:"NEWLINE"},c.prototype={push:function(a){this._stack.push(a);return this},pop:function(){if(this._stack.length>0)return this._stack.pop();throw new Error("Stack Underflow")},peek:function(){return this._stack.length>0?this._stack[this._stack.length-1]:null},count:function(){return this._stack.length},raw:function(){return this._stack}},d.modes={MKP:"MARKUP",BLK:"BLOCK",EXP:"EXPRESSION"},d.exceptions=function(){var a={UNMATCHED:function(a){this.name="UnmatchedCharacterError",this.message="Unmatched "+a.type+" at line "+a.line+", character "+a.chr+". Value: "+a.val,this.lineNumber=a.line,this.stack=""},INVALIDINPUT:function(a){this.name="InvalidParserInputError",this.message="Asked to parse invalid or non-string input: "+a,this.lineNumber=0,this.stack=""}};for(var b in a)a.hasOwnProperty(b)&&(a[b].prototype=new Error,a[b].constructor=a[b]);return a}(),d.prototype={parse:function(){var a,b,c,e;while(a=this.lex.advance()){this.debug&&console.debug(this.mode,a.type,a,a.val);if(this.mode===d.modes.MKP){this._handleMKP(a);continue}if(this.mode===d.modes.BLK){this._handleBLK(a);continue}if(this.mode===d.modes.EXP){this._handleEXP(a);continue}}this._endMode(d.modes.MKP);for(b=0,c=this.blockStack.count();b<c;b++){e=this.blockStack.pop();if(e.type===d.modes.BLK)throw new d.exceptions.UNMATCHED(e.tok)}return this.buffers},compile:function(a){a=a||{},a.useWith=a.useWith===!0?!0:!1,a.modelName=a.modelName||"model";var b,c,e=null,f=null,g='var out = "";\n',h=d.modes,i=/[\"']/gi,j=/[\n\r]/gi;for(b=0,c=this.buffers.length;b<c;b++)e=f,f=this.buffers[b],f.type===h.MKP&&(g+=(e!==null&&(e.type===h.MKP||e.type===h.EXP)?"+":"out += ")+"'"+f.value.replace(i,'"').replace(j,"\\n")+"'\n"),f.type===h.BLK&&(g+=f.value.replace(i,'"').replace(j,"")+"\n"),f.type===h.EXP&&(g+=(e!==null&&(e.type===h.MKP||e.type===h.EXP)?"+":"out +=")+f.value.replace(i,'"').replace(j,"\\n")+"\n");this.debug&&console.debug(g);return new Function(a.modelName,(a.useWith===!0?"with("+a.modelName+" || {}){"+g+"}":g)+"\nreturn out;")},_useToken:function(a){this.buffer+=a.val},_useTokens:function(a){for(var b=0,c=a.length;b<c;b++)this.buffer+=a[b].val},_advanceUntilMatched:function(a,b,c){var e=a,f=0,g=0,h=[];while(e){e.type===b&&f++,e.type===c&&g++,h.push(e);if(f===g)break;e=this.lex.advance();if(!e)throw new d.exceptions.UNMATCHED(a)}return h},_retconMode:function(a){this.mode=a},_endMode:function(a){this.buffer!==""&&(this.buffers.push({type:this.mode,value:this.buffer}),this.buffer=""),this.mode=a||d.modes.MKP},_handleMKP:function(a){var b=this.lex.lookahead(1),c=this.lex.lookahead(2),e=null,f=null,g=[];switch(a.type){case this.tks.AT_STAR_OPEN:this._advanceUntilMatched(a,this.tks.AT_STAR_OPEN,this.tks.AT_STAR_CLOSE);break;case this.tks.AT:if(b)switch(b.type){case this.tks.PAREN_OPEN:case this.tks.IDENTIFIER:this._endMode(d.modes.EXP);break;case this.tks.KEYWORD:case this.tks.BRACE_OPEN:this._endMode(d.modes.BLK);break;default:this._useToken(this.lex.advance())}break;case this.tks.BRACE_OPEN:this._endMode(d.modes.BLK),this.lex.defer(a);break;case this.tks.BRACE_CLOSE:this._endMode(d.modes.BLK),this.lex.defer(a);break;case this.tks.TEXT_TAG_OPEN:case this.tks.HTML_TAG_OPEN:f=a.val.match(/^<([^\/ >]+)/i),f===null&&b&&b.type===this.tks.AT&&c&&(f=c.val.match(/(.*)/)),this.blockStack.push({type:d.modes.MKP,tag:f[1],tok:a}),this.tks.HTML_TAG_OPEN===a.type&&this._useToken(a);break;case this.tks.TEXT_TAG_CLOSE:case this.tks.HTML_TAG_CLOSE:f=a.val.match(/^<\/([^>]+)/i),f===null&&b&&b.type===this.tks.AT&&c&&(f=c.val.match(/(.*)/)),e=this.blockStack.pop();while(e!==null){if(e.type===d.modes.MKP&&f[1]===e.tag)break;g.push(e),e=this.blockStack.pop()}if(e===null)throw new d.exceptions.UNMATCHED(e.tok);this.blockStack.raw().push.apply(this.blockStack.raw(),g),this.tks.HTML_TAG_CLOSE===a.type&&this._useToken(a),e=this.blockStack.peek(),e!==null&&e.type===d.modes.BLK&&this._endMode(d.modes.BLK);break;default:this._useToken(a)}},_handleBLK:function(a){var b=this.lex.lookahead(1),c=null,e=[];switch(a.type){case this.tks.AT:switch(b.type){case this.tks.AT:break;default:this.lex.defer(a),this._endMode(d.modes.MKP)}break;case this.tks.AT_COLON:this._endMode(d.modes.MKP);break;case this.tks.TEXT_TAG_OPEN:case this.tks.TEXT_TAG_CLOSE:case this.tks.HTML_TAG_SELFCLOSE:case this.tks.HTML_TAG_OPEN:case this.tks.HTML_TAG_CLOSE:this._endMode(d.modes.MKP),this.lex.defer(a);break;case this.tks.BRACE_OPEN:case this.tks.PAREN_OPEN:this.blockStack.push({type:d.modes.BLK,tok:a}),this._useToken(a);break;case this.tks.BRACE_CLOSE:case this.tks.PAREN_CLOSE:c=this.blockStack.pop();while(c!==null&&c.type!==d.modes.BLK)e.push(c),c=this.blockStack.pop();this.blockStack.raw().push.apply(this.blockStack.raw(),e);if(c===null||c!==null&&c.type!==d.modes.BLK)throw new d.exceptions.UNMATCHED(a);this._useToken(a),c=this.blockStack.peek(),c!==null&&c.type===d.modes.MKP&&this._endMode(d.modes.MKP);break;default:this._useToken(a)}},_handleEXP:function(a){var b=null;switch(a.type){case this.tks.KEYWORD:this._endMode(d.modes.BLK),this.lex.defer(a);break;case this.tks.IDENTIFIER:this._useToken(a);break;case this.tks.HARD_PAREN_OPEN:this._useTokens(this._advanceUntilMatched(a,this.tks.HARD_PAREN_OPEN,this.tks.HARD_PAREN_CLOSE)),b=this.lex.lookahead(1),b&&b.type===this.tks.IDENTIFIER&&this._endMode(d.modes.MKP);break;case this.tks.PAREN_OPEN:b=this.lex.lookahead(1),b&&b.type===this.tks.KEYWORD?(this.lex.defer(a),this._retconMode(d.modes.BLK)):(this._useTokens(this._advanceUntilMatched(a,this.tks.PAREN_OPEN,this.tks.PAREN_CLOSE)),b=this.lex.lookahead(1),b&&b.type===this.tks.IDENTIFIER&&this._endMode(d.modes.MKP));break;case this.tks.PERIOD:b=this.lex.lookahead(1),!b||b.type!==this.tks.IDENTIFIER&&b.type!==this.tks.KEYWORD?(this._endMode(d.modes.MKP),this.lex.defer(a)):this._useToken(a);break;default:this._endMode(d.modes.MKP),this.lex.defer(a)}}},a.VLexer=b,a.VParser=d,a.compile=function e(b,c){var e=new d(b),f;c=c||{},c.useWith=typeof c.useWith=="undefined"?a.config.useWith:c.useWith,c.modelName=c.modelName||a.config.modelName,e.parse(),f=e.compile(c);return function(a){return f(a)}}})(typeof exports=="undefined"?this.vash={}:exports)
{
"name": "vash",
"description": "Razor syntax template parser/generator, for JS",
"version": "0.2.2",
"version": "0.3.0-291",
"author": "Andrew Petersen <senofpeter@gmail.com>",

@@ -10,3 +10,3 @@ "keywords": ["razor", "parser", "template", "express"],

"files": ["build", "test/vash.test.js"],
"engines": { "node": ">= 0.4.1 < 0.5.0" }
}
"engines": { "node": ">= 0.4.1" }
}

@@ -128,2 +128,12 @@ var vows = require('vows')

}
,'forEach blocks and markup with complex interpolation/expression': {
topic: function(){
var str = '@model.forEach(function(p){ <li class="@(p.x % 2 == 0 ? \'blue\' : \'red\')">list item</li> });';
return vash.compile(str);
}
,'output markup': function(topic){
var model = [{ x: 0, y: 1 }];
assert.equal(topic(model), '<li class="blue">list item</li>');
}
}
,'empty try/catch block': {

@@ -174,2 +184,16 @@ topic: function(){

}
,'simple expression with valid identifier following': {
topic: function(){
var str = '<a href="@(true)that"></a>';
return str;
}
,'outputs true': function(topic){
assert.doesNotThrow( function(){ vash.compile(topic) }, Error );
try {
var tpl = vash.compile(topic);
assert.equal(tpl(), '<a href="truethat"></a>');
} catch(e){}
}
}
,'expression with nested parenthesis': {

@@ -211,2 +235,11 @@ topic: function(){

}
,'expression with indexed property followed by valid identifer': {
topic: function(){
var str = '<a href="@what[0]yeah"></a>';
return vash.compile(str);
}
,'outputs 1yeah': function(topic){
assert.equal( topic({ what: '1'}), '<a href="1yeah"></a>');
}
}
,'empty anonymous block': {

@@ -213,0 +246,0 @@ topic: function(){

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc