Some speed optimization.
authorGoalSmashers <jakub@goalsmashers.com>
Sun, 18 Nov 2012 12:01:39 +0000 (12:01 +0000)
committerGoalSmashers <jakub@goalsmashers.com>
Sun, 18 Nov 2012 12:01:39 +0000 (12:01 +0000)
lib/clean.js
test/unit-test.js

index a8e4372..7a3b109 100644 (file)
@@ -24,6 +24,7 @@ var CleanCSS = {
       else
         data = data.replace.apply(data, arguments);
     };
+    var lineBreak = process.platform == 'win32' ? '\r\n' : '\n';
 
     options = options || {};
 
@@ -81,8 +82,8 @@ var CleanCSS = {
     replace(/;[ ]?;+/g, ';');
 
     // multiple line breaks to one
-    replace(/ (\r\n|\n)/g, '$1');
-    replace(/(\r\n|\n)+/g, '$1');
+    replace(/ (?:\r\n|\n)/g, lineBreak);
+    replace(/(?:\r\n|\n)+/g, lineBreak);
 
     // remove spaces around selectors
     replace(/ ([+~>]) /g, '$1');
@@ -149,7 +150,7 @@ var CleanCSS = {
 
     // zero + unit to zero
     replace(/(\s|:|,)0(px|em|ex|cm|mm|in|pt|pc|%)/g, '$1' + '0');
-    replace(/rect\(0(px|em|ex|cm|mm|in|pt|pc|%)/g, 'rect(0');
+    replace(/rect\(0(?:px|em|ex|cm|mm|in|pt|pc|%)/g, 'rect(0');
 
     // none to 0
     replace(/(border|border-top|border-right|border-bottom|border-left|outline):none/g, '$1:0');
index ae8e0cf..068f320 100644 (file)
@@ -2,6 +2,7 @@ var vows = require('vows'),
   assert = require('assert'),
   cleanCSS = require('../index');
 
+var lineBreak = process.platform == 'win32' ? '\r\n' : '\n';
 var cssContext = function(groups, options) {
   var context = {};
   var clean = function(cleanedCSS) {
@@ -117,15 +118,21 @@ vows.describe('clean-units').addBatch({
     ]
   }),
   'line breaks': cssContext({
-    'line breaks': 'div\na\r\n{width:500px}',
-    'line breaks #2': 'div\na\r\n,p{width:500px}',
+    'line breaks': [
+      'div\na\r\n{width:500px}',
+      'div' + lineBreak + 'a' + lineBreak + '{width:500px}'
+    ],
+    'line breaks #2': [
+      'div\na\r\n,p{width:500px}',
+      'div' + lineBreak + 'a' + lineBreak + ',p{width:500px}'
+    ],
     'multiple line breaks #2': [
       'div \r\n\r\na\r\n,p{width:500px}',
-      'div\r\na\r\n,p{width:500px}'
+      'div' + lineBreak + 'a' + lineBreak + ',p{width:500px}'
     ],
     'line breaks with whitespace lines': [
       'div \n \t\n \na\r\n, p { width:500px }',
-      'div\na\r\n,p{width:500px}'
+      'div' + lineBreak + 'a' + lineBreak + ',p{width:500px}'
     ]
   }, { keepBreaks: true }),
   'selectors': cssContext({