Skip to content

Latest commit

 

History

History
2359 lines (1931 loc) · 65.2 KB

File metadata and controls

2359 lines (1931 loc) · 65.2 KB

revert-macros

A codemod for turning macros from ember-awesome-macros & ember-macro-helpers into simple computed properties.

Currently ember-macro-helpers isn't fully compatible with Ember Octane (ember-macro-helpers#291). In addition, Glimmer tracked properties mitigate the need for those addons. If you heavily rely on those addons and want to follow Ember upgrades, this addon is for you!

Option Value Default Details
--with-fallbacks boolean false Some macros come with default values (eg. filterBy default to []) if the computed key is undefined. This option will keep the fallback behavior to avoid exceptions on async properties

Requirements

  • Node.js > 11

Usage

npx ember-macros-codemod revert-macros path/of/files/ or/some**/*glob.js

# or

yarn global add ember-macros-codemod
ember-macros-codemod revert-macros path/of/files/ or/some**/*glob.js

Input / Output


add

Input (add.input.js):

import Component from '@ember/component';
import { add, sum, or } from 'ember-awesome-macros';

export default Component.extend({
  prop1: add('a', 'b'),
  prop2: sum('a', 'b'),
  prop3: add(or('a', 'b'), 'c'),
  prop4: add('a', 'b', 'c'),
});

Output (add.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', 'b', function () {
    return get(this, "a") + get(this, "b");
  }),
  prop2: computed('a', 'b', function () {
    return get(this, "a") + get(this, "b");
  }),
  prop3: computed('a', 'b', 'c', function () {
    return (get(this, "a") || get(this, "b")) + get(this, "c");
  }),
  prop4: computed('a', 'b', 'c', function () {
    return get(this, "a") + get(this, "b") + get(this, "c");
  }),
});

and

Input (and.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { and, gt } from 'ember-awesome-macros';

export default Component.extend({
  prop1: and('a', 'b', 'c'),
  prop2: and('a', raw('b'), 'c'),
  prop3: and('a.b.c', 'd.e.f', 'g.h.i'),
  prop4: and(gt('a', 'd'), raw('b'), 'c'),
});

Output (and.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', 'b', 'c', function () {
    return get(this, "a") && get(this, "b") && get(this, "c");
  }),
  prop2: computed('a', 'c', function () {
    return get(this, "a") && 'b' && get(this, "c");
  }),
  prop3: computed('a.b.c', 'd.e.f', 'g.h.i', function () {
    return get(this, "a.b.c") && get(this, "d.e.f") && get(this, "g.h.i");
  }),
  prop4: computed('a', 'd', 'c', function () {
    return get(this, "a") > get(this, "d") && 'b' && get(this, "c");
  }),
});

array-any

Input (array-any.input.js):

import Component from '@ember/component';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.any('array', item => item.test),
});

Output (array-any.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.[]", function () {
    return get(this, "array").any(item => item.test);
  }),
});

array-compact

Input (array-compact.input.js):

import Component from '@ember/component';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.compact('array'),
});

Output (array-compact.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.[]", function () {
    return get(this, "array").compact();
  }),
});

array-concat

Input (array-concat.input.js):

import Component from '@ember/component';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.concat('array', 'array2'),
});

Output (array-concat.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.[]", "array2.[]", function () {
    return get(this, "array").concat(get(this, "array2"));
  }),
});

array-every

Input (array-every.input.js):

import Component from '@ember/component';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.every('array', item => item.test),
});

Output (array-every.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.[]", function () {
    return get(this, "array").every(item => item.test);
  }),
});

array-filter

Input (array-filter.input.js):

import Component from '@ember/component';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.filter('array', item => item.test === 2),
});

Output (array-filter.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.[]", function () {
    return get(this, "array").filter(item => item.test === 2);
  }),
});

array-filterBy

Input (array-filterBy.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.filterBy('array', raw('test'), 2),
  prop2: array.filterBy('array', raw('test')),
  prop3: array.filterBy('array', raw('test'), null),
  prop4: array.filterBy('array', raw('test'), true),
});

Output (array-filterBy.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.@each.test", function () {
    return get(this, "array").filterBy('test', 2);
  }),
  prop2: computed("array.@each.test", function () {
    return get(this, "array").filterBy('test');
  }),
  prop3: computed("array.@each.test", function () {
    return get(this, "array").filterBy('test', null);
  }),
  prop4: computed("array.@each.test", function () {
    return get(this, "array").filterBy('test', true);
  }),
});

array-find

Input (array-find.input.js):

import Component from '@ember/component';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.find('array', item => item.test === 2),
});

