Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-4036

Suggestion: insert semicolons into recalled JavaScript in the shell

    • Server Tooling & Methods

      I'll say up front that I'm not sure if this is worth doing. But it might be easy, and have some benefit, so maybe.

      If pull request 102 is accepted, we will retrieve multiline JavaScript onto the command line when up-arrow is pressed following a multiline entry. In order to enable command line editing, we will have converted newlines into spaces. This converts the entry into something that we can edit on a single line.

      It can also break legal JavaScript by preventing JavaScript's automatic semicolon insertion from seeing the newlines that the user entered.

      MongoDB shell version: 2.1.0-pre-
      connecting to: test
      > f=function(){
      ... a=1 // automatic JavaScript semicolon insertion
      ... b=2
      ... }
      function () {
          a = 1; // cool, mongo types better than I do, with better spacing and punctuation
          b = 2;
      }
      > f() // life is good
      > f=function(){ a=1 b=2 } // press up-arrow, command is as-typed with newlines converted to spaces
      Fri Oct 07 13:35:51 SyntaxError: missing ; before statement (shell):1 // but it's not legal JavaScript anymore
      

      Note also that the "pretty print" code shows where semicolons would be inserted by this JavaScript feature. If we grabbed the text that this code displays (called the same code) and then converted the newlines into spaces then we could provide command line editing of legal code even if the user typed it in differently. We're already converting newlines into spaces to make this scenario possible, so it's not a big stretch to shove semicolons into the string to keep their legal JavaScript legal.

            Assignee:
            backlog-server-stm Backlog - Server Tooling and Methods (STM) (Inactive)
            Reporter:
            tad Tad Marshall
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: