aboutsummaryrefs
aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-02-13 13:15:11 +0000
committerGitHub <noreply@github.com>2021-02-13 21:15:11 +0800
commit94e8944f677f624d8ab4ae2b8731e87244f9476e (patch)
treefe98fd1093ee1cb82f69c4cfafa0ac9d80f2e81a /test
parent83197ffdb3c9055b5699674e111d2dee390d5560 (diff)
downloadtracifyjs-94e8944f677f624d8ab4ae2b8731e87244f9476e.tar.gz
tracifyjs-94e8944f677f624d8ab4ae2b8731e87244f9476e.zip
avoid false positive in `--reduce-test` (#4648)
Diffstat (limited to 'test')
-rw-r--r--test/mocha/reduce.js33
-rw-r--r--test/reduce.js11
-rw-r--r--test/ufuzz/index.js21
3 files changed, 53 insertions, 12 deletions
diff --git a/test/mocha/reduce.js b/test/mocha/reduce.js
index e3653314..587aa7be 100644
--- a/test/mocha/reduce.js
+++ b/test/mocha/reduce.js
@@ -294,6 +294,39 @@ describe("test/reduce.js", function() {
"// }",
]).join("\n"));
});
+ it("Should maintain block-scope for const & let", function() {
+ if (semver.satisfies(process.version, "<4")) return;
+ var code = [
+ '"use strict";',
+ "",
+ "L: for (let a = (1 - .8).toString(); ;) {",
+ " if (!console.log(a)) {",
+ " break L;",
+ " }",
+ "}",
+ ].join("\n");
+ var result = reduce_test(code, {
+ compress: {
+ unsafe_math: true,
+ },
+ mangle: false,
+ });
+ if (result.error) throw result.error;
+ assert.strictEqual(result.code, [
+ "// (beautified)",
+ code,
+ "// output: 0.19999999999999996",
+ "// ",
+ "// minify: 0.2",
+ "// ",
+ "// options: {",
+ '// "compress": {',
+ '// "unsafe_math": true',
+ '// },',
+ '// "mangle": false',
+ "// }",
+ ].join("\n"));
+ });
it("Should handle corner cases when intermediate case differs only in Error.message", function() {
if (semver.satisfies(process.version, "<=0.10")) return;
var result = reduce_test(read("test/input/reduce/diff_error.js"), {
diff --git a/test/reduce.js b/test/reduce.js
index d5758ccc..4d628aa2 100644
--- a/test/reduce.js
+++ b/test/reduce.js
@@ -300,7 +300,7 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
node.start._permute += step;
if (expr && (expr !== node.body || !has_loopcontrol(expr, node, parent))) {
CHANGED = true;
- return to_statement(expr);
+ return to_statement_init(expr);
}
}
else if (node instanceof U.AST_ForEnumeration) {
@@ -322,7 +322,7 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
node.start._permute += step;
if (expr) {
CHANGED = true;
- return to_statement(expr);
+ return to_statement_init(expr);
}
}
else if (node instanceof U.AST_If) {
@@ -695,6 +695,13 @@ function to_statement(node) {
});
}
+function to_statement_init(node) {
+ return node instanceof U.AST_Const || node instanceof U.AST_Let ? new U.AST_BlockStatement({
+ body: [ node ],
+ start: {},
+ }) : to_statement(node);;
+}
+
function wrap_with_console_log(node) {
// wrap with console.log()
return new U.AST_Call({
diff --git a/test/ufuzz/index.js b/test/ufuzz/index.js
index 7f7da390..9df41929 100644
--- a/test/ufuzz/index.js
+++ b/test/ufuzz/index.js
@@ -2139,6 +2139,17 @@ for (var round = 1; round <= num_iterations; round++) {
ok = sandbox.same_stdout(original_result, uglify_result);
// ignore v8 parser bug
if (!ok && bug_async_arrow_rest(uglify_result)) ok = true;
+ // handle difference caused by time-outs
+ if (!ok && errored && is_error_timeout(original_result)) {
+ if (is_error_timeout(uglify_result)) {
+ // ignore difference in error message
+ ok = true;
+ } else {
+ // ignore spurious time-outs
+ if (!orig_result[toplevel ? 3 : 2]) orig_result[toplevel ? 3 : 2] = sandbox.run_code(original_code, toplevel, 10000);
+ ok = sandbox.same_stdout(orig_result[toplevel ? 3 : 2], uglify_result);
+ }
+ }
// ignore declaration order of global variables
if (!ok && !toplevel) {
ok = sandbox.same_stdout(sandbox.run_code(sort_globals(original_code)), sandbox.run_code(sort_globals(uglify_code)));
@@ -2157,16 +2168,6 @@ for (var round = 1; round <= num_iterations; round++) {
}
// ignore difference in error message caused by Temporal Dead Zone
if (!ok && errored && uglify_result.name == "ReferenceError" && original_result.name == "ReferenceError") ok = true;
- if (!ok && errored && is_error_timeout(original_result)) {
- if (is_error_timeout(uglify_result)) {
- // ignore difference in error message
- ok = true;
- } else {
- // ignore spurious time-outs
- if (!orig_result[toplevel ? 3 : 2]) orig_result[toplevel ? 3 : 2] = sandbox.run_code(original_code, toplevel, 10000);
- ok = sandbox.same_stdout(orig_result[toplevel ? 3 : 2], uglify_result);
- }
- }
// ignore difference in error message caused by `in`
if (!ok && errored && is_error_in(uglify_result) && is_error_in(original_result)) ok = true;
// ignore difference in error message caused by spread syntax