ember-native-class-codemod
ember-native-class-codemod copied to clipboard
Handle Object.freeze when used with EmberObject.extend()
When using:
export default Controller.extend({
prop1: Object.freeze({ whatever: 'here' }),
})
The file is not transformed (due to the member expression for prop1). We have a few plausible solutions here. We know exactly what Object.freeze does, and can choose a few different paths forward:
- Set
prop1on the prototype:
export default class Foo extend Controller {
}
Foo.prototype.prop1 = Object.freeze({ whatever: 'here' });
- Set
prop1as a class field:
export default class Foo extend Controller {
prop1 = { whatever: 'here' };
}
- Something else?
I vaguely think we should do the second one, thoughts?
hmm, my main concern is the second solution is allowed to be stateful, which could be problematic. If it was truly meant to be a constant, I feel like it would make more sense to assign it as a static field (still frozen). That said, that isn't codemoddable, so this could work for now and we could guide people to transition toward that in the future.