17
test/input/reduce/export_default.js
Normal file
17
test/input/reduce/export_default.js
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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"));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
1071
test/reduce.js
1071
test/reduce.js
File diff suppressed because it is too large
Load Diff
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user