microsoft / microsoft/TypeScript
feature request: public the TransformationContext.addDiagnostic and read them in the compiler and transpileModule
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Search Terms
custom transformer diagnostic
Suggestion
mark the method addDiagnostic in TransformationContext as public and read the diagnostic result in the compiler
Use Cases
I'm writing a custom transformer. In some cases, the transform will fail but I don't want to throw an Error. I want to add my error to the diagnostics.
Examples
I have tried to call the addDiagnostic by as any
function createDiagnosticForNodeInSourceFile(
ts: ts,
sourceFile: SourceFile,
node: Node,
message: DiagnosticMessage,
arg0?: string | number,
arg1?: string | number,
arg2?: string | number,
arg3?: string | number,
): DiagnosticWithLocation | undefined {
return (ts as any).createDiagnosticForNodeInSourceFile?.(sourceFile, node, message, arg0, arg1, arg2, arg3)
}
function appendDiagnosticMessageForNode(context: TransformationContext, diag: DiagnosticWithLocation | undefined) {
if (!diag) return false
const _context = internalTransformationContext(context)
if (!_context.addDiagnostic) return false
_context.addDiagnostic(diag)
return true
function internalTransformationContext(
context: TransformationContext,
): TransformationContext & { addDiagnostic?(diag: DiagnosticWithLocation): void } {
return context as any
}
}
But that doesn't work. After digging into the source code, I found that it seems like the diagnostics only read in the dts generating.
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、issue で言及されている compiler、transpileModule、および宣言生成のパスを通じて TransformationContext.addDiagnostic を追跡します。現在 transformer の診断がどこで読み取られているかを確認し、カスタム transformer によって追加された診断が compiler と transpileModule の結果に到達することを示すために必要なテストを特定します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 35/100