All files / libs/amalia-lang/formula/parsing/src/lib/formula-parser computed-item-to-error-context.ts

14.63% Statements 6/41
100% Branches 0/0
0% Functions 0/1
14.63% Lines 6/41

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 421x 1x 1x 1x 1x                                                                       1x  
import { TokenType, VariableType } from '@amalia/amalia-lang/tokens/types';
import { type EngineErrorContext } from '@amalia/core/types';
import { ComputedItemTypes, DatasetType, type ComputedItem, type Dataset } from '@amalia/payout-calculation/types';
 
export const computedItemToErrorContext = (
  computedItem: ComputedItem | Dataset,
  more: Partial<EngineErrorContext> = {},
): Partial<EngineErrorContext> => ({
  ...(() => {
    switch (computedItem.type) {
      case ComputedItemTypes.RULE:
        return {
          tokenType: TokenType.RULE,
          tokenMachineName: computedItem.ruleMachineName,
        };
      case ComputedItemTypes.VARIABLE:
        return {
          tokenType:
            computedItem.variableType === VariableType.statement
              ? TokenType.VARIABLE
              : computedItem.variableType === VariableType.object
                ? TokenType.FIELD
                : TokenType.QUOTA,
          tokenMachineName: computedItem.variableMachineName,
        };
      case ComputedItemTypes.FUNCTION_RESULT:
        return {
          tokenType: TokenType.FUNCTION,
          tokenMachineName: computedItem.function,
        };
      case DatasetType.filter:
        return {
          tokenType: TokenType.FILTER,
          tokenMachineName: computedItem.filterMachineName,
        };
      default:
        return {};
    }
  })(),
  ...more,
});