Follow up to #86 - removing extra line break when cleaning up extra comments.
authorGoalSmashers <jakub@goalsmashers.com>
Sat, 30 Mar 2013 11:44:08 +0000 (12:44 +0100)
committerGoalSmashers <jakub@goalsmashers.com>
Sat, 30 Mar 2013 11:48:16 +0000 (12:48 +0100)
lib/clean.js
test/unit-test.js

index 3779351..c40642f 100644 (file)
@@ -321,13 +321,14 @@ var CleanCSS = {
     });
 
     var specialCommentsCount = context.specialComments.length;
-    replace(/__CSSCOMMENT__/g, function() {
+    var breakSuffix = options.keepBreaks ? lineBreak : '';
+    replace(new RegExp('__CSSCOMMENT__(' + lineBreak + ')?', 'g'), function() {
       switch (options.keepSpecialComments) {
         case '*':
-          return context.specialComments.shift();
+          return context.specialComments.shift() + breakSuffix;
         case 1:
           return context.specialComments.length == specialCommentsCount ?
-            context.specialComments.shift() :
+            context.specialComments.shift() + breakSuffix :
             '';
         case 0:
           return '';
index 1b2d7f6..6de079d 100644 (file)
@@ -165,6 +165,12 @@ vows.describe('clean-units').addBatch({
       "@charset 'utf-8';" + lineBreak + "a{}"
     ]
   }, { keepBreaks: true }),
+  'line breaks and important comments': cssContext({
+    'charset to beginning with comment removal': [
+      "/*! some comment */" + lineBreak + lineBreak + "@charset 'utf-8';" + lineBreak + lineBreak + "a{}",
+      "@charset 'utf-8';" + lineBreak + "a{}"
+    ]
+  }, { keepBreaks: true, keepSpecialComments: 0 }),
   'selectors': cssContext({
     'remove spaces around selectors': [
       'div + span >   em',