fix(site): support satisfies in api-docs data attrs extraction (#517)

This commit is contained in:
Darius Cepulis
2026-02-12 10:16:18 -06:00
committed by GitHub
parent bdb9d7b506
commit 4d62a1ff7d
2 changed files with 73 additions and 9 deletions
@@ -1,6 +1,26 @@
import * as ts from 'typescript';
import type { DataAttrsExtraction } from './types.js';
function unwrapObjectLiteral(node: ts.Expression): ts.ObjectLiteralExpression | undefined {
if (ts.isObjectLiteralExpression(node)) {
return node;
}
if (ts.isParenthesizedExpression(node)) {
return unwrapObjectLiteral(node.expression);
}
if (ts.isAsExpression(node)) {
return unwrapObjectLiteral(node.expression);
}
if (ts.isSatisfiesExpression(node)) {
return unwrapObjectLiteral(node.expression);
}
return undefined;
}
/**
* Extract data attributes from a data-attrs file.
*
@@ -37,15 +57,7 @@ export function extractDataAttrs(
continue;
}
// Handle `as const` assertions
let objLiteral: ts.ObjectLiteralExpression | undefined;
if (ts.isObjectLiteralExpression(decl.initializer)) {
objLiteral = decl.initializer;
} else if (ts.isAsExpression(decl.initializer) && ts.isObjectLiteralExpression(decl.initializer.expression)) {
objLiteral = decl.initializer.expression;
}
const objLiteral = unwrapObjectLiteral(decl.initializer);
if (!objLiteral) continue;
// Extract properties with their JSDoc comments