Skip to content

Commit 259f14c

Browse files
committed
Calculator: implement missing unary operators
1 parent 21b3bc2 commit 259f14c

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

kubejs/server_scripts/utils/calculator.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,17 @@ let calculatorExec = (() => {
165165
*/
166166
function calculate(node) {
167167
switch (node.type) {
168+
case "unOp": {
169+
let value = calculate(node.value);
170+
switch (node.operator) {
171+
case "+":
172+
validateArguments("plus", ["number"], [value]);
173+
return value;
174+
case "-":
175+
validateArguments("negate", ["number"], [value]);
176+
return -value;
177+
}
178+
}
168179
case "binOp": {
169180
let left = calculate(node.left);
170181
let right = calculate(node.right);

0 commit comments

Comments
 (0)