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

Fix transform of unary expression in Babel plugin

All of our static evaluation & dead-code elimination transforms need to
happen in post-order, transforming inner nodes first. This is so that
in complex nested cases all transforms see the simplified version of
their inner nodes.

For example:
  async getNimbusExperimentData() {
    if (!PDFJSDev.test("GECKOVIEW")) { return null; }
    // other code
  }
-> [evaluation of PDFJSDev.*]
  async getNimbusExperimentData() {
    if (!false) { return null; }
    // other code
  }
-> [!false -> true]
  async getNimbusExperimentData() {
    if (true) { return null; }
    // other code
  }
-> [if (true) -> replace with the if branch]
  async getNimbusExperimentData() {
    return null;
    // other code
  }
-> [early return -> remove dead code]
  async getNimbusExperimentData() {
    return null;
    // other code
  }

This was done correctly in all cases except for our `UnaryExpression`
transform, which was happening in pre-order.
This commit is contained in:
Nicolò Ribaudo 2024-01-29 11:13:48 +01:00
parent 802f702695
commit a352f28785
No known key found for this signature in database
GPG key ID: AAFDA9101C58F338
4 changed files with 21 additions and 12 deletions

View file

@ -400,7 +400,7 @@ class ExternalServices extends BaseExternalServices {
}
async getNimbusExperimentData() {
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("GECKOVIEW")) {
if (!PDFJSDev.test("GECKOVIEW")) {
return null;
}
const nimbusData = await FirefoxCom.requestAsync(