Skip to content
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

feat: add support for async transform #76

Merged
merged 2 commits into from
Feb 25, 2022

Conversation

SimenB
Copy link
Contributor

@SimenB SimenB commented Feb 24, 2022

Jest has supported async code transformation since v27, so why not support it.

And there's no need for this transformer to attempt to detect ESM support - Jest provides the necessary options (specifically supportsStaticESM) as of v25.3.0.


I can split this up into two PRs if you want

@CLAassistant
Copy link

CLAassistant commented Feb 24, 2022

CLA assistant check
All committers have signed the CLA.

index.ts Outdated Show resolved Hide resolved
const supportsEsm = 'Module' in vm

function createTransformer(swcTransformOpts?: Options) {
function createTransformer(swcTransformOpts?: Options): Transformer {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly to type jestOptions correctly

@kdy1
Copy link
Member

kdy1 commented Feb 25, 2022

Can you rebase?

@SimenB
Copy link
Contributor Author

SimenB commented Feb 25, 2022

Done 🙂

index.ts Show resolved Hide resolved
...computedSwcOptions,
module: {
...computedSwcOptions.module,
type: jestOptions.supportsStaticESM ? 'es6' : 'commonjs'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we now also do async transformation, it's not safe to mutate the shared option as there might be concurrency issues

Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Thank you!

@kdy1 kdy1 merged commit 95bdd6c into swc-project:master Feb 25, 2022
@SimenB SimenB deleted the add-async-transform branch February 25, 2022 08:20
@SimenB
Copy link
Contributor Author

SimenB commented Feb 25, 2022

Thanks!

Feel free to ping me if any issues crop up (I don't personally use this module, just noticed the needless complexity when browsing the code. I did verify it works for native ESM, though 🙂)

set(computedSwcOptions, 'module.type', isEsm(filename, jestOptions) ? 'es6' : 'commonjs')
}
process(src, filename, jestOptions) {
set(computedSwcOptions, 'module.type', jestOptions.supportsStaticESM ? 'es6' : 'commonjs')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, should have deleted this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants