-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API: Allow passing TypeScript.SourceFile / AST directly to transpileModule #28365
Comments
Thanks for opening this! I'm also wanting this feature. Instead of creating a new function, what about changing the current function signature from... function transpileModule(input: string, transpileOptions: TranspileOptions): TranspileOutput; ...to... function transpileModule(input: string | SourceFile, transpileOptions: TranspileOptions): TranspileOutput; Some questions with doing this:
Perhaps the answer to both of these is that the @weswigham would you accept a PR for this? I'm eager to get this in. |
I think we probably need to have a real discussion on our API layers, and what layers we wanna expose. Internally we've got stuff like a dedicated AST pretty-printer and a dedicated AST transformer - exposing them separately and then allowing the community to tie them together themselves might make more sense. |
Sounds good! Isn't the pretty printer already exposed? (and maybe this is the transformer too?) I'm not too familiar with the internals so I'm not sure. I agree though that a better way to take an AST and get one transformed to the target would be nice and from there people can decide to print it or not. Also, seems slightly inefficient how |
Any news on this? This is still not solved. const sourceFile = ts.createSourceFile(…)
const transformedSourceFile = ts.transform(sourceFile, …)
const code = ts.transpile(transformedSourceFile, …) |
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 acceptTypeScript.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 sincetranspileModule
uses some internal options such assuppressOutputPathCheck
andallowNonTsExtensions
)Examples
Proposed API:
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: