swc-project / pkgs

node.js packages for SWC
62 stars 20 forks source link

What's the difference between parser and transform in .swcrc? #30

Closed biryusal closed 8 months ago

biryusal commented 8 months ago

My stack is:

"@nestjs/common": "^9.1.2",
"@nestjs/config": "^2.2.0",
"@nestjs/core": "^9.4.3",
"@swc/jest": "^0.2.36",

I also tried with a ^10 NestJS — also had a bug

I was wondering straight for 4 hours why my providers from simple code snippet:

const module: TestingModule = await Test.createTestingModule({
  providers: [
    DocumentsService,
    PartnersService,
    FakeConfigService,
    {
      provide: Logger,
      useValue: {
        log: jest.fn(),
      },
    },
  ],
}).compile()

are undefined in service's constructor method when I use @swc/jest, and not when I use ts-jest:

"compilerOptions": {
    "builder": "swc",
    "typeCheck": true,
    "assets": [
      "assets/**/*"
    ]
  }

I've updated all dependencies and did all the things that I only could, but I still was getting an error that they're undefined

And after I just tried to add the following properties to my .swcrc file:

"transform": {
  "legacyDecorator": true,
  "decoratorMetadata": true
},

And it did work And I was like: "What a heck?!?!?!?!"

Because I already did have decorators enabled in my parser of .swcrc:

"parser": {
  "syntax": "typescript",
  "decorators": true,
  "dynamicImport": true,
  "decoratorsBeforeExport": true
},

I didn't find any description of difference between transform and parser options in .swcrc, maybe you could explain it to me?

The thing, that confused me — that I already have a NestJS project that's using swc as a compiler, it's also uses a decorators — and it works just fine without transform properties specifying in .swcrc (it works in a production already for a month and it's fine) — and even though my own project starts and builds fine, it's just fails with running a tests with @swc/jest and I want to know, why is add transform properties helped me!

I would really appreciate your help ❤️.

kdy1 commented 8 months ago

Use discussion instead