Output (array-find.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.[]", function () {
    return get(this, "array").find(item => item.test === 2);
  }),
});

array-findBy

Input (array-findBy.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.findBy('array', raw('test'), 2),
  prop2: array.findBy('array', raw('test')),
});

Output (array-findBy.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.@each.test", function () {
    return get(this, "array").findBy('test', 2);
  }),
  prop2: computed("array.@each.test", function () {
    return get(this, "array").findBy('test');
  }),
});

array-first

Input (array-first.input.js):

import Component from '@ember/component';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.first('array'),
});

Output (array-first.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.[]", function () {
    return get(this, "array")[0];
  }),
});

array-includes

Input (array-includes.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.includes('array', raw('item')),
  prop2: array.includes('array', 'item'),
});

Output (array-includes.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.[]", function () {
    return get(this, "array").includes('item');
  }),
  prop2: computed("array.[]", 'item', function () {
    return get(this, "array").includes(get(this, "item"));
  }),
});

array-indexOf

Input (array-indexOf.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.indexOf('array', raw('item')),
  prop2: array.indexOf('array', 'item'),
});

Output (array-indexOf.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.[]", function () {
    return get(this, "array").indexOf('item');
  }),
  prop2: computed("array.[]", 'item', function () {
    return get(this, "array").indexOf(get(this, "item"));
  }),
});

array-isAny

Input (array-isAny.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.isAny('array', raw('test'), 2),
  prop2: array.isAny('array', raw('test')),
});

Output (array-isAny.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.@each.test", function () {
    return get(this, "array").isAny('test', 2);
  }),
  prop2: computed("array.@each.test", function () {
    return get(this, "array").isAny('test');
  }),
});

array-isEvery

Input (array-isEvery.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.isEvery('array', raw('test'), 2),
  prop2: array.isEvery('array', raw('test')),
});

Output (array-isEvery.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.@each.test", function () {
    return get(this, "array").isEvery('test', 2);
  }),
  prop2: computed("array.@each.test", function () {
    return get(this, "array").isEvery('test');
  }),
});

array-join

Input (array-join.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.join('array', raw('sep')),
  prop2: array.join('array', 'sep'),
});

Output (array-join.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.[]", function () {
    return get(this, "array").join('sep');
  }),
  prop2: computed("array.[]", 'sep', function () {
    return get(this, "array").join(get(this, "sep"));
  }),
});

array-length

Input (array-length.input.js):

import Component from '@ember/component';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.length('array'),
});

Output (array-length.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.[]", function () {
    return get(this, "array").length;
  }),
});

array-map

Input (array-map.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.map('array', (item) => item.test),
});

Output (array-map.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.[]", function () {
    return get(this, "array").map((item) => item.test);
  }),
});

array-mapBy

Input (array-mapBy.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.mapBy('array', raw('test')),
});

Output (array-mapBy.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.@each.test", function () {
    return get(this, "array").mapBy('test');
  }),
});

array-objectAt

Input (array-objectAt.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.objectAt('array', raw(0)),
  prop2: array.objectAt('array', 'index'),
});

Output (array-objectAt.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.[]", function () {
    return get(this, "array").objectAt(0);
  }),
  prop2: computed("array.[]", 'index', function () {
    return get(this, "array").objectAt(get(this, "index"));
  }),
});

array-reduce

Input (array-reduce.input.js):

import Component from '@ember/component';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.reduce('array', (arr, cur, i) => arr.concat(cur, i), []),
  prop2: array.reduce('array', (acc, cur, i) => acc + cur),
});

Output (array-reduce.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.[]", function () {
    return get(this, "array").reduce((arr, cur, i) => arr.concat(cur, i), []);
  }),
  prop2: computed("array.[]", function () {
    return get(this, "array").reduce((acc, cur, i) => acc + cur);
  }),
});

array-rejectBy

Input (array-rejectBy.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.rejectBy('array', raw('test'), 2),
  prop2: array.rejectBy('array', raw('test')),
});

Output (array-rejectBy.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.@each.test", function () {
    return get(this, "array").rejectBy('test', 2);
  }),
  prop2: computed("array.@each.test", function () {
    return get(this, "array").rejectBy('test');
  }),
});

array-reverse

Input (array-reverse.input.js):

import Component from '@ember/component';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.reverse('array'),
});

Output (array-reverse.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.[]", function () {
    return get(this, "array").reverse();
  }),
});

array-slice

Input (array-slice.input.js):

import Component from '@ember/component';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.slice('array', 1, 2),
  prop2: array.slice('array', 1),
  prop3: array.slice('array', 'index'),
});

