From dc2130c940b0f9e1faab557542859f530db89116 Mon Sep 17 00:00:00 2001 From: GoalSmashers Date: Fri, 6 Sep 2013 09:24:27 +0200 Subject: [PATCH] Adds simplified comments processing & imports. --- History.md | 1 + lib/clean.js | 22 +++++++--------------- test/unit-test.js | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/History.md b/History.md index 8ec40055..b61db1a5 100644 --- a/History.md +++ b/History.md @@ -10,6 +10,7 @@ * Fixed issue [#130](https://github.com/GoalSmashers/clean-css/issues/130) - better code modularity. * Fixed issue [#135](https://github.com/GoalSmashers/clean-css/issues/135) - require node.js 0.8+. * Renamed lib's `debug` option to `benchmark` when doing per-minification benchmarking. +* Added simplified comments processing & imports. 1.0.12 / 2013-07-19 =================== diff --git a/lib/clean.js b/lib/clean.js index 20bb6930..e8f1ff53 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -63,17 +63,6 @@ var CleanCSS = { var urlsProcessor = new UrlsProcessor(); var importInliner = new ImportInliner(); - var removeComments = function() { - replace(function escapeComments() { - data = commentsProcessor.escape(data); - }); - }; - - removeComments(); - - // replace all escaped line breaks - replace(/\\(\r\n|\n)/mg, ''); - if (options.processImport) { // inline all imports replace(function inlineImports() { @@ -82,12 +71,15 @@ var CleanCSS = { relativeTo: options.relativeTo }); }); - - // strip comments with inlined imports - if (data.indexOf('/*') > -1) - removeComments(); } + replace(function escapeComments() { + data = commentsProcessor.escape(data); + }); + + // replace all escaped line breaks + replace(/\\(\r\n|\n)/mg, ''); + // strip parentheses in urls if possible (no spaces inside) replace(/url\((['"])([^\)]+)['"]\)/g, function(match, quote, url) { if (url.match(/[ \t]/g) !== null || url.indexOf('data:') === 0) diff --git a/test/unit-test.js b/test/unit-test.js index 2348035d..49e1776f 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -960,7 +960,7 @@ title']", ".five{background:url(data:image/jpeg;base64,/9j/)}" ], 'inside a comment': [ - '/* @import */a { color: red; }', + '/* @import url(test/data/partials/five.css); */a { color: red; }', 'a{color:red}' ], 'of a file with a comment': [ -- 2.34.1