aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-12-20 03:22:45 +0000
committerGitHub <noreply@github.com>2020-12-20 11:22:45 +0800
commitcaea6aac81555040071c21e9e35888f78aeb5a82 (patch)
tree5dbc98bc4b77a73349472f109cef2bce7fa5b983
parentf5224ca1f5075d6912616675f1aa7fa8cc7741f1 (diff)
downloadtracifyjs-caea6aac81555040071c21e9e35888f78aeb5a82.tar.gz
tracifyjs-caea6aac81555040071c21e9e35888f78aeb5a82.zip
handle destructuring `catch` in `--reduce-test` (#4427)
-rw-r--r--test/input/reduce/destructured_catch.js7
-rw-r--r--test/input/reduce/destructured_catch.reduced.js15
-rw-r--r--test/mocha/reduce.js8
-rw-r--r--test/reduce.js2
-rw-r--r--test/ufuzz/index.js2
5 files changed, 32 insertions, 2 deletions
diff --git a/test/input/reduce/destructured_catch.js b/test/input/reduce/destructured_catch.js
new file mode 100644
index 00000000..3b248455
--- /dev/null
+++ b/test/input/reduce/destructured_catch.js
@@ -0,0 +1,7 @@
+try {
+ "foo" in 42;
+} catch ({
+ message,
+}) {
+ console.log(message);
+}
diff --git a/test/input/reduce/destructured_catch.reduced.js b/test/input/reduce/destructured_catch.reduced.js
new file mode 100644
index 00000000..c7a6736d
--- /dev/null
+++ b/test/input/reduce/destructured_catch.reduced.js
@@ -0,0 +1,15 @@
+// (beautified)
+try {
+ 1 in 0;
+} catch ({
+ message: message
+}) {
+ console.log(message);
+}
+// output: Cannot use 'in' operator to search for '1' in 0
+//
+// minify: Cannot use 'in' operator to search for '0' in 0
+//
+// options: {
+// "mangle": false
+// } \ No newline at end of file
diff --git a/test/mocha/reduce.js b/test/mocha/reduce.js
index 7e2d4601..c06efd67 100644
--- a/test/mocha/reduce.js
+++ b/test/mocha/reduce.js
@@ -313,4 +313,12 @@ describe("test/reduce.js", function() {
if (result.error) throw result.error;
assert.strictEqual(result.code, read("test/input/reduce/diff_error.reduced.js"));
});
+ it("Should handle destructured catch expressions", function() {
+ if (semver.satisfies(process.version, "<6")) return;
+ var result = reduce_test(read("test/input/reduce/destructured_catch.js"), {
+ mangle: false,
+ });
+ if (result.error) throw result.error;
+ assert.strictEqual(result.code, read("test/input/reduce/destructured_catch.reduced.js"));
+ });
});
diff --git a/test/reduce.js b/test/reduce.js
index 1ab18411..bcb30fe8 100644
--- a/test/reduce.js
+++ b/test/reduce.js
@@ -465,7 +465,7 @@ module.exports = function reduce_test(testcase, minify_options, reduce_options)
if (node.TYPE == "Call" && node.expression.print_to_string() == "console.log") {
return to_sequence(node.args);
}
- if (node instanceof U.AST_Catch && node.argname) {
+ if (node instanceof U.AST_Catch && node.argname instanceof U.AST_SymbolCatch) {
descend(node, this);
node.body.unshift(new U.AST_SimpleStatement({
body: wrap_with_console_log(new U.AST_SymbolRef(node.argname)),
diff --git a/test/ufuzz/index.js b/test/ufuzz/index.js
index 8fce55de..74fbd4bd 100644
--- a/test/ufuzz/index.js
+++ b/test/ufuzz/index.js
@@ -1714,7 +1714,7 @@ function patch_try_catch(orig, toplevel) {
offset: 0,
tries: [],
} ];
- var re = /(?:(?:^|[\s{}):;])try|}\s*catch\s*\(([^)]+)\)|}\s*finally)\s*(?={)/g;
+ var re = /(?:(?:^|[\s{}):;])try|}\s*catch\s*\(([^)[{]+)\)|}\s*finally)\s*(?={)/g;
while (stack.length) {
var code = stack[0].code;
var offset = stack[0].offset;