Output (array-slice.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.[]", function () {
    return get(this, "array").slice(1, 2);
  }),
  prop2: computed("array.[]", function () {
    return get(this, "array").slice(1);
  }),
  prop3: computed("array.[]", 'index', function () {
    return get(this, "array").slice(get(this, "index"));
  }),
});

array-sort

Input (array-sort.input.js):

import Component from '@ember/component';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.sort('array'),
  prop2: array.sort('array', (a, b) => a.key < b.key),
});

Output (array-sort.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.[]", function () {
    return get(this, "array").sort();
  }),
  prop2: computed("array.[]", function () {
    return get(this, "array").sort((a, b) => a.key < b.key);
  }),
});

array-uniq

Input (array-uniq.input.js):

import Component from '@ember/component';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.uniq('array'),
});

Output (array-uniq.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.[]", function () {
    return get(this, "array").uniq();
  }),
});

array-uniqBy

Input (array-uniqBy.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.uniqBy('array', raw('test')),
});

Output (array-uniqBy.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.@each.test", function () {
    return get(this, "array").uniqBy('test');
  }),
});

array-without

Input (array-without.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { array } from 'ember-awesome-macros';

export default Component.extend({
  prop1: array.without('array', 'item'),
  prop2: array.without('array', raw('item')),
});

Output (array-without.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed("array.[]", 'item', function () {
    return get(this, "array").without(get(this, "item"));
  }),
  prop2: computed("array.[]", function () {
    return get(this, "array").without('item');
  }),
});

basic

Input (basic.input.js):

Output (basic.output.js):


bool

Input (bool.input.js):

import Component from '@ember/component';
import { bool, conditional } from 'ember-awesome-macros';

export default Component.extend({
  prop1: bool('a'),
  prop2: bool(conditional('a', 'b', 'c')),
});

Output (bool.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', function () {
    return !!get(this, "a");
  }),
  prop2: computed('a', 'b', 'c', function () {
    return !!(get(this, "a") ? get(this, "b") : get(this, "c"));
  }),
});

cleanup-import-1

Input (cleanup-import-1.input.js):

import Component from '@ember/component';
import { computed } from '@ember/object';
import comp from 'ember-macro-helpers/computed';

export default Component.extend({
  prop1: comp('a', (a) => {
    // do something
    return a;
  }),
});

Output (cleanup-import-1.output.js):

import Component from '@ember/component';
import { computed, get } from '@ember/object';

export default Component.extend({
  prop1: computed('a', function () {
    let a = get(this, "a");
    // do something
    return a;
  }),
});

cleanup-import-2

Input (cleanup-import-2.input.js):

import Component from '@ember/component';
import { get } from '@ember/object';
import comp from 'ember-macro-helpers/computed';

export default Component.extend({
  prop1: comp('a', (a) => {
    // do something
    return a;
  }),
});

Output (cleanup-import-2.output.js):

import Component from '@ember/component';
import { get, computed } from '@ember/object';

export default Component.extend({
  prop1: computed('a', function () {
    let a = get(this, "a");
    // do something
    return a;
  }),
});

collect

Input (collect.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { collect } from 'ember-awesome-macros';

export default Component.extend({
  prop1: collect('a', 'b', 'c'),
  prop2: collect('a', raw('b'), 'c'),
});

Output (collect.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', 'b', 'c', function () {
    return [get(this, "a"), get(this, "b"), get(this, "c")];
  }),
  prop2: computed('a', 'c', function () {
    return [get(this, "a"), 'b', get(this, "c")];
  }),
});

comp

Input (comp.input.js):

import Component from '@ember/component';
import comp from 'ember-macro-helpers/computed';

export default Component.extend({
  prop1: comp('a', (a) => {
    // do something
    return a;
  }),
  prop2: comp('a', 'b', 'c', (a, b, c) => {
    // do something
    return a + b + c;
  }),
  prop3: comp('a.[]', 'b.@each.c', (a, b) => {
    // do something
    return a + b;
  }),
  prop4: comp('a.b.c', (c) => {
    // do something
    return c;
  }),

  prop5: comp('a', (foo) => {
    // do something
    return foo;
  }),
  prop6: comp('a', 'b', 'c', (foo, bar, baz) => {
    // do something
    return foo + bar + baz;
  }),
  prop7: comp('a.[]', 'b.@each.c', (foo, bar) => {
    // do something
    return foo + bar;
  }),
  prop8: comp('a.b.c', (foo) => {
    // do something
    return foo;
  }),

  prop9: comp('a', (foo) => foo),
  prop10: comp(() => foo()),

  prop11: comp('a.{b,c}', 'd.e.{f}', 'g.h.{i,j,k}', (b, c, f, i, j, k) => {
    return b + c + f + i + j + k;
  })
});

