CHANGED = true;
stat = stat.clone();
stat.alternative = ret[0] || make_node(AST_Return, stat, {
- value: make_node(AST_Undefined, stat)
+ value: null
});
ret[0] = stat.transform(compressor);
continue loop;
&& !stat.alternative) {
CHANGED = true;
ret.push(make_node(AST_Return, ret[0], {
- value: make_node(AST_Undefined, ret[0])
+ value: null
}).transform(compressor));
ret.unshift(stat);
continue loop;
}));
};
+ function is_undefined(node) {
+ return node instanceof AST_Undefined || node.is_undefined;
+ }
+
/* -----[ boolean/negation helpers ]----- */
// methods to determine whether an expression has a boolean result type
return make_node(self.body.CTOR, self, {
value: make_node(AST_Conditional, self, {
condition : self.condition,
- consequent : self.body.value || make_node(AST_Undefined, self.body).optimize(compressor),
- alternative : self.alternative.value || make_node(AST_Undefined, self.alternative).optimize(compressor)
+ consequent : self.body.value || make_node(AST_Undefined, self.body),
+ alternative : self.alternative.value || make_node(AST_Undefined, self.alternative)
})
}).transform(compressor);
}
return self.car;
}
}
- if (self.cdr instanceof AST_Undefined) {
+ if (is_undefined(self.cdr)) {
return make_node(AST_UnaryPrefix, self, {
operator : "void",
expression : self.car
self.expression = e;
return self;
} else {
- return make_node(AST_Undefined, self);
+ return make_node(AST_Undefined, self).transform(compressor);
}
}
if (compressor.option("booleans") && compressor.in_boolean_context()) {
&& (!self.scope.uses_with || !compressor.find_parent(AST_With))) {
switch (self.name) {
case "undefined":
- return make_node(AST_Undefined, self);
+ return make_node(AST_Undefined, self).transform(compressor);
case "NaN":
return make_node(AST_NaN, self).transform(compressor);
case "Infinity":
var scope = compressor.find_parent(AST_Scope);
var undef = scope.find_variable("undefined");
if (undef) {
- return make_node(AST_SymbolRef, self, {
+ var ref = make_node(AST_SymbolRef, self, {
name : "undefined",
scope : scope,
thedef : undef
});
+ ref.is_undefined = true;
+ return ref;
}
}
return self;
OPT(AST_RegExp, literals_in_boolean_context);
OPT(AST_Return, function(self, compressor){
- if (self.value instanceof AST_Undefined) {
+ if (self.value && is_undefined(self.value)) {
self.value = null;
}
return self;