From 96b89e34a3c404749b9b58efa78b490989aaba3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Thu, 15 Jan 2015 13:27:30 +0000 Subject: [PATCH] test that names used in destructurings don't get hoisted --- lib/compress.js | 1 - test/compress/hoist.js | 67 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 test/compress/hoist.js diff --git a/lib/compress.js b/lib/compress.js index bfdb1952..9e94a6b7 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1280,7 +1280,6 @@ merge(Compressor.prototype, { // collect only vars which don't show up in self's arguments list var defs = []; vars.each(function(def, name){ - // TODO test this too if (self instanceof AST_Lambda && find_if(function(x){ return x.name == def.name.name }, self.args_as_names())) { diff --git a/test/compress/hoist.js b/test/compress/hoist.js new file mode 100644 index 00000000..2b359fc5 --- /dev/null +++ b/test/compress/hoist.js @@ -0,0 +1,67 @@ + +hoist_vars: { + options = { + hoist_vars: true + } + input: { + function a() { + bar(); + var var1; + var var2; + } + function b(anArg) { + bar(); + var var1; + var anArg; + } + } + expect: { + function a() { + var var1, var2; // Vars go up and are joined + bar(); + } + function b(anArg) { + var var1; + bar(); + // But vars named like arguments go away! + } + } +} + +hoist_funs: { + options = { + hoist_funs: true + } + input: { + function a() { + bar(); + function foo() {} + } + } + expect: { + function a() { + function foo() {} // Funs go up + bar(); + } + } +} + +hoist_no_destructurings: { + options = { + hoist_vars: true, + hoist_funs: true + } + input: { + function a([anArg]) { + bar(); + var var1; + var anArg; // Because anArg is already declared, this goes away! + } + } + expect: { + function a([anArg]) { + var var1; + bar(); + } + } +}