Skip to content

Split TypeTransformer.TransformAll into named phases + fix duplicate GroupTypesByFile call #222

Description

@danfma

Problems

src/Metano.Compiler.TypeScript/Transformation/TypeTransformer.cs (1894 LOC):

  • Bug-shaped: `GroupTypesByFile(transpilableTypes)` invoked at line 345 (result hoisted) and again at line 360 inside the try block (assigned to `groups`). First call's result is overwritten and discarded.
  • `TransformAll` is ~280 LOC orchestrating 8 phases (assembly probe, name-map clone, type-entry projection, interface-prefix strip, type-mapping context build, no-container scan, context build, parallel transform loop, post-merge of diagnostics + deps + cache write).
  • `BuildTypeStatements` is a 100-LOC `if/else if` ladder dispatching on TypeKind.
  • `TryEmitModuleViaIr` is 150 LOC mixing entry-point discovery + signature validation + body extraction + trailing-export rewrite.

Fix

  1. Delete the duplicate `GroupTypesByFile` call.
  2. Extract `TransformAll` phases: `BuildInitialNameMaps`, `RunPerGroupTransform`, `DrainCrossPackageMisses`, `DrainCrossPackageDependencies`. Parallel.For body becomes `TransformGroupOrReuseFromCache(int index, …)`.
  3. `BuildTypeStatements` → `TryEmit{Enum,Interface,Delegate,Exception,JsonContext,Module,Branded,PlainObject,Class}` chain.
  4. `TryEmitModuleViaIr` → `FindEntryPoint` + `ValidateEntryPointSignature` + `ExtractAndValidateEntryBody` + `EmitEntryPointBodyAsTopLevel` + `ApplyExportVarFromBody`.

Motivation

Adding any new emission shape (Stage 4 indexers landed forward-compat; Stage 5 operators is next) requires touching the same 1894-LOC file. Splitting drops navigability cliff below 600 LOC.

Behaviour-preserving refactor — golden tests under `targets/` must stay byte-identical.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions