UNPKG

prettier-plugin-solidity

Version:

A Prettier Plugin for automatically formatting your Solidity code.

47 lines 2.03 kB
import { NonterminalKind } from '@nomicfoundation/slang/cst'; import { doc } from 'prettier'; import { satisfies } from 'semver'; import { SlangNode } from './SlangNode.js'; import { TerminalNode } from './TerminalNode.js'; import { ContractSpecifiers } from './ContractSpecifiers.js'; import { ContractMembers } from './ContractMembers.js'; const { group, line } = doc.builders; export class ContractDefinition extends SlangNode { constructor(ast, collected, options) { var _a; super(ast, collected); this.kind = NonterminalKind.ContractDefinition; this.abstractKeyword = (_a = ast.abstractKeyword) === null || _a === void 0 ? void 0 : _a.unparse(); this.name = new TerminalNode(ast.name, collected); this.specifiers = new ContractSpecifiers(ast.specifiers, collected, options); this.members = new ContractMembers(ast.members, collected, options); this.updateMetadata(this.specifiers, this.members); // Older versions of Solidity defined a constructor as a function having // the same name as the contract. // So we delegate to the parents the responsibility of cleaning the // arguments of modifier invocations. if (!satisfies(options.compiler, '>=0.5.0')) { for (const member of this.members.items) { if (member.kind === NonterminalKind.FunctionDefinition && member.name.value !== this.name.value) { member.cleanModifierInvocationArguments(); } } } } print(path, print) { return [ group([ this.abstractKeyword ? 'abstract ' : '', 'contract ', path.call(print, 'name'), path.call(print, 'specifiers'), this.specifiers.items.length > 0 ? '' : line, '{' ]), path.call(print, 'members'), '}' ]; } } //# sourceMappingURL=ContractDefinition.js.map