swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
30.97k stars 1.21k forks source link

reflect-metadata does not work as expected in some scenarios #9430

Closed cjnoname closed 1 month ago

cjnoname commented 1 month ago

Describe the bug

Hi,

We are developing NodeJS applications using TypeORM and TypeGraphQL, both of which heavily rely on decorators and emitDecoratorMetadata.

We have encountered some unusual behaviors during the SWC compilation process. I have provided an example below:

https://github.com/cjnoname/example-esm

Please check out the repository, install the package, and run npm start. You will see the issues within seconds.

You can easily toggle the “swc” flag between true and false in tsconfig.json file to compare the output between tsc and swc.

Issue 1: A getter function within a class object does not return the correct type, as demonstrated in the example code. It should return “String” as shown in tsc, but it is showing “Function” in swc.

Issue 2: The enum metadata is correct when the enum is in the same file as the class, but it is incorrect when loaded from another TypeScript file. enum1 and enum2 are incorrect, displaying the original file content in their metadata, while enum3 shows correctly in its prototype.

Input code

No response

Config

No response

Playground link (or link to the minimal reproduction)

https://github.com/cjnoname/example-esm

SWC Info output

No response

Expected behavior

Both of these issues should be fixed to align the output with the compilation results of tsc.

Actual behavior

As shown in the example on Git

Version

"@swc/core": "1.7.11"

Additional context

No response

kdy1 commented 1 month ago

swc works on a single-file basis so enum from another module cannot work.

cjnoname commented 1 month ago

Issue 1: A getter function within a class object does not return the correct type, as demonstrated in the example code. It should return “String” as shown in tsc, but it is showing “Function” in swc.

How about this one mate? This happens in a single file. @kdy1

kdy1 commented 1 month ago

Please provide a minimal reproduction

cjnoname commented 1 month ago

Please provide a minimal reproduction

It's in the same GitHub repo, mate. Could you take a quick look at both issues? It might take you less than five minutes. I love this library and hope it can be perfect. Many thanks mate.

kdy1 commented 1 month ago

I meant that your reproduction is way too big

kdy1 commented 1 month ago

Minimal reproduction is something like https://github.com/swc-project/swc/issues/9435

cjnoname commented 1 month ago

Minimal reproduction is something like #9435

Thanks mate :) This is the first time I did it :)

swc-bot commented 1 week ago

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.