Skip to content

Commit

Permalink
Enforce operator validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jerivas committed Jul 8, 2023
1 parent a17f1e0 commit cd6a2b9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/src/value/calculations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ export class SassCalculation extends Value {
}
}

export type CalculationOperator = '+' | '-' | '*' | '/';
const operators = ['+', '-', '*', '/'] as const;
export type CalculationOperator = typeof operators[number];

export class CalculationOperation implements ValueObject {
readonly operator: CalculationOperator;
Expand All @@ -123,6 +124,9 @@ export class CalculationOperation implements ValueObject {
left: CalculationValue,
right: CalculationValue
) {
if (!operators.includes(operator)) {
throw new Error(`Unknown operator ${operator}`);
}
this.operator = operator;
this.left = left;
this.right = right;
Expand Down

0 comments on commit cd6a2b9

Please sign in to comment.