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

jsep

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsep - npm Package Compare versions

Comparing version 0.2.9 to 0.3.0

28

build/jsep.js

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

// JavaScript Expression Parser (JSEP) 0.2.9
// JavaScript Expression Parser (JSEP) 0.3.0
// JSEP may be freely distributed under the MIT License

@@ -23,3 +23,3 @@ // http://jsep.from.so/

CONDITIONAL_EXP = 'ConditionalExpression',
ARRAY_EXP = 'Array',
ARRAY_EXP = 'ArrayExpression',

@@ -41,3 +41,3 @@ PERIOD_CODE = 46, // '.'

error.index = index;
error.dedscription = message;
error.description = message;
throw error;

@@ -144,6 +144,5 @@ },

consequent, alternate;
gobbleSpaces();
// Ternary expression: test ? consequent : alternate
if(exprICode(index) === QUMARK_CODE) {
// Ternary expression: test ? consequent : alternate
index++;

@@ -254,3 +253,3 @@ consequent = gobbleExpression();

gobbleToken = function() {
var ch, curr_node, unop, to_check, tc_len;
var ch, to_check, tc_len;

@@ -269,2 +268,4 @@ gobbleSpaces();

return gobbleVariable();
} else if (ch === OBRACK_CODE) {
return gobbleArray();
} else {

@@ -292,3 +293,3 @@ to_check = expr.substr(index, max_unop_len);

gobbleNumericLiteral = function() {
var number = '', ch;
var number = '', ch, chCode;
while(isDecimalDigit(exprICode(index))) {

@@ -322,6 +323,9 @@ number += exprI(index++);

chCode = exprICode(index);
// Check to make sure this isn't a variable name that start with a number (123abc)
if(isIdentifierStart(exprICode(index))) {
throwError( 'Variable names cannot start with a number (' +
if(isIdentifierStart(chCode)) {
throwError('Variable names cannot start with a number (' +
number + exprI(index) + ')', index);
} else if(chCode === PERIOD_CODE) {
throwError('Unexpected period', index);
}

@@ -514,3 +518,3 @@

type: ARRAY_EXP,
body: gobbleArguments(CBRACK_CODE)
elements: gobbleArguments(CBRACK_CODE)
};

@@ -528,4 +532,2 @@ },

index++; // ignore separators
} else if (ch_i === OBRACK_CODE && (node = gobbleArray())) {
nodes.push(node);
} else {

@@ -555,3 +557,3 @@ // Try to gobble each expression individually

// To be filled in by the template
jsep.version = '0.2.9';
jsep.version = '0.3.0';
jsep.toString = function() { return 'JavaScript Expression Parser (JSEP) v' + jsep.version; };

@@ -558,0 +560,0 @@

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

/* jsep v0.2.9 (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="Array",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.dedscription=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&&57>=a},J=function(a){return 36===a||95===a||a>=65&&90>=a||a>=97&&122>=a},K=function(a){return 36===a||95===a||a>=65&&90>=a||a>=97&&122>=a||a>=48&&57>=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}):(x("Expected :",y),void 0))},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();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="";I(N(y));)b+=M(y++);if(N(y)===m)for(b+=M(y++);I(N(y));)b+=M(y++);if(a=M(y),"e"===a||"E"===a){for(b+=M(y++),a=M(y),("+"===a||"-"===a)&&(b+=M(y++));I(N(y));)b+=M(y++);I(N(y-1))||x("Expected exponent ("+b+M(y)+")",y)}return J(N(y))&&x("Variable names cannot start with a number ("+b+M(y)+")",y),{type:e,value:parseFloat(b),raw:b}},V=function(){for(var a,b="",c=M(y++),d=!1;O>y;){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+=" ";break;case"b":b+="\b";break;case"f":b+="\f";break;case"v":b+=" "}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);O>y&&(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=[];O>y;){if(P(),c=N(y),c===a){y++;break}c===n?y++:(d=Q(),d&&d.type!==b||x("Expected comma",y),e.push(d))}return 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):(x("Unclosed (",y),void 0)},$=function(){return y++,{type:l,body:X(t)}},_=[];O>y;)i=N(y),i===v||i===n?y++:i===s&&(j=$())?_.push(j):(j=Q())?_.push(j):O>y&&x('Unexpected "'+M(y)+'"',y);return 1===_.length?_[0]:{type:b,body:_}};if(L.version="0.2.9",L.toString=function(){return"JavaScript Expression Parser (JSEP) v"+L.version},L.addUnaryOp=function(a){return z[a]=y,this},L.addBinaryOp=function(a,b){return D=Math.max(a.length,D),A[a]=b,this},L.removeUnaryOp=function(a){return delete z[a],a.length===C&&(C=B(z)),this},L.removeBinaryOp=function(a){return delete A[a],a.length===D&&(D=B(A)),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.0 (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&&57>=a},J=function(a){return 36===a||95===a||a>=65&&90>=a||a>=97&&122>=a},K=function(a){return 36===a||95===a||a>=65&&90>=a||a>=97&&122>=a||a>=48&&57>=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;O>y;){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+=" ";break;case"b":b+="\b";break;case"f":b+="\f";break;case"v":b+=" "}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);O>y&&(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=[];O>y;){if(P(),c=N(y),c===a){y++;break}c===n?y++:(d=Q(),d&&d.type!==b||x("Expected comma",y),e.push(d))}return 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)}},_=[];O>y;)i=N(y),i===v||i===n?y++:(j=Q())?_.push(j):O>y&&x('Unexpected "'+M(y)+'"',y);return 1===_.length?_[0]:{type:b,body:_}};if(L.version="0.3.0",L.toString=function(){return"JavaScript Expression Parser (JSEP) v"+L.version},L.addUnaryOp=function(a){return z[a]=y,this},L.addBinaryOp=function(a,b){return D=Math.max(a.length,D),A[a]=b,this},L.removeUnaryOp=function(a){return delete z[a],a.length===C&&(C=B(z)),this},L.removeBinaryOp=function(a){return delete A[a],a.length===D&&(D=B(A)),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);
//# sourceMappingURL=jsep.min.js.map
{
"name": "jsep",
"version": "0.2.9",
"version": "0.3.0",
"description": "a tiny JavaScript expression parser",

@@ -5,0 +5,0 @@ "author": "Stephen Oney <swloney@gmail.com> (http://from.so/)",

@@ -23,3 +23,3 @@ // JavaScript Expression Parser (JSEP) <%= version %>

CONDITIONAL_EXP = 'ConditionalExpression',
ARRAY_EXP = 'Array',
ARRAY_EXP = 'ArrayExpression',

@@ -41,3 +41,3 @@ PERIOD_CODE = 46, // '.'

error.index = index;
error.dedscription = message;
error.description = message;
throw error;

@@ -144,6 +144,5 @@ },

consequent, alternate;
gobbleSpaces();
// Ternary expression: test ? consequent : alternate
if(exprICode(index) === QUMARK_CODE) {
// Ternary expression: test ? consequent : alternate
index++;

@@ -254,3 +253,3 @@ consequent = gobbleExpression();

gobbleToken = function() {
var ch, curr_node, unop, to_check, tc_len;
var ch, to_check, tc_len;

@@ -269,2 +268,4 @@ gobbleSpaces();

return gobbleVariable();
} else if (ch === OBRACK_CODE) {
return gobbleArray();
} else {

@@ -292,3 +293,3 @@ to_check = expr.substr(index, max_unop_len);

gobbleNumericLiteral = function() {
var number = '', ch;
var number = '', ch, chCode;
while(isDecimalDigit(exprICode(index))) {

@@ -322,6 +323,9 @@ number += exprI(index++);

chCode = exprICode(index);
// Check to make sure this isn't a variable name that start with a number (123abc)
if(isIdentifierStart(exprICode(index))) {
throwError( 'Variable names cannot start with a number (' +
if(isIdentifierStart(chCode)) {
throwError('Variable names cannot start with a number (' +
number + exprI(index) + ')', index);
} else if(chCode === PERIOD_CODE) {
throwError('Unexpected period', index);
}

@@ -514,3 +518,3 @@

type: ARRAY_EXP,
body: gobbleArguments(CBRACK_CODE)
elements: gobbleArguments(CBRACK_CODE)
};

@@ -528,4 +532,2 @@ },

index++; // ignore separators
} else if (ch_i === OBRACK_CODE && (node = gobbleArray())) {
nodes.push(node);
} else {

@@ -532,0 +534,0 @@ // Try to gobble each expression individually

@@ -78,7 +78,7 @@ (function() {

test('Arrays', function() {
test_parser("[]", {type: 'Array', body: []});
test_parser("[]", {type: 'ArrayExpression', elements: []});
test_parser("[a]", {
type: 'Array',
body: [{type: 'Identifier', name: 'a'}]
type: 'ArrayExpression',
elements: [{type: 'Identifier', name: 'a'}]
});

@@ -102,3 +102,15 @@ });

test('Bad Numbers', function() {
test_parser("1.", {type: "Literal", value: 1, raw: "1."});
try {
var x = jsep("1.2.3");
console.log(x);
ok(false);
} catch(e) {
ok(true);
}
});
test('Esprima Comparison', function() {
([

@@ -119,3 +131,4 @@ " true",

"(Object.variable.toLowerCase()).length == 3",
"(Object.variable.toLowerCase()) . length == 3"
"(Object.variable.toLowerCase()) . length == 3",
"[1] + [2]"
]).map(esprima_comparison_test);

@@ -122,0 +135,0 @@ });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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