Output (comp.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', function () {
    let a = get(this, "a");
    // do something
    return a;
  }),
  prop2: computed('a', 'b', 'c', function () {
    let a = get(this, "a");
    let b = get(this, "b");
    let c = get(this, "c");
    // do something
    return a + b + c;
  }),
  prop3: computed('a.[]', 'b.@each.c', function () {
    let a = get(this, "a");
    let b = get(this, "b");
    // do something
    return a + b;
  }),
  prop4: computed('a.b.c', function () {
    let c = get(this, "a.b.c");
    // do something
    return c;
  }),

  prop5: computed('a', function () {
    let foo = get(this, "a");
    // do something
    return foo;
  }),
  prop6: computed('a', 'b', 'c', function () {
    let foo = get(this, "a");
    let bar = get(this, "b");
    let baz = get(this, "c");
    // do something
    return foo + bar + baz;
  }),
  prop7: computed('a.[]', 'b.@each.c', function () {
    let foo = get(this, "a");
    let bar = get(this, "b");
    // do something
    return foo + bar;
  }),
  prop8: computed('a.b.c', function () {
    let foo = get(this, "a.b.c");
    // do something
    return foo;
  }),

  prop9: computed('a', function () {
    let foo = get(this, "a");
    return foo;
  }),
  prop10: computed(function () {
    return foo();
  }),

  prop11: computed('a.{b,c}', 'd.e.{f}', 'g.h.{i,j,k}', function () {
    let b = get(this, "a.b");
    let c = get(this, "a.c");
    let f = get(this, "d.e.f");
    let i = get(this, "g.h.i");
    let j = get(this, "g.h.j");
    let k = get(this, "g.h.k");
    return b + c + f + i + j + k;
  })
});

conditional

Input (conditional.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { conditional, gt } from 'ember-awesome-macros';

export default Component.extend({
  prop1: conditional('a', 'b', 'c'),
  prop2: conditional('a', raw('b'), 'c'),
  prop3: conditional('a.b.c', 'd.e.f', 'g.h.i'),
  prop4: conditional(gt('a', 'd'), raw('b'), 'c'),
  prop5: conditional('a', 'b'),
  prop6: conditional('a', 'a', 'c'),
});

Output (conditional.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', 'b', 'c', function () {
    return get(this, "a") ? get(this, "b") : get(this, "c");
  }),
  prop2: computed('a', 'c', function () {
    return get(this, "a") ? 'b' : get(this, "c");
  }),
  prop3: computed('a.b.c', 'd.e.f', 'g.h.i', function () {
    return get(this, "a.b.c") ? get(this, "d.e.f") : get(this, "g.h.i");
  }),
  prop4: computed('a', 'd', 'c', function () {
    return get(this, "a") > get(this, "d") ? 'b' : get(this, "c");
  }),
  prop5: computed('a', 'b', function () {
    return get(this, "a") ? get(this, "b") : undefined;
  }),
  prop6: computed('a', 'c', function () {
    return get(this, "a") ? get(this, "a") : get(this, "c");
  }),
});

difference

Input (difference.input.js):

import Component from '@ember/component';
import { difference, substract, or } from 'ember-awesome-macros';

export default Component.extend({
  prop1: difference('a', 'b'),
  prop2: substract('a', 'b'),
  prop3: difference(or('a', 'b'), 'c'),
  prop4: difference('a', 'b', 'c'),
});

Output (difference.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', 'b', function () {
    return get(this, "a") - get(this, "b");
  }),
  prop2: computed('a', 'b', function () {
    return get(this, "a") - get(this, "b");
  }),
  prop3: computed('a', 'b', 'c', function () {
    return (get(this, "a") || get(this, "b")) - get(this, "c");
  }),
  prop4: computed('a', 'b', 'c', function () {
    return get(this, "a") - get(this, "b") - get(this, "c");
  }),
});

divide

Input (divide.input.js):

import Component from '@ember/component';
import { divide, quotient, or } from 'ember-awesome-macros';

export default Component.extend({
  prop1: divide('a', 'b'),
  prop2: quotient('a', 'b'),
  prop3: divide(or('a', 'b'), 'c'),
  prop4: divide('a', 'b', 'c'),
});

Output (divide.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', 'b', function () {
    return get(this, "a") / get(this, "b");
  }),
  prop2: computed('a', 'b', function () {
    return get(this, "a") / get(this, "b");
  }),
  prop3: computed('a', 'b', 'c', function () {
    return (get(this, "a") || get(this, "b")) / get(this, "c");
  }),
  prop4: computed('a', 'b', 'c', function () {
    return get(this, "a") / get(this, "b") / get(this, "c");
  }),
});

