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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

astTransformer not doing the transformations #2905

Closed
acalvo opened this issue Sep 20, 2021 · 2 comments
Closed

astTransformer not doing the transformations #2905

acalvo opened this issue Sep 20, 2021 · 2 comments
Labels
Not An Issue Not ts-jest issue

Comments

@acalvo
Copy link

acalvo commented Sep 20, 2021

馃悰 Bug Report

After seeing #2831 I tried to set a (simple) astTransformer in pure JS with no luck. Not sure if I'm hitting a bug or I misunderstood something. I made a minimal repo (based in the one from that issue, thanks for the boilerplate):

https://github.com/acalvo/ts-jest-ast-transformer

Use case:

To Reproduce

git clone https://github.com/acalvo/ts-jest-ast-transformer.git
npm install
npm start

Expected behavior

I'd expect the transformation (import.meta.url -> 'http://localhost/') to apply, and the test to pass.

Instead, the test fails because the unsupported import.meta.url is still there.

Link to repo (highly encouraged)

https://github.com/acalvo/ts-jest-ast-transformer

Debug log:

-

envinfo

System:
    OS: macOS 11
    Node version: v14.17.1

Npm packages:
    jest: 27.2.1
    ts-jest: 27.0.5
    typescript: 4.4.3
    babel(optional): -

Thanks!!

@acalvo acalvo added Bug Report Needs Repo Need a minimium repository to reproduce the problem Needs Triage labels Sep 20, 2021
@ahnpnl
Copy link
Collaborator

ahnpnl commented Sep 20, 2021

Hi, if you run jest with no-cache, do you see your transformer code hit debug point?

@ahnpnl
Copy link
Collaborator

ahnpnl commented Sep 20, 2021

Hi, I've checked your repo. Your transformer works correctly. However, type checking process in TypeScript doesn't perform on the js output but it runs on original ts, which explains why you still get the error

error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', or 'system'.

Note that custom AST transformers only affects how you want your js to be. It doesn't affect on type checking process

@ahnpnl ahnpnl closed this as completed Sep 20, 2021
@ahnpnl ahnpnl added Not An Issue Not ts-jest issue and removed Needs Repo Need a minimium repository to reproduce the problem Bug Report Needs Triage labels Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Not An Issue Not ts-jest issue
Projects
None yet
Development

No branches or pull requests

2 participants