Migrate ember-addons from ES6 -> JS

Migrate ember-addons from ES6 -> JS

diff --git a/app/assets/javascripts/ember-addons/decorator-alias.js b/app/assets/javascripts/ember-addons/decorator-alias.js
new file mode 100644
index 0000000..327dc7a
--- /dev/null
+++ b/app/assets/javascripts/ember-addons/decorator-alias.js
@@ -0,0 +1,22 @@
+import extractValue from "./utils/extract-value";
+
+export default function decoratorAlias(fn, errorMessage) {
+  return function(...params) {
+    // determine if user called as @discourseComputed('blah', 'blah') or @discourseComputed
+    if (params.length === 0) {
+      throw new Error(errorMessage);
+    } else {
+      return function(target, key, desc) {
+        return {
+          enumerable: desc.enumerable,
+          configurable: desc.configurable,
+          writable: desc.writable,
+          initializer: function() {
+            var value = extractValue(desc);
+            return fn.apply(null, params.concat(value));
+          }
+        };
+      };
+    }
+  };
+}
diff --git a/app/assets/javascripts/ember-addons/decorator-alias.js.es6 b/app/assets/javascripts/ember-addons/decorator-alias.js.es6
deleted file mode 100644
index 327dc7a..0000000
--- a/app/assets/javascripts/ember-addons/decorator-alias.js.es6
+++ /dev/null
@@ -1,22 +0,0 @@
-import extractValue from "./utils/extract-value";
-
-export default function decoratorAlias(fn, errorMessage) {
-  return function(...params) {
-    // determine if user called as @discourseComputed('blah', 'blah') or @discourseComputed
-    if (params.length === 0) {
-      throw new Error(errorMessage);
-    } else {
-      return function(target, key, desc) {
-        return {
-          enumerable: desc.enumerable,
-          configurable: desc.configurable,
-          writable: desc.writable,
-          initializer: function() {
-            var value = extractValue(desc);
-            return fn.apply(null, params.concat(value));
-          }
-        };
-      };
-    }
-  };
-}
diff --git a/app/assets/javascripts/ember-addons/fmt.js b/app/assets/javascripts/ember-addons/fmt.js
new file mode 100644
index 0000000..b9c28e8
--- /dev/null
+++ b/app/assets/javascripts/ember-addons/fmt.js
@@ -0,0 +1,25 @@
+export default function(str, formats) {
+  let cachedFormats = formats;
+
+  if (!_.isArray(cachedFormats) || arguments.length > 2) {
+    cachedFormats = new Array(arguments.length - 1);
+
+    for (let i = 1, l = arguments.length; i < l; i++) {
+      cachedFormats[i - 1] = arguments[i];
+    }
+  }
+
+  // first, replace any ORDERED replacements.
+  let idx = 0; // the current index for non-numerical replacements
+  return str.replace(/%@([0-9]+)?/g, function(s, argIndex) {
+    argIndex = argIndex ? parseInt(argIndex, 10) - 1 : idx++;
+    s = cachedFormats[argIndex];
+    return typeof s === "string"
+      ? s
+      : s === null
+      ? "(null)"
+      : s === undefined
+      ? ""
+      : "" + s;
+  });
+}
diff --git a/app/assets/javascripts/ember-addons/fmt.js.es6 b/app/assets/javascripts/ember-addons/fmt.js.es6
deleted file mode 100644
index b9c28e8..0000000
--- a/app/assets/javascripts/ember-addons/fmt.js.es6
+++ /dev/null
@@ -1,25 +0,0 @@
-export default function(str, formats) {
-  let cachedFormats = formats;
-
-  if (!_.isArray(cachedFormats) || arguments.length > 2) {
-    cachedFormats = new Array(arguments.length - 1);
-
-    for (let i = 1, l = arguments.length; i < l; i++) {
-      cachedFormats[i - 1] = arguments[i];
-    }
-  }
-
-  // first, replace any ORDERED replacements.
-  let idx = 0; // the current index for non-numerical replacements
-  return str.replace(/%@([0-9]+)?/g, function(s, argIndex) {
-    argIndex = argIndex ? parseInt(argIndex, 10) - 1 : idx++;
-    s = cachedFormats[argIndex];
-    return typeof s === "string"
-      ? s
-      : s === null
-      ? "(null)"
-      : s === undefined
-      ? ""
-      : "" + s;
-  });
-}
diff --git a/app/assets/javascripts/ember-addons/macro-alias.js b/app/assets/javascripts/ember-addons/macro-alias.js
new file mode 100644
index 0000000..a882e96
--- /dev/null
+++ b/app/assets/javascripts/ember-addons/macro-alias.js
@@ -0,0 +1,24 @@
+import isDescriptor from "./utils/is-descriptor";
+
+function handleDescriptor(target, property, desc, fn, params = []) {
+  return {
+    enumerable: desc.enumerable,
+    configurable: desc.configurable,
+    writable: desc.writable,
+    initializer: function() {
+      return fn(...params);
+    }
+  };
+}
+
+export default function macroAlias(fn) {
+  return function(...params) {
+    if (isDescriptor(params[params.length - 1])) {
+      return handleDescriptor(...params, fn);
+    } else {
+      return function(target, property, desc) {
+        return handleDescriptor(target, property, desc, fn, params);
+      };
+    }
+  };
+}
diff --git a/app/assets/javascripts/ember-addons/macro-alias.js.es6 b/app/assets/javascripts/ember-addons/macro-alias.js.es6
deleted file mode 100644
index a882e96..0000000
--- a/app/assets/javascripts/ember-addons/macro-alias.js.es6
+++ /dev/null
@@ -1,24 +0,0 @@
-import isDescriptor from "./utils/is-descriptor";
-
-function handleDescriptor(target, property, desc, fn, params = []) {
-  return {
-    enumerable: desc.enumerable,
-    configurable: desc.configurable,
-    writable: desc.writable,
-    initializer: function() {
-      return fn(...params);
-    }
-  };
-}
-
-export default function macroAlias(fn) {
-  return function(...params) {
-    if (isDescriptor(params[params.length - 1])) {
-      return handleDescriptor(...params, fn);
-    } else {
-      return function(target, property, desc) {
-        return handleDescriptor(target, property, desc, fn, params);
-      };
-    }
-  };
-}
diff --git a/app/assets/javascripts/ember-addons/utils/extract-value.js b/app/assets/javascripts/ember-addons/utils/extract-value.js
new file mode 100644
index 0000000..839d2e9
--- /dev/null
+++ b/app/assets/javascripts/ember-addons/utils/extract-value.js
@@ -0,0 +1,5 @@
+export default function extractValue(desc) {
+  return (
+    desc.value || (typeof desc.initializer === "function" && desc.initializer())
+  );
+}
diff --git a/app/assets/javascripts/ember-addons/utils/extract-value.js.es6 b/app/assets/javascripts/ember-addons/utils/extract-value.js.es6
deleted file mode 100644
index 839d2e9..0000000
--- a/app/assets/javascripts/ember-addons/utils/extract-value.js.es6
+++ /dev/null
@@ -1,5 +0,0 @@
-export default function extractValue(desc) {
-  return (
-    desc.value || (typeof desc.initializer === "function" && desc.initializer())
-  );
-}
diff --git a/app/assets/javascripts/ember-addons/utils/handle-descriptor.js b/app/assets/javascripts/ember-addons/utils/handle-descriptor.js
new file mode 100644
index 0000000..e4899c9
--- /dev/null
+++ b/app/assets/javascripts/ember-addons/utils/handle-descriptor.js
@@ -0,0 +1,71 @@
+import { computed, get } from "@ember/object";
+import extractValue from "./extract-value";
+
+export default function handleDescriptor(target, key, desc, params = []) {
+  return {
+    enumerable: desc.enumerable,
+    configurable: desc.configurable,
+    writeable: desc.writeable,
+    initializer: function() {
+      let computedDescriptor;
+
+      if (desc.writable) {
+        var val = extractValue(desc);
+        if (typeof val === "object") {
+          let value = {};
+          if (val.get) {
+            value.get = callUserSuppliedGet(params, val.get);
+          }
+          if (val.set) {
+            value.set = callUserSuppliedSet(params, val.set);
+          }
+          computedDescriptor = value;
+        } else {
+          computedDescriptor = callUserSuppliedGet(params, val);
+        }
+      } else {
+        throw new Error(
+          "ember-computed-decorators does not support using getters and setters"
+        );
+      }
+
+      return computed.apply(null, params.concat(computedDescriptor));
+    }
+  };
+}
+
+function niceAttr(attr) {
+  const parts = attr.split(".");
+  let i;
+
+  for (i = 0; i < parts.length; i++) {
+    if (

[... diff too long, it was truncated ...]

GitHub sha: 4d190c93