From db433f852f7870db85c8d944d0d0a06ef166870f Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Fri, 10 Nov 2017 11:48:12 +0800 Subject: [PATCH] suppress `hoist_props` on `export` fixes #2462 --- lib/compress.js | 6 ++++-- test/compress/hoist_props.js | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 8ebecd7f..432755b1 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -2895,7 +2895,8 @@ merge(Compressor.prototype, { self.variables.each(function(def, name) { var_names[name] = true; }); - return self.transform(new TreeTransformer(function(node) { + var tt = new TreeTransformer(function(node) { + if (node instanceof AST_Definitions && tt.parent() instanceof AST_Export) return node; if (node instanceof AST_VarDef) { var sym = node.name, def, value; if (sym.scope === self @@ -2946,7 +2947,8 @@ merge(Compressor.prototype, { var_names[name] = true; return new_var; } - })); + }); + return self.transform(tt); }); // drop_side_effect_free() diff --git a/test/compress/hoist_props.js b/test/compress/hoist_props.js index b2925af6..6d612816 100644 --- a/test/compress/hoist_props.js +++ b/test/compress/hoist_props.js @@ -511,3 +511,22 @@ new_this: { } expect_stdout: "1 2" } + +issue_2462: { + options = { + hoist_props: true, + reduce_vars: true, + } + input: { + export const Foo = { + a: 1, + b: () => 2 + }; + } + expect: { + export const Foo = { + a: 1, + b: () => 2 + }; + } +}