-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathhandle-library-definition-comments.ts
More file actions
41 lines (35 loc) · 1.11 KB
/
handle-library-definition-comments.ts
File metadata and controls
41 lines (35 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { util } from 'prettier';
import { locEnd } from '../../slang-utils/loc.js';
import addCollectionFirstComment from './add-collection-first-comment.js';
import addCollectionLastComment from './add-collection-last-comment.js';
import type { HandlerParams } from './types.d.ts';
export default function handleLibraryDefinitionComments({
text,
precedingNode,
enclosingNode,
followingNode,
comment
}: HandlerParams): boolean {
if (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?.kind === NonterminalKind.LibraryMembers) {
addCollectionLastComment(precedingNode, comment);
return true;
}
// The last comments before the body.
if (
nextCharacter === '{' &&
followingNode?.kind === NonterminalKind.LibraryMembers
) {
addCollectionFirstComment(followingNode, comment);
return true;
}
return false;
}