From 93826da6c17aeaa1a3277d2dbe4528a3e2968fc3 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Sat, 19 Oct 2024 01:45:54 +0400 Subject: [PATCH] fix(util): arithmetic logic --- src/utils/arithmetic-helper.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/utils/arithmetic-helper.ts b/src/utils/arithmetic-helper.ts index 5d44b95..530a7d5 100644 --- a/src/utils/arithmetic-helper.ts +++ b/src/utils/arithmetic-helper.ts @@ -56,11 +56,12 @@ export const getParameterFromArithmeticExpression = ( */ export const evaluateArithmeticOutput = ( outputParameter: string, - calculatedResult: number + output: PluginParams ) => { const checkedOutputParameter = getParameterFromArithmeticExpression(outputParameter); const isValidExpression = isValidArithmeticExpression(outputParameter); + const calculatedResult = output[outputParameter] if ( typeof outputParameter === 'string' && @@ -74,15 +75,22 @@ export const evaluateArithmeticOutput = ( .replace(/['"]/g, ''); const result = evaluateExpression(transformedOutputParameter); + delete output[outputParameter] - return {[checkedOutputParameter]: result}; + return { + ...output, + [checkedOutputParameter]: result + }; } else if (outputParameter !== checkedOutputParameter) { throw new WrongArithmeticExpressionError( `The output parameter \`${outputParameter}\` contains an invalid arithmetic expression. It should start with \`=\` and include the symbols \`*\`, \`+\`, \`-\` and \`/\`.` ); } - return {[outputParameter]: calculatedResult}; + return { + ...output, + [outputParameter]: calculatedResult + }; }; /**