-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathhandle-modifier-invocation-comments.ts
More file actions
43 lines (37 loc) · 1.18 KB
/
handle-modifier-invocation-comments.ts
File metadata and controls
43 lines (37 loc) · 1.18 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
42
43
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 type { HandlerParams } from './types.d.ts';
const { addTrailingComment } = util;
export default function handleModifierInvocationComments({
text,
precedingNode,
enclosingNode,
followingNode,
comment
}: HandlerParams): boolean {
if (enclosingNode?.kind !== NonterminalKind.ModifierInvocation) {
return false;
}
const nextCharacter = util.getNextNonSpaceNonCommentCharacter(
text,
locEnd(comment)
);
// The last comments before the body.
if (
precedingNode?.kind === NonterminalKind.IdentifierPath &&
nextCharacter === '(' &&
followingNode?.kind === NonterminalKind.ArgumentsDeclaration &&
followingNode.variant.kind ===
NonterminalKind.PositionalArgumentsDeclaration
) {
if (followingNode.variant.arguments.items.length === 0) {
addTrailingComment(enclosingNode, comment);
} else {
addCollectionFirstComment(followingNode.variant.arguments, comment);
}
return true;
}
return false;
}