feat(site): extract api reference from components (#464)

This commit is contained in:
Darius Cepulis
2026-02-05 19:57:54 -06:00
committed by GitHub
parent 48364f17fd
commit 0991a899b2
80 changed files with 3425 additions and 1562 deletions
@@ -0,0 +1,33 @@
import * as ts from 'typescript';
import type { HtmlExtraction } from './types.js';
/** Extract tagName from a Lit element file. */
export function extractHtml(filePath: string, program: ts.Program, componentName: string): HtmlExtraction | null {
const sourceFile = program.getSourceFile(filePath);
if (!sourceFile) return null;
let tagName = '';
function visit(node: ts.Node) {
if (ts.isClassDeclaration(node) && node.name?.text === `${componentName}Element`) {
for (const member of node.members) {
if (
ts.isPropertyDeclaration(member) &&
member.name &&
ts.isIdentifier(member.name) &&
member.name.text === 'tagName' &&
member.modifiers?.some((m) => m.kind === ts.SyntaxKind.StaticKeyword) &&
member.initializer &&
ts.isStringLiteral(member.initializer)
) {
tagName = member.initializer.text;
}
}
}
ts.forEachChild(node, visit);
}
visit(sourceFile);
return tagName ? { tagName } : null;
}