New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parcel not respecting tsconfig useDefineForClassFields: false
with decorators
#8036
Comments
Looks like SWC just merged a possible fix. When can we expect this version to be integrated into parcel? |
#8029 is currently blocking an swc upgrade, because swc did some breaking changes. |
Ah i just wasted a whole day on trying to figure out why my reactive properties (added with the Is there any workaround? |
In Lit, declare your reactive properties as you would in JS, |
Well then i would also have to write the constructor instead of just using |
Correct, you would have to write the constructor to initialize your property, but the customElement decorator has nothing to do with the constructor and should still work despite this but because it's a class decorator not an accessor decorator.
|
Im a bit confused rn^^ @property({ type: Number })
count = 0
// to
static properties = { count: { type: Number } } i have to add a class field But your suggestion is to not use decorators and to remove the |
I actually had time to sit down and test my hypothesis. You will not be able to use class fields at all here. Sorry for the confusion! You have to include the constructor, because it seems like SWC will just ignore that flag. You have to do the following: @customElement('my-element')
export class MyElement extends LitElement {
static properties = { count: { type: Number } }
count: Number;
constructor() {
super();
this.count = 0;
}
} Though if you have further questions about Lit, I feel like this is probably an inappropriate place to have this conversation. I recommend you join the Lit Slack for further Lit questions. |
swc is now upgraded in the nightly version ( The real problems appears to be though that Parcel only forwards
and not useDefineForClassFields which is just hardcoded
|
馃悰 bug report
Heya please let me know if this should instead by filed under
swc
.In projects that rely on decorators with accessors, in tsconfig you have to set
useDefineForClassFields: false
because decorators that generate accessors do not get called if the properties are initialized usingObject.defineProperty
.When defining a decorator around a property and you have
useDefineForClassFields:false
, Parcel will still useObject.define
under the hood because it uses@swc/helpers/_initializerDefineProperty.js
.馃帥 Configuration (.babelrc, package.json, cli command)
command:
parcel build
no babelrc, only tsconfig:
馃 Expected Behavior
Given a simple
@logger
decorator that creates aset
andget
in which it willconsole.log
in the getter:this should be transpiled to:
馃槸 Current Behavior
It is instead transpiled to:
Because the constructor gets called after the decorator's
logger()
function, theObject.defineProperty
in the constructor is overriding theObject.defineProperty
in thelogger()
decorator, thus making it near impossible to wrap a class property in a decorator with a class accessor.馃拋 Possible Solution
Opt-out of
useDefineForClassFields
when using decorators if the flag is set tofalse
.Workarounds:
use the TS compiler instead in
.parcelrc
馃敠 Context
Trying to use several libraries that wrap class members in accessors with decorators.
馃捇 Code Sample
馃實 Your Environment
The text was updated successfully, but these errors were encountered: