Merge branch 'master' into harmony

This commit is contained in:
Richard van Velzen
2015-12-26 17:55:38 +01:00
16 changed files with 609 additions and 124 deletions

View File

@@ -4,7 +4,6 @@ var U = require("../tools/node");
var path = require("path");
var fs = require("fs");
var assert = require("assert");
var sys = require("util");
var tests_dir = path.dirname(module.filename);
var failures = 0;
@@ -12,8 +11,8 @@ var failed_files = {};
run_compress_tests();
if (failures) {
sys.error("\n!!! Failed " + failures + " test cases.");
sys.error("!!! " + Object.keys(failed_files).join(", "));
console.error("\n!!! Failed " + failures + " test cases.");
console.error("!!! " + Object.keys(failed_files).join(", "));
process.exit(1);
}
@@ -91,14 +90,15 @@ function run_compress_tests() {
warnings: false
});
var cmp = new U.Compressor(options, true);
var output_options = test.beautify || {};
var expect;
if (test.expect) {
expect = make_code(as_toplevel(test.expect), false);
expect = make_code(as_toplevel(test.expect), output_options);
} else {
expect = test.expect_exact;
}
var input = as_toplevel(test.input);
var input_code = make_code(test.input);
var input_code = make_code(test.input, { beautify: true });
if (test.mangle_props) {
input = U.mangle_properties(input, test.mangle_props);
}
@@ -107,7 +107,7 @@ function run_compress_tests() {
if (test.mangle) {
output.mangle_names(test.mangle);
}
output = make_code(output, false);
output = make_code(output, output_options);
if (expect != output) {
log("!!! failed\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n---EXPECTED---\n{expected}\n\n", {
input: input_code,
@@ -151,7 +151,7 @@ function parse_test(file) {
file: file,
line: node.start.line,
col: node.start.col,
code: make_code(node, false)
code: make_code(node, { beautify: false })
}));
}
@@ -198,15 +198,15 @@ function parse_test(file) {
};
}
function make_code(ast, beautify) {
if (arguments.length == 1) beautify = true;
var stream = U.OutputStream({ beautify: beautify, inline_script: true });
function make_code(ast, options) {
options.inline_script = true;
var stream = U.OutputStream(options);
ast.print(stream);
return stream.get();
}
function evaluate(code) {
if (code instanceof U.AST_Node)
code = make_code(code);
code = make_code(code, { beautify: true });
return new Function("return(" + code + ")")();
}