File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js' ;
2- import { util } from 'prettier' ;
32import addHubNodeFirstComment from './add-hub-node-first-comment.js' ;
3+ import addHubNodeLastComment from './add-hub-node-last-comment.js' ;
44
5- import type { HandlerParams } from './types.js' ;
6-
7- const { addDanglingComment, addTrailingComment } = util ;
5+ import type { HandlerParams } from './types' ;
86
97export default function handleBlockComments ( {
108 precedingNode,
@@ -17,14 +15,7 @@ export default function handleBlockComments({
1715 }
1816
1917 if ( precedingNode ?. kind === NonterminalKind . Statements ) {
20- if ( precedingNode . items . length === 0 ) {
21- addDanglingComment ( precedingNode , comment , false ) ;
22- } else {
23- addTrailingComment (
24- precedingNode . items [ precedingNode . items . length - 1 ] ,
25- comment
26- ) ;
27- }
18+ addHubNodeLastComment ( precedingNode , comment ) ;
2819 return true ;
2920 }
3021
Original file line number Diff line number Diff line change 1+ import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js' ;
2+ import addHubNodeFirstComment from './add-hub-node-first-comment.js' ;
3+ import addHubNodeLastComment from './add-hub-node-last-comment.js' ;
4+
5+ import type { HandlerParams } from './types' ;
6+
7+ export default function handlePositionalArgumentsDeclarationComments ( {
8+ precedingNode,
9+ enclosingNode,
10+ followingNode,
11+ comment
12+ } : HandlerParams ) : boolean {
13+ if ( comment . value . startsWith ( '// test' ) ) {
14+ console . log ( comment ) ;
15+ }
16+ if ( enclosingNode ?. kind !== NonterminalKind . PositionalArgumentsDeclaration ) {
17+ return false ;
18+ }
19+
20+ if ( precedingNode ?. kind === NonterminalKind . PositionalArguments ) {
21+ addHubNodeLastComment ( precedingNode , comment ) ;
22+ return true ;
23+ }
24+
25+ if ( followingNode ?. kind === NonterminalKind . PositionalArguments ) {
26+ addHubNodeFirstComment ( followingNode , comment ) ;
27+ return true ;
28+ }
29+
30+ return false ;
31+ }
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import handleContractDefinitionComments from './handle-contract-definition-comme
33import handleElseBranchComments from './handle-else-branch-comments.js' ;
44import handleIfStatementComments from './handle-if-statement-comments.js' ;
55import handleParametersDeclarationComments from './handle-parameters-declaration-comments.js' ;
6+ import handlePositionalArgumentsDeclarationComments from './handle-positional-arguments-declaration-comments.js' ;
67import handleWhileStatementComments from './handle-while-statement-comments.js' ;
78import handleYulBlockComments from './handle-yul-block-comments.js' ;
89
@@ -12,6 +13,7 @@ export default [
1213 handleElseBranchComments ,
1314 handleIfStatementComments ,
1415 handleParametersDeclarationComments ,
16+ handlePositionalArgumentsDeclarationComments ,
1517 handleWhileStatementComments ,
1618 handleYulBlockComments
1719] ;
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' ;
45
56import type { AstPath , Doc } from 'prettier' ;
67import type { AstNode } from '../slang-nodes' ;
78import type { DocV2 } from './types' ;
89
9- const { join, line } = doc . builders ;
10+ const { breakParent , join, line } = doc . builders ;
1011
1112export function printComments ( path : AstPath < AstNode > ) : Doc [ ] {
1213 const document = join (
@@ -18,7 +19,8 @@ export function printComments(path: AstPath<AstNode>): Doc[] {
1819 return '' ;
1920 }
2021 comment . printed = true ;
21- return printComment ( commentPath ) ;
22+ const printed = printComment ( commentPath ) ;
23+ return isLineComment ( comment ) ? [ printed , breakParent ] : printed ;
2224 } , 'comments' )
2325 . filter ( Boolean )
2426 ) ;
You can’t perform that action at this time.
0 commit comments