Bug 1460606 - browser_parsable_css should not flag classnames with -- as properties;r=Gijs
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 10 May 2018 16:00:13 +0200
changeset 417733 6ee32ec8320b97f7d30958b5352a27c228609f1b
parent 417732 1fb6a87debfa0b498144406271c81e96fdc4270a
child 417734 64588dd6efa32cb71ce4a9602a6b87f51e8aebe9
push id33978
push userdluca@mozilla.com
push dateThu, 10 May 2018 21:54:47 +0000
treeherdermozilla-central@d302824da0ea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1460606
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1460606 - browser_parsable_css should not flag classnames with -- as properties;r=Gijs This allows to parse .application--empty { --test1: red; --test2: red; color: var(--test3); } and extract --test1, --test2, --test3, but not --empty. MozReview-Commit-ID: GNQaZq5k5JU
browser/base/content/test/static/browser_parsable_css.js
--- a/browser/base/content/test/static/browser_parsable_css.js
+++ b/browser/base/content/test/static/browser_parsable_css.js
@@ -257,17 +257,19 @@ function processCSSRules(sheet) {
     }
     if (!(rule instanceof CSSStyleRule))
       continue;
 
     // Extract urls from the css text.
     // Note: CSSStyleRule.cssText always has double quotes around URLs even
     //       when the original CSS file didn't.
     let urls = rule.cssText.match(/url\("[^"]*"\)/g);
-    let props = rule.cssText.match(/(var\()?(--[\w\-]+)/g);
+    // Extract props by searching all "--" preceeded by "var(" or a non-word
+    // character.
+    let props = rule.cssText.match(/(var\(|\W)(--[\w\-]+)/g);
     if (!urls && !props)
       continue;
 
     for (let url of (urls || [])) {
       // Remove the url(" prefix and the ") suffix.
       url = url.replace(/url\("(.*)"\)/, "$1");
       if (url.startsWith("data:"))
         continue;
@@ -285,18 +287,23 @@ function processCSSRules(sheet) {
       }
     }
 
     for (let prop of (props || [])) {
       if (prop.startsWith("var(")) {
         prop = prop.substring(4);
         let prevValue = customPropsToReferencesMap.get(prop) || 0;
         customPropsToReferencesMap.set(prop, prevValue + 1);
-      } else if (!customPropsToReferencesMap.has(prop)) {
-        customPropsToReferencesMap.set(prop, undefined);
+      } else {
+        // Remove the extra non-word character captured by the regular
+        // expression.
+        prop = prop.substring(1);
+        if (!customPropsToReferencesMap.has(prop)) {
+          customPropsToReferencesMap.set(prop, undefined);
+        }
       }
     }
   }
 }
 
 function chromeFileExists(aURI) {
   let available = 0;
   try {