Implement async code transformations
See original GitHub issueEcmaScript Modules can (actually must, but easy to wrap the sync stuff in a promise) resolve asynchronously. While it’s in no way a blocker for ESM support in Jest, it would be nice to add support for async transforms to be used.
This logic should for now not impact anything in Jest beyond @jest/transform as Jest wouldn’t use it until ESM support is in place.
I’m thinking we can add a .transformAsync and .transformSourceAsync to the ScriptTransformer class.
There are some checks and verifications that process is a function - we need to make sure there is one clear code path for sync and one for async transformation that verify the provided reporter implements the correct interface.
Sort of reopening #5556 and all its linked issues.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:22 (11 by maintainers)
Top Results From Across the Web
Creating an Asynchronous Transformation with the Script ...
This example demonstrates the custom code that is required in the ScriptMain class to create an asynchronous transformation component. Note.
Read more >Use code generators to transform a .NET codebase to async ...
Use code generators to transform a .NET codebase to async/await. The asynchronous programming model with async/await has the potential to solve many issues ......
Read more >Code Transformation - Jest
A transformer is a module that provides a method for transforming source files. For example, if you wanted to be able to use...
Read more >Chapter 14. The Async Compiler Transform—in Depth - O'Reilly
The Async Compiler Transform—in Depth Async is implemented in the C# compiler with some help from the .NET framework base class libraries.
Read more >Transforming Async, Await JS and minifying using Uglify
Async and Await makes asynchronous code so much cleaner and nicer to work with. It is widely supported by all the latest versions...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Gave this some more though when working on #11150 (leaving in an extra
asyncthat isn’t needed, but will be when this issue is fixed). And I think it’ll be quite straightforward to implement injest-runtimeonce #9889 lands. I’ll do it soonish, definitely before a stable release of Jest 27 even though it shouldn’t be a breaking change. That way people with async transforms have a major release they can targetThat would break current transformers indeed. We can add some sort of “preload” to transformers where they can do whatever they want async so that they’re ready to transform code synchronously (e.g. do
import('@babel/core')) like you suggest. We need to keep supporting synchronous transformation for JIT when people userequire, but some sort of bootstrapping phase should be fine.Can you open up a new issue with that feature request? SOrta orthogonal to async transformation