support limited ufuzz testing for export (#4693)

fixes #4692
This commit is contained in:
Alex Lam S.L
2021-02-26 20:56:34 +00:00
committed by GitHub
parent ac26993b5a
commit ba4a771bbc
7 changed files with 166 additions and 47 deletions

View File

@@ -49,6 +49,14 @@ exports.same_stdout = semver.satisfies(process.version, "0.12") ? function(expec
} : function(expected, actual) {
return typeof expected == typeof actual && strip_func_ids(expected) == strip_func_ids(actual);
};
exports.strip_exports = function(code) {
var count = 0;
return code.replace(/\bexport(?:\s*\{[^}]*};|\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 "~" + header;
return header.slice(0, -1) + " _" + ++count + header.slice(-1);
});
};
function is_error(result) {
return result && typeof result.name == "string" && typeof result.message == "string";