File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { doc } from 'prettier';
22import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js' ;
33import { printSeparatedItem } from '../slang-printers/print-separated-item.js' ;
44import { 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' ;
66import { Expression } from './Expression.js' ;
77import { Statement } from './Statement.js' ;
88import { 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 : ' ' ,
Original file line number Diff line number Diff line change @@ -21,16 +21,16 @@ const isChainableExpression = createKindCheckFunction([
2121
2222function 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 :
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { createBinaryOperationPrinter } from './create-binary-operation-printer.
44import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js' ;
55
66import type { AstPath , Doc } from 'prettier' ;
7- import type { AstNode , BinaryOperation , StrictAstNode } from '../slang-nodes' ;
7+ import type { BinaryOperation , StrictAstNode } from '../slang-nodes' ;
88import type { ComparisonExpression } from '../slang-nodes/ComparisonExpression' ;
99import type { EqualityExpression } from '../slang-nodes/EqualityExpression' ;
1010
@@ -41,7 +41,7 @@ const binaryGroupRulesBuilder =
4141const 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 ;
Original file line number Diff line number Diff line change 11import { doc } from 'prettier' ;
22import { printComment } from '../slang-comments/printer.js' ;
33import { 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' ;
55import { joinExisting } from '../slang-utils/join-existing.js' ;
66
77import 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
Original file line number Diff line number Diff line change @@ -2,23 +2,13 @@ import { TerminalKind } from '@nomicfoundation/slang/kinds/index.js';
22import { createKindCheckFunction } from './create-kind-check-function.js' ;
33
44import 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
127export 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-
2212export const isComment = createKindCheckFunction ( [
2313 TerminalKind . MultiLineComment ,
2414 TerminalKind . MultiLineNatSpecComment ,
You can’t perform that action at this time.
0 commit comments