Slide 16
Slide 16 text
実装例: 関数コンポーネントの取り出し
const componentsFile = project.getSourceFile(componentsFilePath)
const exportedDeclarations = componentsFile.getExportedDeclarations()
/**
取り出したコンポーネントのメタデータ */
const declarations = Array.from(exportedDeclarations.entries()).map(
([declarationName, declarations]) => {
const [declaration, ...others] = declarations
if (
!Node.isFunctionDeclaration(declaration) && // function
!Node.isVariableDeclaration(declaration) // const Comp: FC
) {
//
関数コンポーネント以外はスキップ
return {
declarationName,
propType: undefined,
}
}
//
コメントや Props
型定義を抜き出す
})
16