eq

Input (eq.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { eq, gt } from 'ember-awesome-macros';

export default Component.extend({
  prop1: eq('a', 'b'),
  prop2: eq('a', 'b', 'c'),
  prop3: eq(gt('a', 'b'), raw('c'), 'd'),
  prop4: eq('a', 4),
  prop5: eq('a', -1),
});

Output (eq.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', 'b', function () {
    return get(this, "a") === get(this, "b");
  }),
  prop2: computed('a', 'b', 'c', function () {
    return get(this, "a") === get(this, "b") && get(this, "a") === get(this, "c");
  }),
  prop3: computed('a', 'b', 'd', function () {
    return get(this, "a") > get(this, "b") === 'c' && get(this, "a") > get(this, "b") === get(this, "d");
  }),
  prop4: computed('a', function () {
    return get(this, "a") === 4;
  }),
  prop5: computed('a', function () {
    return get(this, "a") === -1;
  }),
});

getBy

Input (getBy.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { getBy } from 'ember-awesome-macros';

export default Component.extend({
  prop1: getBy('obj', 'key'),
  prop2: getBy('obj', raw('key')),
});

Output (getBy.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('obj', 'key', function () {
    return get(get(this, "obj"), get(this, "key"));
  }),
  prop2: computed('obj', function () {
    return get(get(this, "obj"), 'key');
  }),
});

gt

Input (gt.input.js):

import Component from '@ember/component';
import { gt, add } from 'ember-awesome-macros';

export default Component.extend({
  prop1: gt('a', 'b'),
  prop2: gt(add('a', 'b'), 'c'),
});

Output (gt.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', 'b', function () {
    return get(this, "a") > get(this, "b");
  }),
  prop2: computed('a', 'b', 'c', function () {
    return get(this, "a") + get(this, "b") > get(this, "c");
  }),
});

gte

Input (gte.input.js):

import Component from '@ember/component';
import { gte, add } from 'ember-awesome-macros';

export default Component.extend({
  prop1: gte('a', 'b'),
  prop2: gte(add('a', 'b'), 'c'),
});

Output (gte.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', 'b', function () {
    return get(this, "a") >= get(this, "b");
  }),
  prop2: computed('a', 'b', 'c', function () {
    return get(this, "a") + get(this, "b") >= get(this, "c");
  }),
});

isEmpty

Input (isEmpty.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { array, isEmpty } from 'ember-awesome-macros';

export default Component.extend({
  prop1: isEmpty('string'),
  prop2: isEmpty(array.join('array', raw(','))),
});

Output (isEmpty.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('string', function () {
    return isEmpty(get(this, "string"));
  }),
  prop2: computed("array.[]", function () {
    return isEmpty(get(this, "array").join(','));
  }),
});

lt

Input (lt.input.js):

import Component from '@ember/component';
import { lt, add } from 'ember-awesome-macros';

export default Component.extend({
  prop1: lt('a', 'b'),
  prop2: lt(add('a', 'b'), 'c'),
});

Output (lt.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', 'b', function () {
    return get(this, "a") < get(this, "b");
  }),
  prop2: computed('a', 'b', 'c', function () {
    return get(this, "a") + get(this, "b") < get(this, "c");
  }),
});

lte

Input (lte.input.js):

import Component from '@ember/component';
import { lte, add } from 'ember-awesome-macros';

export default Component.extend({
  prop1: lte('a', 'b'),
  prop2: lte(add('a', 'b'), 'c'),
});

Output (lte.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', 'b', function () {
    return get(this, "a") <= get(this, "b");
  }),
  prop2: computed('a', 'b', 'c', function () {
    return get(this, "a") + get(this, "b") <= get(this, "c");
  }),
});

multiply

Input (multiply.input.js):

import Component from '@ember/component';
import { multiply, product, or } from 'ember-awesome-macros';

export default Component.extend({
  prop1: multiply('a', 'b'),
  prop2: product('a', 'b'),
  prop3: multiply(or('a', 'b'), 'c'),
  prop4: multiply('a', 'b', 'c'),
});

Output (multiply.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', 'b', function () {
    return get(this, "a") * get(this, "b");
  }),
  prop2: computed('a', 'b', function () {
    return get(this, "a") * get(this, "b");
  }),
  prop3: computed('a', 'b', 'c', function () {
    return (get(this, "a") || get(this, "b")) * get(this, "c");
  }),
  prop4: computed('a', 'b', 'c', function () {
    return get(this, "a") * get(this, "b") * get(this, "c");
  }),
});

nand

