Comparing version 0.3.1 to 0.3.2
@@ -1,2 +0,2 @@ | ||
// JavaScript Expression Parser (JSEP) 0.3.1 | ||
// JavaScript Expression Parser (JSEP) 0.3.2 | ||
// JSEP may be freely distributed under the MIT License | ||
@@ -10,3 +10,3 @@ // http://jsep.from.so/ | ||
// ---------- | ||
// This is the full set of types that any JSEP node can be. | ||
@@ -47,3 +47,3 @@ // Store them here to save space when minified | ||
// ---------- | ||
// Set `t` to `true` to save space (when minified, not gzipped) | ||
@@ -60,3 +60,3 @@ t = true, | ||
'==': 6, '!=': 6, '===': 6, '!==': 6, | ||
'<': 7, '>': 7, '<=': 7, '>=': 7, | ||
'<': 7, '>': 7, '<=': 7, '>=': 7, | ||
'<<':8, '>>': 8, '>>>': 8, | ||
@@ -138,7 +138,7 @@ '+': 9, '-': 9, | ||
// space or tab | ||
while(ch === 32 || ch === 9) { | ||
while(ch === 32 || ch === 9 || ch === 10 || ch === 13) { | ||
ch = exprICode(++index); | ||
} | ||
}, | ||
// The main parsing function. Much of this code is dedicated to ternary expressions | ||
@@ -247,3 +247,3 @@ gobbleExpression = function() { | ||
while(i > 1) { | ||
node = createBinaryExpression(stack[i - 1].value, stack[i - 2], node); | ||
node = createBinaryExpression(stack[i - 1].value, stack[i - 2], node); | ||
i -= 2; | ||
@@ -258,3 +258,3 @@ } | ||
var ch, to_check, tc_len; | ||
gobbleSpaces(); | ||
@@ -289,3 +289,3 @@ ch = exprICode(index); | ||
} | ||
return false; | ||
@@ -309,3 +309,3 @@ } | ||
} | ||
ch = exprI(index); | ||
@@ -325,4 +325,4 @@ if(ch === 'e' || ch === 'E') { // exponent marker | ||
} | ||
chCode = exprICode(index); | ||
@@ -381,3 +381,3 @@ // Check to make sure this isn't a variable name that start with a number (123abc) | ||
}, | ||
// Gobbles only identifiers | ||
@@ -459,3 +459,3 @@ // e.g.: `foo`, `_value`, `$x1` | ||
ch_i = exprICode(index); | ||
if(ch_i === OPAREN_CODE) { | ||
@@ -534,3 +534,3 @@ node = gobbleGroup(); | ||
nodes = [], ch_i, node; | ||
while(index < length) { | ||
@@ -567,3 +567,3 @@ ch_i = exprICode(index); | ||
// To be filled in by the template | ||
jsep.version = '0.3.1'; | ||
jsep.version = '0.3.2'; | ||
jsep.toString = function() { return 'JavaScript Expression Parser (JSEP) v' + jsep.version; }; | ||
@@ -570,0 +570,0 @@ |
@@ -1,3 +0,3 @@ | ||
/* jsep v0.3.1 (http://jsep.from.so/) */ | ||
!function(a){"use strict";var b="Compound",c="Identifier",d="MemberExpression",e="Literal",f="ThisExpression",g="CallExpression",h="UnaryExpression",i="BinaryExpression",j="LogicalExpression",k="ConditionalExpression",l="ArrayExpression",m=46,n=44,o=39,p=34,q=40,r=41,s=91,t=93,u=63,v=59,w=58,x=function(a,b){var c=new Error(a+" at character "+b);throw c.index=b,c.description=a,c},y=!0,z={"-":y,"!":y,"~":y,"+":y},A={"||":1,"&&":2,"|":3,"^":4,"&":5,"==":6,"!=":6,"===":6,"!==":6,"<":7,">":7,"<=":7,">=":7,"<<":8,">>":8,">>>":8,"+":9,"-":9,"*":10,"/":10,"%":10},B=function(a){var b,c=0;for(var d in a)(b=d.length)>c&&a.hasOwnProperty(d)&&(c=b);return c},C=B(z),D=B(A),E={"true":!0,"false":!1,"null":null},F="this",G=function(a){return A[a]||0},H=function(a,b,c){var d="||"===a||"&&"===a?j:i;return{type:d,operator:a,left:b,right:c}},I=function(a){return a>=48&&a<=57},J=function(a){return 36===a||95===a||a>=65&&a<=90||a>=97&&a<=122||a>=128&&!A[String.fromCharCode(a)]},K=function(a){return 36===a||95===a||a>=65&&a<=90||a>=97&&a<=122||a>=48&&a<=57||a>=128&&!A[String.fromCharCode(a)]},L=function(a){for(var i,j,y=0,B=a.charAt,L=a.charCodeAt,M=function(b){return B.call(a,b)},N=function(b){return L.call(a,b)},O=a.length,P=function(){for(var a=N(y);32===a||9===a;)a=N(++y)},Q=function(){var a,b,c=S();return P(),N(y)!==u?c:(y++,a=Q(),a||x("Expected expression",y),P(),N(y)===w?(y++,b=Q(),b||x("Expected expression",y),{type:k,test:c,consequent:a,alternate:b}):void x("Expected :",y))},R=function(){P();for(var b=a.substr(y,D),c=b.length;c>0;){if(A.hasOwnProperty(b))return y+=c,b;b=b.substr(0,--c)}return!1},S=function(){var a,b,c,d,e,f,g,h;if(f=T(),b=R(),!b)return f;for(e={value:b,prec:G(b)},g=T(),g||x("Expected expression after "+b,y),d=[f,e,g];(b=R())&&(c=G(b),0!==c);){for(e={value:b,prec:c};d.length>2&&c<=d[d.length-2].prec;)g=d.pop(),b=d.pop().value,f=d.pop(),a=H(b,f,g),d.push(a);a=T(),a||x("Expected expression after "+b,y),d.push(e,a)}for(h=d.length-1,a=d[h];h>1;)a=H(d[h-1].value,d[h-2],a),h-=2;return a},T=function(){var b,c,d;if(P(),b=N(y),I(b)||b===m)return U();if(b===o||b===p)return V();if(J(b)||b===q)return Y();if(b===s)return $();for(c=a.substr(y,C),d=c.length;d>0;){if(z.hasOwnProperty(c))return y+=d,{type:h,operator:c,argument:T(),prefix:!0};c=c.substr(0,--d)}return!1},U=function(){for(var a,b,c="";I(N(y));)c+=M(y++);if(N(y)===m)for(c+=M(y++);I(N(y));)c+=M(y++);if(a=M(y),"e"===a||"E"===a){for(c+=M(y++),a=M(y),"+"!==a&&"-"!==a||(c+=M(y++));I(N(y));)c+=M(y++);I(N(y-1))||x("Expected exponent ("+c+M(y)+")",y)}return b=N(y),J(b)?x("Variable names cannot start with a number ("+c+M(y)+")",y):b===m&&x("Unexpected period",y),{type:e,value:parseFloat(c),raw:c}},V=function(){for(var a,b="",c=M(y++),d=!1;y<O;){if(a=M(y++),a===c){d=!0;break}if("\\"===a)switch(a=M(y++)){case"n":b+="\n";break;case"r":b+="\r";break;case"t":b+="\t";break;case"b":b+="\b";break;case"f":b+="\f";break;case"v":b+="\x0B";break;default:b+="\\"+a}else b+=a}return d||x('Unclosed quote after "'+b+'"',y),{type:e,value:b,raw:c+b+c}},W=function(){var b,d=N(y),g=y;for(J(d)?y++:x("Unexpected "+M(y),y);y<O&&(d=N(y),K(d));)y++;return b=a.slice(g,y),E.hasOwnProperty(b)?{type:e,value:E[b],raw:b}:b===F?{type:f}:{type:c,name:b}},X=function(a){for(var c,d,e=[],f=!1;y<O;){if(P(),c=N(y),c===a){f=!0,y++;break}c===n?y++:(d=Q(),d&&d.type!==b||x("Expected comma",y),e.push(d))}return f||x("Expected "+String.fromCharCode(a),y),e},Y=function(){var a,b;for(a=N(y),b=a===q?Z():W(),P(),a=N(y);a===m||a===s||a===q;)y++,a===m?(P(),b={type:d,computed:!1,object:b,property:W()}):a===s?(b={type:d,computed:!0,object:b,property:Q()},P(),a=N(y),a!==t&&x("Unclosed [",y),y++):a===q&&(b={type:g,arguments:X(r),callee:b}),P(),a=N(y);return b},Z=function(){y++;var a=Q();return P(),N(y)===r?(y++,a):void x("Unclosed (",y)},$=function(){return y++,{type:l,elements:X(t)}},_=[];y<O;)i=N(y),i===v||i===n?y++:(j=Q())?_.push(j):y<O&&x('Unexpected "'+M(y)+'"',y);return 1===_.length?_[0]:{type:b,body:_}};if(L.version="0.3.1",L.toString=function(){return"JavaScript Expression Parser (JSEP) v"+L.version},L.addUnaryOp=function(a){return C=Math.max(a.length,C),z[a]=y,this},L.addBinaryOp=function(a,b){return D=Math.max(a.length,D),A[a]=b,this},L.addLiteral=function(a,b){return E[a]=b,this},L.removeUnaryOp=function(a){return delete z[a],a.length===C&&(C=B(z)),this},L.removeAllUnaryOps=function(){return z={},C=0,this},L.removeBinaryOp=function(a){return delete A[a],a.length===D&&(D=B(A)),this},L.removeAllBinaryOps=function(){return A={},D=0,this},L.removeLiteral=function(a){return delete E[a],this},L.removeAllLiterals=function(){return E={},this},"undefined"==typeof exports){var M=a.jsep;a.jsep=L,L.noConflict=function(){return a.jsep===L&&(a.jsep=M),L}}else"undefined"!=typeof module&&module.exports?exports=module.exports=L:exports.parse=L}(this); | ||
/* jsep v0.3.2 (http://jsep.from.so/) */ | ||
!function(e){"use strict";var r=function(e,r){var t=new Error(e+" at character "+r);throw t.index=r,t.description=e,t},t={"-":!0,"!":!0,"~":!0,"+":!0},n={"||":1,"&&":2,"|":3,"^":4,"&":5,"==":6,"!=":6,"===":6,"!==":6,"<":7,">":7,"<=":7,">=":7,"<<":8,">>":8,">>>":8,"+":9,"-":9,"*":10,"/":10,"%":10},o=function(e){var r,t=0;for(var n in e)(r=n.length)>t&&e.hasOwnProperty(n)&&(t=r);return t},i=o(t),a=o(n),u={true:!0,false:!1,null:null},s=function(e){return n[e]||0},p=function(e,r,t){return{type:"||"===e||"&&"===e?"LogicalExpression":"BinaryExpression",operator:e,left:r,right:t}},f=function(e){return e>=48&&e<=57},c=function(e){return 36===e||95===e||e>=65&&e<=90||e>=97&&e<=122||e>=128&&!n[String.fromCharCode(e)]},l=function(e){return 36===e||95===e||e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57||e>=128&&!n[String.fromCharCode(e)]},d=function(e){for(var o,d,h=0,v=e.charAt,x=e.charCodeAt,y=function(r){return v.call(e,r)},m=function(r){return x.call(e,r)},b=e.length,E=function(){for(var e=m(h);32===e||9===e||10===e||13===e;)e=m(++h)},g=function(){var e,t,n=w();return E(),63!==m(h)?n:(h++,(e=g())||r("Expected expression",h),E(),58===m(h)?(h++,(t=g())||r("Expected expression",h),{type:"ConditionalExpression",test:n,consequent:e,alternate:t}):void r("Expected :",h))},C=function(){E();for(var r=e.substr(h,a),t=r.length;t>0;){if(n.hasOwnProperty(r))return h+=t,r;r=r.substr(0,--t)}return!1},w=function(){var e,t,n,o,i,a,u,f;if(a=O(),!(t=C()))return a;for(i={value:t,prec:s(t)},(u=O())||r("Expected expression after "+t,h),o=[a,i,u];(t=C())&&0!==(n=s(t));){for(i={value:t,prec:n};o.length>2&&n<=o[o.length-2].prec;)u=o.pop(),t=o.pop().value,a=o.pop(),e=p(t,a,u),o.push(e);(e=O())||r("Expected expression after "+t,h),o.push(i,e)}for(e=o[f=o.length-1];f>1;)e=p(o[f-1].value,o[f-2],e),f-=2;return e},O=function(){var r,n,o;if(E(),r=m(h),f(r)||46===r)return U();if(39===r||34===r)return k();if(c(r)||40===r)return A();if(91===r)return S();for(o=(n=e.substr(h,i)).length;o>0;){if(t.hasOwnProperty(n))return h+=o,{type:"UnaryExpression",operator:n,argument:O(),prefix:!0};n=n.substr(0,--o)}return!1},U=function(){for(var e,t,n="";f(m(h));)n+=y(h++);if(46===m(h))for(n+=y(h++);f(m(h));)n+=y(h++);if("e"===(e=y(h))||"E"===e){for(n+=y(h++),"+"!==(e=y(h))&&"-"!==e||(n+=y(h++));f(m(h));)n+=y(h++);f(m(h-1))||r("Expected exponent ("+n+y(h)+")",h)}return t=m(h),c(t)?r("Variable names cannot start with a number ("+n+y(h)+")",h):46===t&&r("Unexpected period",h),{type:"Literal",value:parseFloat(n),raw:n}},k=function(){for(var e,t="",n=y(h++),o=!1;h<b;){if((e=y(h++))===n){o=!0;break}if("\\"===e)switch(e=y(h++)){case"n":t+="\n";break;case"r":t+="\r";break;case"t":t+="\t";break;case"b":t+="\b";break;case"f":t+="\f";break;case"v":t+="\v";break;default:t+="\\"+e}else t+=e}return o||r('Unclosed quote after "'+t+'"',h),{type:"Literal",value:t,raw:n+t+n}},L=function(){var t,n=m(h),o=h;for(c(n)?h++:r("Unexpected "+y(h),h);h<b&&(n=m(h),l(n));)h++;return t=e.slice(o,h),u.hasOwnProperty(t)?{type:"Literal",value:u[t],raw:t}:"this"===t?{type:"ThisExpression"}:{type:"Identifier",name:t}},j=function(e){for(var t,n,o=[],i=!1;h<b;){if(E(),(t=m(h))===e){i=!0,h++;break}44===t?h++:((n=g())&&"Compound"!==n.type||r("Expected comma",h),o.push(n))}return i||r("Expected "+String.fromCharCode(e),h),o},A=function(){var e,t;for(t=40===(e=m(h))?P():L(),E(),e=m(h);46===e||91===e||40===e;)h++,46===e?(E(),t={type:"MemberExpression",computed:!1,object:t,property:L()}):91===e?(t={type:"MemberExpression",computed:!0,object:t,property:g()},E(),93!==(e=m(h))&&r("Unclosed [",h),h++):40===e&&(t={type:"CallExpression",arguments:j(41),callee:t}),E(),e=m(h);return t},P=function(){h++;var e=g();if(E(),41===m(h))return h++,e;r("Unclosed (",h)},S=function(){return h++,{type:"ArrayExpression",elements:j(93)}},B=[];h<b;)59===(o=m(h))||44===o?h++:(d=g())?B.push(d):h<b&&r('Unexpected "'+y(h)+'"',h);return 1===B.length?B[0]:{type:"Compound",body:B}};if(d.version="0.3.2",d.toString=function(){return"JavaScript Expression Parser (JSEP) v"+d.version},d.addUnaryOp=function(e){return i=Math.max(e.length,i),t[e]=!0,this},d.addBinaryOp=function(e,r){return a=Math.max(e.length,a),n[e]=r,this},d.addLiteral=function(e,r){return u[e]=r,this},d.removeUnaryOp=function(e){return delete t[e],e.length===i&&(i=o(t)),this},d.removeAllUnaryOps=function(){return t={},i=0,this},d.removeBinaryOp=function(e){return delete n[e],e.length===a&&(a=o(n)),this},d.removeAllBinaryOps=function(){return n={},a=0,this},d.removeLiteral=function(e){return delete u[e],this},d.removeAllLiterals=function(){return u={},this},"undefined"==typeof exports){var h=e.jsep;e.jsep=d,d.noConflict=function(){return e.jsep===d&&(e.jsep=h),d}}else"undefined"!=typeof module&&module.exports?exports=module.exports=d:exports.parse=d}(this); | ||
//# sourceMappingURL=jsep.min.js.map |
@@ -0,0 +0,0 @@ module.exports = function(grunt) { |
{ | ||
"name": "jsep", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "a tiny JavaScript expression parser", | ||
@@ -17,11 +17,11 @@ "author": "Stephen Oney <swloney@gmail.com> (http://from.so/)", | ||
"devDependencies": { | ||
"grunt": "~0.4.5", | ||
"grunt-contrib-jshint": "~1.0", | ||
"grunt-contrib-qunit": "~1.2", | ||
"grunt-contrib-uglify": "~1.0", | ||
"grunt-contrib-concat": "~1.0", | ||
"grunt-contrib-watch": "~1.0", | ||
"grunt-contrib-compress": "~1.0", | ||
"grunt-contrib-clean": "~1.0", | ||
"grunt-docco": "~0.4" | ||
"grunt": "~1.0.1", | ||
"grunt-contrib-jshint": "~1.1.0", | ||
"grunt-contrib-qunit": "~2.0.0", | ||
"grunt-contrib-uglify": "~3.0.1", | ||
"grunt-contrib-concat": "~1.0.1", | ||
"grunt-contrib-watch": "~1.0.0", | ||
"grunt-contrib-compress": "~1.4.3", | ||
"grunt-contrib-clean": "~1.1.0", | ||
"grunt-docco": "~0.5.0" | ||
}, | ||
@@ -35,4 +35,6 @@ "engines": { | ||
"scripts": { | ||
"test": "grunt test" | ||
"default": "node ./node_modules/grunt/bin/grunt default", | ||
"test": "node ./node_modules/grunt/bin/grunt test", | ||
"package": "node ./node_modules/grunt/bin/grunt package" | ||
} | ||
} |
@@ -1,5 +0,5 @@ | ||
##jsep: A Tiny JavaScript Expression Parser | ||
## jsep: A Tiny JavaScript Expression Parser | ||
[jsep](http://jsep.from.so/) is a simple expression parser written in JavaScript. It can parse JavaScript expressions but not operations. The difference between expressions and operations is akin to the difference between a cell in an Excel spreadsheet vs. a proper JavaScript program. | ||
###Why jsep? | ||
### Why jsep? | ||
I wanted a lightweight, tiny parser to be included in one of my other libraries. [esprima](http://esprima.org/) and other parsers are great, but had more power than I need and were *way* too large to be included in a library that I wanted to keep relatively small. | ||
@@ -9,3 +9,3 @@ | ||
###Custom Build | ||
### Custom Build | ||
First, install [Grunt](http://gruntjs.com/). While in the jsep project directory, run: | ||
@@ -18,8 +18,8 @@ | ||
###Usage | ||
####Client-side | ||
### Usage | ||
#### Client-side | ||
<script src="/PATH/TO/jsep.min.js" type="text/javascript"></script> | ||
... | ||
var parse_tree = jsep("1 + 1"); | ||
####Node.JS | ||
#### Node.JS | ||
First, run `npm install jsep`. Then, in your source file: | ||
@@ -30,3 +30,3 @@ | ||
####Custom Operators | ||
#### Custom Operators | ||
// Add a custom ^ binary operator with precedence 10 | ||
@@ -44,6 +44,6 @@ jsep.addBinaryOp("^", 10); | ||
###License | ||
### License | ||
jsep is under the MIT license. See LICENSE file. | ||
###Thanks | ||
### Thanks | ||
Some parts of the latest version of jsep were adapted from the esprima parser. |
@@ -10,3 +10,3 @@ // JavaScript Expression Parser (JSEP) <%= version %> | ||
// ---------- | ||
// This is the full set of types that any JSEP node can be. | ||
@@ -47,3 +47,3 @@ // Store them here to save space when minified | ||
// ---------- | ||
// Set `t` to `true` to save space (when minified, not gzipped) | ||
@@ -60,3 +60,3 @@ t = true, | ||
'==': 6, '!=': 6, '===': 6, '!==': 6, | ||
'<': 7, '>': 7, '<=': 7, '>=': 7, | ||
'<': 7, '>': 7, '<=': 7, '>=': 7, | ||
'<<':8, '>>': 8, '>>>': 8, | ||
@@ -138,7 +138,7 @@ '+': 9, '-': 9, | ||
// space or tab | ||
while(ch === 32 || ch === 9) { | ||
while(ch === 32 || ch === 9 || ch === 10 || ch === 13) { | ||
ch = exprICode(++index); | ||
} | ||
}, | ||
// The main parsing function. Much of this code is dedicated to ternary expressions | ||
@@ -247,3 +247,3 @@ gobbleExpression = function() { | ||
while(i > 1) { | ||
node = createBinaryExpression(stack[i - 1].value, stack[i - 2], node); | ||
node = createBinaryExpression(stack[i - 1].value, stack[i - 2], node); | ||
i -= 2; | ||
@@ -258,3 +258,3 @@ } | ||
var ch, to_check, tc_len; | ||
gobbleSpaces(); | ||
@@ -289,3 +289,3 @@ ch = exprICode(index); | ||
} | ||
return false; | ||
@@ -309,3 +309,3 @@ } | ||
} | ||
ch = exprI(index); | ||
@@ -325,4 +325,4 @@ if(ch === 'e' || ch === 'E') { // exponent marker | ||
} | ||
chCode = exprICode(index); | ||
@@ -381,3 +381,3 @@ // Check to make sure this isn't a variable name that start with a number (123abc) | ||
}, | ||
// Gobbles only identifiers | ||
@@ -459,3 +459,3 @@ // e.g.: `foo`, `_value`, `$x1` | ||
ch_i = exprICode(index); | ||
if(ch_i === OPAREN_CODE) { | ||
@@ -534,3 +534,3 @@ node = gobbleGroup(); | ||
nodes = [], ch_i, node; | ||
while(index < length) { | ||
@@ -537,0 +537,0 @@ ch_i = exprICode(index); |
@@ -0,0 +0,0 @@ /** |
@@ -95,2 +95,3 @@ (function() { | ||
test_op_expession("1 + 2- 3* 4 /8"); | ||
test_op_expession("\n1\r\n+\n2\n"); | ||
}); | ||
@@ -97,0 +98,0 @@ |
@@ -0,0 +0,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 9 instances in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
695705
30
8018
10