UNPKG

prettier-plugin-solidity

Version:

A Prettier Plugin for automatically formatting your Solidity code.

45 lines (32 loc) 1.33 kB
import { NonterminalKind } from '@nomicfoundation/slang/cst'; import { printLogicalOperation } from '../slang-printers/print-logical-operation.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { Expression } from './Expression.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; import type { AstNode } from './types.d.ts'; import type { PrintFunction, SlangNode } from '../types.d.ts'; export class AndExpression implements SlangNode { readonly kind = NonterminalKind.AndExpression; comments; loc; leftOperand: Expression; operator: string; rightOperand: Expression; constructor(ast: ast.AndExpression, options: ParserOptions<AstNode>) { 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; } print( path: AstPath<AndExpression>, print: PrintFunction, options: ParserOptions<AstNode> ): Doc { return printLogicalOperation(this, path, print, options); } }