question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implement async code transformations

See original GitHub issue

EcmaScript 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:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:22 (11 by maintainers)

github_iconTop GitHub Comments

7reactions
SimenBcommented, Mar 5, 2021

Gave this some more though when working on #11150 (leaving in an extra async that isn’t needed, but will be when this issue is fixed). And I think it’ll be quite straightforward to implement in jest-runtime once #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 target

3reactions
SimenBcommented, Feb 12, 2021

That 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 use require, 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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found