Part 1 - Custom decorators blocked in LWC
I'm trying to implement a custom decorator, very simple book example but getting LWC error in both LWC open source and LWC for salesforce,
LWC1100: Invalid decorator usage. Supported decorators (api, wire, track) should be imported from "lwc"
export default class Logdecorator extends LightningElement {
readonly(target, name, descriptor) {
descriptor.writable = false;
return descriptor;
} }
export default class Decoratortest extends LightningElement {
@readonly
sum(a, b) {
return a + b;
}
}
The document clearly says as per this link it supports ES2015-2019, since decorators part of ES2015 itself not sure why its explicitly blocked by framework and I also see the js spec test for throwing error if anything other than @api, @track, @wire to comfirm my assumption.
From LWC documentation site, https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.get_started_supported_javascript
Lightning Web Components JavaScript support includes:
ES6 (ECMAScript 2015)
ES7 (ECMAScript 2016)
ES8 (ECMAScript 2017)—excluding Shared Memory and Atomics
ES9 (ECMAScript 2018)—including only Object Spread Properties (not Object Rest Properties)
Part -2 - Dynamically creating web components is blocked as well.
Given that we can't create dynamically create LWC components, there is less chance to even try alternative solution similar to React Higher Order Components. So both solutions doesn't work in current framewor.
We are only left with basic funtion important and calling them as old fashion javascript not able to leverage modern features seems to be not fair for modern web component framework.
Thanks