Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep the original class/function names when minifying code (issue 12209) #12210

Merged
merged 2 commits into from
Aug 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -909,18 +909,30 @@ function parseMinified(dir) {
console.log("### Minifying js files");

var Terser = require("terser");
// V8 chokes on very long sequences. Works around that.
var optsForHugeFile = { compress: { sequences: false } };
var options = {
compress: {
// V8 chokes on very long sequences, work around that.
sequences: false,
},
keep_classnames: true,
keep_fnames: true,
};

fs.writeFileSync(dir + "/web/pdf.viewer.js", Terser.minify(viewerFiles).code);
fs.writeFileSync(dir + "/build/pdf.min.js", Terser.minify(pdfFile).code);
fs.writeFileSync(
dir + "/web/pdf.viewer.js",
Terser.minify(viewerFiles, options).code
);
fs.writeFileSync(
dir + "/build/pdf.min.js",
Terser.minify(pdfFile, options).code
);
fs.writeFileSync(
dir + "/build/pdf.worker.min.js",
Terser.minify(pdfWorkerFile, optsForHugeFile).code
Terser.minify(pdfWorkerFile, options).code
);
fs.writeFileSync(
dir + "image_decoders/pdf.image_decoders.min.js",
Terser.minify(pdfImageDecodersFile).code
Terser.minify(pdfImageDecodersFile, options).code
);

console.log();
Expand Down
15 changes: 10 additions & 5 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2271,11 +2271,16 @@ class WorkerTransport {
reason = new UnknownErrorException(ex.message, ex.details);
break;
}
if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || TESTING")
) {
assert(reason instanceof Error, "DocException: expected an Error.");
if (!(reason instanceof Error)) {
const msg = "DocException - expected a valid Error.";
if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || TESTING")
) {
unreachable(msg);
} else {
warn(msg);
}
}
loadingTask._capability.reject(reason);
});
Expand Down