Comparing version 0.3.2 to 0.3.3
@@ -1,2 +0,2 @@ | ||
// JavaScript Expression Parser (JSEP) 0.3.2 | ||
// JavaScript Expression Parser (JSEP) 0.3.3 | ||
// JSEP may be freely distributed under the MIT License | ||
@@ -263,5 +263,2 @@ // http://jsep.from.so/ | ||
return gobbleStringLiteral(); | ||
} else if(isIdentifierStart(ch) || ch === OPAREN_CODE) { // open parenthesis | ||
// `foo`, `bar.baz` | ||
return gobbleVariable(); | ||
} else if (ch === OBRACK_CODE) { | ||
@@ -285,4 +282,9 @@ return gobbleArray(); | ||
return false; | ||
if (isIdentifierStart(ch) || ch === OPAREN_CODE) { // open parenthesis | ||
// `foo`, `bar.baz` | ||
return gobbleVariable(); | ||
} | ||
} | ||
return false; | ||
}, | ||
@@ -357,3 +359,3 @@ // Parse simple numeric literals: `12`, `3.4`, `.5`. Do this by using a string to | ||
case 'v': str += '\x0B'; break; | ||
default : str += '\\' + ch; | ||
default : str += ch; | ||
} | ||
@@ -558,3 +560,3 @@ } else { | ||
// To be filled in by the template | ||
jsep.version = '0.3.2'; | ||
jsep.version = '0.3.3'; | ||
jsep.toString = function() { return 'JavaScript Expression Parser (JSEP) v' + jsep.version; }; | ||
@@ -615,3 +617,3 @@ | ||
max_unop_len = 0; | ||
return this; | ||
@@ -640,3 +642,3 @@ }; | ||
max_binop_len = 0; | ||
return this; | ||
@@ -661,3 +663,3 @@ }; | ||
literals = {}; | ||
return this; | ||
@@ -664,0 +666,0 @@ }; |
@@ -1,3 +0,3 @@ | ||
/* 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); | ||
/* 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); | ||
//# sourceMappingURL=jsep.min.js.map |
@@ -0,1 +1,9 @@ | ||
## 0.3.3 - 2017-12-16 | ||
### Notice | ||
- No functional changes, only updated support for typescript definitions. | ||
- There may be a few known issues, check the issue page for details. | ||
### Changed | ||
- Updated typings. | ||
- Updated grunt-uglify for 0.03 kB smaller jsep.min.js! :) | ||
## 0.3.2 - 2017-08-31 | ||
@@ -2,0 +10,0 @@ ### Notice |
{ | ||
"name": "jsep", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": "a tiny JavaScript expression parser", | ||
@@ -19,4 +19,4 @@ "author": "Stephen Oney <swloney@gmail.com> (http://from.so/)", | ||
"grunt-contrib-jshint": "~1.1.0", | ||
"grunt-contrib-qunit": "~2.0.0", | ||
"grunt-contrib-uglify": "~3.0.1", | ||
"grunt-contrib-qunit": "~1.3.0", | ||
"grunt-contrib-uglify": "~3.2.1", | ||
"grunt-contrib-concat": "~1.0.1", | ||
@@ -23,0 +23,0 @@ "grunt-contrib-watch": "~1.0.0", |
@@ -32,3 +32,3 @@ ## jsep: A Tiny JavaScript Expression Parser | ||
// Add a custom @ unary operator with precedence 10 | ||
// Add a custom @ unary operator | ||
jsep.addUnaryOp('@'); | ||
@@ -35,0 +35,0 @@ |
@@ -263,5 +263,2 @@ // JavaScript Expression Parser (JSEP) <%= version %> | ||
return gobbleStringLiteral(); | ||
} else if(isIdentifierStart(ch) || ch === OPAREN_CODE) { // open parenthesis | ||
// `foo`, `bar.baz` | ||
return gobbleVariable(); | ||
} else if (ch === OBRACK_CODE) { | ||
@@ -285,4 +282,9 @@ return gobbleArray(); | ||
return false; | ||
if (isIdentifierStart(ch) || ch === OPAREN_CODE) { // open parenthesis | ||
// `foo`, `bar.baz` | ||
return gobbleVariable(); | ||
} | ||
} | ||
return false; | ||
}, | ||
@@ -357,3 +359,3 @@ // Parse simple numeric literals: `12`, `3.4`, `.5`. Do this by using a string to | ||
case 'v': str += '\x0B'; break; | ||
default : str += '\\' + ch; | ||
default : str += ch; | ||
} | ||
@@ -614,3 +616,3 @@ } else { | ||
max_unop_len = 0; | ||
return this; | ||
@@ -639,3 +641,3 @@ }; | ||
max_binop_len = 0; | ||
return this; | ||
@@ -660,3 +662,3 @@ }; | ||
literals = {}; | ||
return this; | ||
@@ -663,0 +665,0 @@ }; |
@@ -98,3 +98,3 @@ (function() { | ||
test('Custom ops', function() { | ||
test('Custom operators', function() { | ||
jsep.addBinaryOp("^", 10); | ||
@@ -109,4 +109,33 @@ test_parser("a^b", {}); | ||
}); | ||
jsep.addUnaryOp("#"); | ||
test_parser("#a", { | ||
type: "UnaryExpression", | ||
operator: "#", | ||
argument: {type: "Identifier", name: "a"} | ||
}); | ||
}); | ||
test('Custom alphanumeric operators', function() { | ||
jsep.addBinaryOp("and", 2); | ||
test_parser("a and b", { | ||
type: "BinaryExpression", | ||
operator: "and", | ||
left: {type: "Identifier", name: "a"}, | ||
right: {type: "Identifier", name: "b"} | ||
}); | ||
test_parser("bands", {type: "Identifier", name: "bands"}); | ||
// TODO: https://github.com/soney/jsep/issues/68 | ||
//test_parser("b ands", {type: "Compound"}); | ||
jsep.addUnaryOp("not"); | ||
test_parser("not a", { | ||
type: "UnaryExpression", | ||
operator: "not", | ||
argument: {type: "Identifier", name: "a"} | ||
}); | ||
// TODO: https://github.com/soney/jsep/issues/68 | ||
//test_parser("notes", {type: "Identifier", name: "notes"}); | ||
}); | ||
test('Bad Numbers', function() { | ||
@@ -113,0 +142,0 @@ test_parser("1.", {type: "Literal", value: 1, raw: "1."}); |
@@ -1,45 +0,90 @@ | ||
declare module 'jsep' { | ||
namespace jsep { | ||
export interface IExpression { | ||
type: string; | ||
} | ||
namespace jsep { | ||
export interface Expression { | ||
type: ExpressionType; | ||
} | ||
export interface ILiteral extends IExpression { | ||
type: "Literal"; | ||
value: any; | ||
raw: string; | ||
} | ||
export interface ArrayExpression extends Expression { | ||
type: 'ArrayExpression'; | ||
elements: Expression[]; | ||
} | ||
export interface IIdentifier extends IExpression { | ||
type: 'Identifier' | ||
name: string; | ||
} | ||
export interface BinaryExpression extends Expression { | ||
type: 'BinaryExpression'; | ||
operator: string; | ||
left: Expression; | ||
right: Expression; | ||
} | ||
export interface IBinaryExpression extends IExpression { | ||
type: 'BinaryExpression'; | ||
operator: string; | ||
left: IExpression; | ||
right: IExpression; | ||
} | ||
export interface CallExpression extends Expression { | ||
type: 'CallExpression'; | ||
arguments: Expression[]; | ||
callee: Expression; | ||
} | ||
export interface IUnaryExpression extends IExpression { | ||
type: 'UnaryExpression'; | ||
operator: string; | ||
argument: IExpression; | ||
prefix: boolean; | ||
} | ||
export interface Compound extends Expression { | ||
type: 'Compound'; | ||
body: Expression[]; | ||
} | ||
export interface IMemberExpression extends IExpression { | ||
type: 'MemberExpression'; | ||
computed: boolean; | ||
object: IExpression; | ||
property: IExpression; | ||
export interface ConditionalExpression extends Expression { | ||
type: 'ConditionalExpression'; | ||
test: Expression; | ||
consequent: Expression; | ||
alternate: Expression; | ||
} | ||
export interface Identifier extends Expression { | ||
type: 'Identifier'; | ||
name: string; | ||
} | ||
export interface Literal extends Expression { | ||
type: 'Literal'; | ||
value: boolean | number | string; | ||
raw: string; | ||
} | ||
export interface LogicalExpression extends Expression { | ||
type: 'LogicalExpression'; | ||
operator: string; | ||
left: Expression; | ||
right: Expression; | ||
} | ||
export interface MemberExpression extends Expression { | ||
type: 'MemberExpression'; | ||
computed: boolean; | ||
object: Expression; | ||
property: Expression; | ||
} | ||
export interface ThisExpression extends Expression { | ||
type: 'ThisExpression'; | ||
} | ||
export interface UnaryExpression extends Expression { | ||
type: 'UnaryExpression'; | ||
operator: string; | ||
argument: Expression; | ||
prefix: boolean; | ||
} | ||
type ExpressionType = 'Compound' | 'Identifier' | 'MemberExpression' | 'Literal' | 'ThisExpression' | 'CallExpression' | 'UnaryExpression' | 'BinaryExpression' | 'LogicalExpression' | 'ConditionalExpression' | 'ArrayExpression'; | ||
function addBinaryOp(operatorName: string, precedence: number): void; | ||
function addUnaryOp(operatorName: string): void; | ||
function removeBinaryOp(operatorName: string): void; | ||
function removeUnaryOp(operatorName: string): void; | ||
const version: string; | ||
} | ||
} | ||
function jsep(obj: string | jsep.IExpression): jsep.IExpression; | ||
function jsep(val: string | jsep.Expression): jsep.Expression; | ||
export = jsep; | ||
} | ||
export = jsep; | ||
} |
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
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
698450
8081
9