Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/slang-nodes/SlangNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import { MultiLineNatSpecComment } from './MultiLineNatSpecComment.js';
import { SingleLineComment } from './SingleLineComment.js';
import { SingleLineNatSpecComment } from './SingleLineNatSpecComment.js';

import type { NonterminalKind } from '@nomicfoundation/slang/cst';
import type {
AstLocation,
CollectedMetadata,
SlangAstNode
} from '../types.d.ts';
import type { Comment, StrictAstNode } from './types.d.ts';
import type { TerminalNode } from './TerminalNode.js';
import type { TerminalNode } from './TerminalNode.ts';

function reversedIterator<T>(children: T[]): Iterable<T> {
return {
Expand All @@ -30,7 +31,9 @@ function reversedIterator<T>(children: T[]): Iterable<T> {
};
}

export class SlangNode {
export abstract class SlangNode {
abstract readonly kind: TerminalKind | NonterminalKind;

comments?: Comment[];

loc: AstLocation;
Expand Down Expand Up @@ -126,7 +129,7 @@ export class SlangNode {
if (childNode === undefined) continue;
const { leadingOffset, start } = childNode.loc;

if (start - leadingOffset === loc.start) {
if (leadingOffset > 0 && start - leadingOffset === loc.start) {
loc.leadingOffset = leadingOffset;
loc.start = start;
break;
Expand All @@ -139,7 +142,7 @@ export class SlangNode {
if (childNode === undefined) continue;
const { trailingOffset, end } = childNode.loc;

if (end + trailingOffset === loc.end) {
if (trailingOffset > 0 && end + trailingOffset === loc.end) {
loc.trailingOffset = trailingOffset;
loc.end = end;
break;
Expand Down