swc-project / plugins

Plugins for swc, written in rust
Apache License 2.0
334 stars 55 forks source link

`styled-components`: `displayName` not showing when importing from `.js` file in React #335

Closed rakleed closed 2 months ago

rakleed commented 3 months ago

Description of problem

displayName is not displayed when importing styled-component from .js file in React, although there is no such problem when importing from .jsx.

Steps to reproduce

  1. git clone https://github.com/rakleed/styled-test-swc
  2. npm install && npm run dev
  3. Open DevTools and look at div with text styled-test-swc

However, there is no such problem with babel-plugin-styled-components. To check this, you can comment out lines 1 and 7 and uncomment lines 2 and 8 in the vite.config.js file.

Screenshots

Screenshot with @swc/plugin-styled-components: ![CleanShot 2024-08-03 at 03 08 24](https://github.com/user-attachments/assets/db2ba6e8-fe9f-48f0-b79e-3d30f252f558)
Screenshot with babel-plugin-styled-components: ![CleanShot 2024-08-03 at 03 08 51](https://github.com/user-attachments/assets/15d91e8e-6d94-4c51-bdff-e2b3226bd9d0)

Minimal reproduction

https://github.com/rakleed/styled-test-swc

kdy1 commented 2 months ago

I think this is a bug of vite-plugin-swc. SWC transforms has nothing to do with file extensions