Input (nand.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { nand, gt } from 'ember-awesome-macros';

export default Component.extend({
  prop1: nand('a', 'b', 'c'),
  prop2: nand('a', raw('b'), 'c'),
  prop3: nand('a.b.c', 'd.e.f', 'g.h.i'),
  prop4: nand(gt('a', 'd'), raw('b'), 'c'),
});

Output (nand.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', 'b', 'c', function () {
    return !(get(this, "a") && get(this, "b") && get(this, "c"));
  }),
  prop2: computed('a', 'c', function () {
    return !(get(this, "a") && 'b' && get(this, "c"));
  }),
  prop3: computed('a.b.c', 'd.e.f', 'g.h.i', function () {
    return !(get(this, "a.b.c") && get(this, "d.e.f") && get(this, "g.h.i"));
  }),
  prop4: computed('a', 'd', 'c', function () {
    return !(get(this, "a") > get(this, "d") && 'b' && get(this, "c"));
  }),
});

neq

Input (neq.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { neq, gt } from 'ember-awesome-macros';

export default Component.extend({
  prop1: neq('a', 'b'),
  prop2: neq('a', 'b', 'c'),
  prop3: neq(gt('a', 'b'), raw('c'), 'd'),
});

Output (neq.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', 'b', function () {
    return get(this, "a") !== get(this, "b");
  }),
  prop2: computed('a', 'b', 'c', function () {
    return get(this, "a") !== get(this, "b") && get(this, "a") !== get(this, "c");
  }),
  prop3: computed('a', 'b', 'd', function () {
    return get(this, "a") > get(this, "b") !== 'c' && get(this, "a") > get(this, "b") !== get(this, "d");
  }),
});

nor

Input (nor.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { nor, gt } from 'ember-awesome-macros';

export default Component.extend({
  prop1: nor('a', 'b', 'c'),
  prop2: nor('a', raw('b'), 'c'),
  prop3: nor('a.b.c', 'd.e.f', 'g.h.i'),
  prop4: nor(gt('a', 'd'), raw('b'), 'c'),
});

Output (nor.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', 'b', 'c', function () {
    return !(get(this, "a") || get(this, "b") || get(this, "c"));
  }),
  prop2: computed('a', 'c', function () {
    return !(get(this, "a") || 'b' || get(this, "c"));
  }),
  prop3: computed('a.b.c', 'd.e.f', 'g.h.i', function () {
    return !(get(this, "a.b.c") || get(this, "d.e.f") || get(this, "g.h.i"));
  }),
  prop4: computed('a', 'd', 'c', function () {
    return !(get(this, "a") > get(this, "d") || 'b' || get(this, "c"));
  }),
});

not

Input (not.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { gt, not } from 'ember-awesome-macros';

export default Component.extend({
  prop1: not('a'),
  prop2: not(gt('a', 'b')),
});

Output (not.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', function () {
    return !get(this, "a");
  }),
  prop2: computed('a', 'b', function () {
    return !(get(this, "a") > get(this, "b"));
  }),
});

notEmpty

Input (notEmpty.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { array, notEmpty } from 'ember-awesome-macros';

export default Component.extend({
  prop1: notEmpty('string'),
  prop2: notEmpty(array.join('array', raw(','))),
});

Output (notEmpty.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('string', function () {
    return !isEmpty(get(this, "string"));
  }),
  prop2: computed("array.[]", function () {
    return !isEmpty(get(this, "array").join(','));
  }),
});

or

Input (or.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { or, gt } from 'ember-awesome-macros';

export default Component.extend({
  prop1: or('a', 'b', 'c'),
  prop2: or('a', raw('b'), 'c'),
  prop3: or('a.b.c', 'd.e.f', 'g.h.i'),
  prop4: or(gt('a', 'd'), raw('b'), 'c'),
});

Output (or.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', 'b', 'c', function () {
    return get(this, "a") || get(this, "b") || get(this, "c");
  }),
  prop2: computed('a', 'c', function () {
    return get(this, "a") || 'b' || get(this, "c");
  }),
  prop3: computed('a.b.c', 'd.e.f', 'g.h.i', function () {
    return get(this, "a.b.c") || get(this, "d.e.f") || get(this, "g.h.i");
  }),
  prop4: computed('a', 'd', 'c', function () {
    return get(this, "a") > get(this, "d") || 'b' || get(this, "c");
  }),
});

parseFloat

Input (parseFloat.input.js):

import Component from '@ember/component';
import { parseFloat, conditional } from 'ember-awesome-macros';

export default Component.extend({
  prop1: parseFloat('a'),
  prop2: parseFloat(conditional('a', 'b', 'c')),
});

