patch export default within sandbox correctly (#5346)

fixes #5345
This commit is contained in:
Alex Lam S.L
2022-02-10 08:07:40 +00:00
committed by GitHub
parent b6c72c84d4
commit 33c163f648
4 changed files with 569 additions and 538 deletions

View File

@@ -0,0 +1,17 @@
var unused;
export default class {
____11111() {
a, b, c, d, e;
f, g, h, i, j;
k, l, m, n, o;
p, q, r, s, t;
u, v, w, x, y, z;
A, B, C, D, E;
F, G, H, I, J;
K, L, M, N, O;
P, Q, R, S, T;
U, V, W, X, Y, Z;
$, _;
unused;
}
}

View File

@@ -434,4 +434,18 @@ describe("test/reduce.js", function() {
"// }", "// }",
].join("\n")); ].join("\n"));
}); });
it("Should transform `export default` correctly", function() {
var result = reduce_test(read("test/input/reduce/export_default.js"), {
compress: false,
toplevel: true,
});
if (result.error) throw result.error;
assert.strictEqual(result.code, [
"// Can't reproduce test failure",
"// minify options: {",
'// "compress": false,',
'// "toplevel": true',
"// }",
].join("\n"));
});
}); });

File diff suppressed because it is too large Load Diff

View File

@@ -56,7 +56,10 @@ exports.patch_module_statements = function(code) {
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) { 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 ""; if (!header) return "";
if (header.length == 1) return "0, " + header; if (header.length == 1) return "0, " + header;
return header.slice(0, -1) + " _" + ++count + header.slice(-1); do {
var name = "_export_default_" + ++count;
} while (code.indexOf(name) >= 0);
return header.slice(0, -1) + " " + name + header.slice(-1);
}).replace(/\bimport\.meta\b/g, function() { }).replace(/\bimport\.meta\b/g, function() {
return '({ url: "https://example.com/path/index.html" })'; return '({ url: "https://example.com/path/index.html" })';
}).replace(/\bimport\b(?:\s*([^\s('"][^('"]*)\bfrom\b)?\s*(['"]).*?\2(?:$|\n|;)/g, function(match, symbols) { }).replace(/\bimport\b(?:\s*([^\s('"][^('"]*)\bfrom\b)?\s*(['"]).*?\2(?:$|\n|;)/g, function(match, symbols) {