Bug 711401 - prettyify CSS source even if it has spaces or newlines at the end of file; r=jwalker
authorHeather Arthur <fayearthur@gmail.com>
Fri, 14 Mar 2014 15:03:37 -0700
changeset 190924 30f5d80302192e942c2e6e264ef55ee10e336c71
parent 190788 ecbac0e39fdd6684c2fe7e774bdc31a201169c65
child 190925 8106dd48d2e850d144225d9c15f7be10c4524f2f
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalker
bugs711401
milestone30.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 711401 - prettyify CSS source even if it has spaces or newlines at the end of file; r=jwalker
browser/devtools/styleeditor/StyleSheetEditor.jsm
browser/devtools/styleeditor/test/browser.ini
browser/devtools/styleeditor/test/minified.html
browser/devtools/styleeditor/test/pretty.css
--- a/browser/devtools/styleeditor/StyleSheetEditor.jsm
+++ b/browser/devtools/styleeditor/StyleSheetEditor.jsm
@@ -591,19 +591,19 @@ function prettifyCSS(text)
       case ";":
       case "{":
         shouldIndent = true;
         break;
     }
 
     if (shouldIndent) {
       let la = text[i+1]; // one-character lookahead
-      if (!/\s/.test(la)) {
-        // following character should be a new line (or whitespace) but it isn't
-        // force indentation then
+      if (!/\n/.test(la) || /^\s+$/.test(text.substring(i+1, text.length))) {
+        // following character should be a new line, but isn't,
+        // or it's whitespace at the end of the file
         parts.push(indent + text.substring(partStart, i + 1));
         if (c == "}") {
           parts.push(""); // for extra line separator
         }
         partStart = i + 1;
       } else {
         return text; // assume it is not minified, early exit
       }
--- a/browser/devtools/styleeditor/test/browser.ini
+++ b/browser/devtools/styleeditor/test/browser.ini
@@ -9,16 +9,17 @@ support-files =
   import2.css
   inline-1.html
   inline-2.html
   longload.html
   media-small.css
   media.html
   minified.html
   nostyle.html
+  pretty.css
   resources_inpage.jsi
   resources_inpage1.css
   resources_inpage2.css
   simple.css
   simple.css.gz
   simple.css.gz^headers^
   simple.gz.html
   simple.html
@@ -40,17 +41,15 @@ skip-if = os == "linux" || "mac" # bug 9
 [browser_styleeditor_import.js]
 [browser_styleeditor_import_rule.js]
 [browser_styleeditor_init.js]
 [browser_styleeditor_inline_friendly_names.js]
 [browser_styleeditor_loading.js]
 [browser_styleeditor_new.js]
 [browser_styleeditor_nostyle.js]
 [browser_styleeditor_pretty.js]
-# Disabled because of intermittent failures - See Bug 942473
-skip-if = true
 [browser_styleeditor_private_perwindowpb.js]
 [browser_styleeditor_reload.js]
 [browser_styleeditor_sv_keynav.js]
 [browser_styleeditor_sv_resize.js]
 [browser_styleeditor_selectstylesheet.js]
 [browser_styleeditor_sourcemaps.js]
 [browser_styleeditor_sourcemap_watching.js]
--- a/browser/devtools/styleeditor/test/minified.html
+++ b/browser/devtools/styleeditor/test/minified.html
@@ -1,15 +1,13 @@
 <!doctype html>
 <html>
 <head>
   <title>minified testcase</title>
-  <style type="text/css"><!--
-body{background:white;}div{font-size:4em;color:red}
---></style>
+  <link rel="stylesheet" href="pretty.css"/>
   <style type="text/css">body { background: red; }
 div {
 font-size: 5em;
 color: red
 }</style>
 </head>
 <body>
 	<div>minified <span>testcase</span></div>
new file mode 100644
--- /dev/null
+++ b/browser/devtools/styleeditor/test/pretty.css
@@ -0,0 +1,5 @@
+
+
+body{background:white;}div{font-size:4em;color:red}
+
+