Output (parseFloat.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', function () {
    return parseFloat(get(this, "a"));
  }),
  prop2: computed('a', 'b', 'c', function () {
    return parseFloat(get(this, "a") ? get(this, "b") : get(this, "c"));
  }),
});

parseInt

Input (parseInt.input.js):

import Component from '@ember/component';
import { parseInt, conditional } from 'ember-awesome-macros';

export default Component.extend({
  prop1: parseInt('a'),
  prop2: parseInt(conditional('a', 'b', 'c')),
  prop3: parseInt(conditional('a', 'b', 'c'), 1),
});

Output (parseInt.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', function () {
    return parseInt(get(this, "a"));
  }),
  prop2: computed('a', 'b', 'c', function () {
    return parseInt(get(this, "a") ? get(this, "b") : get(this, "c"));
  }),
  prop3: computed('a', 'b', 'c', function () {
    return parseInt(get(this, "a") ? get(this, "b") : get(this, "c"), 1);
  }),
});

real-case-1

Input (real-case-1.input.js):

Output (real-case-1.output.js):


string-camelize

Input (string-camelize.input.js):

import Component from '@ember/component';
import { array, string } from 'ember-awesome-macros';

export default Component.extend({
  prop1: string.camelize('string'),
  prop2: string.camelize(array.join('array')),
});

Output (string-camelize.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('string', function () {
    return get(this, "string").camelize();
  }),
  prop2: computed("array.[]", function () {
    return get(this, "array").join().camelize();
  }),
});

string-capitalize

Input (string-capitalize.input.js):

import Component from '@ember/component';
import { array, string } from 'ember-awesome-macros';

export default Component.extend({
  prop1: string.capitalize('string'),
  prop2: string.capitalize(array.join('array')),
});

Output (string-capitalize.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('string', function () {
    return get(this, "string").capitalize();
  }),
  prop2: computed("array.[]", function () {
    return get(this, "array").join().capitalize();
  }),
});

string-classify

Input (string-classify.input.js):

import Component from '@ember/component';
import { array, string } from 'ember-awesome-macros';

export default Component.extend({
  prop1: string.classify('string'),
  prop2: string.classify(array.join('array')),
});

Output (string-classify.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('string', function () {
    return get(this, "string").classify();
  }),
  prop2: computed("array.[]", function () {
    return get(this, "array").join().classify();
  }),
});

string-dasherize

Input (string-dasherize.input.js):

import Component from '@ember/component';
import { array, string } from 'ember-awesome-macros';

export default Component.extend({
  prop1: string.dasherize('string'),
  prop2: string.dasherize(array.join('array')),
});

Output (string-dasherize.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('string', function () {
    return get(this, "string").dasherize();
  }),
  prop2: computed("array.[]", function () {
    return get(this, "array").join().dasherize();
  }),
});

string-decamelize

Input (string-decamelize.input.js):

import Component from '@ember/component';
import { array, string } from 'ember-awesome-macros';

export default Component.extend({
  prop1: string.decamelize('string'),
  prop2: string.decamelize(array.join('array')),
});

Output (string-decamelize.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('string', function () {
    return get(this, "string").decamelize();
  }),
  prop2: computed("array.[]", function () {
    return get(this, "array").join().decamelize();
  }),
});

string-htmlSafe

Input (string-htmlSafe.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { array, string } from 'ember-awesome-macros';

export default Component.extend({
  prop1: string.htmlSafe('string'),
  prop2: string.htmlSafe(array.join('array', raw(','))),
});

Output (string-htmlSafe.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('string', function () {
    return htmlSafe(get(this, "string"));
  }),
  prop2: computed("array.[]", function () {
    return htmlSafe(get(this, "array").join(','));
  }),
});

string-indexOf

Input (string-indexOf.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { string } from 'ember-awesome-macros';

export default Component.extend({
  prop1: string.indexOf('string', raw('item')),
  prop2: string.indexOf('string', 'item'),
});

Output (string-indexOf.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('string', function () {
    return get(this, "string").indexOf('item');
  }),
  prop2: computed('string', 'item', function () {
    return get(this, "string").indexOf(get(this, "item"));
  }),
});

string-length

Input (string-length.input.js):

import Component from '@ember/component';
import { string } from 'ember-awesome-macros';

export default Component.extend({
  prop1: string.length('string'),
});

Output (string-length.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('string', function () {
    return get(this, "string").length;
  }),
});

string-split

Input (string-split.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { array, string } from 'ember-awesome-macros';

export default Component.extend({
  prop1: string.split('string', 'key'),
  prop2: string.split(array.join('array'), raw(',')),
});

Output (string-split.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('string', 'key', function () {
    return get(this, "string").split(get(this, "key"));
  }),
  prop2: computed("array.[]", function () {
    return get(this, "array").join().split(',');
  }),
});

