Repository: mozilla/pdf.js
File: src/core/jpx.js (JavaScript)

Code before:
  }

  static async #instantiateWasm(imports, successCallback) {
    const filename = "openjpeg.wasm";
    try {
      if (!this.#buffer) {
        if (this.#wasmUrl !== null) {
          this.#buffer = await fetchBinaryData(`${this.#wasmUrl}${filename}`);
        } else {
          this.#buffer = await this.#handler.sendWithPromise(
            "FetchBinaryData",
            { type: "wasmFactory", filename }
          );
        }
      }
      const results = await WebAssembly.instantiate(this.#buffer, imports);
      return successCallback(results.instance);
    } catch (reason) {
      warn(`JpxImage#instantiateWasm: ${reason}`);

      if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING")) {
        this.#wasmUrl ??= "/build/generic/web/wasm/";
      }
      const path =
        (typeof PDFJSDev === "undefined" ? "../" : "") +
        `${this.#wasmUrl}openjpeg_nowasm_fallback.js`;

      let instance = null;
      try {
        const mod = await (typeof PDFJSDev === "undefined"
          ? import(path) // eslint-disable-line no-unsanitized/method
          : __non_webpack_import__(path));
        instance = mod.default();
      } catch (e) {
        warn(`JpxImage#instantiateWasm: ${e}`);
      }

      this.#importModuleResolver.resolve(instance);
      return null;
    } finally {
      this.#handler = null;
      this.#wasmUrl = null;
    }
  }

  static async decode(
    bytes,
    { numComponents = 4, isIndexedColormap = false, smaskInData = false } = {}
  ) {
    this.#modulePromise ||= OpenJPEG({
      warn,

Review comment (suggestion):
I don't think the pre-processor is "smart" enough to be able to concatenate strings, so I'd suggest just re-writing this as follows instead.
```suggestion
      const path =
        typeof PDFJSDev === "undefined"
          ? `../${this.#wasmUrl}openjpeg_nowasm_fallback.js`
          : `${this.#wasmUrl}openjpeg_nowasm_fallback.js`;
```

Code after:
    }
  }

  static async #getJsModule(fallbackCallback) {
    if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING")) {
      this.#wasmUrl ??= "/build/generic/web/wasm/";
    }
    const path =
      typeof PDFJSDev === "undefined"
        ? `../${this.#wasmUrl}openjpeg_nowasm_fallback.js`
        : `${this.#wasmUrl}openjpeg_nowasm_fallback.js`;

    let instance = null;
    try {
      const mod = await (typeof PDFJSDev === "undefined"
        ? import(path) // eslint-disable-line no-unsanitized/method
        : __non_webpack_import__(path));
      instance = mod.default();
    } catch (e) {
      warn(`JpxImage#getJsModule: ${e}`);
    }

    this.#hasJSFallback = true;
    fallbackCallback(instance);
  }

  static async #instantiateWasm(fallbackCallback, imports, successCallback) {
    const filename = "openjpeg.wasm";
    try {
      if (!this.#buffer) {
        if (this.#wasmUrl !== null) {
          this.#buffer = await fetchBinaryData(`${this.#wasmUrl}${filename}`);
        } else {
          this.#buffer = await this.#handler.sendWithPromise(
            "FetchBinaryData",
            { type: "wasmFactory", filename }
          );
        }
      }
      const results = await WebAssembly.instantiate(this.#buffer, imports);
      return successCallback(results.instance);
    } catch (reason) {
      warn(`JpxImage#instantiateWasm: ${reason}`);

      this.#getJsModule(fallbackCallback);
      return null;
    } finally {
      this.#handler = null;
    }
  }