pfaffman
(Jay Pfaffman)
July 10, 2023, 5:35pm
1
I don’t understand why prettier is unhappy with the following code. Error is SyntaxError: Decorators cannot be used to decorate object literal properties. (9:3)
import Component from "@ember/component";
import discourseComputed from "discourse-common/utils/decorators";
function splitGroup(item) {
const x = item.split(":");
return { group: x[0], required: x[1] };
}
export default Component.extend({
@discourseComputed("siteSettings.radiant_group_values")
groupStatus(values) {
let required = values.split("|").map(splitGroup);
return required;
},
});
I have the same construction in other places that look, to me, to be exactly the same.
EDIT: this seems to have started working for reasons completely unclear. I’ll delete this next. Except I can’t.
5 Likes
pfaffman
(Jay Pfaffman)
April 13, 2025, 5:15pm
2
I’m getting this same error again on a different plugin on @action
, @on
, and @discourseComputed
. I thought maybe it was something with the prettier config, but I just copied it from discourse-plugin-skeleton
.
1 Like
Does the plugin still use the legacy .extend({})
syntax?
Over the last few years, we’ve been moving away from Ember’s legacy .extend({ ... }) syntax and towards native-class syntax like class extends Foo {...}.
While the legacy syntax is technically still supported, modern JS tooling including IDEs, and Prettier 3.0, do not support decorators in the legacy object-literal-based syntaxes. In the latest version of our recommended linting config, you’ll see these errors when using legacy syntax:
ESLint: error Native JS classes should be used instead of…
3 Likes
pfaffman
(Jay Pfaffman)
April 13, 2025, 6:36pm
4
YESSSSS!
Thanks! I just figured it out and now am trying to get all of the stuff switched over . . . oh, wait. . .
No. Way.
Much of the work can be done using the ember-native-class-codemod . From inside your theme/plugin repository, run:
NO_TELEMETRY=true npx ember-native-class-codemod@4.1.1 --no-classic-decorator **/*.js
I’ve been trying to get mass-pr
to help, but it’s not been very . . .helpful. I guess I’ll need to try that some more.
Thanks very much!!
I thought I’d been paying attention to those topics, but I guess I missed or didn’t understand that one.
3 Likes
pfaffman
(Jay Pfaffman)
Closed
May 13, 2025, 6:37pm
5
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.