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

未关闭
#162 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
重构
描述清晰度
基本清楚
活跃度
冷清
领域
tooling

调研方向

从 src/extract.mjs 以及 unstable/sync 的 Program 和 Checker API 开始,使用 src/resolve.mjs 了解输入路径如何到达程序。为 union、object、literal、array 和 signature 形状构建建议的 classify() proof of concept,然后通过 test/sandbox harness 运行大约五个 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 分钟
30 天内合并 PR
6

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

juspay/rescript-bindgen 的其他 Issue

查看 juspay/rescript-bindgen 的全部 Issue

相似的 Issue

更多 DevTools Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。