Bug 1225192 - remove leading whitespace before prettifying css; r=pbrosset

This commit is contained in:
Tom Tromey 2015-11-16 10:27:01 -07:00
Родитель 375dcc04c9
Коммит 8f69e173dd
2 изменённых файлов: 12 добавлений и 4 удалений

Просмотреть файл

@ -978,11 +978,13 @@ CssLogic.prettifyCSS = function(text, ruleCount) {
// remove initial and terminating HTML comments and surrounding whitespace
text = text.replace(/(?:^\s*<!--[\r\n]*)|(?:\s*-->\s*$)/g, "");
let originalText = text;
text = text.trim();
// don't attempt to prettify if there's more than one line per rule.
let lineCount = text.split("\n").length - 1;
if (ruleCount !== null && lineCount >= ruleCount) {
return text;
return originalText;
}
// We reformat the text using a simple state machine. The
@ -1139,7 +1141,7 @@ CssLogic.prettifyCSS = function(text, ruleCount) {
// the text.
if (pushbackToken && token && token.tokenType === "whitespace" &&
/\n/g.test(text.substring(token.startOffset, token.endOffset))) {
return text;
return originalText;
}
// Finally time for that newline.

Просмотреть файл

@ -7,7 +7,6 @@
const {CssLogic} = require("devtools/shared/styleinspector/css-logic");
const TESTS = [
{ name: "simple test",
input: "div { font-family:'Arial Black', Arial, sans-serif; }",
@ -29,7 +28,6 @@ const TESTS = [
{ name: "minified with trailing newline",
input: "\nbody{background:white;}div{font-size:4em;color:red}span{color:green;}\n",
expected: [
"",
"body {",
"\tbackground:white;",
"}",
@ -43,6 +41,14 @@ const TESTS = [
]
},
{ name: "leading whitespace",
input: "\n div{color: red;}",
expected: [
"div {",
"\tcolor: red;",
"}"
]
},
];
function run_test() {