@@ -434,7 +434,7 @@ describe("test/reduce.js", function() {
|
||||
"// }",
|
||||
].join("\n"));
|
||||
});
|
||||
it("Should transform `export default` correctly", function() {
|
||||
it("Should transform `export default class` correctly", function() {
|
||||
var result = reduce_test(read("test/input/reduce/export_default.js"), {
|
||||
compress: false,
|
||||
toplevel: true,
|
||||
@@ -448,4 +448,22 @@ describe("test/reduce.js", function() {
|
||||
"// }",
|
||||
].join("\n"));
|
||||
});
|
||||
it("Should transform `export default function` correctly", function() {
|
||||
var code = [
|
||||
"for (var k in this)",
|
||||
" console.log(k);",
|
||||
"export default (function f() {});",
|
||||
"console.log(k);",
|
||||
].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"));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -52,12 +52,14 @@ exports.same_stdout = semver.satisfies(process.version, "0.12") ? function(expec
|
||||
return typeof expected == typeof actual && strip_func_ids(expected) == strip_func_ids(actual);
|
||||
};
|
||||
exports.patch_module_statements = function(code) {
|
||||
var count = 0, imports = [];
|
||||
var count = 0, has_default = "", imports = [];
|
||||
code = code.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 (!header) return "";
|
||||
has_default = "var _uglify_export_default_;";
|
||||
if (header.length == 1) return "0, " + header;
|
||||
do {
|
||||
var name = "_export_default_" + ++count;
|
||||
var name = "_uglify_export_default_";
|
||||
if (/^class\b/.test(header)) do {
|
||||
name = "_uglify_export_default_" + ++count;
|
||||
} while (code.indexOf(name) >= 0);
|
||||
return header.slice(0, -1) + " " + name + header.slice(-1);
|
||||
}).replace(/\bimport\.meta\b/g, function() {
|
||||
@@ -76,7 +78,7 @@ exports.patch_module_statements = function(code) {
|
||||
return "";
|
||||
});
|
||||
imports.push("");
|
||||
return imports.join("\n") + code;
|
||||
return has_default + imports.join("\n") + code;
|
||||
};
|
||||
|
||||
function is_error(result) {
|
||||
|
||||
Reference in New Issue
Block a user