Skip to content

API: Allow passing TypeScript.SourceFile / AST directly to transpileModule #28365

Open
@ryanelian

Description

Search Terms

transpileModule directly AST SourceFile source performance

Suggestion

Currently, TypeScript.transpileModule accepts string and option as parameters. It would be nice to have another method like this which can accept TypeScript.SourceFile directly.

Use Cases

Currently I'm building a parser which accepts JS for scanning whether ECMAScript syntax above user's project language level / tsconfig.json:target is used. (For example: Your project targets ES2015 but one of the library imported uses ES2017 async-await syntax)

When benchmarked, simply scanning the AST is faster (medium-sized project: 2s. no scan: 1 second) rather than straight-up transpiling every single library in node_modules (same project: 8s). Then, I only need to transpile JS files above project target level for optimal build performance!

It would be nice if I can pass the AST which I obtained from above process straight to transpileModule to prevent double parsing. (Especially since transpileModule uses some internal options such as suppressOutputPathCheck and allowNonTsExtensions)

Examples

Proposed API:

transpileModuleAst(source: TypeScript.SourceFile, transpileOptions: TypeScript.transpileOptions): TypeScript.TranspileOutput

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
  • This isn't a runtime feature (e.g. new expression-level syntax)

Metadata

Assignees

No one assigned

    Labels

    APIRelates to the public API for TypeScriptIn DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions