aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-09-12 13:00:13 +0300
committerMihai Bazon <mihai@bazon.net>2012-09-12 13:00:13 +0300
commit2b4093ba8342b79bac3f9f89428817231728bb01 (patch)
tree83584a611bf43aa7014905b5ef1f69b803ce5454
parent9a629abe00101d56ccc1a9bd01a90b9f7f19421f (diff)
downloadtracifyjs-2b4093ba8342b79bac3f9f89428817231728bb01.tar.gz
tracifyjs-2b4093ba8342b79bac3f9f89428817231728bb01.zip
fixed run-tests and an issue about reversing the condition in AST_If
-rw-r--r--lib/compress.js3
-rw-r--r--lib/output.js2
-rwxr-xr-xtest/run-tests.js9
3 files changed, 9 insertions, 5 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 82898fd4..7faf2df5 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -745,6 +745,7 @@ function Compressor(options, false_by_default) {
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();
@@ -776,7 +777,7 @@ function Compressor(options, false_by_default) {
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,
diff --git a/lib/output.js b/lib/output.js
index 25718816..f7cb47c6 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -885,7 +885,7 @@ function OutputStream(options) {
});
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");
diff --git a/test/run-tests.js b/test/run-tests.js
index 385c43f1..2949bbf9 100755
--- a/test/run-tests.js
+++ b/test/run-tests.js
@@ -48,7 +48,9 @@ function as_toplevel(input) {
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() {
@@ -62,8 +64,9 @@ 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),