self = p;
}
};
+ function find_parent(type) {
+ for (var i = stack.length; --i >= 0;) {
+ var x = stack[i];
+ if (x instanceof type) return x;
+ }
+ };
return {
option : function(key) { return options[key] },
push_node : function(node) { stack.push(node) },
if (options.warnings)
AST_Node.warn.apply(AST_Node, arguments);
},
- in_boolean_context: in_boolean_context
+ in_boolean_context: in_boolean_context,
+ find_parent: find_parent,
};
};
});
AST_Undefined.DEFMETHOD("optimize", function(compressor){
- // if (compressor.option("unsafe") && !(compressor.parent() instanceof AST_Array)) {
- // return make_node(AST_Sub, this, {
- // expression: make_node(AST_Array, this, {
- // elements: []
- // }),
- // property: make_node(AST_Number, this, {
- // value: 0
- // })
- // });
- // }
+ if (compressor.option("unsafe")) {
+ var scope = compressor.find_parent(AST_Scope);
+ var undef = scope.find_variable("undefined");
+ if (undef) {
+ var ref = make_node(AST_SymbolRef, this, {
+ name : "undefined",
+ scope : scope,
+ thedef : undef
+ });
+ ref.reference();
+ return ref;
+ }
+ }
return this;
});