static-eval
Advanced tools
Comparing version 2.0.3 to 2.0.4
22
index.js
@@ -43,2 +43,21 @@ var unparse = require('escodegen').generate; | ||
node.type === 'LogicalExpression') { | ||
var op = node.operator; | ||
if (op === '&&') { | ||
var l = walk(node.left); | ||
if (l === FAIL) return FAIL; | ||
if (!l) return l; | ||
var r = walk(node.right); | ||
if (r === FAIL) return FAIL; | ||
return r; | ||
} | ||
else if (op === '||') { | ||
var l = walk(node.left); | ||
if (l === FAIL) return FAIL; | ||
if (l) return l; | ||
var r = walk(node.right); | ||
if (r === FAIL) return FAIL; | ||
return r; | ||
} | ||
var l = walk(node.left); | ||
@@ -49,3 +68,2 @@ if (l === FAIL) return FAIL; | ||
var op = node.operator; | ||
if (op === '==') return l == r; | ||
@@ -67,4 +85,2 @@ if (op === '===') return l === r; | ||
if (op === '^') return l ^ r; | ||
if (op === '&&') return l && r; | ||
if (op === '||') return l || r; | ||
@@ -71,0 +87,0 @@ return FAIL; |
{ | ||
"name": "static-eval", | ||
"version": "2.0.3", | ||
"description": "evaluate statically-analyzable expressions", | ||
"main": "index.js", | ||
"dependencies": { | ||
"escodegen": "^1.11.1" | ||
}, | ||
"devDependencies": { | ||
"esprima": "^3.1.3", | ||
"tape": "^4.10.1" | ||
}, | ||
"scripts": { | ||
"test": "tape test/*.js" | ||
}, | ||
"testling": { | ||
"files": "test/*.js", | ||
"browsers": [ | ||
"ie/8..latest", | ||
"ff/latest", | ||
"chrome/latest", | ||
"opera/latest", | ||
"safari/latest" | ||
] | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/substack/static-eval.git" | ||
}, | ||
"homepage": "https://github.com/substack/static-eval", | ||
"keywords": [ | ||
"static", | ||
"eval", | ||
"expression", | ||
"esprima", | ||
"ast", | ||
"abstract", | ||
"syntax", | ||
"tree", | ||
"analysis" | ||
], | ||
"author": { | ||
"name": "James Halliday", | ||
"email": "mail@substack.net", | ||
"url": "http://substack.net" | ||
}, | ||
"license": "MIT" | ||
"name": "static-eval", | ||
"version": "2.0.4", | ||
"description": "evaluate statically-analyzable expressions", | ||
"main": "index.js", | ||
"dependencies": { | ||
"escodegen": "^1.11.1" | ||
}, | ||
"devDependencies": { | ||
"esprima": "^3.1.3", | ||
"tape": "^4.10.1" | ||
}, | ||
"scripts": { | ||
"test": "tape test/*.js" | ||
}, | ||
"testling": { | ||
"files": "test/*.js", | ||
"browsers": [ | ||
"ie/8..latest", | ||
"ff/latest", | ||
"chrome/latest", | ||
"opera/latest", | ||
"safari/latest" | ||
] | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/substack/static-eval.git" | ||
}, | ||
"homepage": "https://github.com/substack/static-eval", | ||
"keywords": [ | ||
"static", | ||
"eval", | ||
"expression", | ||
"esprima", | ||
"ast", | ||
"abstract", | ||
"syntax", | ||
"tree", | ||
"analysis" | ||
], | ||
"author": { | ||
"name": "James Halliday", | ||
"email": "mail@substack.net", | ||
"url": "http://substack.net" | ||
}, | ||
"license": "MIT" | ||
} |
@@ -124,1 +124,27 @@ var test = require('tape'); | ||
}); | ||
test('short circuit evaluation AND', function(t) { | ||
t.plan(1); | ||
var variables = { | ||
value: null | ||
}; | ||
var src = 'value && value.func()'; | ||
var ast = parse(src).body[0].expression; | ||
var res = evaluate(ast, variables); | ||
t.equals(res, null); | ||
}) | ||
test('short circuit evaluation OR', function(t) { | ||
t.plan(1); | ||
var fnInvoked = false; | ||
var variables = { | ||
value: true, | ||
fn: function() { fnInvoked = true} | ||
}; | ||
var src = 'value || fn()'; | ||
var ast = parse(src).body[0].expression; | ||
evaluate(ast, variables); | ||
t.equals(fnInvoked, false); | ||
}) |
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
17976
13
359