maintain compatibility options when testing (#4376)
This commit is contained in:
@@ -18,9 +18,18 @@ var sandbox = require("./sandbox");
|
|||||||
|
|
||||||
Error.stackTraceLimit = Infinity;
|
Error.stackTraceLimit = Infinity;
|
||||||
module.exports = function reduce_test(testcase, minify_options, reduce_options) {
|
module.exports = function reduce_test(testcase, minify_options, reduce_options) {
|
||||||
if (testcase instanceof U.AST_Node) testcase = testcase.print_to_string();
|
|
||||||
minify_options = minify_options || {};
|
minify_options = minify_options || {};
|
||||||
reduce_options = reduce_options || {};
|
reduce_options = reduce_options || {};
|
||||||
|
var print_options = {};
|
||||||
|
[
|
||||||
|
"ie8",
|
||||||
|
"v8",
|
||||||
|
"webkit",
|
||||||
|
].forEach(function(name) {
|
||||||
|
var value = minify_options[name] || minify_options.output && minify_options.output[name];
|
||||||
|
if (value) print_options[name] = value;
|
||||||
|
});
|
||||||
|
if (testcase instanceof U.AST_Node) testcase = testcase.print_to_string(print_options);
|
||||||
var max_iterations = reduce_options.max_iterations || 1000;
|
var max_iterations = reduce_options.max_iterations || 1000;
|
||||||
var max_timeout = reduce_options.max_timeout || 10000;
|
var max_timeout = reduce_options.max_timeout || 10000;
|
||||||
var warnings = [];
|
var warnings = [];
|
||||||
@@ -459,7 +468,7 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
var code = testcase_ast.print_to_string();
|
var code = testcase_ast.print_to_string(print_options);
|
||||||
var diff = test_for_diff(code, minify_options, result_cache, max_timeout);
|
var diff = test_for_diff(code, minify_options, result_cache, max_timeout);
|
||||||
if (diff && !diff.timed_out && !diff.error) {
|
if (diff && !diff.timed_out && !diff.error) {
|
||||||
testcase = code;
|
testcase = code;
|
||||||
@@ -483,7 +492,7 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
|
|||||||
var code_ast = testcase_ast.clone(true).transform(tt);
|
var code_ast = testcase_ast.clone(true).transform(tt);
|
||||||
if (!CHANGED) break;
|
if (!CHANGED) break;
|
||||||
try {
|
try {
|
||||||
var code = code_ast.print_to_string();
|
var code = code_ast.print_to_string(print_options);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
// AST is not well formed.
|
// AST is not well formed.
|
||||||
// no harm done - just log the error, ignore latest change and continue iterating.
|
// no harm done - just log the error, ignore latest change and continue iterating.
|
||||||
@@ -525,11 +534,13 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
|
|||||||
var beautified = U.minify(testcase, {
|
var beautified = U.minify(testcase, {
|
||||||
compress: false,
|
compress: false,
|
||||||
mangle: false,
|
mangle: false,
|
||||||
output: {
|
output: function() {
|
||||||
beautify: true,
|
var options = JSON.parse(JSON.stringify(print_options));
|
||||||
braces: true,
|
options.beautify = true;
|
||||||
comments: true,
|
options.braces = true;
|
||||||
},
|
options.comments = true;
|
||||||
|
return options;
|
||||||
|
}(),
|
||||||
});
|
});
|
||||||
testcase = {
|
testcase = {
|
||||||
code: testcase,
|
code: testcase,
|
||||||
|
|||||||
@@ -1445,25 +1445,35 @@ function errorln(msg) {
|
|||||||
writeln(process.stderr, msg);
|
writeln(process.stderr, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
function try_beautify(code, toplevel, result, printfn) {
|
function try_beautify(code, toplevel, result, printfn, options) {
|
||||||
var beautified = UglifyJS.minify(code, {
|
var beautified = UglifyJS.minify(code, JSON.parse(beautify_options));
|
||||||
compress: false,
|
|
||||||
mangle: false,
|
|
||||||
output: {
|
|
||||||
beautify: true,
|
|
||||||
braces: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
if (beautified.error) {
|
if (beautified.error) {
|
||||||
printfn("// !!! beautify failed !!!");
|
printfn("// !!! beautify failed !!!");
|
||||||
printfn(beautified.error);
|
printfn(beautified.error);
|
||||||
} else if (sandbox.same_stdout(sandbox.run_code(beautified.code, toplevel), result)) {
|
beautified = null;
|
||||||
|
} else if (!sandbox.same_stdout(sandbox.run_code(beautified.code, toplevel), result)) {
|
||||||
|
beautified = null;
|
||||||
|
} else if (options) {
|
||||||
|
var uglified = UglifyJS.minify(beautified.code, JSON.parse(options));
|
||||||
|
var expected, actual;
|
||||||
|
if (typeof uglify_code != "string" || uglified.error) {
|
||||||
|
expected = uglify_code;
|
||||||
|
actual = uglified.error;
|
||||||
|
} else {
|
||||||
|
expected = uglify_result;
|
||||||
|
actual = sandbox.run_code(uglified.code, toplevel);
|
||||||
|
}
|
||||||
|
if (!sandbox.same_stdout(expected, actual)) {
|
||||||
|
beautified = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (beautified) {
|
||||||
printfn("// (beautified)");
|
printfn("// (beautified)");
|
||||||
printfn(beautified.code);
|
printfn(beautified.code);
|
||||||
return;
|
} else {
|
||||||
|
printfn("//");
|
||||||
|
printfn(code);
|
||||||
}
|
}
|
||||||
printfn("//");
|
|
||||||
printfn(code);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var default_options = UglifyJS.default_options();
|
var default_options = UglifyJS.default_options();
|
||||||
@@ -1536,37 +1546,7 @@ function log(options) {
|
|||||||
errorln("//=============================================================");
|
errorln("//=============================================================");
|
||||||
if (!ok) errorln("// !!!!!! Failed... round " + round);
|
if (!ok) errorln("// !!!!!! Failed... round " + round);
|
||||||
errorln("// original code");
|
errorln("// original code");
|
||||||
var beautified = UglifyJS.minify(original_code, {
|
try_beautify(original_code, toplevel, original_result, errorln, options);
|
||||||
compress: false,
|
|
||||||
mangle: false,
|
|
||||||
output: {
|
|
||||||
beautify: true,
|
|
||||||
braces: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
if (beautified.error) {
|
|
||||||
errorln("// !!! beautify failed !!!");
|
|
||||||
errorln(beautified.error);
|
|
||||||
errorln("//");
|
|
||||||
errorln(original_code);
|
|
||||||
} else {
|
|
||||||
var uglified = UglifyJS.minify(beautified.code, JSON.parse(options));
|
|
||||||
var expected, actual;
|
|
||||||
if (typeof uglify_code != "string" || uglified.error) {
|
|
||||||
expected = uglify_code;
|
|
||||||
actual = uglified.error;
|
|
||||||
} else {
|
|
||||||
expected = uglify_result;
|
|
||||||
actual = sandbox.run_code(uglified.code, toplevel);
|
|
||||||
}
|
|
||||||
if (sandbox.same_stdout(expected, actual)) {
|
|
||||||
errorln("// (beautified)");
|
|
||||||
errorln(beautified.code);
|
|
||||||
} else {
|
|
||||||
errorln("//");
|
|
||||||
errorln(original_code);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
errorln();
|
errorln();
|
||||||
errorln();
|
errorln();
|
||||||
errorln("//-------------------------------------------------------------");
|
errorln("//-------------------------------------------------------------");
|
||||||
@@ -1698,13 +1678,23 @@ function patch_try_catch(orig, toplevel) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var beautify_options = {
|
||||||
|
compress: false,
|
||||||
|
mangle: false,
|
||||||
|
output: {
|
||||||
|
beautify: true,
|
||||||
|
braces: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
var minify_options = require("./options.json");
|
var minify_options = require("./options.json");
|
||||||
if (SUPPORT.destructuring && typeof sandbox.run_code("console.log([ 1 ], {} = 2);") != "string") {
|
if (SUPPORT.destructuring && typeof sandbox.run_code("console.log([ 1 ], {} = 2);") != "string") {
|
||||||
|
beautify_options.output.v8 = true;
|
||||||
minify_options.forEach(function(o) {
|
minify_options.forEach(function(o) {
|
||||||
if (!("output" in o)) o.output = {};
|
if (!("output" in o)) o.output = {};
|
||||||
o.output.v8 = true;
|
o.output.v8 = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
beautify_options = JSON.stringify(beautify_options);
|
||||||
minify_options = minify_options.map(JSON.stringify);
|
minify_options = minify_options.map(JSON.stringify);
|
||||||
var original_code, original_result, errored;
|
var original_code, original_result, errored;
|
||||||
var uglify_code, uglify_result, ok;
|
var uglify_code, uglify_result, ok;
|
||||||
|
|||||||
Reference in New Issue
Block a user