Skip to content

Commit

Permalink
Custom logical and/or
Browse files Browse the repository at this point in the history
  • Loading branch information
Marek Sierociński committed Mar 25, 2020
1 parent 86b7824 commit 586b956
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
18 changes: 15 additions & 3 deletions dist/meval.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* meval v1.0.2 | Copyright 2020 (c) Marek Sierociński| https://github.com/marverix/meval/blob/master/LICENSE */
/* meval v1.0.3 | Copyright 2020 (c) Marek Sierociński| https://github.com/marverix/meval/blob/master/LICENSE */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
Expand Down Expand Up @@ -1325,7 +1325,13 @@
_createClass(LogicalAndOperator, [{
key: "_execute",
value: function _execute(leftSide, rightSide, context) {
return this.resolveSide(leftSide, context) && this.resolveSide(rightSide, context);
var leftSideResolved = this.resolveSide(leftSide, context);

if (!leftSideResolved) {
return false;
} else {
return this.resolveSide(rightSide, context);
}
}
}]);

Expand All @@ -1349,7 +1355,13 @@
_createClass(LogicalOrOperator, [{
key: "_execute",
value: function _execute(leftSide, rightSide, context) {
return this.resolveSide(leftSide, context) || this.resolveSide(rightSide, context);
var leftSideResolved = this.resolveSide(leftSide, context);

if (leftSideResolved) {
return true;
} else {
return this.resolveSide(rightSide, context);
}
}
}]);

Expand Down
4 changes: 2 additions & 2 deletions dist/meval.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meval",
"version": "1.0.2",
"version": "1.0.3",
"description": "Mimic eval in given context",
"main": "dist/meval.js",
"scripts": {
Expand Down
7 changes: 6 additions & 1 deletion src/operators/LogicalAnd.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ class LogicalAndOperator extends Abstract2ArgOperator {
}

_execute (leftSide, rightSide, context) {
return this.resolveSide(leftSide, context) && this.resolveSide(rightSide, context);
let leftSideResolved = this.resolveSide(leftSide, context);
if (!leftSideResolved) {
return false;
} else {
return this.resolveSide(rightSide, context);
}
}

}
Expand Down
7 changes: 6 additions & 1 deletion src/operators/LogicalOr.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ class LogicalOrOperator extends Abstract2ArgOperator {
}

_execute (leftSide, rightSide, context) {
return this.resolveSide(leftSide, context) || this.resolveSide(rightSide, context);
let leftSideResolved = this.resolveSide(leftSide, context);
if (leftSideResolved) {
return true;
} else {
return this.resolveSide(rightSide, context);
}
}

}
Expand Down

0 comments on commit 586b956

Please sign in to comment.