reactjs / reactjs/react-docgen
Support extracting of type information from tagged templates
まだ誰も着手していません。
- 主要言語
- TypeScript
- スター
- 3.8k
- フォーク
- 316
- 平均マージ
- 5時間 7分
- マージ済み PR(30日)
- 4
説明
It looks like even if I have a resolver that resolves to components that use tagged templates like styled-components, the type annotations aren't extracted.
Consider the following example:
import styled from "styled-components";
interface FlexProps {
bool: boolean
}
const Flex = styled('div')<FlexProps>`
display: flex;
`;
/** @component */
export default Flex;
When used with an react-docgen-annotation-resolver, the type definitions won't be extracted.
I scoped it to this place in code that's responsible for finding type annotations: https://github.com/okonet/react-docgen/blob/8fb401089e3fe2b38d41638bc5690436e23aceb3/src/utils/getTypeAnnotation.js#L22
and it looks like it's searching for specific key typeAnnotation in the AST. For styled-component example, though, it won't present. But what's going to present is
Node {
type: 'TaggedTemplateExpression',
start: 95,
end: 138,
loc: SourceLocation { start: [Position], end: [Position] },
tag:
Node {
type: 'CallExpression',
start: 95,
end: 108,
loc: [SourceLocation],
callee: [Node],
arguments: [Array] },
quasi:
Node {
type: 'TemplateLiteral',
start: 119,
end: 138,
loc: [SourceLocation],
expressions: [],
quasis: [Array] },
typeParameters:
Node {
type: 'TSTypeParameterInstantiation',
start: 108,
end: 119,
loc: [SourceLocation],
params: [Array] } },
So, it looks like there is something related to types in there but its not being properly handled.
Does anyone has any pointers on how to fix it?
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
src/utils/getTypeAnnotation.js の、issue でリンクされている型アノテーションの検索箇所から始め、次に、示されている TaggedTemplateExpression AST と現在処理されているノードを比較します。react-docgen-annotation-resolver が結果をどのように利用するかを追跡します。styled-components の例から FlexProps のような型定義を抽出できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- react, typescript
- 領域
- documentation
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100