Skip to content
This repository has been archived by the owner on Apr 13, 2021. It is now read-only.

Decorator Transpilation #5

Open
kamal opened this issue Jan 5, 2021 · 4 comments
Open

Decorator Transpilation #5

kamal opened this issue Jan 5, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@kamal
Copy link

kamal commented Jan 5, 2021

I'm trying out this package against an Ember Octane app. Looks like esbuild trips up on decorators with an error like error: Expected identifier but found "@"

The class definition itself looks like

import { inject as service } from '@ember/service';
import { Ability } from 'ember-can';

export default class extends Ability {
  @service state;
}

I saw that esbuild added initial support for Typescript decorators in 0.4.10 but I'm guessing it doesn't perform the transformation for ES6 files?

@alexlafroscia
Copy link
Owner

Huh! Good question -- I honestly have no idea 😅 I don't know much about esbuild honestly. Since this package uses 0.8.X of esbuild I would assume that if it should work, it would...

@alexlafroscia
Copy link
Owner

The only mention of decorators on their docs site refers to them like this:

TypeScript-only syntax extensions are supported, and are always converted to JavaScript (a non-exhaustive list):
Experimental decorators

So... I don't think that esbuild can handle decorators in JS files. TIL!

@alexlafroscia
Copy link
Owner

There might be some kind of way to trick/force esbuild to process the JS files as TS files and then do whatever it needs to with decorators... but I'm not sure if there are other impacts that that would also have.

@alexlafroscia alexlafroscia added this to the Initial Release milestone Mar 16, 2021
@alexlafroscia alexlafroscia added the bug Something isn't working label Mar 16, 2021
@alexlafroscia
Copy link
Owner

I was hoping that the esbuild-plugin-babel package mentioned here would be a resolution to this, but I'm not sure that's going to be the answer here. I tried to use it, only to realize that plugins are only support for the build API that it provides, not the transform API.

We might be able to take the same approach, though, just running the Babel plugin on the code and then passing it along to esbuild but without that plugin being involved.

I'm not sure how much that ends up making sense, because now we just have Babel involved again... 🤷‍♂️

@alexlafroscia alexlafroscia added this to To Do in Support Required Babel Behavior via automation Mar 16, 2021
@alexlafroscia alexlafroscia changed the title Decorator support Decorator Transpilation Mar 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants