TS 7 migration: port extract.mjs from the classic ts.* API to typescript/unstable/sync

オープン
#162 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
リファクタリング
明瞭さ
おおむね明確
活発さ
静か
技術スタック
javascript, typescript
領域
tooling

調査の方向性

src/extract.mjs と unstable/sync の Program および Checker API から始め、src/resolve.mjs を使って入力パスがどのようにプログラムへ到達するかを理解します。union、object、literal、array、signature の各 shape に対して、提案されている classify() の proof of concept を実装し、その後 test/sandbox harness で約 5 件の Golden Cases を実行します。完了の条件は、byte-diff した出力がコミット済みの Golden Results と一致し、API-mapping の不足箇所が文書化されていることです。

索引モデルが issue の本文から書いたものです。

説明

enhancement

Split from #137 (the impossible 7.0.2 drop-in bump) and related to #160 (compiler-version tracking).

Why this exists

The generator reads TypeScript via the classic JS compiler API (ts.createProgram, program.getTypeChecker(), checker.getTypeOfSymbolAtLocation, TypeFlags, SymbolFlags, forEachChild, type.isUnion(), checker.isArrayType(), …) throughout src/extract.mjs (~4,700 lines). TS 7 (native Go rewrite) removed that API — [email protected]'s top-level export is just version.cjs. So 6.x (this repo pins ^6.0.3, #161) is the end of the classic-API line; moving to TS 7+ means porting to the new API.

The good news — the new API exists and maps closely

TS 7 exposes a synchronous programmatic API at typescript/unstable/sync (+ typescript/unstable/ast). Verified surface:

  • Program — getSourceFile, getSourceFileNames, diagnostics.
  • Checker — getSymbolAtLocation, getTypeOfSymbol, getDeclaredTypeOfSymbol, getTypeAtLocation, getSignaturesOfType, getTypeFromTypeNode, getNonNullableType, getBaseTypeOfLiteralType, getContextualType, getWidenedType, isArrayLikeType, isTypeAssignableTo, resolveName, getResolvedSymbol, …
  • Standalone type predicates — isUnionType, isObjectType, isTupleType, isTypeReference, isClassOrInterfaceType, isStringLiteralType, isIntersectionType, isConditionalType, isIndexedAccessType, isTypeParameter, … (replace t.isUnion() / checker.isArrayType()).
  • Flags — TypeFlags, SymbolFlags, ObjectFlags, ModifierFlags, SignatureKind, ModuleKind.
  • typescript/unstable/ast — SyntaxKind, forEachChild*, createScanner, getJSDocTags, cast, …

So most of extract.mjs's calls have a near-1:1 target; the port is mechanical for the bulk, with a handful of shape changes (a Checker class vs program.getTypeChecker(); standalone predicates vs methods; Program construction via the API/parseConfigFile/updateSnapshot lifecycle).

The catch — it's unstable/*

That prefix means the TS team may change the API shape across 7.x without a semver-major. Building the released tool on it invites churn. This repo's mitigation is strong, though: the golden suite (105 byte-diffed cases) + benchmark (9 real packages) catch any output drift immediately, so a breaking TS 7.x change surfaces as a red CI, not silent breakage.

When to actually migrate (trigger)

Not now — 6.0.3 works and parses every package we bind. Migrate when any of:

  • the API is promoted out of typescript/unstable/* (frozen), or
  • a package we must bind ships .d.ts using TS-7-only syntax that 6.x can't parse, or
  • the 6.x line stops getting maintenance/security fixes.

Suggested first step — a POC/spike (before the full port)

Prove feasibility + size the effort on a subset before touching 4,700 lines:

  1. New makeProgram on unstable/sync (Program + Checker).
  2. Port the core classify() path for a handful of shapes (union / object / literal / array / signature).
  3. Run ~5 golden cases through it; diff against committed output.
  4. Report the API-mapping delta (what's 1:1, what needs rework, any missing capability) — that scopes the full migration.

Anchors

  • src/extract.mjs — all classic-API usage (the port target).
  • src/resolve.mjs — typesEntry feeds file paths to the program (largely API-agnostic).
  • test/sandbox + the golden/benchmark suites — the validation harness (already byte-diffs output, so it doubles as the migration's correctness gate).
主要言語
ReScript
スター
11
フォーク
0
平均マージ
7時間 27分
マージ済み PR(30日)
6

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

juspay/rescript-bindgen のほかの issue

juspay/rescript-bindgen の issue をすべて見る

似ている issue

DevTools の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。