microsoft / microsoft/TypeScript
API: Allow passing TypeScript.SourceFile / AST directly to transpileModule
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/services/transpile.ts and the transpileModule entry point named in the issue. Review how the current string-based API obtains its SourceFile and handles the listed internal options. Done means a supported API accepts a TypeScript.SourceFile and transpile options while returning TypeScript.TranspileOutput without requiring the caller's AST to be parsed again.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100