prettier-plugin-solidity
Version:
A Prettier Plugin for automatically formatting your Solidity code.
24 lines • 1.35 kB
JavaScript
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { util } from 'prettier';
import { locEnd } from '../../slang-utils/loc.js';
import addCollectionNodeFirstComment from './add-collection-node-first-comment.js';
import addCollectionNodeLastComment from './add-collection-node-last-comment.js';
export default function handleLibraryDefinitionComments({ text, precedingNode, enclosingNode, followingNode, comment }) {
if ((enclosingNode === null || enclosingNode === void 0 ? void 0 : enclosingNode.kind) !== NonterminalKind.LibraryDefinition) {
return false;
}
const nextCharacter = util.getNextNonSpaceNonCommentCharacter(text, locEnd(comment));
// The comment is at the end of the body of the ContractDefinition.
if ((precedingNode === null || precedingNode === void 0 ? void 0 : precedingNode.kind) === NonterminalKind.LibraryMembers) {
addCollectionNodeLastComment(precedingNode, comment);
return true;
}
// The last comments before the body.
if (nextCharacter === '{' &&
(followingNode === null || followingNode === void 0 ? void 0 : followingNode.kind) === NonterminalKind.LibraryMembers) {
addCollectionNodeFirstComment(followingNode, comment);
return true;
}
return false;
}
//# sourceMappingURL=handle-library-definition-comments.js.map