1- import { TerminalKind , TerminalNode } from '@nomicfoundation/slang/cst' ;
2- import { createKindCheckFunction } from '../slang-utils/create-kind-check-function.js' ;
1+ import {
2+ TerminalKind ,
3+ TerminalKindExtensions ,
4+ TerminalNode
5+ } from '@nomicfoundation/slang/cst' ;
36import { MultiLineComment } from '../slang-nodes/MultiLineComment.js' ;
47import { MultiLineNatSpecComment } from '../slang-nodes/MultiLineNatSpecComment.js' ;
58import { SingleLineComment } from '../slang-nodes/SingleLineComment.js' ;
@@ -9,15 +12,6 @@ import type { Edge } from '@nomicfoundation/slang/cst';
912import type { Comment , StrictAstNode } from '../slang-nodes/types.d.ts' ;
1013import type { AstLocation , SlangAstNode } from '../types.d.ts' ;
1114
12- const isCommentOrWhiteSpace = createKindCheckFunction ( [
13- TerminalKind . MultiLineComment ,
14- TerminalKind . MultiLineNatSpecComment ,
15- TerminalKind . SingleLineComment ,
16- TerminalKind . SingleLineNatSpecComment ,
17- TerminalKind . EndOfLine ,
18- TerminalKind . Whitespace
19- ] ) ;
20-
2115const offsets = new Map < number , number > ( ) ;
2216export function clearOffsets ( ) : void {
2317 offsets . clear ( ) ;
@@ -40,7 +34,10 @@ function reversedIterator<T>(children: T[]): Iterable<T> {
4034function getOffset ( children : Edge [ ] | Iterable < Edge > ) : number {
4135 let offset = 0 ;
4236 for ( const { node } of children ) {
43- if ( node . isNonterminalNode ( ) || ! isCommentOrWhiteSpace ( node ) ) {
37+ if (
38+ node . isNonterminalNode ( ) ||
39+ ! TerminalKindExtensions . isTrivia ( node . kind )
40+ ) {
4441 // The node's content starts when we find the first non-terminal token,
4542 // or if we find a non-comment, non-whitespace token.
4643 return offset ;
0 commit comments