aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-01-07 08:53:29 +0000
committerGitHub <noreply@github.com>2021-01-07 16:53:29 +0800
commit6c419bc083e097337960f1a19d2c352336d75e16 (patch)
tree87febc2499af74b116f8d4b0e5fb76a910f10291
parent25321df959eb7aac7bd144be428a0aea0d29a0b9 (diff)
downloadtracifyjs-6c419bc083e097337960f1a19d2c352336d75e16.tar.gz
tracifyjs-6c419bc083e097337960f1a19d2c352336d75e16.zip
implement `UGLIFY_BUG_REPORT` (#4516)
-rw-r--r--.github/ISSUE_TEMPLATE/bug_report.md9
-rwxr-xr-xbin/uglifyjs2
-rw-r--r--test/mocha/bug-report.js40
-rw-r--r--tools/node.js31
4 files changed, 81 insertions, 1 deletions
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
index e46005a1..19958945 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.md
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -31,6 +31,15 @@ test case will be closed.
<!--
Command-line or API call to UglifyJS without third party tools or libraries.
+
+For users using bundlers or transpilers, you may be able to gather the required
+information through setting the `UGLIFY_BUG_REPORT` environment variable:
+
+ UGLIFY_BUG_REPORT=1 (Linux)
+ set UGLIFY_BUG_REPORT=1 (Windows)
+
+before running your usual build process. The resulting "minified" output should
+contain the necessary details for this report.
-->
**JavaScript output or error produced.**
diff --git a/bin/uglifyjs b/bin/uglifyjs
index ed01f986..c2576ba0 100755
--- a/bin/uglifyjs
+++ b/bin/uglifyjs
@@ -265,7 +265,7 @@ if (paths.length) {
process.stdin.on("data", function(chunk) {
chunks.push(chunk);
}).on("end", function() {
- files = [ chunks.join("") ];
+ files = { STDIN: chunks.join("") };
run();
});
process.stdin.resume();
diff --git a/test/mocha/bug-report.js b/test/mocha/bug-report.js
new file mode 100644
index 00000000..480850df
--- /dev/null
+++ b/test/mocha/bug-report.js
@@ -0,0 +1,40 @@
+var assert = require("assert");
+var exec = require("child_process").exec;
+
+describe("UGLIFY_BUG_REPORT", function() {
+ var env = Object.create(process.env);
+ env.UGLIFY_BUG_REPORT = 1;
+ it("Should generate bug report via API", function(done) {
+ exec('"' + process.argv[0] + '"', { env: env }, function(err, stdout) {
+ if (err) throw err;
+ assert.strictEqual(stdout, [
+ "// UGLIFY_BUG_REPORT",
+ "// <<undefined>>",
+ "",
+ "//-------------------------------------------------------------",
+ "// INPUT CODE",
+ "...---...",
+ "",
+ ].join("\n"));
+ done();
+ }).stdin.end('console.log(require("./").minify("...---...").code);');
+ });
+ it("Should generate bug report via CLI", function(done) {
+ exec('"' + process.argv[0] + '" bin/uglifyjs -mc', { env: env }, function(err, stdout) {
+ if (err) throw err;
+ assert.strictEqual(stdout, [
+ "// UGLIFY_BUG_REPORT",
+ "// {",
+ '// "mangle": {},',
+ '// "compress": {}',
+ "// }",
+ "",
+ "//-------------------------------------------------------------",
+ "// STDIN",
+ "...---...",
+ "",
+ ].join("\n"));
+ done();
+ }).stdin.end("...---...");
+ });
+});
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 = "<<undefined>>";
+ 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) {