Skip to content

Commit 52bf673

Browse files
committed
more accurate type to avoid type assertion and destructure
1 parent 7e3e7fd commit 52bf673

15 files changed

Lines changed: 52 additions & 51 deletions

src/slang-comments/handlers/add-collection-node-first-comment.ts renamed to src/slang-comments/handlers/add-collection-first-comment.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { util } from 'prettier';
22

3-
import type { Comment, CollectionNode } from '../../slang-nodes/types.d.ts';
3+
import type { Comment, Collection } from '../../slang-nodes/types.js';
44

55
const { addDanglingComment, addLeadingComment } = util;
66

7-
export default function addCollectionNodeFirstComment(
8-
node: CollectionNode,
7+
export default function addCollectionFirstComment(
8+
node: Collection,
99
comment: Comment
1010
): void {
1111
if (node.items.length === 0) {

src/slang-comments/handlers/add-collection-node-last-comment.ts renamed to src/slang-comments/handlers/add-collection-last-comment.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { util } from 'prettier';
22

3-
import type { Comment, CollectionNode } from '../../slang-nodes/types.d.ts';
3+
import type { Comment, Collection } from '../../slang-nodes/types.js';
44

55
const { addDanglingComment, addTrailingComment } = util;
66

7-
export default function addCollectionNodeLastComment(
8-
node: CollectionNode,
7+
export default function addCollectionLastComment(
8+
node: Collection,
99
comment: Comment
1010
): void {
1111
if (node.items.length === 0) {

src/slang-comments/handlers/handle-block-comments.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/cst';
2-
import addCollectionNodeFirstComment from './add-collection-node-first-comment.js';
3-
import addCollectionNodeLastComment from './add-collection-node-last-comment.js';
2+
import addCollectionFirstComment from './add-collection-first-comment.js';
3+
import addCollectionLastComment from './add-collection-last-comment.js';
44

55
import type { HandlerParams } from './types.d.ts';
66

@@ -15,12 +15,12 @@ export default function handleBlockComments({
1515
}
1616

1717
if (precedingNode?.kind === NonterminalKind.Statements) {
18-
addCollectionNodeLastComment(precedingNode, comment);
18+
addCollectionLastComment(precedingNode, comment);
1919
return true;
2020
}
2121

2222
if (followingNode?.kind === NonterminalKind.Statements) {
23-
addCollectionNodeFirstComment(followingNode, comment);
23+
addCollectionFirstComment(followingNode, comment);
2424
return true;
2525
}
2626

src/slang-comments/handlers/handle-contract-definition-comments.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/cst';
22
import { util } from 'prettier';
33
import { locEnd } from '../../slang-utils/loc.js';
4-
import addCollectionNodeLastComment from './add-collection-node-last-comment.js';
4+
import addCollectionLastComment from './add-collection-last-comment.js';
55

66
import type { HandlerParams } from './types.d.ts';
77

@@ -36,7 +36,7 @@ export default function handleContractDefinitionComments({
3636

3737
// The comment is at the end of the body of the ContractDefinition.
3838
if (precedingNode?.kind === NonterminalKind.ContractMembers) {
39-
addCollectionNodeLastComment(precedingNode, comment);
39+
addCollectionLastComment(precedingNode, comment);
4040
return true;
4141
}
4242

@@ -52,7 +52,7 @@ export default function handleContractDefinitionComments({
5252
// If the last ContractSpecifier's an InheritanceSpecifier, the comment
5353
// is appended to the last InheritanceType.
5454
if (lastContractSpecifier.kind === NonterminalKind.InheritanceSpecifier) {
55-
addCollectionNodeLastComment(lastContractSpecifier.types, comment);
55+
addCollectionLastComment(lastContractSpecifier.types, comment);
5656
return true;
5757
}
5858
if (

src/slang-comments/handlers/handle-contract-specifiers-comments.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/cst';
22
import { util } from 'prettier';
3-
import addCollectionNodeLastComment from './add-collection-node-last-comment.js';
3+
import addCollectionLastComment from './add-collection-last-comment.js';
44

55
import type { HandlerParams } from './types.d.ts';
66

@@ -20,7 +20,7 @@ export default function handleContractSpecifiersComments({
2020
precedingNode.kind === NonterminalKind.ContractSpecifier
2121
) {
2222
if (precedingNode.variant.kind === NonterminalKind.InheritanceSpecifier) {
23-
addCollectionNodeLastComment(precedingNode.variant.types, comment);
23+
addCollectionLastComment(precedingNode.variant.types, comment);
2424
return true;
2525
}
2626
if (precedingNode.variant.kind === NonterminalKind.StorageLayoutSpecifier) {

src/slang-comments/handlers/handle-else-branch-comments.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/cst';
22
import { util } from 'prettier';
3-
import addCollectionNodeFirstComment from './add-collection-node-first-comment.js';
3+
import addCollectionFirstComment from './add-collection-first-comment.js';
44

55
import type { HandlerParams } from './types.d.ts';
66

@@ -20,7 +20,7 @@ export default function handleElseBranchComments({
2020
followingNode.variant.kind === NonterminalKind.IfStatement
2121
) {
2222
if (followingNode.variant.body.variant.kind === NonterminalKind.Block) {
23-
addCollectionNodeFirstComment(
23+
addCollectionFirstComment(
2424
followingNode.variant.body.variant.statements,
2525
comment
2626
);

src/slang-comments/handlers/handle-if-statement-comments.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/cst';
22
import { util } from 'prettier';
33
import { locEnd } from '../../slang-utils/loc.js';
4-
import addCollectionNodeFirstComment from './add-collection-node-first-comment.js';
4+
import addCollectionFirstComment from './add-collection-first-comment.js';
55

66
import type { HandlerParams } from './types.d.ts';
77

@@ -45,10 +45,7 @@ export default function handleIfStatementComments({
4545

4646
if (followingNode.kind === NonterminalKind.IfStatement) {
4747
if (followingNode.body.variant.kind === NonterminalKind.Block) {
48-
addCollectionNodeFirstComment(
49-
followingNode.body.variant.statements,
50-
comment
51-
);
48+
addCollectionFirstComment(followingNode.body.variant.statements, comment);
5249
} else {
5350
addLeadingComment(followingNode.body.variant, comment);
5451
}
@@ -60,7 +57,7 @@ export default function handleIfStatementComments({
6057
// if (a) /* comment */ true
6158
if (enclosingNode.body === followingNode) {
6259
if (followingNode.variant.kind === NonterminalKind.Block) {
63-
addCollectionNodeFirstComment(followingNode.variant.statements, comment);
60+
addCollectionFirstComment(followingNode.variant.statements, comment);
6461
} else {
6562
addLeadingComment(followingNode, comment);
6663
}

src/slang-comments/handlers/handle-interface-definition-comments.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/cst';
22
import { util } from 'prettier';
33
import { locEnd } from '../../slang-utils/loc.js';
4-
import addCollectionNodeFirstComment from './add-collection-node-first-comment.js';
5-
import addCollectionNodeLastComment from './add-collection-node-last-comment.js';
4+
import addCollectionFirstComment from './add-collection-first-comment.js';
5+
import addCollectionLastComment from './add-collection-last-comment.js';
66

77
import type { HandlerParams } from './types.d.ts';
88

@@ -24,7 +24,7 @@ export default function handleInterfaceDefinitionComments({
2424

2525
// The comment is at the end of the body of the InterfaceDefinition.
2626
if (precedingNode?.kind === NonterminalKind.InterfaceMembers) {
27-
addCollectionNodeLastComment(precedingNode, comment);
27+
addCollectionLastComment(precedingNode, comment);
2828
return true;
2929
}
3030

@@ -33,7 +33,7 @@ export default function handleInterfaceDefinitionComments({
3333
nextCharacter === '{' &&
3434
followingNode?.kind === NonterminalKind.InterfaceMembers
3535
) {
36-
addCollectionNodeFirstComment(followingNode, comment);
36+
addCollectionFirstComment(followingNode, comment);
3737
return true;
3838
}
3939

src/slang-comments/handlers/handle-library-definition-comments.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/cst';
22
import { util } from 'prettier';
33
import { locEnd } from '../../slang-utils/loc.js';
4-
import addCollectionNodeFirstComment from './add-collection-node-first-comment.js';
5-
import addCollectionNodeLastComment from './add-collection-node-last-comment.js';
4+
import addCollectionFirstComment from './add-collection-first-comment.js';
5+
import addCollectionLastComment from './add-collection-last-comment.js';
66

77
import type { HandlerParams } from './types.d.ts';
88

@@ -24,7 +24,7 @@ export default function handleLibraryDefinitionComments({
2424

2525
// The comment is at the end of the body of the ContractDefinition.
2626
if (precedingNode?.kind === NonterminalKind.LibraryMembers) {
27-
addCollectionNodeLastComment(precedingNode, comment);
27+
addCollectionLastComment(precedingNode, comment);
2828
return true;
2929
}
3030

@@ -33,7 +33,7 @@ export default function handleLibraryDefinitionComments({
3333
nextCharacter === '{' &&
3434
followingNode?.kind === NonterminalKind.LibraryMembers
3535
) {
36-
addCollectionNodeFirstComment(followingNode, comment);
36+
addCollectionFirstComment(followingNode, comment);
3737
return true;
3838
}
3939

src/slang-comments/handlers/handle-modifier-invocation-comments.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/cst';
22
import { util } from 'prettier';
33
import { locEnd } from '../../slang-utils/loc.js';
4-
import addCollectionNodeFirstComment from './add-collection-node-first-comment.js';
4+
import addCollectionFirstComment from './add-collection-first-comment.js';
55

66
import type { HandlerParams } from './types.d.ts';
77

@@ -34,7 +34,7 @@ export default function handleModifierInvocationComments({
3434
if (followingNode.variant.arguments.items.length === 0) {
3535
addTrailingComment(enclosingNode, comment);
3636
} else {
37-
addCollectionNodeFirstComment(followingNode.variant.arguments, comment);
37+
addCollectionFirstComment(followingNode.variant.arguments, comment);
3838
}
3939
return true;
4040
}

0 commit comments

Comments
 (0)