prettier-plugin-solidity
Version:
A Prettier Plugin for automatically formatting your Solidity code.
37 lines • 1.7 kB
JavaScript
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { printBinaryOperation } from '../slang-printers/print-binary-operation.js';
import { createHugFunction } from '../slang-utils/create-hug-function.js';
import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js';
import { Expression } from './Expression.js';
const multiplicationTryToHug = createHugFunction(['/', '%']);
const divisionTryToHug = createHugFunction(['*', '%']);
const moduloTryToHug = createHugFunction(['*', '/', '%']);
export class MultiplicativeExpression {
constructor(ast, options) {
this.kind = NonterminalKind.MultiplicativeExpression;
let metadata = getNodeMetadata(ast);
this.leftOperand = new Expression(ast.leftOperand, options);
this.operator = ast.operator.unparse();
this.rightOperand = new Expression(ast.rightOperand, options);
metadata = updateMetadata(metadata, [this.leftOperand, this.rightOperand]);
this.comments = metadata.comments;
this.loc = metadata.loc;
switch (this.operator) {
case '*':
this.leftOperand = multiplicationTryToHug(this.leftOperand);
break;
case '/':
this.leftOperand = divisionTryToHug(this.leftOperand);
break;
case '%':
this.leftOperand = moduloTryToHug(this.leftOperand);
break;
default:
throw new Error(`Unexpected operator: ${this.operator}`);
}
}
print(path, print, options) {
return printBinaryOperation(this, path, print, options);
}
}
//# sourceMappingURL=MultiplicativeExpression.js.map