string-substr

Input (string-substr.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { array, string } from 'ember-awesome-macros';

export default Component.extend({
  prop1: string.substr('string', 'key'),
  prop2: string.substr('string', 1),
  prop3: string.substr(array.join('array'), 1, 2),
});

Output (string-substr.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('string', 'key', function () {
    return get(this, "string").substr(get(this, "key"));
  }),
  prop2: computed('string', function () {
    return get(this, "string").substr(1);
  }),
  prop3: computed("array.[]", function () {
    return get(this, "array").join().substr(1, 2);
  }),
});

string-substring

Input (string-substring.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { array, string } from 'ember-awesome-macros';

export default Component.extend({
  prop1: string.substring('string', 'key'),
  prop2: string.substring('string', 1),
  prop3: string.substring(array.join('array'), 1, 2),
});

Output (string-substring.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('string', 'key', function () {
    return get(this, "string").substring(get(this, "key"));
  }),
  prop2: computed('string', function () {
    return get(this, "string").substring(1);
  }),
  prop3: computed("array.[]", function () {
    return get(this, "array").join().substring(1, 2);
  }),
});

string-toLower

Input (string-toLower.input.js):

import Component from '@ember/component';
import { array, string } from 'ember-awesome-macros';

export default Component.extend({
  prop1: string.toLower('string'),
  prop2: string.toLower(array.join('array')),
});

Output (string-toLower.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('string', function () {
    return get(this, "string").toLowerCase();
  }),
  prop2: computed("array.[]", function () {
    return get(this, "array").join().toLowerCase();
  }),
});

string-toUpper

Input (string-toUpper.input.js):

import Component from '@ember/component';
import { array, string } from 'ember-awesome-macros';

export default Component.extend({
  prop1: string.toUpper('string'),
  prop2: string.toUpper(array.join('array')),
});

Output (string-toUpper.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('string', function () {
    return get(this, "string").toUpperCase();
  }),
  prop2: computed("array.[]", function () {
    return get(this, "array").join().toUpperCase();
  }),
});

tag

Input (tag.input.js):

import Component from '@ember/component';
import { tag, string } from 'ember-awesome-macros';

export default Component.extend({
  prop1: tag`${'a'}`,
  prop2: tag`foo${'a'}`,
  prop3: tag`foo${'a'}bar`,
  prop4: tag`foo${'a'}bar${'b'}`,
  prop5: tag`foo${'a'}bar${'a'}`,
  prop6: tag`one ${string.toUpper('source')} three`,
  prop7: string.toUpper(tag`one ${'source'} three`),
});

Output (tag.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', function () {
    return `${get(this, "a")}`;
  }),
  prop2: computed('a', function () {
    return `foo${get(this, "a")}`;
  }),
  prop3: computed('a', function () {
    return `foo${get(this, "a")}bar`;
  }),
  prop4: computed('a', 'b', function () {
    return `foo${get(this, "a")}bar${get(this, "b")}`;
  }),
  prop5: computed('a', function () {
    return `foo${get(this, "a")}bar${get(this, "a")}`;
  }),
  prop6: computed('source', function () {
    return `one ${get(this, "source").toUpperCase()} three`;
  }),
  prop7: computed('source', function () {
    return `one ${get(this, "source")} three`.toUpperCase();
  }),
});

unless

Input (unless.input.js):

import Component from '@ember/component';
import raw from 'ember-macro-helpers/raw';
import { unless, gt } from 'ember-awesome-macros';

export default Component.extend({
  prop1: unless('a', 'b', 'c'),
  prop2: unless('a', raw('b'), 'c'),
  prop3: unless('a.b.c', 'd.e.f', 'g.h.i'),
  prop4: unless(gt('a', 'd'), raw('b'), 'c'),
});

Output (unless.output.js):

import { computed, get } from '@ember/object';
import Component from '@ember/component';

export default Component.extend({
  prop1: computed('a', 'b', 'c', function () {
    return !get(this, "a") ? get(this, "b") : get(this, "c");
  }),
  prop2: computed('a', 'c', function () {
    return !get(this, "a") ? 'b' : get(this, "c");
  }),
  prop3: computed('a.b.c', 'd.e.f', 'g.h.i', function () {
    return !get(this, "a.b.c") ? get(this, "d.e.f") : get(this, "g.h.i");
  }),
  prop4: computed('a', 'd', 'c', function () {
    return !(get(this, "a") > get(this, "d")) ? 'b' : get(this, "c");
  }),
});