eliminate redundant directives in the same scope
authorMihai Bazon <mihai@bazon.net>
Mon, 8 Oct 2012 09:53:17 +0000 (12:53 +0300)
committerMihai Bazon <mihai@bazon.net>
Mon, 8 Oct 2012 09:53:17 +0000 (12:53 +0300)
lib/compress.js

index 84f66b3..3d55ecc 100644 (file)
@@ -194,12 +194,20 @@ merge(Compressor.prototype, {
         return statements;
 
         function eliminate_spurious_blocks(statements) {
+            var seen_dirs = [];
             return statements.reduce(function(a, stat){
                 if (stat instanceof AST_BlockStatement) {
                     CHANGED = true;
                     a.push.apply(a, eliminate_spurious_blocks(stat.body));
                 } else if (stat instanceof AST_EmptyStatement) {
                     CHANGED = true;
+                } else if (stat instanceof AST_Directive) {
+                    if (seen_dirs.indexOf(stat.value) < 0) {
+                        a.push(stat);
+                        seen_dirs.push(stat.value);
+                    } else {
+                        CHANGED = true;
+                    }
                 } else {
                     a.push(stat);
                 }