From ea5581b70ae161d384ab4aae7e1d6f0d178d3b76 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 13 Aug 2020 09:49:46 +0200 Subject: [PATCH 1/2] Keep the original class/function names when minifying code (issue 12209) While this will obviously increase the size of the output of `gulp minified`/`gulp minified-es5` *slightly*, the resulting files are still a lot smaller than the non-minified builds. See https://github.com/terser/terser#minify-options for information about various Terser options. --- gulpfile.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index e6739ccd9..a953db9fe 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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(); From b26d736809a49941fe2a9fc7b691365496f20eeb Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 13 Aug 2020 13:17:30 +0200 Subject: [PATCH 2/2] Ensure that the "DocException" message handler, in the API, will always either error or warn (depending on the build) if a valid `Error` isn't found Having this present would have made debugging issues 11941 and 12209 so much quicker and easier. --- src/display/api.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index c94bf977f..ff17ffec8 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -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); });