Comparing version 0.3.3 to 0.3.4
@@ -1,2 +0,2 @@ | ||
// JavaScript Expression Parser (JSEP) 0.3.3 | ||
// JavaScript Expression Parser (JSEP) 0.3.4 | ||
// JSEP may be freely distributed under the MIT License | ||
@@ -181,3 +181,9 @@ // http://jsep.from.so/ | ||
while(tc_len > 0) { | ||
if(binary_ops.hasOwnProperty(to_check)) { | ||
// Don't accept a binary op when it is an identifier. | ||
// Binary ops that start with a identifier-valid character must be followed | ||
// by a non identifier-part valid character | ||
if(binary_ops.hasOwnProperty(to_check) && ( | ||
!isIdentifierStart(exprICode(index)) || | ||
(index+to_check.length< expr.length && !isIdentifierPart(exprICode(index+to_check.length))) | ||
)) { | ||
index += tc_len; | ||
@@ -270,3 +276,9 @@ return to_check; | ||
while(tc_len > 0) { | ||
if(unary_ops.hasOwnProperty(to_check)) { | ||
// Don't accept an unary op when it is an identifier. | ||
// Unary ops that start with a identifier-valid character must be followed | ||
// by a non identifier-part valid character | ||
if(unary_ops.hasOwnProperty(to_check) && ( | ||
!isIdentifierStart(exprICode(index)) || | ||
(index+to_check.length < expr.length && !isIdentifierPart(exprICode(index+to_check.length))) | ||
)) { | ||
index += tc_len; | ||
@@ -288,3 +300,3 @@ return { | ||
} | ||
return false; | ||
@@ -560,3 +572,3 @@ }, | ||
// To be filled in by the template | ||
jsep.version = '0.3.3'; | ||
jsep.version = '0.3.4'; | ||
jsep.toString = function() { return 'JavaScript Expression Parser (JSEP) v' + jsep.version; }; | ||
@@ -563,0 +575,0 @@ |
@@ -1,3 +0,3 @@ | ||
/* jsep v0.3.3 (http://jsep.from.so/) */ | ||
!function(e){"use strict";var r="Compound",t="MemberExpression",n="Literal",o=function(e,r){var t=new Error(e+" at character "+r);throw t.index=r,t.description=e,t},i={"-":!0,"!":!0,"~":!0,"+":!0},a={"||":1,"&&":2,"|":3,"^":4,"&":5,"==":6,"!=":6,"===":6,"!==":6,"<":7,">":7,"<=":7,">=":7,"<<":8,">>":8,">>>":8,"+":9,"-":9,"*":10,"/":10,"%":10},u=function(e){var r,t=0;for(var n in e)(r=n.length)>t&&e.hasOwnProperty(n)&&(t=r);return t},s=u(i),p=u(a),f={true:!0,false:!1,null:null},c=function(e){return a[e]||0},l=function(e,r,t){return{type:"||"===e||"&&"===e?"LogicalExpression":"BinaryExpression",operator:e,left:r,right:t}},d=function(e){return e>=48&&e<=57},h=function(e){return 36===e||95===e||e>=65&&e<=90||e>=97&&e<=122||e>=128&&!a[String.fromCharCode(e)]},v=function(e){return 36===e||95===e||e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57||e>=128&&!a[String.fromCharCode(e)]},x=function(e){for(var u,x,y=0,m=e.charAt,b=e.charCodeAt,g=function(r){return m.call(e,r)},E=function(r){return b.call(e,r)},w=e.length,C=function(){for(var e=E(y);32===e||9===e||10===e||13===e;)e=E(++y)},O=function(){var e,r,t=k();return C(),63!==E(y)?t:(y++,(e=O())||o("Expected expression",y),C(),58===E(y)?(y++,(r=O())||o("Expected expression",y),{type:"ConditionalExpression",test:t,consequent:e,alternate:r}):void o("Expected :",y))},U=function(){C();for(var r=e.substr(y,p),t=r.length;t>0;){if(a.hasOwnProperty(r))return y+=t,r;r=r.substr(0,--t)}return!1},k=function(){var e,r,t,n,i,a,u,s;if(a=j(),!(r=U()))return a;for(i={value:r,prec:c(r)},(u=j())||o("Expected expression after "+r,y),n=[a,i,u];(r=U())&&0!==(t=c(r));){for(i={value:r,prec:t};n.length>2&&t<=n[n.length-2].prec;)u=n.pop(),r=n.pop().value,a=n.pop(),e=l(r,a,u),n.push(e);(e=j())||o("Expected expression after "+r,y),n.push(i,e)}for(e=n[s=n.length-1];s>1;)e=l(n[s-1].value,n[s-2],e),s-=2;return e},j=function(){var r,t,n;if(C(),r=E(y),d(r)||46===r)return A();if(39===r||34===r)return P();if(91===r)return q();for(n=(t=e.substr(y,s)).length;n>0;){if(i.hasOwnProperty(t))return y+=n,{type:"UnaryExpression",operator:t,argument:j(),prefix:!0};t=t.substr(0,--n)}return!(!h(r)&&40!==r)&&B()},A=function(){for(var e,r,t="";d(E(y));)t+=g(y++);if(46===E(y))for(t+=g(y++);d(E(y));)t+=g(y++);if("e"===(e=g(y))||"E"===e){for(t+=g(y++),"+"!==(e=g(y))&&"-"!==e||(t+=g(y++));d(E(y));)t+=g(y++);d(E(y-1))||o("Expected exponent ("+t+g(y)+")",y)}return r=E(y),h(r)?o("Variable names cannot start with a number ("+t+g(y)+")",y):46===r&&o("Unexpected period",y),{type:n,value:parseFloat(t),raw:t}},P=function(){for(var e,r="",t=g(y++),i=!1;y<w;){if((e=g(y++))===t){i=!0;break}if("\\"===e)switch(e=g(y++)){case"n":r+="\n";break;case"r":r+="\r";break;case"t":r+="\t";break;case"b":r+="\b";break;case"f":r+="\f";break;case"v":r+="\v";break;default:r+=e}else r+=e}return i||o('Unclosed quote after "'+r+'"',y),{type:n,value:r,raw:t+r+t}},S=function(){var r,t=E(y),i=y;for(h(t)?y++:o("Unexpected "+g(y),y);y<w&&(t=E(y),v(t));)y++;return r=e.slice(i,y),f.hasOwnProperty(r)?{type:n,value:f[r],raw:r}:"this"===r?{type:"ThisExpression"}:{type:"Identifier",name:r}},L=function(e){for(var t,n,i=[],a=!1;y<w;){if(C(),(t=E(y))===e){a=!0,y++;break}44===t?y++:((n=O())&&n.type!==r||o("Expected comma",y),i.push(n))}return a||o("Expected "+String.fromCharCode(e),y),i},B=function(){var e,r;for(r=40===(e=E(y))?M():S(),C(),e=E(y);46===e||91===e||40===e;)y++,46===e?(C(),r={type:t,computed:!1,object:r,property:S()}):91===e?(r={type:t,computed:!0,object:r,property:O()},C(),93!==(e=E(y))&&o("Unclosed [",y),y++):40===e&&(r={type:"CallExpression",arguments:L(41),callee:r}),C(),e=E(y);return r},M=function(){y++;var e=O();if(C(),41===E(y))return y++,e;o("Unclosed (",y)},q=function(){return y++,{type:"ArrayExpression",elements:L(93)}},J=[];y<w;)59===(u=E(y))||44===u?y++:(x=O())?J.push(x):y<w&&o('Unexpected "'+g(y)+'"',y);return 1===J.length?J[0]:{type:r,body:J}};if(x.version="0.3.3",x.toString=function(){return"JavaScript Expression Parser (JSEP) v"+x.version},x.addUnaryOp=function(e){return s=Math.max(e.length,s),i[e]=!0,this},x.addBinaryOp=function(e,r){return p=Math.max(e.length,p),a[e]=r,this},x.addLiteral=function(e,r){return f[e]=r,this},x.removeUnaryOp=function(e){return delete i[e],e.length===s&&(s=u(i)),this},x.removeAllUnaryOps=function(){return i={},s=0,this},x.removeBinaryOp=function(e){return delete a[e],e.length===p&&(p=u(a)),this},x.removeAllBinaryOps=function(){return a={},p=0,this},x.removeLiteral=function(e){return delete f[e],this},x.removeAllLiterals=function(){return f={},this},"undefined"==typeof exports){var y=e.jsep;e.jsep=x,x.noConflict=function(){return e.jsep===x&&(e.jsep=y),x}}else"undefined"!=typeof module&&module.exports?exports=module.exports=x:exports.parse=x}(this); | ||
/* jsep v0.3.4 (http://jsep.from.so/) */ | ||
!function(e){"use strict";var w="Compound",C="MemberExpression",O="Literal",U=function(e,r){var t=new Error(e+" at character "+r);throw t.index=r,t.description=e,t},k={"-":!0,"!":!0,"~":!0,"+":!0},j={"||":1,"&&":2,"|":3,"^":4,"&":5,"==":6,"!=":6,"===":6,"!==":6,"<":7,">":7,"<=":7,">=":7,"<<":8,">>":8,">>>":8,"+":9,"-":9,"*":10,"/":10,"%":10},r=function(e){var r,t=0;for(var n in e)(r=n.length)>t&&e.hasOwnProperty(n)&&(t=r);return t},A=r(k),P=r(j),S={true:!0,false:!1,null:null},L=function(e){return j[e]||0},B=function(e,r,t){return{type:"||"===e||"&&"===e?"LogicalExpression":"BinaryExpression",operator:e,left:r,right:t}},M=function(e){return 48<=e&&e<=57},q=function(e){return 36===e||95===e||65<=e&&e<=90||97<=e&&e<=122||128<=e&&!j[String.fromCharCode(e)]},J=function(e){return 36===e||95===e||65<=e&&e<=90||97<=e&&e<=122||48<=e&&e<=57||128<=e&&!j[String.fromCharCode(e)]},t=function(n){for(var e,r,s=0,t=n.charAt,o=n.charCodeAt,i=function(e){return t.call(n,e)},a=function(e){return o.call(n,e)},u=n.length,p=function(){for(var e=a(s);32===e||9===e||10===e||13===e;)e=a(++s)},f=function(){var e,r,t=l();return p(),63!==a(s)?t:(s++,(e=f())||U("Expected expression",s),p(),58===a(s)?(s++,(r=f())||U("Expected expression",s),{type:"ConditionalExpression",test:t,consequent:e,alternate:r}):void U("Expected :",s))},c=function(){p();for(var e=n.substr(s,P),r=e.length;0<r;){if(j.hasOwnProperty(e)&&(!q(a(s))||s+e.length<n.length&&!J(a(s+e.length))))return s+=r,e;e=e.substr(0,--r)}return!1},l=function(){var e,r,t,n,o,i,a,u;if(i=h(),!(r=c()))return i;for(o={value:r,prec:L(r)},(a=h())||U("Expected expression after "+r,s),n=[i,o,a];(r=c())&&0!==(t=L(r));){for(o={value:r,prec:t};2<n.length&&t<=n[n.length-2].prec;)a=n.pop(),r=n.pop().value,i=n.pop(),e=B(r,i,a),n.push(e);(e=h())||U("Expected expression after "+r,s),n.push(o,e)}for(e=n[u=n.length-1];1<u;)e=B(n[u-1].value,n[u-2],e),u-=2;return e},h=function(){var e,r,t;if(p(),e=a(s),M(e)||46===e)return d();if(39===e||34===e)return v();if(91===e)return b();for(t=(r=n.substr(s,A)).length;0<t;){if(k.hasOwnProperty(r)&&(!q(a(s))||s+r.length<n.length&&!J(a(s+r.length))))return s+=t,{type:"UnaryExpression",operator:r,argument:h(),prefix:!0};r=r.substr(0,--t)}return!(!q(e)&&40!==e)&&g()},d=function(){for(var e,r,t="";M(a(s));)t+=i(s++);if(46===a(s))for(t+=i(s++);M(a(s));)t+=i(s++);if("e"===(e=i(s))||"E"===e){for(t+=i(s++),"+"!==(e=i(s))&&"-"!==e||(t+=i(s++));M(a(s));)t+=i(s++);M(a(s-1))||U("Expected exponent ("+t+i(s)+")",s)}return r=a(s),q(r)?U("Variable names cannot start with a number ("+t+i(s)+")",s):46===r&&U("Unexpected period",s),{type:O,value:parseFloat(t),raw:t}},v=function(){for(var e,r="",t=i(s++),n=!1;s<u;){if((e=i(s++))===t){n=!0;break}if("\\"===e)switch(e=i(s++)){case"n":r+="\n";break;case"r":r+="\r";break;case"t":r+="\t";break;case"b":r+="\b";break;case"f":r+="\f";break;case"v":r+="\v";break;default:r+=e}else r+=e}return n||U('Unclosed quote after "'+r+'"',s),{type:O,value:r,raw:t+r+t}},x=function(){var e,r=a(s),t=s;for(q(r)?s++:U("Unexpected "+i(s),s);s<u&&(r=a(s),J(r));)s++;return e=n.slice(t,s),S.hasOwnProperty(e)?{type:O,value:S[e],raw:e}:"this"===e?{type:"ThisExpression"}:{type:"Identifier",name:e}},y=function(e){for(var r,t,n=[],o=!1;s<u;){if(p(),(r=a(s))===e){o=!0,s++;break}44===r?s++:((t=f())&&t.type!==w||U("Expected comma",s),n.push(t))}return o||U("Expected "+String.fromCharCode(e),s),n},g=function(){var e,r;for(r=40===(e=a(s))?m():x(),p(),e=a(s);46===e||91===e||40===e;)s++,46===e?(p(),r={type:C,computed:!1,object:r,property:x()}):91===e?(r={type:C,computed:!0,object:r,property:f()},p(),93!==(e=a(s))&&U("Unclosed [",s),s++):40===e&&(r={type:"CallExpression",arguments:y(41),callee:r}),p(),e=a(s);return r},m=function(){s++;var e=f();if(p(),41===a(s))return s++,e;U("Unclosed (",s)},b=function(){return s++,{type:"ArrayExpression",elements:y(93)}},E=[];s<u;)59===(e=a(s))||44===e?s++:(r=f())?E.push(r):s<u&&U('Unexpected "'+i(s)+'"',s);return 1===E.length?E[0]:{type:w,body:E}};if(t.version="0.3.4",t.toString=function(){return"JavaScript Expression Parser (JSEP) v"+t.version},t.addUnaryOp=function(e){return A=Math.max(e.length,A),k[e]=!0,this},t.addBinaryOp=function(e,r){return P=Math.max(e.length,P),j[e]=r,this},t.addLiteral=function(e,r){return S[e]=r,this},t.removeUnaryOp=function(e){return delete k[e],e.length===A&&(A=r(k)),this},t.removeAllUnaryOps=function(){return k={},A=0,this},t.removeBinaryOp=function(e){return delete j[e],e.length===P&&(P=r(j)),this},t.removeAllBinaryOps=function(){return j={},P=0,this},t.removeLiteral=function(e){return delete S[e],this},t.removeAllLiterals=function(){return S={},this},"undefined"==typeof exports){var n=e.jsep;(e.jsep=t).noConflict=function(){return e.jsep===t&&(e.jsep=n),t}}else"undefined"!=typeof module&&module.exports?exports=module.exports=t:exports.parse=t}(this); | ||
//# sourceMappingURL=jsep.min.js.map |
@@ -0,1 +1,5 @@ | ||
## 0.3.4 - 2018-03-29 | ||
### Fixed | ||
- Fixed identifiers as custom ops (#68,#83) | ||
## 0.3.3 - 2017-12-16 | ||
@@ -2,0 +6,0 @@ ### Notice |
{ | ||
"name": "jsep", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "a tiny JavaScript expression parser", | ||
@@ -20,3 +20,3 @@ "author": "Stephen Oney <swloney@gmail.com> (http://from.so/)", | ||
"grunt-contrib-qunit": "~1.3.0", | ||
"grunt-contrib-uglify": "~3.2.1", | ||
"grunt-contrib-uglify": "~3.3.0", | ||
"grunt-contrib-concat": "~1.0.1", | ||
@@ -23,0 +23,0 @@ "grunt-contrib-watch": "~1.0.0", |
@@ -12,4 +12,6 @@ ## jsep: A Tiny JavaScript Expression Parser | ||
npm install . | ||
grunt | ||
```bash | ||
npm install . | ||
grunt | ||
``` | ||
@@ -20,24 +22,28 @@ The jsep built files will be in the build/ directory. | ||
#### Client-side | ||
<script src="/PATH/TO/jsep.min.js" type="text/javascript"></script> | ||
... | ||
var parse_tree = jsep("1 + 1"); | ||
```javascript | ||
<script src="/PATH/TO/jsep.min.js" type="text/javascript"></script> | ||
... | ||
var parse_tree = jsep("1 + 1"); | ||
``` | ||
#### Node.JS | ||
First, run `npm install jsep`. Then, in your source file: | ||
```javascript | ||
var jsep = require("jsep"); | ||
var parse_tree = jsep("1 + 1"); | ||
``` | ||
#### Custom Operators | ||
```javascript | ||
// Add a custom ^ binary operator with precedence 10 | ||
jsep.addBinaryOp("^", 10); | ||
var jsep = require("jsep"); | ||
var parse_tree = jsep("1 + 1"); | ||
// Add a custom @ unary operator | ||
jsep.addUnaryOp('@'); | ||
#### Custom Operators | ||
// Add a custom ^ binary operator with precedence 10 | ||
jsep.addBinaryOp("^", 10); | ||
// Add a custom @ unary operator | ||
jsep.addUnaryOp('@'); | ||
// Remove a binary operator | ||
jsep.removeBinaryOp(">>>"); | ||
// Remove a unary operator | ||
jsep.removeUnaryOp("~"); | ||
// Remove a binary operator | ||
jsep.removeBinaryOp(">>>"); | ||
// Remove a unary operator | ||
jsep.removeUnaryOp("~"); | ||
``` | ||
### License | ||
@@ -44,0 +50,0 @@ jsep is under the MIT license. See LICENSE file. |
@@ -181,3 +181,9 @@ // JavaScript Expression Parser (JSEP) <%= version %> | ||
while(tc_len > 0) { | ||
if(binary_ops.hasOwnProperty(to_check)) { | ||
// Don't accept a binary op when it is an identifier. | ||
// Binary ops that start with a identifier-valid character must be followed | ||
// by a non identifier-part valid character | ||
if(binary_ops.hasOwnProperty(to_check) && ( | ||
!isIdentifierStart(exprICode(index)) || | ||
(index+to_check.length< expr.length && !isIdentifierPart(exprICode(index+to_check.length))) | ||
)) { | ||
index += tc_len; | ||
@@ -270,3 +276,9 @@ return to_check; | ||
while(tc_len > 0) { | ||
if(unary_ops.hasOwnProperty(to_check)) { | ||
// Don't accept an unary op when it is an identifier. | ||
// Unary ops that start with a identifier-valid character must be followed | ||
// by a non identifier-part valid character | ||
if(unary_ops.hasOwnProperty(to_check) && ( | ||
!isIdentifierStart(exprICode(index)) || | ||
(index+to_check.length < expr.length && !isIdentifierPart(exprICode(index+to_check.length))) | ||
)) { | ||
index += tc_len; | ||
@@ -288,3 +300,3 @@ return { | ||
} | ||
return false; | ||
@@ -291,0 +303,0 @@ }, |
@@ -109,2 +109,21 @@ (function() { | ||
jsep.addBinaryOp("or", 1); | ||
test_parser("oneWord ordering anotherWord", { | ||
type: 'Compound', | ||
body: [ | ||
{ | ||
type: 'Identifier', | ||
name: 'oneWord' | ||
}, | ||
{ | ||
type: 'Identifier', | ||
name: 'ordering' | ||
}, | ||
{ | ||
type: 'Identifier', | ||
name: 'anotherWord' | ||
} | ||
] | ||
}); | ||
jsep.addUnaryOp("#"); | ||
@@ -116,2 +135,15 @@ test_parser("#a", { | ||
}); | ||
jsep.addUnaryOp("not"); | ||
test_parser("not a", { | ||
type: "UnaryExpression", | ||
operator: "not", | ||
argument: {type: "Identifier", name: "a"} | ||
}); | ||
jsep.addUnaryOp("notes"); | ||
test_parser("notes", { | ||
type: "Identifier", | ||
name: "notes" | ||
}); | ||
}); | ||
@@ -128,5 +160,5 @@ | ||
test_parser("bands", {type: "Identifier", name: "bands"}); | ||
// TODO: https://github.com/soney/jsep/issues/68 | ||
//test_parser("b ands", {type: "Compound"}); | ||
test_parser("b ands", {type: "Compound"}); | ||
jsep.addUnaryOp("not"); | ||
@@ -138,4 +170,4 @@ test_parser("not a", { | ||
}); | ||
// TODO: https://github.com/soney/jsep/issues/68 | ||
//test_parser("notes", {type: "Identifier", name: "notes"}); | ||
test_parser("notes", {type: "Identifier", name: "notes"}); | ||
}); | ||
@@ -142,0 +174,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
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
717168
35
8132
52