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

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

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.2.0
    • Affects Version/s: 3.1.13
    • Component/s: Native
    • Labels:

      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!

       

            Assignee:
            katherine.walker@mongodb.com Katherine Walker (Inactive)
            Reporter:
            arichiardi Andrea Richiardi
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: