diff --git a/lib/compress.js b/lib/compress.js index 6f80b25e..10335634 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -2384,7 +2384,7 @@ merge(Compressor.prototype, { dirs.push(node); return make_node(AST_EmptyStatement, node); } - if (node instanceof AST_Defun && hoist_funs) { + if (hoist_funs && node instanceof AST_Defun && !(tt.parent() instanceof AST_Export)) { hoisted.push(node); return make_node(AST_EmptyStatement, node); } diff --git a/test/compress/issue-2001.js b/test/compress/issue-2001.js index aa3380e9..cdc19e4a 100644 --- a/test/compress/issue-2001.js +++ b/test/compress/issue-2001.js @@ -1,5 +1,6 @@ export_func_1: { options = { + hoist_funs: true, unused: true, } input: { @@ -10,6 +11,7 @@ export_func_1: { export_func_2: { options = { + hoist_funs: true, side_effects: false, unused: true, } @@ -21,6 +23,7 @@ export_func_2: { export_func_3: { options = { + hoist_funs: true, side_effects: true, unused: true, } @@ -32,6 +35,7 @@ export_func_3: { export_default_func_1: { options = { + hoist_funs: true, unused: true, } input: { @@ -42,6 +46,7 @@ export_default_func_1: { export_default_func_2: { options = { + hoist_funs: true, side_effects: false, unused: true, } @@ -53,6 +58,7 @@ export_default_func_2: { export_default_func_3: { options = { + hoist_funs: true, side_effects: true, unused: true, }