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

fix Babel transform to handle TS type annotations #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

petebacondarwin
Copy link

The @babel/plugin-transform-modules-commonjs transform runs before the esbuild step, which is where TS type annotations are removed.

This can cause files that contain typings to fail with errors like:

SyntaxError: xxx.ts: Cannot transform the imported binding "XXX" since it's also used in a type annotation. Please strip type annotations using @babel/preset-typescript or @babel/preset-flow.

This commit ensures that files that are transformed via this Babel plugin have their type annotations removed via the @babel/preset-typescript preset beforehand.

Fixes #57

The `@babel/plugin-transform-modules-commonjs` transform runs before the esbuild step, which is where TS type annotations are removed.

This can cause files that contain typings to fail with errors like:

```
SyntaxError: xxx.ts: Cannot transform the imported binding "XXX" since it's also used in a type annotation. Please strip type annotations using @babel/preset-typescript or @babel/preset-flow.
```

This commit ensures that files that are transformed via this Babel plugin have their type annotations removed via the `@babel/preset-typescript` preset beforehand.

Fixes aelbore#57
@thebanjomatic
Copy link

Rather than use @babel/preset-typescript to strip the type annotations, it seems like maybe it would be better to do the esbuild transform first and then pass the results of that into babel-jest to do the jest.mock hoisting? With a little extra work you would also probably be able to hook up the inputSourceMap as well.

@vertic4l
Copy link

Can somebody release it in the way @thebanjomatic mentions it, please ?

@dforsl
Copy link

dforsl commented Mar 23, 2022

Any progress here? If this solution works - despite there being more ideal one - I think anything right now that lets us use type annotations in tests would be a huge improvement 🙏

@peteratdivvy
Copy link

Any word on this? This is preventing us from using esbuild-jest.

@Crafoord
Copy link

Is repo abandoned by @aelbore ?

@anttiviljami
Copy link

This change fixed our problem. 🙏 I've published @petebacondarwin's branch under @epilot/esbuild-jest in case anyone needs it.

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

Successfully merging this pull request may close these issues.

Cannot transform the imported binding xxxxx since it's also used in a type annotation
7 participants