Skip to content

[api] No replacement for ts.transform / TransformationContext / custom transformers in program.emit #64861

Open

Description

@Smrtnyk

Acknowledgement

  • I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.

Comment

Trying to collect what we need to migrate our custom ts build in ts 6 to new ts native.

In 6.0, a build could plug custom transformers into the compiler:

  • program.emit(undefined, undefined, undefined, undefined, { before: [factory] })
  • ts.transform(sourceFile, [factory]) with TransformationContext, ts.visitEachChild(node, visitor, context), context.readEmitHelpers(), ts.addEmitHelpers

In 7.1:

  • Program.emit(emitOnly?) / emitToString(emitOnly?) don't accept transformers.
  • There's no transform function and no TransformationContext type.
  • visitEachChild(node, visitor) exists in typescript/ast without a context.

The only remaining pattern is: parse with api.createSourceFile, rewrite with visitEachChild + typescript/ast/factory, print with api.printer.printNode, then pass the text to another compiler or bundler. That loses:

Our use case: build-time instrumentation of a browser agent (wrapping function bodies, await expressions and .apply() calls) during the TypeScript emit of a build.

Is support for custom transformers planned for the native API, either as JS callbacks during emit or as a supported "transform the AST, then emit" path with source maps? If it isn't planned, is the parse → visit → print → re-emit approach the intended long-term pattern?

Related: #14419, #54276 (transformer plugins in 6.x, not about the native API).

Metadata

Metadata

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions