import type { BabelFile } from '@babel/core' ; import type { NodePath } from '@babel/traverse' ; import type * as t from '@babel/types' ; import type { Metadata } from '../types' ; param path { NodePath < t . Node > } param meta { Metadata } returns { before export const getNodeComments = ( path , meta ) : { before : t . CommentLine [ ] ; current : t . CommentLine [ ] ; } => { const lineNumber = path . node ?. loc ?. start . line ; if ( ! lineNumber || lineNumber !== path . node ?. loc ?. end . line ) { return { before : [ ] , current : [ ] } ; } const file = meta . state . file ; const commentLines = file . ast . comments ?. filter < t . CommentLine > ( ( comment ) : comment is t . CommentLine => comment . type === 'CommentLine' ) ?? [ ] ; return { before : commentLines . filter ( ( comment ) => comment . loc . start . line === lineNumber - 1 && comment . loc . end . line === lineNumber - 1 ) , current : commentLines . filter ( ( comment ) => comment . loc . start . line === lineNumber && comment . loc . end . line === lineNumber ) , } ; } ;