ember-native-class-codemod icon indicating copy to clipboard operation
ember-native-class-codemod copied to clipboard

Handle Object.freeze when used with EmberObject.extend()

Open rwjblue opened this issue 6 years ago • 2 comments

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:

  1. Set prop1 on the prototype:
export default class Foo extend Controller {
}
Foo.prototype.prop1 = Object.freeze({ whatever: 'here' });
  1. Set prop1 as a class field:
export default class Foo extend Controller {
  prop1 = { whatever: 'here' };
}
  1. Something else?

rwjblue avatar Jun 23 '19 22:06 rwjblue

I vaguely think we should do the second one, thoughts?

rwjblue avatar Jun 23 '19 22:06 rwjblue

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.

pzuraq avatar Jun 24 '19 18:06 pzuraq