templateLiterals
uses tcmts.core.ts.parse, which uses tcmts.core.ts.compiler, which uses process
The template literals in some code (parsed as file, x.ts or x.tsx), whole: from the backtick opening one to
the one closing it, substitutions and all.
import { forEachChild, parse } from "#codebase/tcmts/core/ts"; import { SyntaxKind as ts_SyntaxKind } from "typescript/ast"; import type { Node as ts_Node } from "typescript/ast"; export function templateLiterals(text: string, file: string): [number, number][] { const sf = parse(file, text); const out: [number, number][] = []; const visit = (n: ts_Node) => { if ( n.kind === ts_SyntaxKind.NoSubstitutionTemplateLiteral || n.kind === ts_SyntaxKind.TemplateExpression ) out.push([n.getStart(sf), n.end]); forEachChild(n, visit); }; forEachChild(sf, visit); return out; }