npx @ota-insight/ember-computed-macro-codemod path/of/files/ or/some**/*glob.js
node ./bin/cli.js computed-macro path/of/files/ or/some**/*glob.js
- add-computed-decorator-import
- add-computed-decorator
- alias
- and
- cleanup-imports
- equal
- gt
- gte
- ignore-object-syntax
- lt
- lte
- or
- read-only
Input (add-computed-decorator-import.input.js):
import { set } from '@ember/object';
import { readOnly } from '@ember/object/computed';
class Foo {
@readOnly('foo.bar') bar;
etc() {
set(this, 'test', 1);
}
}
Output (add-computed-decorator-import.output.js):
import { set, computed } from '@ember/object';
class Foo {
@computed('foo.bar')
get bar() {
return this.foo?.bar;
}
etc() {
set(this, 'test', 1);
}
}
Input (add-computed-decorator.input.js):
import { readOnly } from '@ember/object/computed';
class Foo {
@readOnly('foo.bar') bar;
@and('foo', 'bar', 'etc') fooBar;
}
Output (add-computed-decorator.output.js):
import { computed } from '@ember/object';
class Foo {
@computed('foo.bar')
get bar() {
return this.foo?.bar;
}
@computed('foo', 'bar', 'etc')
get fooBar() {
return this.foo && this.bar && this.etc;
}
}
Input (alias.input.js):
import { alias } from '@ember/object/computed';
class Foo {
@alias('foo.bar') fooBar;
}
Output (alias.output.js):
class Foo {
get fooBar() {
return this.foo?.bar;
}
set fooBar(value) {
this.foo.bar = value;
}
}
Input (and.input.js):
import { and } from '@ember/object/computed';
class Foo {
@and('foo', 'bar', 'etc', 'deep.property') fooBar;
}
Output (and.output.js):
class Foo {
get fooBar() {
return this.foo && this.bar && this.etc && this.deep?.property;
}
}
Input (cleanup-imports.input.js):
import { readOnly, uniqBy } from '@ember/object/computed';
class Foo {
@readOnly('foo.bar') bar;
@uniqBy('fruits', 'id') uniqueFruits;
}
Output (cleanup-imports.output.js):
import { uniqBy } from '@ember/object/computed';
class Foo {
get bar() {
return this.foo?.bar;
}
@uniqBy('fruits', 'id') uniqueFruits;
}
Input (equal.input.js):
import { equal } from '@ember/object/computed';
class Foo {
@equal('foo.bar', 1) isOne;
}
Output (equal.output.js):
class Foo {
get isOne() {
return this.foo?.bar === 1;
}
}
Input (gt.input.js):
import { gt } from '@ember/object/computed';
class Foo {
@gt('foo.bar', 9000) bar;
}
Output (gt.output.js):
class Foo {
get bar() {
return this.foo?.bar > 9000;
}
}
Input (gte.input.js):
import { gte } from '@ember/object/computed';
class Foo {
@gte('foo.bar', 9000) bar;
}
Output (gte.output.js):
class Foo {
get bar() {
return this.foo?.bar >= 9000;
}
}
Input (ignore-object-syntax.input.js):
import Component from '@ember/component';
import { and, gt } from '@ember/object/computed';
export default Component.extend({
propAnd: and('x', 'y'),
propGt: gt('x', 123),
});
Output (ignore-object-syntax.output.js):
import Component from '@ember/component';
import { and, gt } from '@ember/object/computed';
export default Component.extend({
propAnd: and('x', 'y'),
propGt: gt('x', 123),
});
Input (lt.input.js):
import { lt } from '@ember/object/computed';
class Foo {
@lt('foo.bar', 9000) bar;
}
Output (lt.output.js):
class Foo {
get bar() {
return this.foo?.bar < 9000;
}
}
Input (lte.input.js):
import { lte } from '@ember/object/computed';
class Foo {
@lte('foo.bar', 9000) bar;
}
Output (lte.output.js):
class Foo {
get bar() {
return this.foo?.bar <= 9000;
}
}
Input (or.input.js):
import { or } from '@ember/object/computed';
class Foo {
@or('foo', 'bar') fooBar;
}
Output (or.output.js):
class Foo {
get fooBar() {
return this.foo || this.bar;
}
}
Input (read-only.input.js):
import { readOnly } from '@ember/object/computed';
class Foo {
@readOnly('foo.bar.thing') bar;
}
Output (read-only.output.js):
class Foo {
get bar() {
return this.foo?.bar?.thing;
}
}