diff --git a/test/mocha/reduce.js b/test/mocha/reduce.js index 366db94d..e022d3a7 100644 --- a/test/mocha/reduce.js +++ b/test/mocha/reduce.js @@ -449,6 +449,27 @@ describe("test/reduce.js", function() { ].join("\n")); }); it("Should transform `export default function` correctly", function() { + if (semver.satisfies(process.version, "<8")) return; + var code = [ + "export default function f(a) {", + " for (var k in a)", + " console.log(k);", + " (async function() {})();", + "}", + "f(this);", + ].join("\n"); + var result = reduce_test(code, { + mangle: false, + }); + if (result.error) throw result.error; + assert.strictEqual(result.code, [ + "// Can't reproduce test failure", + "// minify options: {", + '// "mangle": false', + "// }", + ].join("\n")); + }); + it("Should transform `export default (function)` correctly", function() { var code = [ "for (var k in this)", " console.log(k);", diff --git a/test/sandbox.js b/test/sandbox.js index 3c2d0e4a..8f00619c 100644 --- a/test/sandbox.js +++ b/test/sandbox.js @@ -57,7 +57,7 @@ exports.patch_module_statements = function(code) { strict_mode = match; return ""; }).replace(/\bexport(?:\s*\{[^{}]*}\s*?(?:$|\n|;)|\s+default\b(?:\s*(\(|\{|class\s*\{|class\s+(?=extends\b)|(?:async\s+)?function\s*(?:\*\s*)?\())?|\b)/g, function(match, header) { - if (/^export\s+default/.test(match)) has_default = "var _uglify_export_default_;"; + if (/^export\s+default/.test(match)) has_default = "function _uglify_export_default_() {}"; if (!header) return ""; if (header.length == 1) return "0, " + header; var name = "_uglify_export_default_";