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

Ouverte
#162 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
35/100
Type d'issue
Refactorisation
Clarté
Plutôt claire
Activité
Calme
Stack technique
javascript, typescript
Domaine
tooling

Piste de recherche

Commencez par src/extract.mjs et les API Program et Checker de unstable/sync, en utilisant src/resolve.mjs pour comprendre comment les chemins d’entrée parviennent au programme. Construisez le proof of concept suggéré de classify() pour les formes union, object, literal, array et signature, puis exécutez environ cinq Golden Cases avec le test/sandbox harness. Le travail est terminé lorsque la sortie comparée octet par octet correspond aux Golden Results commités et que les lacunes du mappage des API sont documentées.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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).
Langage dominant
ReScript
Étoiles
11
Forks
0
Merge moyen
7 h 27 min
PR mergées (30 j)
6

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de juspay/rescript-bindgen

Toutes les issues de juspay/rescript-bindgen

Issues similaires

Plus d'issues DevTools

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.