create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

Add swc transpilation behind a flag

Open raix opened this issue 3 years ago • 14 comments

This pr swaps out babel and use swc for transpiling code building/testing

Overview:

  • [x] Make start/build/test work with swc
  • [x] fix any broken tests
  • [x] enable browserlists support
  • [x] Remove support for Flow (currently not supported in swc)
  • [x] load project tsconfig/jsconfig and map into swc config
  • [x] ~use ts-jest for jest ts/tsx file transformation (keeping an eye on stc)~ (keeping the scope of the pr to swc)
  • [x] QA if project browserslist config is working
  • [x] QA project tsconfig mapping works
  • [x] ~QA project tsconfig is loaded in ts-jest~
  • [x] Add babel back
  • [x] Move js/ts transformation out into separate files for swc and babel
  • [x] Add and document SWC_TRANSFORM
  • [x] QA both babel and swc configurations
  • [x] Allow comments in jsconfig.json - we use this file to configure swc in non TypeScript projects
  • [ ] Cover by tests - reuse the kitchensink?

Notes:

  • Currently eslint use use babel parser (waiting for someone to write eslint in rust / swc ast or transform swc ast to espree ast?)

Dependency updates:

  • remove tar-pack seems to be unmaintained had a dependency on tar 2.x - we are now on tar 6.x
  • jest patch update to 27.4.4

BREAKING CHANGE:

  • When using swc it will removed support for Flow (done in one commit we can revert if https://github.com/swc-project/swc/issues/256 gets added)

raix avatar Dec 10 '21 21:12 raix

Will it land with CRA5? :)))

Bnaya avatar Dec 12 '21 15:12 Bnaya

3 options as it removes support for Flow (on the short run) it's a breaking change - could be in v5, v6 or not at all 🙂

raix avatar Dec 12 '21 16:12 raix

We might add this behind a flag in 5.x to gather feedback for v6

raix avatar Dec 12 '21 23:12 raix

Thanks @raix It would fantastic to have this behind a FF for 5.x to benchmark on larger projects.

sshquack avatar Dec 13 '21 20:12 sshquack

Since we are adding json5 in this pr we should fix https://github.com/facebook/create-react-app/issues/7426 in the same go

raix avatar Dec 17 '21 09:12 raix

@mrmckeb regarding #7426 this pr adds support for comments in jsconfig.json - the pr uses jsconfig.json to configure swc language features - a project could then use jsconfig.json for configuring the IDE and swc without using TypeScript. I went for JSON5 as npm why json5 showed usage in multiple dependencies already.

raix avatar Dec 19 '21 07:12 raix

Hi. I'm the author of the swc project. I'm curious if there's something I can help.

Currently eslint use use babel parser (waiting for someone to write eslint in rust / swc ast or transform swc ast to espree ast?)

swc has code to convert swc AST into other estree AST, but it's not exposed as a js api just because there was no good usecase.

Does this still apply? I'm not sure if it's the case, and I'm also curious about tasks left.

kdy1 avatar Jan 17 '22 16:01 kdy1

Thanks @kdy1 this pr doesn't remove babel transform due to eslint, it sounds like it could be fairly trivial to create a swc-parser for eslint, if the espree ast is already in swc?

raix avatar Jan 17 '22 18:01 raix

Yeah, I think so. It needs more testing about range fields of FunctionExpression, but it would not take so much time IMHO.

But I'm not sure about the API for it. Does parseAs sound good to you?

kdy1 avatar Jan 18 '22 08:01 kdy1

Hi @raix will it be possible to make some progress here and maybe land it in 5.0.2 ?

krreet avatar May 06 '22 06:05 krreet

Would be awesome if anyone is up for taking over this pr - I'm currently out of time 🙏

raix avatar Aug 17 '22 17:08 raix

@raix Can you provide a list of plugins that require porting?

kdy1 avatar Aug 20 '22 08:08 kdy1

I think to remember that it was eslint only using babel - not sure if there's a eslint-swc parser. (It's along time ago since I did this work)

Congrats on you 25th b-day btw 🙂

raix avatar Sep 14 '22 19:09 raix

Thank you!

kdy1 avatar Sep 15 '22 00:09 kdy1