From f0ef7de84c0360341458f9f7de34d49886c6c8bc Mon Sep 17 00:00:00 2001 From: GoalSmashers Date: Mon, 30 Sep 2013 16:58:34 +0200 Subject: [PATCH] Adds longer escape markers to speed up searching. --- lib/text/comments.js | 4 ++-- lib/text/escape-store.js | 2 ++ lib/text/expressions.js | 2 +- lib/text/free.js | 4 ++-- lib/text/urls.js | 2 +- test/unit-test.js | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/text/comments.js b/lib/text/comments.js index 7528b752..5667e7ec 100644 --- a/lib/text/comments.js +++ b/lib/text/comments.js @@ -1,10 +1,10 @@ var EscapeStore = require('./escape-store'); module.exports = function Comments(keepSpecialComments, keepBreaks, lineBreak) { - var comments = new EscapeStore('CSSCOMMENT'); + var comments = new EscapeStore('COMMENT'); return { - // Strip special comments (/*! ... */) by replacing them by __CSSCOMMENT__ marker + // Strip special comments (/*! ... */) by replacing them by a special marker // for further restoring. Plain comments are removed. It's done by scanning data using // String#indexOf scanning instead of regexps to speed up the process. escape: function(data) { diff --git a/lib/text/escape-store.js b/lib/text/escape-store.js index a4fded89..8c2f07f9 100644 --- a/lib/text/escape-store.js +++ b/lib/text/escape-store.js @@ -1,4 +1,6 @@ module.exports = function EscapeStore(placeholderRoot) { + placeholderRoot = 'ESCAPED_' + placeholderRoot + '_CLEAN_CSS'; + var placeholderToData = {}; var dataToPlaceholder = {}; var count = 0; diff --git a/lib/text/expressions.js b/lib/text/expressions.js index 948ef0eb..2ca193bc 100644 --- a/lib/text/expressions.js +++ b/lib/text/expressions.js @@ -34,7 +34,7 @@ module.exports = function Expressions() { }; return { - // Escapes expressions by replacing them by the __EXPRESSION__ + // Escapes expressions by replacing them by a special // marker for further restoring. It's done via string scanning // instead of regexps to speed up the process. escape: function(data) { diff --git a/lib/text/free.js b/lib/text/free.js index c66c4030..eb0f057e 100644 --- a/lib/text/free.js +++ b/lib/text/free.js @@ -1,7 +1,7 @@ var EscapeStore = require('./escape-store'); module.exports = function Free() { - var texts = new EscapeStore('CSSFREETEXT'); + var texts = new EscapeStore('FREE_TEXT'); var findNonEscapedEnd = function(data, matched, start) { var end = start; @@ -20,7 +20,7 @@ module.exports = function Free() { }; return { - // Strip content tags by replacing them by the __CSSFREETEXT__ + // Strip content tags by replacing them by the a special // marker for further restoring. It's done via string scanning // instead of regexps to speed up the process. escape: function(data) { diff --git a/lib/text/urls.js b/lib/text/urls.js index 669352ab..007e41d2 100644 --- a/lib/text/urls.js +++ b/lib/text/urls.js @@ -4,7 +4,7 @@ module.exports = function Urls() { var urls = new EscapeStore('URL'); return { - // Strip urls by replacing them by the __URL__ + // Strip urls by replacing them by a special // marker for further restoring. It's done via string scanning // instead of regexps to speed up the process. escape: function(data) { diff --git a/test/unit-test.js b/test/unit-test.js index 17eb951e..3c7a88bc 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -648,7 +648,7 @@ vows.describe('clean-units').addBatch({ 'keep urls from being stripped down #1': 'a{background:url(/image-1.0.png)}', 'keep urls from being stripped down #2': "a{background:url(/image-white.png)}", 'keep urls from being stripped down #3': "a{background:#eee url(/libraries/jquery-ui-1.10.1.custom/images/ui-bg_highlight-soft_100_eeeeee_1x100.png) 50% top repeat-x}", - 'keep __URL__ in comments (so order is important)': '/*! __URL__ */a{display:block}', + 'keep special markers in comments (so order is important)': '/*! __ESCAPED_URL_CLEAN_CSS0__ */a{display:block}', 'strip new line in urls': [ 'a{background:url(/very/long/\ path)}', -- 2.34.1