strippedStart
Start of a declaration with export / default modifiers removed.
import { canHaveModifiers, getModifiers } from "#codebase/tcmts/core/ts"; import { SyntaxKind as ts_SyntaxKind } from "typescript/ast"; import type { Node as ts_Node, SourceFile as ts_SourceFile } from "typescript/ast"; export function strippedStart(node: ts_Node, sf: ts_SourceFile): number { const mods = canHaveModifiers(node) ? getModifiers(node) : undefined; if (!mods) return node.getStart(sf); let last: ts_Node | undefined; for (const m of mods) { if (m.kind === ts_SyntaxKind.ExportKeyword || m.kind === ts_SyntaxKind.DefaultKeyword) last = m; else break; } if (!last) return node.getStart(sf); const rest = sf.text.slice(last.end); const skip = /^(?:\s|\/\/[^\n]*\n|\/\*[\s\S]*?\*\/)*/.exec(rest)![0].length; return last.end + skip; }