Fixes #114 - removing comments from imported stylesheets.
authorGoalSmashers <jakub@goalsmashers.com>
Thu, 13 Jun 2013 19:08:59 +0000 (21:08 +0200)
committerGoalSmashers <jakub@goalsmashers.com>
Thu, 13 Jun 2013 19:11:05 +0000 (21:11 +0200)
History.md
lib/clean.js
test/data/partials/comment.css [new file with mode: 0644]
test/unit-test.js

index 1588ca8..551310f 100644 (file)
@@ -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
 ==================
 
index 2af9486..de6f989 100644 (file)
@@ -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 (file)
index 0000000..a44f49f
--- /dev/null
@@ -0,0 +1 @@
+/* comment to be stripped */
index 56e866a..a965694 100644 (file)
@@ -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({