1- import { TerminalKind , TerminalNode } from '@nomicfoundation/slang/cst' ;
1+ import { TerminalKind } from '@nomicfoundation/slang/cst' ;
22import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js' ;
33import { MultiLineComment } from '../slang-nodes/MultiLineComment.js' ;
44import { MultiLineNatSpecComment } from '../slang-nodes/MultiLineNatSpecComment.js' ;
@@ -7,7 +7,7 @@ import { SingleLineNatSpecComment } from '../slang-nodes/SingleLineNatSpecCommen
77
88import type { Node } from '@nomicfoundation/slang/cst' ;
99import type { Comment , StrictAstNode } from '../slang-nodes/types.d.ts' ;
10- import type { AstLocation , SlangAstNode } from '../types.d.ts' ;
10+ import type { AstLocation } from '../types.d.ts' ;
1111
1212const isCommentOrWhiteSpace = createKindCheckFunction ( [
1313 TerminalKind . MultiLineComment ,
@@ -29,7 +29,7 @@ function getLeadingOffset(children: Node[]): number {
2929 if ( child . isNonterminalNode ( ) || ! isCommentOrWhiteSpace ( child ) ) {
3030 // The node's content starts when we find the first non-terminal token,
3131 // or if we find a non-comment, non-whitespace token.
32- return offset ;
32+ break ;
3333 }
3434 offset += child . textLength . utf16 ;
3535 }
@@ -56,24 +56,20 @@ export class SlangNode {
5656
5757 loc : AstLocation ;
5858
59- constructor (
60- ast : SlangAstNode | TerminalNode ,
61- enclosePeripheralComments = false
62- ) {
63- if ( ast instanceof TerminalNode ) {
64- const offset = offsets . get ( ast . id ) || 0 ;
59+ constructor ( { cst } : { cst : Node } , enclosePeripheralComments = false ) {
60+ if ( cst . isTerminalNode ( ) ) {
61+ const offset = offsets . get ( cst . id ) || 0 ;
6562 this . loc = {
6663 start : offset ,
67- end : offset + ast . textLength . utf16 ,
64+ end : offset + cst . textLength . utf16 ,
6865 leadingOffset : 0 ,
6966 trailingOffset : 0
7067 } ;
7168 return ;
7269 }
73- const parent = ast . cst ;
74- const children = parent . children ( ) . map ( ( child ) => child . node ) ;
70+ const children = cst . children ( ) . map ( ( child ) => child . node ) ;
7571
76- const initialOffset = offsets . get ( parent . id ) || 0 ;
72+ const initialOffset = offsets . get ( cst . id ) || 0 ;
7773 let offset = initialOffset ;
7874
7975 for ( const child of children ) {
0 commit comments