From: GoalSmashers Date: Thu, 13 Jun 2013 19:08:59 +0000 (+0200) Subject: Fixes #114 - removing comments from imported stylesheets. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=06081d2318992b8f693c65f792ee5daa051dc9bf;p=clean-css.git Fixes #114 - removing comments from imported stylesheets. --- diff --git a/History.md b/History.md index 1588ca8f..551310f8 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,8 @@ +1.0.10 / 2013-xx-xx +================== + +* Fixed issue [#114](https://github.com/GoalSmashers/clean-css/issues/114) - comments in imported stylesheets. + 1.0.9 / 2013-06-11 ================== diff --git a/lib/clean.js b/lib/clean.js index 2af9486c..de6f9898 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -74,13 +74,16 @@ var CleanCSS = { }; } + var removeComments = function() { + replace(function stripComments() { + data = CleanCSS._stripComments(context, data); + }); + }; + // replace all escaped line breaks replace(/\\(\r\n|\n)/mg, ''); - // strip comments one by one - replace(function stripComments() { - data = CleanCSS._stripComments(context, data); - }); + removeComments(); // inline all imports replace(function inlineImports() { @@ -90,6 +93,10 @@ var CleanCSS = { }); }); + // strip comments with inlined imports + if (data.indexOf('/*') > -1) + removeComments(); + // 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/data/partials/comment.css b/test/data/partials/comment.css new file mode 100644 index 00000000..a44f49f3 --- /dev/null +++ b/test/data/partials/comment.css @@ -0,0 +1 @@ +/* comment to be stripped */ diff --git a/test/unit-test.js b/test/unit-test.js index 56e866a6..a965694b 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -837,6 +837,10 @@ title']", 'inside a comment': [ '/* @import */a { color: red; }', 'a{color:red}' + ], + 'of a file with a comment': [ + '@import url(test/data/partials/comment.css);', + '' ] }), '@import with absolute paths': cssContext({