From 600f22f43abac8b3d24c169819f39a4506b0b710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=C3=89vrard?= Date: Thu, 14 Apr 2022 10:21:53 +0200 Subject: [PATCH] Remove extra operator when simplifying nested domains issue11406 review390621002 --- src/common.js | 15 +++++++++++---- tests/sao.js | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/common.js b/src/common.js index 84a636e132..9e624891a7 100644 --- a/src/common.js +++ b/src/common.js @@ -2574,12 +2574,19 @@ return this.simplify_nested(domain[0]); } else { var simplified = []; - var domain_op = this._bool_operator(domain); for (var branch of domain) { var simplified_branch = this.simplify_nested(branch); - if ((this._bool_operator(branch) == domain_op) || - (simplified_branch.length == 1)) { - simplified.push(...simplified_branch); + if ((this._bool_operator(simplified_branch) == + this._bool_operator(simplified)) || + (simplified_branch.length == 1)) { + if ((simplified.length > 0) && + (simplified_branch.length > 0) && + ((simplified_branch[0] == 'AND') || + (simplified_branch[0] == 'OR'))) { + simplified.push(...simplified_branch.slice(1)); + } else { + simplified.push(...simplified_branch); + } } else { simplified.push(simplified_branch); } diff --git a/tests/sao.js b/tests/sao.js index a81cea0f49..90b81c81ed 100644 --- a/tests/sao.js +++ b/tests/sao.js @@ -2612,6 +2612,9 @@ [ ['OR', ['x', '=', 3], ['AND', ['y', '=', 5]]], ['OR', ['x', '=', 3], ['y', '=', 5]]], + [ + ['OR', ['x', '=', 1], ['OR', ['x', '=', 2], ['x', '=', 3]]], + ['OR', ['x', '=', 1], ['x', '=', 2], ['x', '=', 3]]], [[['x', '=', 3], ['OR']], [['x', '=', 3]]], [['OR', ['x', '=', 3], []], []], [['OR', ['x', '=', 3], ['OR']], []],