We have static initialization blocks that include pre-processor statements which make them conditionally empty, note e.g. how the following source code:
|
static { |
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { |
|
if (isNodeJS) { |
|
// Workers aren't supported in Node.js, force-disabling them there. |
|
this.#isWorkerDisabled = true; |
|
|
|
GlobalWorkerOptions.workerSrc ||= PDFJSDev.test("LIB") |
|
? "../pdf.worker.js" |
|
: "./pdf.worker.mjs"; |
|
} |
|
|
|
// Check if URLs have the same origin. For non-HTTP based URLs, returns |
|
// false. |
|
this._isSameOrigin = (baseUrl, otherUrl) => { |
|
let base; |
|
try { |
|
base = new URL(baseUrl); |
|
if (!base.origin || base.origin === "null") { |
|
return false; // non-HTTP url |
|
} |
|
} catch { |
|
return false; |
|
} |
|
const other = new URL(otherUrl, base); |
|
return base.origin === other.origin; |
|
}; |
|
|
|
this._createCDNWrapper = url => { |
|
// We will rely on blob URL's property to specify origin. |
|
// We want this function to fail in case if createObjectURL or Blob do |
|
// not exist or fail for some reason -- our Worker creation will fail |
|
// anyway. |
|
const wrapper = `await import("${url}");`; |
|
return URL.createObjectURL( |
|
new Blob([wrapper], { type: "text/javascript" }) |
|
); |
|
}; |
|
} |
|
} |
is transformed into (in that case for the MOZCENTRAL build):
https://searchfox.org/mozilla-central/rev/b6671f4c3afdb2b36e63c9d176f98a5959907259/toolkit/components/pdfjs/content/build/pdf.mjs#10434
Hence it seems like a good idea to, if possible, extend the Babel plugin to remove static initialization blocks that become empty during building.
We have static initialization blocks that include pre-processor statements which make them conditionally empty, note e.g. how the following source code:
pdf.js/src/display/api.js
Lines 2016 to 2054 in c60c0d1
is transformed into (in that case for the MOZCENTRAL build):
https://searchfox.org/mozilla-central/rev/b6671f4c3afdb2b36e63c9d176f98a5959907259/toolkit/components/pdfjs/content/build/pdf.mjs#10434
Hence it seems like a good idea to, if possible, extend the Babel plugin to remove static initialization blocks that become empty during building.