embroider-build / embroider

Compiling Ember apps into spec-compliant, modern Javascript.
MIT License
337 stars 137 forks source link

Publishing v2 addons with `@embroider/addon-dev` should allow to ship untransformed decorator code #1014

Open simonihmig opened 2 years ago

simonihmig commented 2 years ago

The "Ember Language Standard" defined in the v2 spec supports shipping addon code with (legacy) decorators. However the build support for v2 addons in @embroider/addon-dev uses Babel, which fails to parse decorators code when not transforming them.

This is described in more detail in https://github.com/babel/babel/discussions/13927, and probably an issue of Babel itself. But raising this here for visibility and tracking.

The only workaround I found was to add the plugins that actually transform decorators.

ef4 commented 2 years ago

I think the suggestion in that thread is correct, we should be adding the syntax plugin without adding the transform plugin.

simonihmig commented 2 years ago

Well, but the issue I described on that thread is that this does not work...

ef4 commented 2 years ago

Sorry, I missed that, you're correct.

ef4 commented 2 years ago

The problem here is that rollup's own parser (which is acorn) needs to understand the syntax. Which is unlikely to happen, because the legacy decorator syntax isn't really standards track -- the decorators proposal moves onward, but with different syntax.

I think instead we're going to need to move forward on having our own intermediate representation that is safe JS syntax. This is a good idea anyway -- publishing packages to NPM that general purpose JS tooling can't parse is not great.