Skip to content

Commit e33e1f8

Browse files
committed
Removing unneeded helper function isLineComment
1 parent 65f4a66 commit e33e1f8

5 files changed

Lines changed: 11 additions & 21 deletions

File tree

src/slang-nodes/IfStatement.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { doc } from 'prettier';
22
import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js';
33
import { printSeparatedItem } from '../slang-printers/print-separated-item.js';
44
import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js';
5-
import { isLineComment } from '../slang-utils/is-comment.js';
5+
import { isBlockComment } from '../slang-utils/is-comment.js';
66
import { Expression } from './Expression.js';
77
import { Statement } from './Statement.js';
88
import { ElseBranch } from './ElseBranch.js';
@@ -66,7 +66,7 @@ export class IfStatement implements SlangNode {
6666
this.body.variant.kind !== NonterminalKind.Block || // else on a new line if body is not a block
6767
this.body.variant.comments.some(
6868
(comment) =>
69-
isLineComment(comment) || comment.placement === 'ownLine'
69+
!isBlockComment(comment) || comment.placement === 'ownLine'
7070
) // or if body has trailing single line comments or a block comment on a new line
7171
? hardline
7272
: ' ',

src/slang-nodes/MemberAccessExpression.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ const isChainableExpression = createKindCheckFunction([
2121

2222
function isEndOfChain(
2323
node: MemberAccessExpression,
24-
path: AstPath<AstNode>
24+
path: AstPath<StrictAstNode>
2525
): boolean {
2626
for (
2727
let i = 0,
28-
currentNode: AstNode = node,
29-
grandparentNode = path.getNode(i + 2) as StrictAstNode;
28+
currentNode: StrictAstNode = node,
29+
grandparentNode = path.getNode(i + 2)!;
3030
isChainableExpression(grandparentNode);
3131
i += 2,
3232
currentNode = grandparentNode,
33-
grandparentNode = path.getNode(i + 2) as StrictAstNode
33+
grandparentNode = path.getNode(i + 2)!
3434
) {
3535
switch (grandparentNode.kind) {
3636
case NonterminalKind.MemberAccessExpression:

src/slang-printers/print-binary-operation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createBinaryOperationPrinter } from './create-binary-operation-printer.
44
import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js';
55

66
import type { AstPath, Doc } from 'prettier';
7-
import type { AstNode, BinaryOperation, StrictAstNode } from '../slang-nodes';
7+
import type { BinaryOperation, StrictAstNode } from '../slang-nodes';
88
import type { ComparisonExpression } from '../slang-nodes/ComparisonExpression';
99
import type { EqualityExpression } from '../slang-nodes/EqualityExpression';
1010

@@ -41,7 +41,7 @@ const binaryGroupRulesBuilder =
4141
const binaryIndentRulesBuilder =
4242
(path: AstPath<BinaryOperation>) =>
4343
(document: Doc): Doc => {
44-
let node = path.getNode() as AstNode;
44+
let node = path.getNode() as StrictAstNode;
4545
for (let i = 2; ; i += 2) {
4646
const grandparentNode = path.getNode(i) as StrictAstNode;
4747
if (grandparentNode.kind === NonterminalKind.ReturnStatement) break;

src/slang-printers/print-comments.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { doc } from 'prettier';
22
import { printComment } from '../slang-comments/printer.js';
33
import { isPrettier2 } from '../slang-utils/backward-compatibility.js';
4-
import { isLineComment } from '../slang-utils/is-comment.js';
4+
import { isBlockComment } from '../slang-utils/is-comment.js';
55
import { joinExisting } from '../slang-utils/join-existing.js';
66

77
import type { AstPath, Doc } from 'prettier';
@@ -20,7 +20,7 @@ export function printComments(path: AstPath<AstNode>): Doc[] {
2020
}
2121
comment.printed = true;
2222
const printed = printComment(commentPath);
23-
return isLineComment(comment) ? [printed, breakParent] : printed;
23+
return isBlockComment(comment) ? printed : [printed, breakParent];
2424
}, 'comments')
2525
);
2626

src/slang-utils/is-comment.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,13 @@ import { TerminalKind } from '@nomicfoundation/slang/kinds/index.js';
22
import { createKindCheckFunction } from './create-kind-check-function.js';
33

44
import type { Node } from '@nomicfoundation/slang/cst';
5-
import type {
6-
AstNode,
7-
BlockComment,
8-
Comment,
9-
LineComment
10-
} from '../slang-nodes';
5+
import type { AstNode, BlockComment, Comment } from '../slang-nodes';
116

127
export const isBlockComment = createKindCheckFunction([
138
TerminalKind.MultiLineComment,
149
TerminalKind.MultiLineNatSpecComment
1510
]) as (node: AstNode) => node is BlockComment;
1611

17-
export const isLineComment = createKindCheckFunction([
18-
TerminalKind.SingleLineComment,
19-
TerminalKind.SingleLineNatSpecComment
20-
]) as (node: AstNode) => node is LineComment;
21-
2212
export const isComment = createKindCheckFunction([
2313
TerminalKind.MultiLineComment,
2414
TerminalKind.MultiLineNatSpecComment,

0 commit comments

Comments
 (0)