static-eval
Advanced tools
Comparing version 1.1.1 to 2.0.0
37
index.js
@@ -7,3 +7,3 @@ var unparse = require('escodegen').generate; | ||
var result = (function walk (node) { | ||
var result = (function walk (node, scopeVars) { | ||
if (node.type === 'Literal') { | ||
@@ -101,3 +101,6 @@ return node.value; | ||
var obj = walk(node.object); | ||
if (obj === FAIL) return FAIL; | ||
// do not allow access to methods on Function | ||
if((obj === FAIL) || (typeof obj == 'function')){ | ||
return FAIL; | ||
} | ||
if (node.property.type === 'Identifier') { | ||
@@ -115,3 +118,33 @@ return obj[node.property.name]; | ||
} | ||
else if (node.type === 'ExpressionStatement') { | ||
var val = walk(node.expression) | ||
if (val === FAIL) return FAIL; | ||
return val; | ||
} | ||
else if (node.type === 'ReturnStatement') { | ||
return walk(node.argument) | ||
} | ||
else if (node.type === 'FunctionExpression') { | ||
var bodies = node.body.body; | ||
// Create a "scope" for our arguments | ||
var oldVars = {}; | ||
Object.keys(vars).forEach(function(element){ | ||
oldVars[element] = vars[element]; | ||
}) | ||
node.params.forEach(function(key) { | ||
if(key.type == 'Identifier'){ | ||
vars[key.name] = null; | ||
} | ||
}); | ||
for(var i in bodies){ | ||
if(walk(bodies[i]) === FAIL){ | ||
return FAIL; | ||
} | ||
} | ||
// restore the vars and scope after we walk | ||
vars = oldVars; | ||
var keys = Object.keys(vars); | ||
@@ -118,0 +151,0 @@ var vals = keys.map(function(key) { |
{ | ||
"name": "static-eval", | ||
"version": "1.1.1", | ||
"version": "2.0.0", | ||
"description": "evaluate statically-analyzable expressions", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
10620
7
179