Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-1874

Wrong JavaScript const use in lib/operations/db_ops.js

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 3.1.13
    • Fix Version/s: 3.2.0
    • Component/s: native
    • Labels:
      None

      Description

      Hi all!

      We were debugging a compilation error in my team and opened [a github issue][https://github.com/thheller/shadow-cljs/issues/290] against our compiler. We are using ClojureScript but we have actually run against a JavaScript usage error.

       

      The compiler maintainer Thomas Heller pointed out that there could be a problem at this [line][https://github.com/mongodb/node-mongodb-native/blob/v3.1.13/lib/operations/db_ops.js#L91] in lib/operations/db_ops.js.

       

      The problem is that the db var is used in if scope but then declared in the inner scope as const. Order counts as it can be observed in the different comment in the issue. Specifically, this fails:

       

      function f(a) {
        if (true) {
          console.log("1: " + a);
          const a = "b";
        }  console.log("2: " + a);
      }f(5);
      // Uncaught ReferenceError: a is not defined 

       

      I am reporting it but I do not really understand it as I am not a JavaScript expert myself.

       

      Thank you!

       

        Attachments

          Activity

            People

            Assignee:
            katherine.walker Katherine Walker (Inactive)
            Reporter:
            arichiardi Andrea Richiardi [X] (Inactive)
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: