From 192ed6b034c1ea0bdbf63542a5b0105c2c0cf475 Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Wed, 16 Jan 2019 03:11:45 -0800 Subject: [PATCH] Fix subtract and divide in expression.evaluate --- lib/common/expression.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/common/expression.js b/lib/common/expression.js index 2fc5988..699e581 100644 --- a/lib/common/expression.js +++ b/lib/common/expression.js @@ -14,7 +14,7 @@ function reduce(exp, callback) { while (loop) { loop = false; for (let i = 2; i < exp.length; ++i) { - const res = callback(exp[i - 1], exp[i]); + const res = callback(exp[i - 1], exp[i], i - 2); if (res !== REDUCE_SKIP) { loop = true; exp = exp.slice(); @@ -126,10 +126,10 @@ function evaluate(exp, obj, now, cb) { return REDUCE_SKIP; }); } else if (e[0] === "/") { - return reduce(e, (a, b) => { + return reduce(e, (a, b, i) => { if (!isArray(a) && !isArray(b)) { if (a == null || b == null) return null; - return a / b; + return i === 0 ? a / b : a * b; } return REDUCE_SKIP; }); @@ -142,10 +142,10 @@ function evaluate(exp, obj, now, cb) { return REDUCE_SKIP; }); } else if (e[0] === "-") { - return reduce(e, (a, b) => { + return reduce(e, (a, b, i) => { if (!isArray(a) && !isArray(b)) { if (a == null || b == null) return null; - return a - b; + return i === 0 ? a - b : a + b; } return REDUCE_SKIP; });