From 093a9031dc15b2e2bd85850f3f3eb7fe90f01bd7 Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Mon, 8 Oct 2012 12:53:17 +0300 Subject: [PATCH] eliminate redundant directives in the same scope --- lib/compress.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/compress.js b/lib/compress.js index 84f66b3c..3d55ecc1 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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); } -- 2.34.1