var negated = self.condition.negate(compressor);
var negated_is_best = best_of(self.condition, negated) === negated;
if (self.alternative && negated_is_best) {
+ negated_is_best = false; // because we already do the switch here.
self.condition = negated;
var tmp = self.body;
self.body = self.alternative || new AST_EmptyStatement();
right : self.body.body
}).optimize(compressor)
});
- else return make_node(AST_SimpleStatement, self, {
+ return make_node(AST_SimpleStatement, self, {
body: make_node(AST_Binary, self, {
operator : "&&",
left : self.condition,
});
DEFPRINT(AST_Symbol, function(self, output){
var def = self.definition();
- output.print_name(def.mangled_name || def.name);
+ output.print_name(def ? def.mangled_name || def.name : self.name);
});
DEFPRINT(AST_This, function(self, output){
output.print("this");
if (input instanceof U.AST_BlockStatement) input = input.body;
else if (input instanceof U.AST_StatementBase) input = [ input ];
else throw new Error("Unsupported input syntax");
- return new U.AST_Toplevel({ body: input });
+ var toplevel = new U.AST_Toplevel({ body: input });
+ toplevel.figure_out_scope();
+ return toplevel;
}
function run_compress_tests() {
var cmp = new U.Compressor(test.options || {}, true);
var expect = make_code(as_toplevel(test.expect), false);
var input = as_toplevel(test.input);
- input.figure_out_scope();
- var output = make_code(input.squeeze(cmp), false);
+ var output = input.squeeze(cmp);
+ output.figure_out_scope();
+ output = make_code(output, false);
if (expect != output) {
log("!!! failed\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n---EXPECTED---\n{expected}\n\n", {
input: make_code(test.input),