Comparing version 0.2.7 to 0.2.8
{ | ||
"name": "jsep", | ||
"version": "0.2.7", | ||
"version": "0.2.8", | ||
"description": "a tiny JavaScript expression parser", | ||
@@ -5,0 +5,0 @@ "author": "Stephen Oney <swloney@gmail.com> (http://from.so/)", |
@@ -102,2 +102,6 @@ // JavaScript Expression Parser (JSEP) <%= version %> | ||
var index = 0, | ||
charAtFunc = expr.charAt, | ||
charCodeAtFunc = expr.charCodeAt, | ||
exprI = function(i) { return charAtFunc.call(expr, i); }, | ||
exprICode = function(i) { return charCodeAtFunc.call(expr, i); }, | ||
length = expr.length, | ||
@@ -107,6 +111,6 @@ | ||
gobbleSpaces = function() { | ||
var ch = expr.charCodeAt(index); | ||
var ch = exprICode(index); | ||
// space or tab | ||
while(ch === 32 || ch === 9) { | ||
ch = expr.charCodeAt(++index); | ||
ch = exprICode(++index); | ||
} | ||
@@ -196,6 +200,6 @@ }, | ||
gobbleToken = function() { | ||
var ch, curr_node, char, unop, to_check, tc_len; | ||
var ch, curr_node, unop, to_check, tc_len; | ||
gobbleSpaces(); | ||
ch = expr.charCodeAt(index); | ||
ch = exprICode(index); | ||
@@ -237,18 +241,33 @@ if(isDecimalDigit(ch) || ch === 46) { | ||
var number = ''; | ||
while(isDecimalDigit(expr.charCodeAt(index))) { | ||
number += expr[index++]; | ||
while(isDecimalDigit(exprICode(index))) { | ||
number += exprI(index++); | ||
} | ||
if(expr[index] === '.') { // can start with a decimal marker | ||
number += expr[index++]; | ||
if(exprI(index) === '.') { // can start with a decimal marker | ||
number += exprI(index++); | ||
while(isDecimalDigit(expr.charCodeAt(index))) { | ||
number += expr[index++]; | ||
while(isDecimalDigit(exprICode(index))) { | ||
number += exprI(index++); | ||
} | ||
} | ||
if(exprI(index) === 'e' || exprI(index) === 'E') { // exponent marker | ||
number += exprI(index++); | ||
if(exprI(index) === '+' || exprI(index) === '-') { // exponent sign | ||
number += exprI(index++); | ||
} | ||
while(isDecimalDigit(exprICode(index))) { //exponent itself | ||
number += exprI(index++); | ||
} | ||
if(!isDecimalDigit(exprICode(index-1)) ) { | ||
throw new Error('Expected exponent (' + | ||
number + exprI(index) + ') at character ' + index); | ||
} | ||
} | ||
// Check to make sure this isn't a varible name that start with a number (123abc) | ||
if(isIdentifierStart(expr.charCodeAt(index))) { | ||
// Check to make sure this isn't a variable name that start with a number (123abc) | ||
if(isIdentifierStart(exprICode(index))) { | ||
throw new Error('Variable names cannot start with a number (' + | ||
number + expr[index] + ') at character ' + index); | ||
number + exprI(index) + ') at character ' + index); | ||
} | ||
@@ -266,6 +285,6 @@ | ||
gobbleStringLiteral = function() { | ||
var str = '', quote = expr[index++], closed = false, ch; | ||
var str = '', quote = exprI(index++), closed = false, ch; | ||
while(index < length) { | ||
ch = expr[index++]; | ||
ch = exprI(index++); | ||
if(ch === quote) { | ||
@@ -276,3 +295,3 @@ closed = true; | ||
// Check for all of the common escape codes | ||
ch = expr[index++]; | ||
ch = exprI(index++); | ||
switch(ch) { | ||
@@ -304,13 +323,15 @@ case 'n': str += '\n'; break; | ||
// e.g.: `foo`, `_value`, `$x1` | ||
// Also, this function checs if that identifier is a literal: | ||
// Also, this function checks if that identifier is a literal: | ||
// (e.g. `true`, `false`, `null`) or `this` | ||
gobbleIdentifier = function() { | ||
var ch = expr.charCodeAt(index), start = index, identifier; | ||
var ch = exprICode(index), start = index, identifier; | ||
if(isIdentifierStart(ch)) { | ||
index++; | ||
} else { | ||
throw new Error('Unexpected ' + exprI(index) + 'at character ' + index); | ||
} | ||
while(index < length) { | ||
ch = expr.charCodeAt(index); | ||
ch = exprICode(index); | ||
if(isIdentifierPart(ch)) { | ||
@@ -347,3 +368,3 @@ index++; | ||
gobbleSpaces(); | ||
ch_i = expr[index]; | ||
ch_i = exprI(index); | ||
if(ch_i === ')') { // done parsing | ||
@@ -373,3 +394,3 @@ index++; | ||
gobbleSpaces(); | ||
ch_i = expr[index]; | ||
ch_i = exprI(index); | ||
while(ch_i === '.' || ch_i === '[' || ch_i === '(') { | ||
@@ -395,3 +416,3 @@ if(ch_i === '.') { | ||
gobbleSpaces(); | ||
ch_i = expr[index]; | ||
ch_i = exprI(index); | ||
if(ch_i !== ']') { | ||
@@ -403,3 +424,3 @@ throw new Error('Unclosed [ at character ' + index); | ||
} else if(ch_i === '(') { | ||
// A function call is being made; gobble all the araguments | ||
// A function call is being made; gobble all the arguments | ||
index++; | ||
@@ -413,3 +434,3 @@ node = { | ||
gobbleSpaces(); | ||
ch_i = expr[index]; | ||
ch_i = exprI(index); | ||
} | ||
@@ -419,5 +440,5 @@ return node; | ||
// Responsible for parsing a group of things within paraenteses `()` | ||
// Responsible for parsing a group of things within parentheses `()` | ||
// This function assumes that it needs to gobble the opening parenthesis | ||
// and then tries to gobble everything within that parenthesis, asusming | ||
// and then tries to gobble everything within that parenthesis, assuming | ||
// that the next thing it should see is the close parenthesis. If not, | ||
@@ -429,3 +450,3 @@ // then the expression probably doesn't have a `)` | ||
gobbleSpaces(); | ||
if(expr[index] === ')') { | ||
if(exprI(index) === ')') { | ||
index++; | ||
@@ -440,3 +461,3 @@ return node; | ||
while(index < length) { | ||
ch_i = expr[index]; | ||
ch_i = exprI(index); | ||
@@ -454,3 +475,3 @@ // Expressions can be separated by semicolons, commas, or just inferred without any | ||
} else if(index < length) { | ||
throw new Error("Unexpected '"+expr[index]+"' at character " + index); | ||
throw new Error("Unexpected '"+exprI(index)+"' at character " + index); | ||
} | ||
@@ -527,3 +548,3 @@ } | ||
root.jsep = jsep; | ||
// And a curteous function willing to move out of the way for other similary-namaed objects! | ||
// And a courteous function willing to move out of the way for other similarly-named objects! | ||
jsep.noConflict = function() { | ||
@@ -530,0 +551,0 @@ if(root.jsep === jsep) { |
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 8 instances in 1 package
0
249841
16
6981