Bug 1419301 - Make HTML comments removal in prettifyCSS faster; r=tromey

MozReview-Commit-ID: LG8GKccRlXr

--HG--
extra : rebase_source : 86eb5612f8264bbe4f765ab5baaea4db8c7a84a3
This commit is contained in:
Patrick Brosset 2017-12-01 16:58:48 +01:00
Родитель 334f5f8700
Коммит 2036033118
2 изменённых файлов: 25 добавлений и 2 удалений

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

@ -158,8 +158,13 @@ function prettifyCSS(text, ruleCount) {
prettifyCSS.LINE_SEPARATOR = (os === "WINNT" ? "\r\n" : "\n");
}
// remove initial and terminating HTML comments and surrounding whitespace
text = text.replace(/(?:^\s*<!--[\r\n]*)|(?:\s*-->\s*$)/g, "");
// Stylesheets may start and end with HTML comment tags (possibly with whitespaces
// before and after). Remove those first. Don't do anything there aren't any.
let trimmed = text.trim();
if (trimmed.startsWith("<!--")) {
text = trimmed.replace(/^<!--/, "").replace(/-->$/, "").trim();
}
let originalText = text;
text = text.trim();

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

@ -122,6 +122,24 @@ const TESTS_SPACE_INDENT = [
"}",
]
},
{ name: "HTML comments with some whitespace padding",
input: " \n\n\t <!--\n\n\t body {color:red} \n\n--> \t\n",
expected: [
"body {",
" color:red",
"}"
]
},
{ name: "HTML comments without whitespace padding",
input: "<!--body {color:red}-->",
expected: [
"body {",
" color:red",
"}"
]
},
];
function run_test() {