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

@@ -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) {
if (!header) return "";
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() {
return '({ url: "https://example.com/path/index.html" })';
}).replace(/\bimport\b(?:\s*([^\s('"][^('"]*)\bfrom\b)?\s*(['"]).*?\2(?:$|\n|;)/g, function(match, symbols) {