From ad344c5be31d9c5df1ae906d7bb49b430fffed88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Thu, 15 Jan 2015 20:08:06 +0000 Subject: [PATCH] Add a test to verify that destructuring arguments work with #203 code --- lib/compress.js | 1 - test/compress/issue-203.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/compress/issue-203.js diff --git a/lib/compress.js b/lib/compress.js index 9e94a6b7..3788ab7d 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1802,7 +1802,6 @@ merge(Compressor.prototype, { if (ex !== ast) throw ex; }; if (!fun) return self; - // TODO does this work with destructuring? Test it. var args = fun.argnames.map(function(arg, i){ return make_node(AST_String, self.args[i], { value: arg.print_to_string() diff --git a/test/compress/issue-203.js b/test/compress/issue-203.js new file mode 100644 index 00000000..d894c586 --- /dev/null +++ b/test/compress/issue-203.js @@ -0,0 +1,30 @@ + +compress_new_function: { + options = { + unsafe: true + } + input: { + new Function("aa, bb", 'return aa;'); + } + expect: { + Function("a", "b", "return a"); + } +} + +compress_new_function_with_destruct: { + options = { + unsafe: true + } + input: { + new Function("aa, [bb]", 'return aa;'); + new Function("aa, {bb}", 'return aa;'); + new Function("[[aa]], [{bb}]", 'return aa;'); + } + expect: { + Function("a", "[b]", "return a"); + Function("a", "{bb}", "return a"); + Function("[[a]]", "[{bb}]", 'return a'); + } +} + +