handle destructuring catch in --reduce-test (#4427)
This commit is contained in:
7
test/input/reduce/destructured_catch.js
Normal file
7
test/input/reduce/destructured_catch.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
try {
|
||||||
|
"foo" in 42;
|
||||||
|
} catch ({
|
||||||
|
message,
|
||||||
|
}) {
|
||||||
|
console.log(message);
|
||||||
|
}
|
||||||
15
test/input/reduce/destructured_catch.reduced.js
Normal file
15
test/input/reduce/destructured_catch.reduced.js
Normal file
@@ -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
|
||||||
|
// }
|
||||||
@@ -313,4 +313,12 @@ describe("test/reduce.js", function() {
|
|||||||
if (result.error) throw result.error;
|
if (result.error) throw result.error;
|
||||||
assert.strictEqual(result.code, read("test/input/reduce/diff_error.reduced.js"));
|
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"));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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") {
|
if (node.TYPE == "Call" && node.expression.print_to_string() == "console.log") {
|
||||||
return to_sequence(node.args);
|
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);
|
descend(node, this);
|
||||||
node.body.unshift(new U.AST_SimpleStatement({
|
node.body.unshift(new U.AST_SimpleStatement({
|
||||||
body: wrap_with_console_log(new U.AST_SymbolRef(node.argname)),
|
body: wrap_with_console_log(new U.AST_SymbolRef(node.argname)),
|
||||||
|
|||||||
@@ -1714,7 +1714,7 @@ function patch_try_catch(orig, toplevel) {
|
|||||||
offset: 0,
|
offset: 0,
|
||||||
tries: [],
|
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) {
|
while (stack.length) {
|
||||||
var code = stack[0].code;
|
var code = stack[0].code;
|
||||||
var offset = stack[0].offset;
|
var offset = stack[0].offset;
|
||||||
|
|||||||
Reference in New Issue
Block a user