1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Stop using the PRODUCTION build-target in the JavaScript code

This *special* build-target is very old, and was introduced with the first pre-processor that only uses comments to enable/disable code.
When the new pre-processor was added `PRODUCTION` effectively became redundant, at least in JavaScript code, since `typeof PDFJSDev === "undefined"` checks now do the same thing.

This patch proposes that we remove `PRODUCTION` from the JavaScript code, since that simplifies the conditions and thus improves readability in many cases.
*Please note:* There's not, nor has there ever been, any gulp-task that set `PRODUCTION = false` during building.
This commit is contained in:
Jonas Jenwald 2023-03-18 12:09:25 +01:00
parent 3e08eee511
commit 804aa896a7
29 changed files with 88 additions and 267 deletions

View file

@ -310,7 +310,7 @@ const PDFViewerApplication = {
params = parseQueryString(hash);
if (
(typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) &&
typeof PDFJSDev === "undefined" &&
params.get("workermodules") === "true"
) {
AppOptions.set("workerSrc", "../src/pdf.worker.js");
@ -377,8 +377,7 @@ const PDFViewerApplication = {
}
// It is not possible to change locale for the (various) extension builds.
if (
(typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || GENERIC")) &&
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
params.has("locale")
) {
AppOptions.set("locale", params.get("locale"));
@ -390,7 +389,7 @@ const PDFViewerApplication = {
*/
async _initializeL10n() {
this.l10n = this.externalServices.createL10n(
typeof PDFJSDev === "undefined" || PDFJSDev.test("!PRODUCTION || GENERIC")
typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")
? { locale: AppOptions.get("locale") }
: null
);
@ -480,8 +479,7 @@ const PDFViewerApplication = {
const pdfScriptingManager = new PDFScriptingManager({
eventBus,
sandboxBundleSrc:
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || GENERIC || CHROME")
typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC || CHROME")
? AppOptions.get("sandboxBundleSrc")
: null,
scriptingFactory: externalServices,
@ -959,7 +957,7 @@ const PDFViewerApplication = {
...args,
};
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
if (typeof PDFJSDev === "undefined") {
params.docBaseUrl ||= document.URL.split("#")[0];
} else if (PDFJSDev.test("MOZCENTRAL || CHROME")) {
params.docBaseUrl ||= this.baseUrl;
@ -2159,7 +2157,7 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
async function loadFakeWorker() {
GlobalWorkerOptions.workerSrc ||= AppOptions.get("workerSrc");
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
if (typeof PDFJSDev === "undefined") {
window.pdfjsWorker = await import("pdfjs/pdf.worker.js");
return;
}
@ -2169,7 +2167,7 @@ async function loadFakeWorker() {
async function loadPDFBug(self) {
const { debuggerScriptPath } = self.appConfig;
const { PDFBug } =
typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")
typeof PDFJSDev === "undefined"
? await import(debuggerScriptPath) // eslint-disable-line no-unsanitized/method
: await __non_webpack_import__(debuggerScriptPath); // eslint-disable-line no-undef

View file

@ -158,7 +158,7 @@ const defaultOptions = {
},
pdfBugEnabled: {
/** @type {boolean} */
value: typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION"),
value: typeof PDFJSDev === "undefined",
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
},
printResolution: {
@ -210,9 +210,7 @@ const defaultOptions = {
cMapUrl: {
/** @type {string} */
value:
typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")
? "../external/bcmaps/"
: "../web/cmaps/",
typeof PDFJSDev === "undefined" ? "../external/bcmaps/" : "../web/cmaps/",
kind: OptionKind.API,
},
disableAutoFetch: {
@ -273,7 +271,7 @@ const defaultOptions = {
standardFontDataUrl: {
/** @type {string} */
value:
typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")
typeof PDFJSDev === "undefined"
? "../external/standard_fonts/"
: "../web/standard_fonts/",
kind: OptionKind.API,
@ -293,7 +291,7 @@ const defaultOptions = {
/** @type {string} */
value:
// eslint-disable-next-line no-nested-ternary
typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")
typeof PDFJSDev === "undefined"
? "../src/worker_loader.js"
: PDFJSDev.test("MOZCENTRAL")
? "resource://pdf.js/build/pdf.worker.js"
@ -301,10 +299,7 @@ const defaultOptions = {
kind: OptionKind.WORKER,
},
};
if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || GENERIC")
) {
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
defaultOptions.defaultUrl = {
/** @type {string} */
value: "compressed.tracemonkey-pldi-09.pdf",
@ -323,7 +318,7 @@ if (
defaultOptions.sandboxBundleSrc = {
/** @type {string} */
value:
typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")
typeof PDFJSDev === "undefined"
? "../build/dev-sandbox/pdf.sandbox.js"
: "../build/pdf.sandbox.js",
kind: OptionKind.VIEWER,

View file

@ -165,10 +165,7 @@ class PDFPageView {
this.renderTask = null;
this.resume = null;
if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || GENERIC")
) {
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
this._isStandalone = !this.renderingQueue?.hasViewer();
}
@ -194,8 +191,7 @@ class PDFPageView {
container?.append(div);
if (
(typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || GENERIC")) &&
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
this._isStandalone
) {
// Ensure that the various layers always get the correct initial size,
@ -548,8 +544,7 @@ class PDFPageView {
this.#setDimensions();
if (
(typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || GENERIC")) &&
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
this._isStandalone
) {
this.div.parentNode?.style.setProperty(
@ -686,8 +681,7 @@ class PDFPageView {
}) {
// Scale target (canvas), its wrapper and page container.
if (
(typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || TESTING")) &&
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
!(target instanceof HTMLCanvasElement)
) {
throw new Error("Expected `target` to be a canvas.");

View file

@ -240,10 +240,7 @@ class PDFViewer {
this.container = options.container;
this.viewer = options.viewer || options.container.firstElementChild;
if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || GENERIC")
) {
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
if (this.container?.tagName !== "DIV" || this.viewer?.tagName !== "DIV") {
throw new Error("Invalid `container` and/or `viewer` option.");
}
@ -274,10 +271,7 @@ class PDFViewer {
options.annotationEditorMode ?? AnnotationEditorType.NONE;
this.imageResourcesPath = options.imageResourcesPath || "";
this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || GENERIC")
) {
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
this.removePageBorders = options.removePageBorders || false;
}
this.useOnlyCssZoom = options.useOnlyCssZoom || false;

View file

@ -22,7 +22,7 @@ import { AppOptions, OptionKind } from "./app_options.js";
*/
class BasePreferences {
#defaults = Object.freeze(
typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")
typeof PDFJSDev === "undefined"
? AppOptions.getAll(OptionKind.PREFERENCE)
: PDFJSDev.eval("DEFAULT_PREFERENCES")
);

View file

@ -64,7 +64,7 @@ function getViewerConfiguration() {
function webViewerLoad() {
const config = getViewerConfiguration();
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
if (typeof PDFJSDev === "undefined") {
window.isGECKOVIEW = true;
}
PDFViewerApplication.run(config);