@fw-components/formula-editor 2.0.7-formula-editor.41 → 2.0.7-formula-editor.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -201,13 +201,13 @@ export class Parser {
201
201
  operatorStack.push("(");
202
202
  }
203
203
  else if (token === ")") {
204
- while (operatorStack.top() != "(") {
204
+ while (!operatorStack.isEmpty() && operatorStack.top() != "(") {
205
205
  outputQueue.enqueue(operatorStack.pop());
206
206
  }
207
207
  operatorStack.pop();
208
208
  }
209
209
  else if (this.allowedOperators.has(token)) {
210
- while (this.allowedOperators.has(operatorStack.top()) && operatorPrecedence[token] <= operatorPrecedence[operatorStack.top()]) {
210
+ while (!operatorStack.isEmpty() && this.allowedOperators.has(operatorStack.top()) && operatorPrecedence[token] <= operatorPrecedence[operatorStack.top()]) {
211
211
  outputQueue.enqueue(operatorStack.pop());
212
212
  }
213
213
  operatorStack.push(token);
@@ -216,7 +216,7 @@ export class Parser {
216
216
  outputQueue.enqueue(token);
217
217
  }
218
218
  }
219
- while (operatorStack.top()) {
219
+ while (!operatorStack.isEmpty() && operatorStack.top()) {
220
220
  outputQueue.enqueue(operatorStack.pop());
221
221
  }
222
222
  return outputQueue;
@@ -291,6 +291,10 @@ export class Parser {
291
291
  calcStack.push(Big(number));
292
292
  }
293
293
  else {
294
+ if (calcStack.size() < 2) {
295
+ calculationResult.errorString = "Calculation error: Invalid formula";
296
+ return calculationResult;
297
+ }
294
298
  const operator = frontItem;
295
299
  const numB = calcStack.pop();
296
300
  const numA = calcStack.pop();
@@ -306,7 +310,7 @@ export class Parser {
306
310
  calcStack.push(Big(numA).mul(Big(numB)));
307
311
  break;
308
312
  case "/":
309
- if (parseFloat(Big(numB).toString()) === 0) {
313
+ if (Big(numB).eq(0)) {
310
314
  calculationResult.errorString = "Division by zero encountered";
311
315
  return calculationResult;
312
316
  }
@@ -322,6 +326,10 @@ export class Parser {
322
326
  }
323
327
  }
324
328
  }
329
+ if (calcStack.isEmpty()) {
330
+ calculationResult.errorString = "Calculation error: Empty result stack";
331
+ return calculationResult;
332
+ }
325
333
  calculationResult.result = parseFloat(calcStack.top().toString());
326
334
  return calculationResult;
327
335
  }
@@ -14,4 +14,7 @@ export class Stack {
14
14
  isEmpty() {
15
15
  return this._elements.length === 0;
16
16
  }
17
+ size() {
18
+ return this._elements.length;
19
+ }
17
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fw-components/formula-editor",
3
- "version": "2.0.7-formula-editor.41",
3
+ "version": "2.0.7-formula-editor.43",
4
4
  "description": "A WYSIWYG type formula editor",
5
5
  "main": "dist/formula-editor/src/formula-editor.js",
6
6
  "exports": {
@@ -31,5 +31,5 @@
31
31
  "@types/big.js": "^6.1.6",
32
32
  "es-dev-server": "^2.1.0"
33
33
  },
34
- "gitHead": "c53252d71f716dfcaf8a1c1e7637f09edb715b3f"
34
+ "gitHead": "0e8a0a79fb18efde64373e0d2ae7c5df9c56ad59"
35
35
  }