@@ -11,9 +11,11 @@ import type { AstPath, Doc, ParserOptions } from 'prettier';
1111import type { CollectedMetadata , PrintFunction } from '../types.d.ts' ;
1212import type { AstNode } from './types.d.ts' ;
1313
14- const multiplicationTryToHug = createHugFunction ( [ '/' , '%' ] ) ;
15- const divisionTryToHug = createHugFunction ( [ '*' , '%' ] ) ;
16- const moduloTryToHug = createHugFunction ( [ '*' , '/' , '%' ] ) ;
14+ const hugFunctions = {
15+ '*' : createHugFunction ( [ '/' , '%' ] ) ,
16+ '/' : createHugFunction ( [ '*' , '%' ] ) ,
17+ '%' : createHugFunction ( [ '*' , '/' , '%' ] )
18+ } ;
1719
1820const printMultiplicativeExpression = printBinaryOperation (
1921 createKindCheckFunction ( [
@@ -55,19 +57,13 @@ export class MultiplicativeExpression extends SlangNode {
5557
5658 this . updateMetadata ( this . leftOperand , this . rightOperand ) ;
5759
58- switch ( this . operator ) {
59- case '*' :
60- this . leftOperand = multiplicationTryToHug ( this . leftOperand ) ;
61- break ;
62- case '/' :
63- this . leftOperand = divisionTryToHug ( this . leftOperand ) ;
64- break ;
65- case '%' :
66- this . leftOperand = moduloTryToHug ( this . leftOperand ) ;
67- break ;
68- default :
69- throw new Error ( `Unexpected operator: ${ this . operator } ` ) ;
60+ const tryToHug = hugFunctions [ this . operator as keyof typeof hugFunctions ] ;
61+
62+ if ( tryToHug === undefined ) {
63+ throw new Error ( `Unexpected operator: ${ this . operator } ` ) ;
7064 }
65+
66+ this . leftOperand = tryToHug ( this . leftOperand ) ;
7167 }
7268
7369 print (
0 commit comments