aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-09-18 13:21:09 +0300
committerMihai Bazon <mihai@bazon.net>2012-09-18 13:21:09 +0300
commit3da0ac4897e1b12adbdedbfa1c3a145931f0af56 (patch)
tree155d17888ea85824a6aef7e81d176cb51a43cf7b /lib/compress.js
parent21968285e8fad1cfe775b389c6bcd16e14b62c6c (diff)
downloadtracifyjs-3da0ac4897e1b12adbdedbfa1c3a145931f0af56.tar.gz
tracifyjs-3da0ac4897e1b12adbdedbfa1c3a145931f0af56.zip
support for directives
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js
index aedd78fd..9d5dac17 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -742,6 +742,13 @@ function Compressor(options, false_by_default) {
/* -----[ node squeezers ]----- */
+ SQUEEZE(AST_Directive, function(self, compressor){
+ if (self.hoisted || self.scope.has_directive(self.value) !== self.scope) {
+ return new AST_EmptyStatement(self);
+ }
+ return self;
+ });
+
SQUEEZE(AST_Debugger, function(self, compressor){
if (compressor.option("drop_debugger"))
return new AST_EmptyStatement(self);
@@ -796,6 +803,10 @@ function Compressor(options, false_by_default) {
var vars = {}, vars_found = 0, vardecl = [];
var tw = new TreeWalker(function(node){
if (node !== self) {
+ if (node instanceof AST_Directive && (hoist_funs || hoist_vars) && !node.hoisted) {
+ hoisted.unshift(node.clone());
+ node.hoisted = true;
+ }
if (node instanceof AST_Defun && hoist_funs && !node.hoisted) {
hoisted.push(node.clone());
node.hoisted = true;