Просмотр исходного кода

Should fix uglify infinite loop on already uglyfied files that crashes YLT

Gaël Métais 9 лет назад
Родитель
Сommit
ada82fa7e1
1 измененных файлов с 12 добавлено и 3 удалено
  1. 12 3
      lib/tools/weightChecker/fileMinifier.js

+ 12 - 3
lib/tools/weightChecker/fileMinifier.js

@@ -146,7 +146,16 @@ var FileMinifier = function() {
         .delay(1)
         .then(splittedUglifyStep2)
         .delay(1)
-        .then(splittedUglifyStep3)
+        .then(function(ast) {
+            // Only do the compression step for smaller files
+            // otherwise it can take a very long time compared to the gain
+            if (body.length < 200*1024) {
+                return splittedUglifyStep3(ast);
+            } else {
+                debug('Skipping step 3 because the file is too big (%d bytes)!', body.length);
+                return ast;
+            }
+        })
         .delay(1)
         .then(splittedUglifyStep4)
         .delay(1)
@@ -311,9 +320,9 @@ var FileMinifier = function() {
         return result;
     }
 
-    // Avoid loosing tome trying to compress JS files if they alreay look minified
+    // Avoid loosing some trying to compress JS files if they alreay look minified
     // by counting the number of lines compared to the total size.
-    // Less than 1000kb per line is suspicious
+    // Less than 1KB per line is suspicious
     function looksAlreadyMinified(code) {
         var linesCount = code.split(/\r\n|\r|\n/).length;
         var linesRatio = code.length / linesCount;