Skip to content

Commit 12f8bcc

Browse files
committedOct 2, 2020
update handler
1 parent d678188 commit 12f8bcc

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed
 

‎src/expander/handler.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
/* eslint-disable no-eval */
12
const Stack = require("./stack");
23

34
const argsStack = new Stack();
45
const operators = ["+", "-", "*", "/", "%"];
56

67
function handle(arg) {
78
if (operators.includes(arg)) {
9+
if (argsStack.Length < 2) {
10+
throw new Error(
11+
`Can't calculate: ${argsStack.Length} elements are in stack. Check your syntax.`
12+
);
13+
}
814
const first = argsStack.pop();
915
const second = argsStack.pop();
10-
// eslint-disable-next-line no-eval
1116
const result = eval(`${second} ${arg} ${first}`);
1217
argsStack.push(result);
1318
}

0 commit comments

Comments
 (0)
Please sign in to comment.