Bug 1291049 - allow non devtools prefs to be loaded in webpack prefs loader draft
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 22 Nov 2016 16:47:15 +0100
changeset 442572 7c4f34770fbcee5f766f94a56fc04603651daf6a
parent 442571 6f3aa6860b33d2fdb35938edeb9907248d7ecb1d
child 442573 e32296a6153bb0a4aeb1d71f7c7eef8415236156
push id36740
push userjdescottes@mozilla.com
push dateTue, 22 Nov 2016 20:25:49 +0000
bugs1291049
milestone53.0a1
Bug 1291049 - allow non devtools prefs to be loaded in webpack prefs loader MozReview-Commit-ID: KOWQsf2wRG6
devtools/client/webpack/prefs-loader.js
--- a/devtools/client/webpack/prefs-loader.js
+++ b/devtools/client/webpack/prefs-loader.js
@@ -1,13 +1,26 @@
 // Rewrite devtools.js or all.js, leaving just the relevant pref() calls.
 
 "use strict";
 
-const PREF_RX = new RegExp("^ *pref\\(\"devtools");
+const PREF_WHITELIST = [
+  "devtools",
+  "layout.css.grid.enabled"
+];
+
+const acceptLine = function (line) {
+  let matches = line.match(/^ *pref\("([^"]+)"/);
+  if (!matches || !matches[1]) {
+    return false;
+  }
+
+  let [, prefName] = matches;
+  return PREF_WHITELIST.some(filter => prefName.startsWith(filter));
+};
 
 module.exports = function (content) {
   this.cacheable && this.cacheable();
 
   // If we're reading devtools.js we have to do some reprocessing.
   // If we're reading all.js we just assume we can dump all the
   // conditionals.
   let isDevtools = this.request.endsWith("/devtools.js");
@@ -38,17 +51,17 @@ module.exports = function (content) {
           throw new Error("missing line in ifMap: " + line);
         }
         ignoring = !ifMap[line];
       } else if (line.startsWith("#else")) {
         ignoring = !ignoring;
       }
     }
 
-    if (continuation || (!ignoring && PREF_RX.test(line))) {
+    if (continuation || (!ignoring && acceptLine(line))) {
       newLines.push(line);
 
       // The call to pref(...); might span more than one line.
       continuation = !/\);/.test(line);
     }
   }
   return newLines.join("\n");
 };