support for directives

This commit is contained in:
Mihai Bazon
2012-09-18 13:21:09 +03:00
parent 21968285e8
commit 3da0ac4897
5 changed files with 27 additions and 4 deletions

View File

@@ -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;