Loading ...
Sorry, an error occurred while loading the content.

Expected ; and saw ...

Expand Messages
  • Rob Richardson
    The error message for a missing semicolon seems confusing to the novice as it highlights the beginning of the subsequent line rather than the end of the
    Message 1 of 1 , Feb 24, 2011
    View Source
    • 0 Attachment
      The error message for a missing semicolon seems confusing to the novice as
      it highlights the beginning of the subsequent line rather than the end of
      the current line.


      Example 1:
      I entered this code into jslint.com:

      /*jslint white: true, onevar: true, undef: true, newcap: true, nomen: true,
      regexp: true, plusplus: true, bitwise: true */
      /*global a: true */
      var a
      a = 2;

      It returns this error: "Problem at line 4 character 1: Expected ';' and
      instead saw 'a'."

      So I changed it to this:

      /*jslint white: true, onevar: true, undef: true, newcap: true, nomen: true,
      regexp: true, plusplus: true, bitwise: true */
      /*global a: true */
      var a
      ;a = 2;

      jslint thought this was just fine.

      Though I grant that this will minify just fine, it is quite confusing.


      Example 2:
      I entered this:

      /*jslint white: true, onevar: true, undef: true, newcap: true, nomen: true,
      regexp: true, plusplus: true, bitwise: true */
      /*global foo: true */
      `var foo = function () {
      ` var a;
      ` return a
      `};

      It returned a very similar error: "Problem at line 6 character 1: Expected
      ';' and instead saw '}'."

      I changed it to this:

      /*jslint white: true, onevar: true, undef: true, newcap: true, nomen: true,
      regexp: true, plusplus: true, bitwise: true */
      /*global foo: true */
      `var foo = function () {
      ` var a;
      ` return a
      `;};

      It replied with errors about spacing, suggesting I should format it like
      this:

      /*jslint white: true, onevar: true, undef: true, newcap: true, nomen: true,
      regexp: true, plusplus: true, bitwise: true */
      `var foo = function () {
      ` var a;
      ` return a
      ` ;
      `};


      Noting the ';' is missing on the subsequent line seems confusing. It seems
      wiser to note that it is missing at the end of the preceding line. In the
      first example, line 3 character 6, and in the second, line 5, character 13.

      Rob
    Your message has been successfully submitted and would be delivered to recipients shortly.