Bug 1291049 - allow non devtools prefs to be loaded in webpack prefs loader;r=tromey draft
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 22 Nov 2016 16:47:15 +0100
changeset 446056 d7340153b73e51bb989fd45968bc59ca0fd54894
parent 446055 bbbdb782a33c6af2533c8fc2a94967563b7c0c43
child 538695 a560982b8ec23a58a585c4e732e65ef9c1b0252c
push id37689
push userjdescottes@mozilla.com
push dateWed, 30 Nov 2016 21:30:01 +0000
reviewerstromey
bugs1291049
milestone53.0a1
Bug 1291049 - allow non devtools prefs to be loaded in webpack prefs loader;r=tromey MozReview-Commit-ID: B6eJcqt7XLK
devtools/client/inspector/webpack/prefs-loader.js
--- a/devtools/client/inspector/webpack/prefs-loader.js
+++ b/devtools/client/inspector/webpack/prefs-loader.js
@@ -1,17 +1,30 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // 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");
@@ -42,17 +55,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");
 };