vitejs / vite-plugin-react-swc

Speed up your Vite dev server with SWC
MIT License
774 stars 49 forks source link

internal error: entered unreachable code: auto_accessor pass should remove this #179

Closed Artur- closed 7 months ago

Artur- commented 7 months ago

I converted a project from using vite-plugin-react to using this because of https://github.com/vitejs/vite-plugin-react/issues/266 and initially it compiles fine. However, as this plugin enforces useDefineForClassFields I need to add accessor to Lit Element properties for them to keep working (https://lit.dev/docs/components/properties/#avoiding-issues-with-class-fields).

When I change something like

  @state()
  foo = false;

to

  @state()
  accessor foo = false;

It all stops working with

thread '<unnamed>' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swc_ecma_compat_es2022-0.1.41/src/class_properties/mod.rs:957:21:
internal error: entered unreachable code: auto_accessor pass should remove this
[vite] Internal server error: failed to handle: internal error: entered unreachable code: auto_accessor pass should remove this
Plugin: vite:react-swc
Artur- commented 7 months ago

This is in a .ts file, so it sounds like the plugin should not even process it.

ArnaudBarre commented 7 months ago

This is either a bug in SWC (at least we could consider the parser should error and not panic) either an incompatibility between Lit and the spec (which I think is the case given this TS flag was removed from the lit template IIRC)

This plugins enforce standards for reason stayed here: https://github.com/vitejs/vite-plugin-react-swc/pull/178#issuecomment-1824272225, so it's either a won't fix or upstream issue.

RoystonS commented 4 months ago

Btw, it looks like it is possible to make this work with SWC, but only if a transform is passed to tell SWC not to use the legacy decorators but to use the new one. It looks like this package deliberately prevents the passing of such transforms.

See:

I understand that the reasons for not passing through transforms are to encourage the use of standard configurations and to encourage the use of new features. However, but right now this means that we can't use the newer non-legacy decorators.

Is there any prospect of a specific decorators switch so that we could use the non-legacy decorators without having to expose the whole of the transforms API, which causes concern?