Skip to content

Include TypeChecker in TransformationContext so that custom transformers can use type information #25147

Description

Search Terms

customTransformers, custom transformers

Suggestion

Though there are several module bundler plugins that support custom transformers, such as ts-loader, awesome-typescript-loader, parcel-plugin-typescript, rollup-plugin-typescript2, currently some of them cannot accept custom transformers that require TypeChecker.
Including TypeChecker in TransformationContext resolves this issue.

Use Cases

ts-loader, for example, currently supports custom transformers by providing getCustomTransformers option whose type is () => { before?: TransformerFactory[]; after?: TransformerFactory[]; }.
It is not possible to use custom transformers that require TypeChecker such as ts-transformer-keys (it actually requires Program but can be rewritten so that it only requires TypeChecker) with ts-loader.

Though awesome-typescript-loader and rollup-plugin-typescript2 supports such custom transformers
by passing Program or LanguageService, respectively, to the callback corresponding to getCustomTransformers in ts-loader, I found that it is difficult to modify ts-loader's code so that it can also pass Program or LanguageService (or TypeChecker) to the callback.

Examples

Using ts-transformer-keys with ts-loader as described above.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript / JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
    • Depends on the behavior of custom transformers to use, but at least TypeScript itself does not need to emit different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. new expression-level syntax)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions