Bug 1296618 - Part 3: Remove destructuring of [id, args] arrays. r?gandalf draft
authorStaś Małolepszy <stas@mozilla.com>
Thu, 25 Aug 2016 17:43:00 +0200
changeset 405646 73eec1e64bc48d1685969888f13a06529fa0506f
parent 405645 2632e11d4b5b9993fed07c4ee58858b5f81304bc
child 405647 aa811f01bc390f7f23f6bd7e116e4c53a8df71ec
push id27552
push usersmalolepszy@mozilla.com
push dateThu, 25 Aug 2016 21:48:38 +0000
reviewersgandalf
bugs1296618
milestone51.0a1
Bug 1296618 - Part 3: Remove destructuring of [id, args] arrays. r?gandalf MozReview-Commit-ID: K85vHThuacY
toolkit/content/l20n-chrome-xul.js
--- a/toolkit/content/l20n-chrome-xul.js
+++ b/toolkit/content/l20n-chrome-xul.js
@@ -236,20 +236,19 @@ class LocalizationObserver {
   getLocalizationForElement(elem) {
     return this.get(elem.getAttribute('data-l10n-bundle') || 'main');
   }
 
   getKeysForElements(elems) {
     return elems.map(elem => {
       const id = elem.getAttribute('data-l10n-id');
       const args = elem.getAttribute('data-l10n-args');
-
-      return args ?
-        [id, JSON.parse(args.replace(reHtml, match => htmlEntities[match]))] :
-        id;
+      const escapedArgs = args ?
+        JSON.parse(args.replace(reHtml, match => htmlEntities[match])) : null;
+      return [id, escapedArgs];
     });
   }
 
   getElementsTranslation(elemsByL10n) {
     return Promise.all(
       Array.from(elemsByL10n).map(
         ([l10n, elems]) => l10n.formatEntities(this.getKeysForElements(elems))
       )
@@ -289,20 +288,17 @@ class L10nError extends Error {
 function keysFromContext(ctx, keys, method, prev) {
   const errors = [];
   const translations = keys.map((key, i) => {
     if (prev && prev[i] && prev[i][1].length === 0) {
       // Use a previously formatted good value if there were no errors
       return prev[i];
     }
 
-    const [id, args] = Array.isArray(key) ?
-      key : [key, undefined];
-
-    const result = method(ctx, id, args);
+    const result = method(ctx, key[0], key[1]);
     errors.push(...result[1]);
     // XXX Depending on the kind of errors it might be better to return prev[i]
     // here;  for instance, when the current translation is completely missing
     return result;
   });
 
   return [translations, errors];
 }
@@ -393,18 +389,21 @@ class Localization {
 
   formatEntities(keys) {
     return this.interactive.then(
       bundles => this.formatWithFallback(bundles, keys, entityFromContext)
     );
   }
 
   formatValues(...keys) {
+    const keyTuples = keys.map(
+      key => Array.isArray(key) ? key : [key, null]
+    );
     return this.interactive.then(
-      bundles => this.formatWithFallback(bundles, keys, valueFromContext)
+      bundles => this.formatWithFallback(bundles, keyTuples, valueFromContext)
     );
   }
 
   formatValue(id, args) {
     return this.formatValues([id, args]).then(
       ([val]) => val
     );
   }