From 6c419bc083e097337960f1a19d2c352336d75e16 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 7 Jan 2021 08:53:29 +0000 Subject: implement `UGLIFY_BUG_REPORT` (#4516) --- tools/node.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tools/node.js') diff --git a/tools/node.js b/tools/node.js index 1ebc7730..f1fb28ba 100644 --- a/tools/node.js +++ b/tools/node.js @@ -23,6 +23,37 @@ new Function("exports", function() { return code.join("\n\n"); }())(exports); +function to_comment(value) { + if (typeof value != "string") value = JSON.stringify(value, function(key, value) { + return typeof value == "function" ? "<[ " + value + " ]>" : value; + }, 2); + return "// " + value.replace(/\n/g, "\n// "); +} + +if (+process.env["UGLIFY_BUG_REPORT"]) exports.minify = function(files, options) { + if (typeof options == "undefined") options = "<>"; + var code = [ + "// UGLIFY_BUG_REPORT", + to_comment(options), + ]; + if (typeof files == "string") { + code.push(""); + code.push("//-------------------------------------------------------------") + code.push("// INPUT CODE", files); + } else for (var name in files) { + code.push(""); + code.push("//-------------------------------------------------------------") + code.push(to_comment(name), files[name]); + } + if (options.sourceMap && options.sourceMap.url) { + code.push(""); + code.push("//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9"); + } + var result = { code: code.join("\n") }; + if (options.sourceMap) result.map = '{"version":3,"sources":[],"names":[],"mappings":""}'; + return result; +}; + function describe_ast() { var out = OutputStream({ beautify: true }); function doitem(ctor) { -- cgit v1.2.3