@@ -8,13 +8,14 @@ import { MultiLineNatSpecComment } from './MultiLineNatSpecComment.js';
88import { SingleLineComment } from './SingleLineComment.js' ;
99import { SingleLineNatSpecComment } from './SingleLineNatSpecComment.js' ;
1010
11+ import type { NonterminalKind } from '@nomicfoundation/slang/cst' ;
1112import type {
1213 AstLocation ,
1314 CollectedMetadata ,
1415 SlangAstNode
1516} from '../types.d.ts' ;
1617import type { Comment , StrictAstNode } from './types.d.ts' ;
17- import type { TerminalNode } from './TerminalNode.js ' ;
18+ import type { TerminalNode } from './TerminalNode.ts ' ;
1819
1920function reversedIterator < T > ( children : T [ ] ) : Iterable < T > {
2021 return {
@@ -30,7 +31,9 @@ function reversedIterator<T>(children: T[]): Iterable<T> {
3031 } ;
3132}
3233
33- export class SlangNode {
34+ export abstract class SlangNode {
35+ abstract readonly kind : TerminalKind | NonterminalKind ;
36+
3437 comments ?: Comment [ ] ;
3538
3639 loc : AstLocation ;
@@ -126,7 +129,7 @@ export class SlangNode {
126129 if ( childNode === undefined ) continue ;
127130 const { leadingOffset, start } = childNode . loc ;
128131
129- if ( start - leadingOffset === loc . start ) {
132+ if ( leadingOffset > 0 && start - leadingOffset === loc . start ) {
130133 loc . leadingOffset = leadingOffset ;
131134 loc . start = start ;
132135 break ;
@@ -139,7 +142,7 @@ export class SlangNode {
139142 if ( childNode === undefined ) continue ;
140143 const { trailingOffset, end } = childNode . loc ;
141144
142- if ( end + trailingOffset === loc . end ) {
145+ if ( trailingOffset > 0 && end + trailingOffset === loc . end ) {
143146 loc . trailingOffset = trailingOffset ;
144147 loc . end = end ;
145148 break ;
0 commit comments