aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-10-08 12:53:17 +0300
committerMihai Bazon <mihai@bazon.net>2012-10-08 12:53:17 +0300
commit093a9031dc15b2e2bd85850f3f3eb7fe90f01bd7 (patch)
treefb2d9cc85e9d74cbb13699733b32a2bf8c8d478a /lib/compress.js
parent80a18fe2fa60d8a689516b921a386839d30b6abe (diff)
downloadtracifyjs-093a9031dc15b2e2bd85850f3f3eb7fe90f01bd7.tar.gz
tracifyjs-093a9031dc15b2e2bd85850f3f3eb7fe90f01bd7.zip
eliminate redundant directives in the same scope
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js8
1 files changed, 8 insertions, 0 deletions
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);
}