UNPKG

prettier-plugin-solidity

Version:

A Prettier Plugin for automatically formatting your Solidity code.

46 lines (38 loc) 1.45 kB
import { NonterminalKind } from '@nomicfoundation/slang/cst'; import { doc } from 'prettier'; import { printSeparatedItem } from '../slang-printers/print-separated-item.js'; import { printPreservingEmptyLines } from '../slang-printers/print-preserving-empty-lines.js'; import { extractVariant } from '../slang-utils/extract-variant.js'; import { SlangNode } from './SlangNode.js'; import { YulStatement } from './YulStatement.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc, ParserOptions } from 'prettier'; import type { CollectedMetadata, PrintFunction } from '../types.d.ts'; import type { AstNode } from './types.d.ts'; const { hardline } = doc.builders; export class YulStatements extends SlangNode { readonly kind = NonterminalKind.YulStatements; items: YulStatement['variant'][]; constructor( ast: ast.YulStatements, collected: CollectedMetadata, options: ParserOptions<AstNode> ) { super(ast, collected, true); this.items = ast.items.map((item) => extractVariant(new YulStatement(item, collected, options)) ); } print( path: AstPath<YulStatements>, print: PrintFunction, options: ParserOptions<AstNode> ): Doc { return this.items.length > 0 || (this.comments?.length || 0) > 0 ? printSeparatedItem( printPreservingEmptyLines(this, path, print, options), { firstSeparator: hardline } ) : ''; } }