the optional chaining operator does not work as expected

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: AsyncRewriter
    • Environment:
      OS:
      node.js / npm versions:
      Additional info:
    • 2
    • None
    • Developer Tools

      Problem Statement/Rationale

      What is going wrong? What action would you like the Engineering team to take?

      const x = 1;
      x?.toString()
      

      Fails with an error, while it should work.

      Please be sure to attach relevant logs with any sensitive data redacted.
      How to retrieve logs for: Compass; Shell

      Steps to Reproduce

      How could an engineer replicate the issue you’re reporting?

      Run the following script in a running mongosh:

      const x = 1;
      x?.toString()
      

      Expected Results

      What do you expect to happen?

      Actual Results

      What do you observe is happening?

      Additional Notes

      Any additional information that may be useful to include.

      According to our investigation, it's likely an issue in the async rewriter, that doesn't handle the optional chaining operator:

      https://github.com/mongodb-js/mongosh/blob/8395a1893b5f44da4bd7d36d7012a11f0533be8a/packages/async-rewriter2/src/stages/transform-maybe-await.ts#L584-L603

      We would need to add support for OptionalMemberExpression and OptionalCallExpression

              Assignee:
              Kræn Hansen
              Reporter:
              Kevin Mas Ruiz
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated: